Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public class ReservationController {
@ApiResponse(responseCode = "200", description = "Успешно", content = @Content(mediaType = "application/json", schema = @Schema(implementation = ReservationDTO[].class))),
@ApiResponse(responseCode = "500", description = "Непредвиденная ошибка со стороны сервера", content = @Content)
})
@PreAuthorize("hasAuthority('ROLE_ADMIN')" )
@SecurityRequirement(name = "JWT")
@GetMapping("/")
public ResponseEntity<List<ReservationDTO>> getReservations() {
List<ReservationDTO> reservationDTOS = reservationService.findAllReservations();
Expand Down Expand Up @@ -72,7 +74,7 @@ public ResponseEntity<List<ReservationDTO>> getUserReservations(Authentication a
@ApiResponse(responseCode = "422", description = "Ошибка валидации", content = @Content),
@ApiResponse(responseCode = "500", description = "Непредвиденная ошибка со стороны сервера", content = @Content)
})
@PreAuthorize("hasAuthority('ROLE_ADMIN') or hasAuthority('ROLE_USER')" )
@PreAuthorize("hasAuthority('ROLE_ADMIN')")
@SecurityRequirement(name = "JWT")
@GetMapping("/{id}")
public ResponseEntity<ReservationDTO> getReservation(@PathVariable
Expand Down Expand Up @@ -114,7 +116,6 @@ public ResponseEntity<ReservationDTO> createReservation(@Valid @ModelAttribute R
})
@PreAuthorize("hasAuthority('ROLE_ADMIN') or hasAuthority('ROLE_USER')" )
@SecurityRequirement(name = "JWT")
@SecurityRequirement(name = "JWT")
@PatchMapping(path = "/{id}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseEntity<ReservationDTO> updateReservation(@PathVariable @Parameter(description = "id бронирования для изменения") long id,
@Valid @ModelAttribute ReservationCreateEditDTO reservationCreateEditDTO) {
Expand All @@ -133,7 +134,6 @@ public ResponseEntity<ReservationDTO> updateReservation(@PathVariable @Parameter
})
@PreAuthorize("hasAuthority('ROLE_ADMIN') or hasAuthority('ROLE_USER')" )
@SecurityRequirement(name = "JWT")
@SecurityRequirement(name = "JWT")
public ResponseEntity<ReservationDTO> deleteReservation(
@PathVariable
@Valid @Parameter(description = "id бронирования", example = "1") long id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public ResponseEntity<UserDTO> updateUser(

@Operation(
summary = "Удалить пользователя",
description = "Удалить пользователя по ID"
description = "Удалить пользователя по ID. Использовать в крайних случаях. При удалении удаляются все его брони и объявления."
)
@DeleteMapping("/{id}")
@ApiResponses(value = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class Reservation {
@JoinColumn(name = "property_id")
private Property property;

@ManyToOne
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
@JoinColumn(name = "renter_id")
private User renter;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,9 @@ public class User {
inverseJoinColumns = @JoinColumn(name = "property_id"))
private Set<Property> favourites = new HashSet<>();

@OneToMany(mappedBy = "renter", cascade = CascadeType.ALL, orphanRemoval = true)
private Set<Reservation> reservations = new HashSet<>();

@OneToMany(mappedBy = "owner", cascade = CascadeType.ALL, orphanRemoval = true)
private Set<Property> properties = new HashSet<>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ public ReservationDTO getReservationDTOById(long reservationId) {
@Transactional
public ReservationDTO createReservation(ReservationCreateEditDTO reservationCreateEditDTO) {
Reservation reservation = reservationMapper.fromReservationCreateEditDTO(reservationCreateEditDTO);

if (reservation.getRenter().getUserId() == reservation.getProperty().getOwner().getUserId()) {
throw new ValidationException(String.format("Owner id: %s can't rent his own property id: %s",
reservationCreateEditDTO.getRenterId(), reservationCreateEditDTO.getPropertyId()));
}

setPrices(reservation);
reservation.setPaymentStatus(PaymentStatus.NOT_PAID);

Expand Down
Loading