Skip to content

Commit

Permalink
cover methode getMovieById in controller
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabi911 committed Aug 19, 2024
1 parent 46c0777 commit 08d06cf
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
import lombok.RequiredArgsConstructor;


import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;


import java.util.List;
import java.util.Optional;

@RestController
@RequestMapping("/api/movies")
Expand All @@ -25,12 +27,15 @@ public List<Movie> getMovies() {


@GetMapping("{id}")
public Movie getMovieById(@PathVariable String id) {
return movieService.getMovieById(id);
public ResponseEntity<Movie> getMovieById(@PathVariable String id) {
Optional<Movie> movieOptional = Optional.ofNullable(movieService.getMovieById(id));
return movieOptional.map(ResponseEntity::ok)
.orElseGet(() -> ResponseEntity.notFound().build());

}

@PostMapping()
public Movie postMovie (@RequestBody MovieDto userEntries) {
public Movie postMovie(@RequestBody MovieDto userEntries) {
return movieService.addMovie(userEntries);

}
Expand Down

0 comments on commit 08d06cf

Please sign in to comment.