Skip to content

Commit

Permalink
feat: 찜한 스토어 디자인 조회 - #61
Browse files Browse the repository at this point in the history
  • Loading branch information
sjk4618 committed Jan 17, 2025
1 parent 052575d commit 2359299
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,18 @@ public ResponseEntity<BaseResponse<?>> getPopularCakes(
);
}

//찜한 스토어의 디자인 조회(인기순)
@GetMapping("/store-liked/popularity")
public ResponseEntity<BaseResponse<?>> getPopularCakesByLikedStore(
@RequestHeader(value = "Authorization", required = true) final long userId,
@RequestParam(value = "cakeIdCursor", required = false) final Long cakeIdCursor,
@RequestParam(value = "cakeLikesCursor", required = false) final Integer cakeLikesCursor,
@RequestParam(value = "size", required = false, defaultValue = "10") final int size
) {
return ApiResponseUtil.success(
SuccessCode.OK,
cakeService.getPopularCakeByStoreLiked(userId, cakeIdCursor, cakeLikesCursor, size)
);
}

}
56 changes: 44 additions & 12 deletions cakey-api/src/main/java/com/cakey/cake/service/CakeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ public void postCakeLike(final Long cakeId, final Long userId) {

//선택한 디자인(케이크) 조회
public CakeSelectedRes getSelectedCakes(final Long cakeId,
final DayCategory dayCategory,
final ThemeName theme,
final Long userId) {
final DayCategory dayCategory,
final ThemeName theme,
final Long userId) {

///스토어 정보 조회
final StoreBySelectedCakeDto storeInfoDto = storeFacade.findStoreBySelectedCakeId(cakeId);
Expand Down Expand Up @@ -152,10 +152,10 @@ public CakeSelectedRes getSelectedCakes(final Long cakeId,

//디자인 둘러보기 조회(최신순)
public CakesLatestListRes findCakesByCategoryAndTheme(final DayCategory dayCategory,
final ThemeName theme,
final Long userId,
final Long cakeIdCursor,
final int limit) {
final ThemeName theme,
final Long userId,
final Long cakeIdCursor,
final int limit) {
///페이지네이션
final List<CakeInfoDto> cakeInfoDtos = cakeFacade.findCakesByCategoryAndTheme(dayCategory,theme, userId, cakeIdCursor, limit);

Expand Down Expand Up @@ -188,11 +188,11 @@ public CakesLatestListRes findCakesByCategoryAndTheme(final DayCategory dayCateg

//디자인 둘러보기 조회(인기순)
public CakesPopularListRes getPopularCakesByCategoryAndTheme(final DayCategory dayCategory,
final ThemeName themeName,
final Long userId,
final Long cakeIdCursor,
final Integer cakeLikesCursor,
final int size) {
final ThemeName themeName,
final Long userId,
final Long cakeIdCursor,
final Integer cakeLikesCursor,
final int size) {

///페이지네이션
final List<CakeInfoDto> cakeInfoDtos = cakeFacade.findPopularCakesByCategoryAndTheme(dayCategory,themeName, userId, cakeIdCursor, cakeLikesCursor, size);
Expand Down Expand Up @@ -220,4 +220,36 @@ public CakesPopularListRes getPopularCakesByCategoryAndTheme(final DayCategory d

return CakesPopularListRes.from(nextLikesCursor, nextCakeIdCursor, totalCakeCount, isLastData, cakes);
}

//찜한 스토어들 디자인 조회(인기순)
public CakesPopularListRes getPopularCakeByStoreLiked(final long userId,
final Long cakeIdCursor,
final Integer cakeLikesCursor,
final int size) {
///페이지네이션
final List<CakeInfoDto> cakeInfoDtos = cakeFacade.findPopularCakesLikedByUser(userId, cakeIdCursor, cakeLikesCursor, size);

///전체 케이크 개수
final int totalCakeCount = cakeFacade.countAllDesignsLikedByUser(userId);

///커서 업데이트
final int lastCakeInfoDtosIndex = cakeInfoDtos.size() - 1;
final int nextLikesCursor = cakeInfoDtos.get(lastCakeInfoDtosIndex).getCakeLikeCount();
final Long nextCakeIdCursor = cakeInfoDtos.get(lastCakeInfoDtosIndex).getCakeIdCursor();
final boolean isLastData = cakeInfoDtos.get(lastCakeInfoDtosIndex).isLastData();

final List<CakeInfo> cakes = cakeInfoDtos.stream()
.map(dto -> CakeInfo.of(
dto.getCakeId(),
dto.getStoreId(),
dto.getStoreName(),
dto.getStation(),
dto.isLiked(),
dto.getImageUrl(),
dto.getCakeLikeCount()
))
.toList();

return CakesPopularListRes.from(nextLikesCursor, nextCakeIdCursor, totalCakeCount, isLastData, cakes);
}
}

0 comments on commit 2359299

Please sign in to comment.