Skip to content

Commit

Permalink
Hotfix: 신체 아이디를 받으면 그것과 관련된 증상을 가진 게시글 리스트를 보낼 수 있도록 수정
Browse files Browse the repository at this point in the history
Hotfix: 신체 아이디를 받으면 그것과 관련된 증상을 가진 게시글 리스트를 보낼 수 있도록 수정
  • Loading branch information
sansan20535 authored Jan 25, 2025
2 parents 8181bde + 738376d commit be15a77
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public ResponseEntity<BaseResponse<PostListResponse>> getPosts(
return SuccessResponse.success(SuccessMessage.OK, postService.getPosts(PrincipalHandler.getMemberIdFromPrincipal(), postListRequest.keyword(),
postListRequest.animalIds(), postListRequest.symptomIds(), postListRequest.diseaseIds(),
postListRequest.sortBy(), postListRequest.cursorId(), postListRequest.categoryId(),
postListRequest.likeCount(), postListRequest.createdAt()));
postListRequest.likeCount(), postListRequest.createdAt(), postListRequest.bodyId()));
}

@GetMapping("/members")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public record PostListRequest(
@Schema(description = "마지막 게시글 좋아요 수 아이디", example = "1 or null")
Long likeCount,
@Schema(description = "마지막 게시글 생성일", example = "YYYY-MM-DD~ or null")
LocalDateTime createdAt
LocalDateTime createdAt,
@Schema(description = "신체 아이디", example = "1")
Long bodyId
) {
}
12 changes: 11 additions & 1 deletion src/main/java/com/cocos/cocos/api/post/service/PostService.java
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ private List<Post> fetchPopularPosts(final Long memberId) {
@Transactional(readOnly = true)
public PostListResponse getPosts(final Long memberId, final String keyword, final List<Long> animalIds, final List<Long> symptomIds,
final List<Long> diseaseIds, final SortCriteria sortBy, final Long cursorId,
final Long categoryId, final Long likeCount, final LocalDateTime createAt) {
final Long categoryId, final Long likeCount, final LocalDateTime createAt, final Long bodyId) {
Specification<Post> spec = (root, query, criteriaBuilder) -> null;
if (keyword != null) {
spec = spec.and(PostSpecification.hasKeyword(keyword));
Expand Down Expand Up @@ -291,6 +291,16 @@ public PostListResponse getPosts(final Long memberId, final String keyword, fina
if (categoryId != null) {
spec = spec.and(PostSpecification.equalCategory(categoryId));
}
if (bodyId != null) {
final List<Long> symptomIdsByBodyId = symptomRepository.findAllByBodyId(bodyId).stream()
.map(Symptom::getId)
.toList();
final List<PostTag> postTags = postTagRepository.findAllByTagIdAndTagType(symptomIds, TagType.SYMPTOM);
final List<Long> postIds = postTags.stream()
.map(PostTag::getPostId)
.toList();
spec = spec.and(PostSpecification.inPostIds(postIds));
}

if (cursorId != null) {
if (sortBy.equals(SortCriteria.RECENT)) {
Expand Down

0 comments on commit be15a77

Please sign in to comment.