Skip to content

Commit 8d1bc4d

Browse files
committed
feat: add getUserReservations by JWT
1 parent 8311b0b commit 8d1bc4d

4 files changed

Lines changed: 27 additions & 1 deletion

File tree

rentplace/src/main/java/kattsyn/dev/rentplace/controllers/ReservationController.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,21 @@ public ResponseEntity<List<ReservationDTO>> getReservations() {
4444
return ResponseEntity.ok(reservationDTOS);
4545
}
4646

47+
@Operation(
48+
summary = "Получение всех бронирований пользователя",
49+
description = "Позволяет получить все бронирования пользователя"
50+
)
51+
@ApiResponses(value = {
52+
@ApiResponse(responseCode = "200", description = "Успешно", content = @Content(mediaType = "application/json", schema = @Schema(implementation = ReservationDTO[].class))),
53+
@ApiResponse(responseCode = "500", description = "Непредвиденная ошибка со стороны сервера", content = @Content)
54+
})
55+
@GetMapping("/my")
56+
@SecurityRequirement(name = "JWT")
57+
public ResponseEntity<List<ReservationDTO>> getUserReservations(Authentication authentication) {
58+
List<ReservationDTO> reservationDTOS = reservationService.findAllReservationsByRenterEmail(authentication.getName());
59+
return ResponseEntity.ok(reservationDTOS);
60+
}
61+
4762
@Operation(
4863
summary = "Получение бронирования",
4964
description = "Получение бронирования по id")
@@ -78,7 +93,6 @@ public ResponseEntity<ReservationDTO> getReservation(@PathVariable
7893
})
7994
@PreAuthorize("hasAuthority('ROLE_ADMIN') or hasAuthority('ROLE_USER')" )
8095
@SecurityRequirement(name = "JWT")
81-
@SecurityRequirement(name = "JWT")
8296
@PostMapping(path = "/", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
8397
public ResponseEntity<ReservationDTO> createReservation(@Valid @ModelAttribute ReservationCreateEditDTO reservationCreateEditDTO,
8498
Authentication authentication) {

rentplace/src/main/java/kattsyn/dev/rentplace/repositories/ReservationRepository.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,10 @@
33
import kattsyn.dev.rentplace.entities.Reservation;
44
import org.springframework.data.jpa.repository.JpaRepository;
55

6+
import java.util.List;
7+
68
public interface ReservationRepository extends JpaRepository<Reservation, Long> {
9+
10+
List<Reservation> findAllByRenterEmail(String email);
11+
712
}

rentplace/src/main/java/kattsyn/dev/rentplace/services/ReservationService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,6 @@ public interface ReservationService {
2626

2727
List<ReservationDTO> findAllReservations();
2828

29+
List<ReservationDTO> findAllReservationsByRenterEmail(String email);
30+
2931
}

rentplace/src/main/java/kattsyn/dev/rentplace/services/impl/ReservationServiceImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ public List<ReservationDTO> findAllReservations() {
5959
return reservationMapper.fromReservations(reservationRepository.findAll());
6060
}
6161

62+
@Override
63+
public List<ReservationDTO> findAllReservationsByRenterEmail(String email) {
64+
return reservationMapper.fromReservations(reservationRepository.findAllByRenterEmail(email));
65+
}
66+
6267
@Override
6368
public Reservation getReservationById(long reservationId) {
6469
return reservationRepository.findById(reservationId).orElseThrow(

0 commit comments

Comments
 (0)