Merge pull request #30 from SlimusMinus/add-post_by_id

added find post by id on map
This commit is contained in:
SlimusMinus
2026-08-28 00:21:29 +03:00
committed by GitHub
2 changed files with 17 additions and 0 deletions

View File

@@ -84,4 +84,10 @@ public class PostController {
return service.getCities(); 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);
}
} }

View File

@@ -381,4 +381,15 @@ public class PostService {
throw new ApiException(ErrorCode.VALIDATION_ERROR, "Некорректный формат existingImages", HttpStatus.BAD_REQUEST); 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<Long> postIds = List.of(postId);
Map<Long, Long> likeCounts = countLikes(postIds);
Set<Long> userFavoriteIds = currentUserFavoriteIds(postIds);
return toResponse(post, likeCounts, userFavoriteIds, true);
}
} }