Skip to content

Commit

Permalink
merge: 찜한 스토어 조회(인기순) - #27
Browse files Browse the repository at this point in the history
[FEAT] 찜한 스토어 조회(인기순) - #27
  • Loading branch information
sjk4618 authored Jan 15, 2025
2 parents 5ec859c + 8321cde commit f14f7b8
Show file tree
Hide file tree
Showing 15 changed files with 363 additions and 100 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.cakey.store.controller;

import com.cakey.OrderBy;
import com.cakey.common.response.ApiResponseUtil;
import com.cakey.common.response.BaseResponse;
import com.cakey.common.response.SuccessCode;
import com.cakey.store.domain.Station;
import com.cakey.store.dto.AllStationRes;
import com.cakey.store.dto.StoreCoordinateListRes;
import com.cakey.store.service.StoreService;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -36,7 +34,7 @@ public ResponseEntity<BaseResponse<?>> getStoreInfoListByStationAndLikes(
@RequestHeader(value = "Authorization", required = false) final Long userId,
@RequestParam(value = "station", required = true) final Station station,
@RequestParam(value = "likesCursor", defaultValue = "0", required = false) final int likesCursor,
@RequestParam(value = "lastStoreId", defaultValue = "0", required = false) final Long lastStoreId,
@RequestParam(value = "storeIdCursor", defaultValue = "0", required = false) final Long storeIdCursor,
@RequestParam(value = "size", defaultValue = "10", required = false) final int size
) {
return ApiResponseUtil.success(
Expand All @@ -45,7 +43,7 @@ public ResponseEntity<BaseResponse<?>> getStoreInfoListByStationAndLikes(
userId,
station,
likesCursor,
lastStoreId,
storeIdCursor,
size));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ public List<StoreCoordinate> getStoreCoordinateList(final Station station) {
public StoreInfoListBylikesRes getStoreInfoListByStationAndLikes(final Long userId,
final Station station,
final int likesCursor,
final Long lastStoreId,
final Long storeIdCursor,
final int size) {

final List<StoreInfoDto> storeInfoDtos = storeFacade.findStoreInfoByStationAndLikes(userId, station, likesCursor, lastStoreId, size);
final List<StoreInfoDto> storeInfoDtos = storeFacade.findStoreInfoByStationAndLikes(userId, station, likesCursor, storeIdCursor, size);

// 조회한 store들의 ID 추출
final List<Long> storeIds = storeFacade.getStoreIds(storeInfoDtos);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,18 @@ public ResponseEntity<BaseResponse<?>> getLatestStoreByUserLikes(
return ApiResponseUtil.success(
SuccessCode.OK,
storeLikesService.getLatestStoreLikesByUser(userId, storeIdCursor, size));
}

@GetMapping("/popularity")
public ResponseEntity<BaseResponse<?>> getPopularityStoreByUserLikes(
@RequestHeader(value = "userId", required = true) final long userId,
@RequestParam(value = "likesCursor", defaultValue = "0", required = false) final int likesCursor,
@RequestParam(value = "storeIdCursor", defaultValue = "0", required = false) final Long storeIdCursor,
@RequestParam(value = "size", defaultValue = "10", required = false) final int size
) {
return ApiResponseUtil.success(
SuccessCode.OK,
storeLikesService.getPopularityStoreByUserLikes(userId, likesCursor, storeIdCursor, size));
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.cakey.storelikes.dto;

import com.cakey.store.dto.StoreInfo;

import java.util.List;

public record StoreLatestLikedByUserRes(
Long lastStoreId,
long storeCount,
List<StoreInfo> stores
) {
public static StoreLatestLikedByUserRes fromStoreInfo(final Long lastStoreId,
final long storeCount,
final List<StoreInfo> stores) {
return new StoreLatestLikedByUserRes(lastStoreId, storeCount, stores);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.cakey.storelikes.dto;

import com.cakey.store.dto.StoreInfo;
import lombok.AccessLevel;
import lombok.Builder;

import java.util.List;

@Builder(access = AccessLevel.PRIVATE)
public record StorePopularityLikedByUserRes(
long nextLikesCursor,
Long nexStoreId,
long storeCount,
List<StoreInfo> stores
) {
public static StorePopularityLikedByUserRes of(final long nextLikesCursor,
final long nexStoreId,
final long storeCount,
final List<StoreInfo> stores) {
return StorePopularityLikedByUserRes.builder()
.nextLikesCursor(nextLikesCursor)
.nexStoreId(nexStoreId)
.storeCount(storeCount)
.stores(stores)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import com.cakey.store.dto.StoreInfo;
import com.cakey.store.dto.StoreInfoDto;
import com.cakey.store.facade.StoreFacade;
import com.cakey.storelikes.dto.StoreLatestLikedByUser;
import com.cakey.storelike.facade.StoreLikeFacade;
import com.cakey.storelikes.dto.StoreLatestLikedByUserRes;
import com.cakey.storelikes.dto.StorePopularityLikedByUserRes;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

Expand All @@ -19,10 +21,12 @@ public class StoreLikesService {

private final StoreFacade storeFacade;
private final CakeFacade cakeFacade;
private final StoreLikeFacade storeLikeFacade;

public StoreLatestLikedByUser getLatestStoreLikesByUser(final long userId,
final Long storeIdCursor,
final int size) {
//찜한 스토어 조회(최신순)
public StoreLatestLikedByUserRes getLatestStoreLikesByUser(final long userId,
final Long storeIdCursor,
final int size) {

//페이지네이션으로 스토어 조회
final List<StoreInfoDto> storeInfoDtos = storeFacade.findLatestStoresLikedByUser(userId, storeIdCursor, size);
Expand All @@ -36,13 +40,46 @@ public StoreLatestLikedByUser getLatestStoreLikesByUser(final long userId,
//storeInfo 생성
final List<StoreInfo> storeInfos = getStoreInfo(storeInfoDtos, mainImageMap);

//스토어 개수 조회
final int storeCount = storeInfos.size();
//찜한 스토어 개수 조회
final int storeCount = storeLikeFacade.countAllLikedStoreByUserId(userId);

//마지막 스토어 아이디
final Long lastStoreId = storeFacade.calculateLastStoreId(storeInfoDtos);

return StoreLatestLikedByUser.fromStoreInfo(lastStoreId, storeCount, storeInfos);
return StoreLatestLikedByUserRes.fromStoreInfo(lastStoreId, storeCount, storeInfos);
}

//찜한 스토어 조회(인기순)
public StorePopularityLikedByUserRes getPopularityStoreByUserLikes(final long userId,
final int likesCursor,
final Long storeIdCursor,
final int size) {
final List<StoreInfoDto> storeInfoOrderByLikesDtos = storeFacade.findPopularityStoresLikedByUser(userId, likesCursor, storeIdCursor, size);


//조회한 store들의 id 추출
final List<Long> storeIds = storeFacade.getStoreIds(storeInfoOrderByLikesDtos);

//메인 이미지 매핑
final Map<Long, List<CakeMainImageDto>> mainImageMap = cakeFacade.getMainImageMap(storeIds);

//storeInfo 생성
final List<StoreInfo> storeInfos = getStoreInfo(storeInfoOrderByLikesDtos, mainImageMap);

//찜한 스토어 개수 조회
final int storeCount = storeLikeFacade.countAllLikedStoreByUserId(userId);

final Long lastStoreId = storeInfoOrderByLikesDtos.isEmpty()
? null // 스토어가 없으면 null 반환
: storeFacade.calculateLastStoreId(storeInfoOrderByLikesDtos);

// 7. 결과 DTO 조립 및 반환
return StorePopularityLikedByUserRes.of(
userId,
lastStoreId != null ? lastStoreId : 0L, // null이면 기본값 0L 설정
storeCount,
storeInfos
);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,36 @@

import com.cakey.store.domain.Station;
import com.querydsl.core.annotations.QueryProjection;
import jakarta.annotation.Nullable;
import lombok.Getter;
import lombok.Setter;


@Getter
@Setter
public class StoreInfoDto {
private final Long storeId;
private final String name;
private final Station station;
private final String address;
private final boolean isLiked;
private final int storeLikesCount;
private Long storeIdCursor;

@QueryProjection
public StoreInfoDto(Long storeId,
String name,
Station station,
String address,
boolean isLiked,
int storeLikesCount) {
int storeLikesCount,
Long storeIdCursor) {
this.storeId = storeId;
this.name = name;
this.station = station;
this.address = address;
this.isLiked = isLiked;
this.storeLikesCount = storeLikesCount;
this.storeIdCursor = storeIdCursor;
}
}
14 changes: 11 additions & 3 deletions cakey-domain/src/main/java/com/cakey/store/facade/StoreFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public List<StoreCoordianteDto> findCoordinatesByStation(final Station station)
public List<StoreInfoDto> findStoreInfoByStationAndLikes(final Long userId,
final Station station,
final int likesCursor,
final Long lastStoreId,
final Long storeIdCursor,
final int size) {
return storeRetriever.findStoreInfoByStationAndLikes(userId, station, likesCursor, lastStoreId, size);
return storeRetriever.findStoreInfoByStationAndLikes(userId, station, likesCursor, storeIdCursor, size);
}

//스토어 조회(최신순)
Expand All @@ -39,13 +39,21 @@ public List<StoreInfoDto> findStoreInfoByStationAndLatest(final Long userId,

return storeRetriever.findStoreInfoByStationAndLatest(userId, station, storeCursorId, size);
}
//찜한 스토어(최신순)
//찜한 스토어 조회(최신순)
public List<StoreInfoDto> findLatestStoresLikedByUser(final Long userId,
final Long storeIdCursor,
final int size) {
return storeRetriever.findStoresLikedByUser(userId, storeIdCursor, size);
}

//찜한 스토어 조회(인기순)
public List<StoreInfoDto> findPopularityStoresLikedByUser(final long userId,
final int likesCursor,
final Long storeIdCursor,
final int size) {
return storeRetriever.findPopularityStoresLikedByUser(userId, likesCursor, storeIdCursor, size);
}

// 조회한 store들의 ID 추출
public List<Long> getStoreIds(final List<StoreInfoDto> storeInfoDtos) {
return storeInfoDtos.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,30 @@ public List<StoreInfoDto> findStoreInfoByStationAndLikes(final Long userId,
final int likesCursor,
final Long lastStoreId,
final int size) {
return storeRepository.findStoreInfoByStationAndLikes(userId, station, likesCursor, lastStoreId, size);
return storeRepository.findPopularitryStoreInfoByStation(userId, station, likesCursor, lastStoreId, size);
}

//스토어 조회(최신순)
public List<StoreInfoDto> findStoreInfoByStationAndLatest(final Long userId,
final Station station,
final Long storeIdCursor,
final int size) {
return storeRepository.findStoreInfoByStationAndLatest(userId, station, storeIdCursor, size);
return storeRepository.findLatestStoreInfoByStation(userId, station, storeIdCursor, size);
}

//찜한 스토어 조회(최신순)
public List<StoreInfoDto> findStoresLikedByUser(final long userId,
final Long storeIdCursor,
final int size) {
return storeRepository.findStoresLikedByUser(userId, storeIdCursor, size);
return storeRepository.findLatestStoresLikedByUser(userId, storeIdCursor, size);
}

//찜한 스토어 조회(인기순)
public List<StoreInfoDto> findPopularityStoresLikedByUser(final long userId,
final int likesCursor,
final Long storeIdCursor,
final int size) {
return storeRepository.findPopularityStoresLikedByUser(userId, likesCursor, storeIdCursor, size);
}

public int countAllStores() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.cakey.store.repository;

import com.cakey.OrderBy;
import com.cakey.store.domain.Station;
import com.cakey.store.dto.StoreCoordianteDto;
import com.cakey.store.dto.StoreInfoDto;
Expand All @@ -10,18 +9,23 @@
public interface StoreRepositoryCustom {
List<StoreCoordianteDto> findStoreCoordinatesByStation(final Station station);

List<StoreInfoDto> findStoreInfoByStationAndLikes(final Long userId,
final Station station,
final int likesCursor,
final Long lastStoreId,
final int size);
List<StoreInfoDto> findPopularitryStoreInfoByStation(final Long userId,
final Station station,
final Integer likesCursor,
final Long lastStoreId,
final int size);

List<StoreInfoDto> findLatestStoreInfoByStation(final Long userId,
final Station station,
final Long storeIdCursor,
final int size);

List<StoreInfoDto> findStoreInfoByStationAndLatest(final Long userId,
final Station station,
final Long storeIdCursor,
final int size);
List<StoreInfoDto> findLatestStoresLikedByUser(final long userId,
final Long storeIdCursor,
final int size);

List<StoreInfoDto> findStoresLikedByUser(final long userId,
final Long storeIdCursor,
final int size);
List<StoreInfoDto>findPopularityStoresLikedByUser(final long userId,
final Integer likesCursor,
final Long storeIdCursor,
final int size);
}
Loading

0 comments on commit f14f7b8

Please sign in to comment.