modify ratings controller (#1536)
* upgrade to spring boot 1.5.2 * add full update to REST API * modify ratings controller
This commit is contained in:
parent
ec089be605
commit
e28dfe6a4a
|
@ -2,6 +2,7 @@ package com.baeldung.spring.cloud.bootstrap.svcrating.rating;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
|
@ -23,11 +24,9 @@ public class RatingController {
|
||||||
private RatingService ratingService;
|
private RatingService ratingService;
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
public List<Rating> findRatingsByBookId(@RequestParam(required = false, defaultValue = "0") Long bookId) {
|
public List<Rating> findRatingsByBookId(@RequestParam(required = false) Optional<Long> bookId) {
|
||||||
if (bookId.equals(0L)) {
|
return bookId.map(ratingService::findRatingsByBookId)
|
||||||
return ratingService.findAllRatings();
|
.orElseGet(ratingService::findAllRatings);
|
||||||
}
|
|
||||||
return ratingService.findRatingsByBookId(bookId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping
|
@PostMapping
|
||||||
|
|
Loading…
Reference in New Issue