Created
August 17, 2023 21:31
-
-
Save davidcsejtei/a10080c803681cff3ae2898f0ff0f4ed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.holnor.moviedatabase.controller; | |
import com.holnor.moviedatabase.dto.CreateMovieCommand; | |
import com.holnor.moviedatabase.dto.MovieDetailsItem; | |
import com.holnor.moviedatabase.dto.MovieListItem; | |
import com.holnor.moviedatabase.service.MovieService; | |
import jakarta.validation.Valid; | |
import org.springframework.dao.DataIntegrityViolationException; | |
import org.springframework.http.HttpStatus; | |
import org.springframework.http.ResponseEntity; | |
import org.springframework.web.bind.annotation.*; | |
import java.util.List; | |
@RestController | |
@RequestMapping("/api/movies") | |
public class MovieController { | |
private MovieService movieService; | |
public MovieController(MovieService movieService) { | |
this.movieService = movieService; | |
} | |
... | |
@PostMapping | |
public ResponseEntity createMovie(@RequestBody @Valid CreateMovieCommand createMovieCommand) { | |
try { | |
movieService.createMovie(createMovieCommand); | |
} catch (DataIntegrityViolationException de) { | |
return new ResponseEntity(de.getLocalizedMessage(), HttpStatus.BAD_REQUEST); | |
} | |
return new ResponseEntity(HttpStatus.CREATED); | |
} | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.holnor.moviedatabase.domain; | |
import jakarta.persistence.*; | |
@Entity | |
@Table(name = "movie") | |
public class Movie { | |
@Id | |
@GeneratedValue(strategy = GenerationType.IDENTITY) | |
@Column(name = "movie_id") | |
private Long id; | |
@Column(name = "title", unique = true) | |
private String title; | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment