Skip to content

Commit

Permalink
Get all reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoxtygen committed Mar 26, 2023
1 parent 62fcf39 commit 284b5f5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/main/java/com/codeplanks/movies/ReviewController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,27 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/v1/reviews")
class ReviewController {
public class ReviewController {
@Autowired
private ReviewService reviewService;

@GetMapping
public ResponseEntity<List<Review>> getAllReviews() {
return new ResponseEntity<List<Review>>(reviewService.allReviews(), HttpStatus.OK);
}

@PostMapping
public ResponseEntity<Review> createReview(@RequestBody Map<String, String> payload) {
return new ResponseEntity<Review>(reviewService.createReview(payload.get("reviewBody"),
payload.get("imdbId")), HttpStatus.CREATED);
}


}
6 changes: 6 additions & 0 deletions src/main/java/com/codeplanks/movies/ReviewService.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class ReviewService {
Expand All @@ -26,4 +27,9 @@ public Review createReview(String reviewBody, String imdbId) {
.first();
return review;
}

public List<Review> allReviews() {
return reviewRepository.findAll();
}

}

0 comments on commit 284b5f5

Please sign in to comment.