diff --git a/src/main/java/com/krylov/refound/controller/PostController.java b/src/main/java/com/krylov/refound/controller/PostController.java index 7ec182d..ca46c9c 100644 --- a/src/main/java/com/krylov/refound/controller/PostController.java +++ b/src/main/java/com/krylov/refound/controller/PostController.java @@ -84,4 +84,10 @@ public class PostController { return service.getCities(); } + @GetMapping("/detail/{postId}") + public PostResponse getPostOnMapById(@PathVariable Long postId) { + log.info("get post on map by id {}", postId); + return service.getPostOnMapById(postId); + } + } diff --git a/src/main/java/com/krylov/refound/service/PostService.java b/src/main/java/com/krylov/refound/service/PostService.java index 502130b..7232ddc 100644 --- a/src/main/java/com/krylov/refound/service/PostService.java +++ b/src/main/java/com/krylov/refound/service/PostService.java @@ -381,4 +381,15 @@ public class PostService { throw new ApiException(ErrorCode.VALIDATION_ERROR, "Некорректный формат existingImages", HttpStatus.BAD_REQUEST); } } + + public PostResponse getPostOnMapById(Long postId) { + Post post = postRepository.findById(postId) + .orElseThrow(() -> new ApiException(ErrorCode.NOT_FOUND, "Post not found", HttpStatus.NOT_FOUND)); + + List postIds = List.of(postId); + Map likeCounts = countLikes(postIds); + Set userFavoriteIds = currentUserFavoriteIds(postIds); + + return toResponse(post, likeCounts, userFavoriteIds, true); + } } \ No newline at end of file