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