source: src/main/java/com/example/skychasemk/controller/ReviewController.java@ c064a42

Last change on this file since c064a42 was a70b5a4, checked in by ste08 <sjovanoska@…>, 4 months ago

Report added

  • Property mode set to 100644
File size: 1.7 KB
Line 
1package com.example.skychasemk.controller;
2
3import com.example.skychasemk.dto.ReviewDTO;
4import com.example.skychasemk.model.Review;
5import com.example.skychasemk.repository.ReviewRepository;
6import com.example.skychasemk.services.ReviewService;
7import org.springframework.beans.factory.annotation.Autowired;
8import org.springframework.http.ResponseEntity;
9import org.springframework.web.bind.annotation.*;
10
11import java.util.List;
12import java.util.Optional;
13
14@RestController
15@RequestMapping("/api/reviews")
16public class ReviewController {
17
18 @Autowired
19 private ReviewService reviewService;
20 @Autowired
21 private ReviewRepository reviewRepository;
22
23 // Get all reviews
24 @GetMapping
25 public List<Review> getAllReviews() {
26 return reviewService.getAllReviews();
27 }
28
29
30 @GetMapping("/{flightId}")
31 public List<Review> getReviewsByFlightId(@PathVariable("flightId") Integer flightId) {
32 return reviewRepository.findReviews(flightId);
33 }
34
35 // Get review by ID
36 @GetMapping("/{id}")
37 public Optional<Review> getReviewById(@PathVariable("id") Integer reviewID) {
38 return reviewService.getReviewById(reviewID);
39 }
40
41 @PostMapping
42 public ResponseEntity<Review> submitReview(@RequestBody ReviewDTO dto) {
43 Review savedReview = reviewService.submitReview(dto);
44 return ResponseEntity.ok(savedReview);
45 }
46
47 // Update an existing review
48 @PutMapping("/{id}")
49 public Review updateReview(@PathVariable("id") Integer reviewID, @RequestBody Review review) {
50 return reviewService.updateReview(reviewID, review);
51 }
52
53 // Delete a review
54 @DeleteMapping("/{id}")
55 public void deleteReview(@PathVariable("id") Integer reviewID) {
56 reviewService.deleteReview(reviewID);
57 }
58}
Note: See TracBrowser for help on using the repository browser.