Skip to content

Commit

Permalink
Merge pull request #199 from bucket-back/no-jira-fix-totalCount
Browse files Browse the repository at this point in the history
[NO-JIRA] 커서 목록조회 : 총 개수를 read 해오는 반환값 추가
  • Loading branch information
HandmadeCloud authored Nov 29, 2023
2 parents ec85e06 + cdd85fa commit 6da5b0e
Show file tree
Hide file tree
Showing 18 changed files with 144 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@

import java.util.List;

import com.programmers.bucketback.common.cursor.CursorSummary;
import com.programmers.bucketback.domains.bucket.application.dto.response.BucketGetCursorServiceResponse;
import com.programmers.bucketback.domains.bucket.model.BucketSummary;

public record BucketGetByCursorResponse(
String nextCursorId,
int totalBucketCount,
List<BucketSummary> buckets
) {
public static BucketGetByCursorResponse from(final CursorSummary<BucketSummary> summary) {
public static BucketGetByCursorResponse from(final BucketGetCursorServiceResponse response) {
return new BucketGetByCursorResponse(
summary.nextCursorId(),
summary.summaries()
response.cursorSummary().nextCursorId(),
response.totalBucketCount(),
response.cursorSummary().summaries()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@

import java.util.List;

import com.programmers.bucketback.common.cursor.CursorSummary;
import com.programmers.bucketback.domains.bucket.application.dto.response.BucketGetMemberItemServiceResponse;
import com.programmers.bucketback.domains.bucket.model.BucketMemberItemSummary;

public record BucketGetMemberItemResponse(
String nextCursorId,
int totalCount,
int totalMemberItemCount,
List<BucketMemberItemSummary> memberItems
) {
public static BucketGetMemberItemResponse from(final CursorSummary<BucketMemberItemSummary> summary) {
public static BucketGetMemberItemResponse from(final BucketGetMemberItemServiceResponse response) {
return new BucketGetMemberItemResponse(
summary.nextCursorId(),
summary.summaryCount(),
summary.summaries()
response.cursorSummary().nextCursorId(),
response.cursorSummary().summaryCount(),
response.totalMemberItemCount(),
response.cursorSummary().summaries()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.programmers.bucketback.common.cursor.CursorSummary;
import com.programmers.bucketback.common.model.Hobby;
import com.programmers.bucketback.common.model.ItemIdRegistry;
import com.programmers.bucketback.domains.bucket.application.dto.response.BucketGetCursorServiceResponse;
import com.programmers.bucketback.domains.bucket.application.dto.response.BucketGetMemberItemServiceResponse;
import com.programmers.bucketback.domains.bucket.domain.BucketInfo;
import com.programmers.bucketback.domains.bucket.implementation.BucketAppender;
import com.programmers.bucketback.domains.bucket.implementation.BucketModifier;
Expand All @@ -15,6 +17,7 @@
import com.programmers.bucketback.domains.bucket.model.BucketMemberItemSummary;
import com.programmers.bucketback.domains.bucket.model.BucketSummary;
import com.programmers.bucketback.domains.item.implementation.ItemReader;
import com.programmers.bucketback.domains.item.implementation.MemberItemReader;
import com.programmers.bucketback.domains.member.implementation.MemberReader;
import com.programmers.bucketback.error.BusinessException;
import com.programmers.bucketback.error.ErrorCode;
Expand All @@ -32,6 +35,7 @@ public class BucketService {
private final BucketReader bucketReader;
private final MemberReader memberReader;
private final ItemReader itemReader;
private final MemberItemReader memberItemReader;
private final MemberUtils memberUtils;

/** 버킷 생성 */
Expand Down Expand Up @@ -68,19 +72,22 @@ public void deleteBucket(final Long bucketId) {
/**
* 버킷 조회 수정을 위한 멤버 아이템 목록 조회
*/
public CursorSummary<BucketMemberItemSummary> getMemberItemsForModify(
public BucketGetMemberItemServiceResponse getMemberItemsForModify(
final Long bucketId,
final Hobby hobby,
final CursorPageParameters parameters
) {
Long memberId = memberUtils.getCurrentMemberId();

return bucketReader.readByMemberItems(
int totalMemberItemCount = memberItemReader.countByMemberIdAndHobby(memberId, hobby);
CursorSummary<BucketMemberItemSummary> cursorSummary = bucketReader.readByMemberItems(
bucketId,
memberId,
hobby,
parameters
);

return new BucketGetMemberItemServiceResponse(cursorSummary, totalMemberItemCount);
}

/**
Expand All @@ -93,14 +100,21 @@ public BucketGetServiceResponse getBucket(final Long bucketId) {
/**
* 버킷 커서 조회
*/
public CursorSummary<BucketSummary> getBucketsByCursor(
public BucketGetCursorServiceResponse getBucketsByCursor(
final String nickname,
final Hobby hobby,
final CursorPageParameters parameters
) {
Long memberId = memberReader.readByNickname(nickname).getId();

return bucketReader.readByCursor(memberId, hobby, parameters);
int totalBucketCount = bucketReader.countByMemberId(memberId);
CursorSummary<BucketSummary> cursorSummary = bucketReader.readByCursor(
memberId,
hobby,
parameters
);

return new BucketGetCursorServiceResponse(cursorSummary, totalBucketCount);
}

private void validateExceedBudget(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.programmers.bucketback.domains.bucket.application.dto.response;

import com.programmers.bucketback.common.cursor.CursorSummary;
import com.programmers.bucketback.domains.bucket.model.BucketSummary;

public record BucketGetCursorServiceResponse(
CursorSummary<BucketSummary> cursorSummary,
int totalBucketCount
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.programmers.bucketback.domains.bucket.application.dto.response;

import com.programmers.bucketback.common.cursor.CursorSummary;
import com.programmers.bucketback.domains.bucket.model.BucketMemberItemSummary;

public record BucketGetMemberItemServiceResponse(
CursorSummary<BucketMemberItemSummary> cursorSummary,
int totalMemberItemCount
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@

import java.util.List;

import com.programmers.bucketback.common.cursor.CursorSummary;
import com.programmers.bucketback.domains.comment.application.dto.response.CommentGetCursorServiceResponse;
import com.programmers.bucketback.domains.comment.repository.CommentSummary;

public record CommentGetCursorResponse(
String nextCursorId,
int totalCount,
int totalCommentCount,
List<CommentSummary> comments
) {
public static CommentGetCursorResponse from(final CursorSummary<CommentSummary> summary) {
public static CommentGetCursorResponse from(
final CommentGetCursorServiceResponse response
) {
return new CommentGetCursorResponse(
summary.nextCursorId(),
summary.summaryCount(),
summary.summaries()
response.commentSummary().nextCursorId(),
response.commentSummary().summaryCount(),
response.totalCommentCount(),
response.commentSummary().summaries()
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import com.programmers.bucketback.common.cursor.CursorPageParameters;
import com.programmers.bucketback.common.cursor.CursorSummary;
import com.programmers.bucketback.domains.comment.application.dto.response.CommentGetCursorServiceResponse;
import com.programmers.bucketback.domains.comment.domain.Comment;
import com.programmers.bucketback.domains.comment.implementation.CommentAppender;
import com.programmers.bucketback.domains.comment.implementation.CommentModifier;
Expand Down Expand Up @@ -63,13 +64,20 @@ public void deleteComment(
commentRemover.remove(commentId);
}

public CursorSummary<CommentSummary> getFeedComments(
public CommentGetCursorServiceResponse getFeedComments(
final Long feedId,
final CursorPageParameters parameters
) {
final Long memberId = memberUtils.getCurrentMemberId();

return commentReader.readByCursor(feedId, memberId, parameters);
int totalCommentCount = commentReader.countComments(feedId);
CursorSummary<CommentSummary> cursorSummary = commentReader.readByCursor(
feedId,
memberId,
parameters
);

return new CommentGetCursorServiceResponse(cursorSummary, totalCommentCount);
}

@PayPoint(20)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.programmers.bucketback.domains.comment.application.dto.response;

import com.programmers.bucketback.common.cursor.CursorSummary;
import com.programmers.bucketback.domains.comment.repository.CommentSummary;

public record CommentGetCursorServiceResponse(
CursorSummary<CommentSummary> commentSummary,
int totalCommentCount
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
import com.programmers.bucketback.domains.item.application.dto.ItemAddServiceResponse;
import com.programmers.bucketback.domains.item.application.dto.ItemGetNamesServiceResponse;
import com.programmers.bucketback.domains.item.application.dto.ItemGetServiceResponse;
import com.programmers.bucketback.domains.item.application.dto.MemberItemGetServiceResponse;
import com.programmers.bucketback.domains.item.model.ItemCursorSummary;
import com.programmers.bucketback.domains.item.model.MemberItemSummary;
import com.programmers.bucketback.global.cursor.CursorRequest;

import io.swagger.v3.oas.annotations.Operation;
Expand Down Expand Up @@ -115,11 +115,11 @@ public ResponseEntity<MemberItemGetByCursorResponse> getMemberItemsByCursor(
@ModelAttribute("request") @Valid final CursorRequest request
) {
Hobby hobby = Hobby.fromName(hobbyName);
CursorSummary<MemberItemSummary> cursorSummary = itemService.getMemberItemsByCursor(
MemberItemGetServiceResponse serviceResponse = itemService.getMemberItemsByCursor(
hobby,
request.toParameters()
);
MemberItemGetByCursorResponse response = MemberItemGetByCursorResponse.from(cursorSummary);
MemberItemGetByCursorResponse response = MemberItemGetByCursorResponse.from(serviceResponse);

return ResponseEntity.ok(response);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@

import java.util.List;

import com.programmers.bucketback.common.cursor.CursorSummary;
import com.programmers.bucketback.domains.item.application.dto.MemberItemGetServiceResponse;
import com.programmers.bucketback.domains.item.model.MemberItemSummary;

public record MemberItemGetByCursorResponse(
String nextCursorId,
int totalCount,
int totalMemberItemCount,
List<MemberItemSummary> summaries
) {
public static MemberItemGetByCursorResponse from(final CursorSummary<MemberItemSummary> summary) {
public static MemberItemGetByCursorResponse from(final MemberItemGetServiceResponse response) {
return new MemberItemGetByCursorResponse(
summary.nextCursorId(),
summary.summaryCount(),
summary.summaries()
response.cursorSummary().nextCursorId(),
response.cursorSummary().summaryCount(),
response.totalMemberItemCount(),
response.cursorSummary().summaries()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.programmers.bucketback.domains.item.application.dto.ItemAddServiceResponse;
import com.programmers.bucketback.domains.item.application.dto.ItemGetNamesServiceResponse;
import com.programmers.bucketback.domains.item.application.dto.ItemGetServiceResponse;
import com.programmers.bucketback.domains.item.application.dto.MemberItemGetServiceResponse;
import com.programmers.bucketback.domains.item.domain.Item;
import com.programmers.bucketback.domains.item.domain.MemberItem;
import com.programmers.bucketback.domains.item.implementation.ItemCursorReader;
Expand Down Expand Up @@ -105,17 +106,20 @@ public CursorSummary<ItemCursorSummary> getItemsByCursor(
);
}

public CursorSummary<MemberItemSummary> getMemberItemsByCursor(
public MemberItemGetServiceResponse getMemberItemsByCursor(
final Hobby hobby,
final CursorPageParameters parameters
) {
Long memberId = memberUtils.getCurrentMemberId();
int totalMemberItemCount = memberItemReader.countByMemberIdAndHobby(memberId, hobby);

return memberItemReader.readMemberItem(
CursorSummary<MemberItemSummary> cursorSummary = memberItemReader.readMemberItem(
hobby,
memberId,
parameters
);

return new MemberItemGetServiceResponse(cursorSummary, totalMemberItemCount);
}

public List<ItemRankingServiceResponse> getRanking() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.programmers.bucketback.domains.item.application.dto;

import com.programmers.bucketback.common.cursor.CursorSummary;
import com.programmers.bucketback.domains.item.model.MemberItemSummary;

public record MemberItemGetServiceResponse(
CursorSummary<MemberItemSummary> cursorSummary,
int totalMemberItemCount
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,8 @@ private int getPageSize(final CursorPageParameters parameters) {
int pageSize = parameters.size() == null ? DEFAULT_PAGING_SIZE : parameters.size();
return pageSize;
}

public int countByMemberId(final Long memberId) {
return bucketRepository.countByMemberId(memberId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ Optional<Bucket> findByIdAndMemberId(
);

List<Bucket> findAllByMemberId(final Long memberId);

int countByMemberId(final Long memberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,13 @@ public CursorSummary<CommentSummary> readByCursor(
return CursorUtils.getCursorSummaries(summaries);
}

public int countComments(final Long feedId) {
return commentRepository.countByFeedId(feedId);
}

private int getPageSize(final CursorPageParameters parameters) {
int pageSize = parameters.size() == null ? DEFAULT_PAGING_SIZE : parameters.size();
return pageSize;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
import com.programmers.bucketback.domains.comment.domain.Comment;

public interface CommentRepository extends JpaRepository<Comment, Long>, CommentRepositoryForCursor {
int countByFeedId(final Long feedId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,14 @@ private int getPageSize(final CursorPageParameters parameters) {

return parameterSize;
}

public int countByMemberIdAndHobby(
final Long memberId,
final Hobby hobby
) {
if (hobby == null) {
return memberItemRepository.countByMemberId(memberId);
}
return memberItemRepository.countByHobbyAndMemberId(hobby, memberId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.programmers.bucketback.common.model.Hobby;
import com.programmers.bucketback.domains.item.domain.Item;
import com.programmers.bucketback.domains.item.domain.MemberItem;

Expand All @@ -31,4 +32,19 @@ CASE WHEN COUNT(mi) > 0
"""
)
boolean existsByMemberIdAndItemsIn(@Param("memberId") Long memberId, @Param("items") List<Item> items);

int countByMemberId(final Long memberId);

@Query(
"""
SELECT COUNT(mi)
FROM MemberItem mi
JOIN mi.item i
WHERE i.hobby = :hobby AND mi.memberId = :memberId
"""
)
int countByHobbyAndMemberId(
final Hobby hobby,
final Long memberId
);
}

0 comments on commit 6da5b0e

Please sign in to comment.