Skip to content

Commit f51db80

Browse files
authored
Merge pull request #40 from TP-RENTPLACE/feature/add-user-reservations-and-properties
Feature/add user reservations and properties
2 parents fbf4208 + 8d1bc4d commit f51db80

8 files changed

Lines changed: 51 additions & 1 deletion

File tree

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,21 @@ public ResponseEntity<List<PropertyDTO>> getProperties() {
7676
return ResponseEntity.ok(properties);
7777
}
7878

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

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/PropertyRepository.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,6 @@ public interface PropertyRepository extends JpaRepository<Property, Long> {
1818
""")
1919
List<Property> findAllWithRelations();
2020

21+
List<Property> findAllByOwnerEmail(String email);
22+
2123
}

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/PropertyService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ public interface PropertyService {
1616

1717
List<PropertyDTO> findAll();
1818

19+
List<PropertyDTO> findAllByOwnerEmail(String email);
20+
1921
PropertyDTO findById(long id);
2022

2123
Property getPropertyById(long id);

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/PropertyServiceImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ public List<PropertyDTO> findAll() {
6464
return propertyMapper.fromProperties(propertyRepository.findAllWithRelations());
6565
}
6666

67+
@Override
68+
public List<PropertyDTO> findAllByOwnerEmail(String email) {
69+
return propertyMapper.fromProperties(propertyRepository.findAllByOwnerEmail(email));
70+
}
71+
6772
@Override
6873
@Transactional
6974
public Property getPropertyById(long id) {

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)