-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
143 additions
and
36 deletions.
There are no files selected for viewing
4 changes: 0 additions & 4 deletions
4
cakey-api/src/main/java/com/cakey/store/dto/StoreInfoListBylikesRes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
cakey-api/src/main/java/com/cakey/storelikes/controller/StoreLikesController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.cakey.storelikes.controller; | ||
|
||
import com.cakey.common.response.ApiResponseUtil; | ||
import com.cakey.common.response.BaseResponse; | ||
import com.cakey.common.response.SuccessCode; | ||
import com.cakey.storelikes.service.StoreLikesService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequestMapping("/api/v1/store/likes") | ||
@RequiredArgsConstructor | ||
public class StoreLikesController { | ||
private final StoreLikesService storeLikesService; | ||
|
||
@GetMapping("/latest") | ||
public ResponseEntity<BaseResponse<?>> getLatestStoreByUserLikes( | ||
@RequestHeader(value = "userId", required = true) final long userId, | ||
@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.getLatestStoreLikesByUser(userId, storeIdCursor, size)); | ||
|
||
} | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
cakey-api/src/main/java/com/cakey/storelikes/dto/StoreLatestLikedByUser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 StoreLatestLikedByUser( | ||
Long lastStoreId, | ||
long storeCount, | ||
List<StoreInfo> stores | ||
) { | ||
public static StoreLatestLikedByUser fromStoreInfo(final Long lastStoreId, | ||
final long storeCount, | ||
final List<StoreInfo> stores) { | ||
return new StoreLatestLikedByUser(lastStoreId, storeCount, stores); | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
cakey-api/src/main/java/com/cakey/storelikes/service/StoreLikesService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.cakey.storelikes.service; | ||
|
||
import com.cakey.cake.dto.CakeMainImageDto; | ||
import com.cakey.cake.facade.CakeFacade; | ||
import com.cakey.store.domain.Station; | ||
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 lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class StoreLikesService { | ||
|
||
private final StoreFacade storeFacade; | ||
private final CakeFacade cakeFacade; | ||
|
||
public StoreLatestLikedByUser getLatestStoreLikesByUser(final long userId, | ||
final Long storeIdCursor, | ||
final int size) { | ||
|
||
//페이지네이션으로 스토어 조회 | ||
final List<StoreInfoDto> storeInfoDtos = storeFacade.findLatestStoresLikedByUser(userId, storeIdCursor, size); | ||
|
||
//조회한 store들의 id 추출 | ||
final List<Long> storeIds = storeFacade.getStoreIds(storeInfoDtos); | ||
|
||
//메인 이미지 매핑 | ||
final Map<Long, List<CakeMainImageDto>> mainImageMap = cakeFacade.getMainImageMap(storeIds); | ||
|
||
//storeInfo 생성 | ||
final List<StoreInfo> storeInfos = getStoreInfo(storeInfoDtos, mainImageMap); | ||
|
||
//스토어 개수 조회 | ||
final int storeCount = storeInfos.size(); | ||
|
||
//마지막 스토어 아이디 | ||
final Long lastStoreId = storeFacade.calculateLastStoreId(storeInfoDtos); | ||
|
||
return StoreLatestLikedByUser.fromStoreInfo(lastStoreId, storeCount, storeInfos); | ||
} | ||
|
||
|
||
//storeInfo 생성 | ||
private List<StoreInfo> getStoreInfo(final List<StoreInfoDto> storeInfoDtos, final Map<Long, List<CakeMainImageDto>> imageMap) { | ||
return storeInfoDtos.stream() | ||
.map(storeInfoDto -> { | ||
// storeId에 해당하는 이미지 리스트 가져오기 | ||
final List<StoreInfo.StoreMainImage> images = imageMap.getOrDefault(storeInfoDto.getStoreId(), List.of()) | ||
.stream() | ||
.map(image -> StoreInfo.StoreMainImage.of(image.getImageId(), image.getImageUrl())) | ||
.toList(); | ||
|
||
// StoreInfo 생성 | ||
return StoreInfo.of( | ||
storeInfoDto.getStoreId(), | ||
storeInfoDto.getName(), | ||
Station.valueOf(String.valueOf(storeInfoDto.getStation())), | ||
storeInfoDto.getAddress(), | ||
storeInfoDto.getStoreLikesCount(), | ||
storeInfoDto.isLiked(), | ||
images | ||
); | ||
}) | ||
.toList(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters