Skip to content

Commit 8311b0b

Browse files
committed
feat: add getUserProperties by JWT
1 parent fbf4208 commit 8311b0b

4 files changed

Lines changed: 24 additions & 0 deletions

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/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/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/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) {

0 commit comments

Comments
 (0)