|
1 | 1 | package travelplanner.controller; |
2 | 2 |
|
3 | 3 | import jakarta.validation.Valid; |
| 4 | +import java.util.List; |
4 | 5 | import java.util.UUID; |
5 | 6 | import lombok.RequiredArgsConstructor; |
6 | 7 | import org.springframework.data.domain.Page; |
7 | 8 | import org.springframework.data.domain.Pageable; |
8 | 9 | import org.springframework.data.web.PageableDefault; |
9 | 10 | import org.springframework.http.HttpStatus; |
| 11 | +import org.springframework.http.MediaType; |
10 | 12 | import org.springframework.http.ResponseEntity; |
11 | 13 | import org.springframework.security.core.annotation.AuthenticationPrincipal; |
12 | 14 | import org.springframework.web.bind.annotation.DeleteMapping; |
|
18 | 20 | import org.springframework.web.bind.annotation.RequestMapping; |
19 | 21 | import org.springframework.web.bind.annotation.RequestParam; |
20 | 22 | import org.springframework.web.bind.annotation.RestController; |
| 23 | +import org.springframework.web.multipart.MultipartFile; |
| 24 | +import travelplanner.dto.trip.PhotoResponse; |
21 | 25 | import travelplanner.dto.trip.TripCreateRequest; |
22 | 26 | import travelplanner.dto.trip.TripResponse; |
23 | 27 | import travelplanner.entity.User; |
@@ -70,6 +74,32 @@ public ResponseEntity<Void> deleteTrip(@PathVariable UUID tripId) { |
70 | 74 | return ResponseEntity.noContent().build(); |
71 | 75 | } |
72 | 76 |
|
| 77 | + @PostMapping(value = "/{tripId}/cover", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) |
| 78 | + public ResponseEntity<TripResponse> updateTripCover( |
| 79 | + @PathVariable UUID tripId, |
| 80 | + @RequestParam("file") MultipartFile file, |
| 81 | + @AuthenticationPrincipal User currentUser |
| 82 | + ) { |
| 83 | + TripResponse response = tripService.updateTripCover(tripId, file, currentUser); |
| 84 | + return ResponseEntity.ok(response); |
| 85 | + } |
| 86 | + |
| 87 | + @PostMapping(value = "/{tripId}/photos", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) |
| 88 | + public ResponseEntity<PhotoResponse> uploadTripPhoto( |
| 89 | + @PathVariable UUID tripId, |
| 90 | + @RequestParam("file") MultipartFile file, |
| 91 | + @AuthenticationPrincipal User currentUser |
| 92 | + ) { |
| 93 | + PhotoResponse response = tripService.uploadTripPhoto(tripId, file, currentUser); |
| 94 | + return ResponseEntity.ok(response); |
| 95 | + } |
| 96 | + |
| 97 | + @GetMapping("/{tripId}/photos") |
| 98 | + public ResponseEntity<List<PhotoResponse>> getTripPhotos(@PathVariable UUID tripId) { |
| 99 | + List<PhotoResponse> response = tripService.getTripPhotos(tripId); |
| 100 | + return ResponseEntity.ok(response); |
| 101 | + } |
| 102 | + |
73 | 103 | @ExceptionHandler(EntityNotFoundException.class) |
74 | 104 | public ResponseEntity<String> handleNotFound(EntityNotFoundException ex) { |
75 | 105 | return ResponseEntity.status(HttpStatus.NOT_FOUND).body(ex.getMessage()); |
|
0 commit comments