1 | package com.example.skychasemk.controller;
|
---|
2 |
|
---|
3 | import com.example.skychasemk.dto.ReviewDTO;
|
---|
4 | import com.example.skychasemk.model.Review;
|
---|
5 | import com.example.skychasemk.services.ReviewService;
|
---|
6 | import org.springframework.beans.factory.annotation.Autowired;
|
---|
7 | import org.springframework.http.ResponseEntity;
|
---|
8 | import org.springframework.web.bind.annotation.*;
|
---|
9 |
|
---|
10 | import java.util.List;
|
---|
11 | import java.util.Optional;
|
---|
12 |
|
---|
13 | @RestController
|
---|
14 | @RequestMapping("/api/reviews")
|
---|
15 | public class ReviewController {
|
---|
16 |
|
---|
17 | @Autowired
|
---|
18 | private ReviewService reviewService;
|
---|
19 |
|
---|
20 | // Get all reviews
|
---|
21 | @GetMapping
|
---|
22 | public List<Review> getAllReviews() {
|
---|
23 | return reviewService.getAllReviews();
|
---|
24 | }
|
---|
25 |
|
---|
26 | // Get review by ID
|
---|
27 | @GetMapping("/{id}")
|
---|
28 | public Optional<Review> getReviewById(@PathVariable("id") Integer reviewID) {
|
---|
29 | return reviewService.getReviewById(reviewID);
|
---|
30 | }
|
---|
31 |
|
---|
32 | @PostMapping
|
---|
33 | public ResponseEntity<Review> submitReview(@RequestBody ReviewDTO dto) {
|
---|
34 | Review savedReview = reviewService.submitReview(dto);
|
---|
35 | return ResponseEntity.ok(savedReview);
|
---|
36 | }
|
---|
37 |
|
---|
38 | // Update an existing review
|
---|
39 | @PutMapping("/{id}")
|
---|
40 | public Review updateReview(@PathVariable("id") Integer reviewID, @RequestBody Review review) {
|
---|
41 | return reviewService.updateReview(reviewID, review);
|
---|
42 | }
|
---|
43 |
|
---|
44 | // Delete a review
|
---|
45 | @DeleteMapping("/{id}")
|
---|
46 | public void deleteReview(@PathVariable("id") Integer reviewID) {
|
---|
47 | reviewService.deleteReview(reviewID);
|
---|
48 | }
|
---|
49 | }
|
---|