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