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 @@ -76,6 +76,21 @@ public ResponseEntity<List<PropertyDTO>> getProperties() {
return ResponseEntity.ok(properties);
}

@Operation(
summary = "Получение объявлений пользователя",
description = "Позволяет получить все объявления пользователя по его токену. Только для авторизованных пользователей."
)
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Успешно", content = @Content(mediaType = "application/json", schema = @Schema(implementation = PropertyDTO[].class))),
@ApiResponse(responseCode = "500", description = "Непредвиденная ошибка со стороны сервера", content = @Content)
})
@SecurityRequirement(name = "JWT")
@GetMapping("/my")
public ResponseEntity<List<PropertyDTO>> getUserProperties(Authentication authentication) {
List<PropertyDTO> properties = propertyService.findAllByOwnerEmail(authentication.getName());
return ResponseEntity.ok(properties);
}

@Operation(
summary = "Получить объявление",
description = "Получить объявление по id"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@ public ResponseEntity<List<ReservationDTO>> getReservations() {
return ResponseEntity.ok(reservationDTOS);
}

@Operation(
summary = "Получение всех бронирований пользователя",
description = "Позволяет получить все бронирования пользователя"
)
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Успешно", content = @Content(mediaType = "application/json", schema = @Schema(implementation = ReservationDTO[].class))),
@ApiResponse(responseCode = "500", description = "Непредвиденная ошибка со стороны сервера", content = @Content)
})
@GetMapping("/my")
@SecurityRequirement(name = "JWT")
public ResponseEntity<List<ReservationDTO>> getUserReservations(Authentication authentication) {
List<ReservationDTO> reservationDTOS = reservationService.findAllReservationsByRenterEmail(authentication.getName());
return ResponseEntity.ok(reservationDTOS);
}

@Operation(
summary = "Получение бронирования",
description = "Получение бронирования по id")
Expand Down Expand Up @@ -78,7 +93,6 @@ public ResponseEntity<ReservationDTO> getReservation(@PathVariable
})
@PreAuthorize("hasAuthority('ROLE_ADMIN') or hasAuthority('ROLE_USER')" )
@SecurityRequirement(name = "JWT")
@SecurityRequirement(name = "JWT")
@PostMapping(path = "/", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseEntity<ReservationDTO> createReservation(@Valid @ModelAttribute ReservationCreateEditDTO reservationCreateEditDTO,
Authentication authentication) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ public interface PropertyRepository extends JpaRepository<Property, Long> {
""")
List<Property> findAllWithRelations();

List<Property> findAllByOwnerEmail(String email);

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,10 @@
import kattsyn.dev.rentplace.entities.Reservation;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface ReservationRepository extends JpaRepository<Reservation, Long> {

List<Reservation> findAllByRenterEmail(String email);

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public interface PropertyService {

List<PropertyDTO> findAll();

List<PropertyDTO> findAllByOwnerEmail(String email);

PropertyDTO findById(long id);

Property getPropertyById(long id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ public interface ReservationService {

List<ReservationDTO> findAllReservations();

List<ReservationDTO> findAllReservationsByRenterEmail(String email);

}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ public List<PropertyDTO> findAll() {
return propertyMapper.fromProperties(propertyRepository.findAllWithRelations());
}

@Override
public List<PropertyDTO> findAllByOwnerEmail(String email) {
return propertyMapper.fromProperties(propertyRepository.findAllByOwnerEmail(email));
}

@Override
@Transactional
public Property getPropertyById(long id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ public List<ReservationDTO> findAllReservations() {
return reservationMapper.fromReservations(reservationRepository.findAll());
}

@Override
public List<ReservationDTO> findAllReservationsByRenterEmail(String email) {
return reservationMapper.fromReservations(reservationRepository.findAllByRenterEmail(email));
}

@Override
public Reservation getReservationById(long reservationId) {
return reservationRepository.findById(reservationId).orElseThrow(
Expand Down
Loading