Merge pull request #30 from SlimusMinus/add-post_by_id
added find post by id on map
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<Long> postIds = List.of(postId);
|
||||
Map<Long, Long> likeCounts = countLikes(postIds);
|
||||
Set<Long> userFavoriteIds = currentUserFavoriteIds(postIds);
|
||||
|
||||
return toResponse(post, likeCounts, userFavoriteIds, true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user