Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.cakey.store.domain.Station;
import jakarta.validation.constraints.Min;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
Expand Down Expand Up @@ -57,9 +56,9 @@ public ResponseEntity<BaseResponse<?>> getRankCakesByStationStore(



//선택 디자인 조회
//디자인 둘러보기 선택 디자인 조회
@GetMapping("/select/{cakeId}")
public ResponseEntity<BaseResponse<?>> getCakeSelect(
public ResponseEntity<BaseResponse<?>> getSearchDesignCakeSelect(
@UserId final Long userId,
@PathVariable(value = "cakeId") @Min(1) final long cakeId,
@RequestParam(value = "dayCategory") final DayCategory dayCategory,
Expand Down Expand Up @@ -129,4 +128,15 @@ public ResponseEntity<BaseResponse<?>> getPopularCakesByLikedStore(
);
}

//지도뷰 선택 디자인 조회
@GetMapping("/select/map/{cakeId}")
public ResponseEntity<BaseResponse<?>> getMapSelectCake(
@UserId final Long userId,
@PathVariable(value = "cakeId") final long cakeId
) {
return ApiResponseUtil.success(
SuccessCode.OK,
cakeService.getMapSelectCake(userId, cakeId)
);
}
}
31 changes: 31 additions & 0 deletions cakey-api/src/main/java/com/cakey/cake/dto/CakeSelectedMapRes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.cakey.cake.dto;

import com.cakey.store.domain.Station;
import lombok.Builder;

@Builder
public record CakeSelectedMapRes(
long storeId,
String storeName,
String address,
Station station,
boolean isLiked,
String imageUrl
) {

public static CakeSelectedMapRes from(final long storeId,
final String storeName,
final String address,
final Station station,
final boolean isLiked,
final String imageUrl) {
return CakeSelectedMapRes.builder()
.storeId(storeId)
.storeName(storeName)
.address(address)
.station(station)
.isLiked(isLiked)
.imageUrl(imageUrl)
.build();
}
}
22 changes: 21 additions & 1 deletion cakey-api/src/main/java/com/cakey/cake/service/CakeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.cakey.store.exception.StoreNotfoundException;
import com.cakey.store.facade.StoreFacade;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.actuate.cache.CachesEndpoint;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -24,6 +25,7 @@
public class CakeService {
private final CakeFacade cakeFacade;
private final StoreFacade storeFacade;
private final CachesEndpoint cachesEndpoint;

//해당역 스토어의 케이크들 조회(최신순)
@Transactional(readOnly = true)
Expand Down Expand Up @@ -284,7 +286,7 @@ public CakesPopularListRes getPopularCakeByStoreLiked(final long userId,
///페이지네이션
try {
cakeInfoDtos = cakeFacade.findPopularCakesLikedByUser(userId, cakeIdCursor, cakeLikesCursor, size);
} catch (final NotFoundBaseException e) {
} catch (NotFoundBaseException e) {
throw new CakeyNotFoundException(CakeErrorCode.CAKE_NOT_FOUND_ENTITY);
}
///전체 케이크 개수
Expand All @@ -310,4 +312,22 @@ public CakesPopularListRes getPopularCakeByStoreLiked(final long userId,

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

//지도뷰 선택 디자인 조회
public CakeSelectedMapRes getMapSelectCake(final Long userId, final long cakeId) {
final CakeSelectedMapDto cakeSelectedMapDto;
try {
cakeSelectedMapDto = cakeFacade.getCakeSelectedMap(userId, cakeId);
} catch (final NotFoundBaseException e) {
throw new CakeyNotFoundException(CakeErrorCode.CAKE_NOT_FOUND_ENTITY);
}

return CakeSelectedMapRes.from(
cakeSelectedMapDto.getStoreId(),
cakeSelectedMapDto.getStoreName(),
cakeSelectedMapDto.getAddress(),
cakeSelectedMapDto.getStation(),
cakeSelectedMapDto.getIsLiked(),
cakeSelectedMapDto.getImageUrl());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.cakey.cake.dto;

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

@Getter
@Setter
public class CakeSelectedMapDto {
private final Long storeId;
private final String storeName;
private final String address;
private final Station station;
private final Boolean isLiked;
private final String imageUrl;

@QueryProjection
public CakeSelectedMapDto(final Long storeId,
final String storeName, final String address,
final Station station,
final Boolean isLiked,
final String imageUrl) {
this.storeId = storeId;
this.storeName = storeName;
this.address = address;
this.station = station;
this.isLiked = isLiked;
this.imageUrl = imageUrl;
}
}
16 changes: 8 additions & 8 deletions cakey-domain/src/main/java/com/cakey/cake/facade/CakeFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import com.cakey.cake.domain.Cake;
import com.cakey.cake.domain.DayCategory;
import com.cakey.cake.dto.CakeByPopularityDto;
import com.cakey.cake.dto.CakeInfoDto;
import com.cakey.cake.dto.CakeMainImageDto;
import com.cakey.cake.dto.CakeSelectedInfoDto;
import com.cakey.cake.dto.*;
import com.cakey.caketheme.domain.ThemeName;
import com.cakey.store.domain.Station;
import com.cakey.store.dto.StoreBySelectedCakeDto;
Expand Down Expand Up @@ -74,9 +71,9 @@ public List<CakeInfoDto> findLatestLikedCakesByUser(final Long userId,

//찜한 디자인(케이크) 조회(인기순)
public List<CakeInfoDto> findPopularLikedCakesByUser(final long userId,
final Long cakeIdCursor,
final Integer cakeLikesCursor,
final int size) {
final Long cakeIdCursor,
final Integer cakeLikesCursor,
final int size) {
return cakeRetriever.findPopularLikedCakesByUser(userId, cakeIdCursor, cakeLikesCursor, size);
}

Expand Down Expand Up @@ -139,5 +136,8 @@ public void isExistCake(final long cakeId) {
cakeRetriever.isExistCake(cakeId);
}


//지도뷰 조회된 디자인 조회
public CakeSelectedMapDto getCakeSelectedMap(final Long userId, final long cakeId) {
return cakeRetriever.getCakeSelectedMap(userId, cakeId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import com.cakey.cake.domain.Cake;
import com.cakey.cake.domain.DayCategory;
import com.cakey.cake.dto.CakeByPopularityDto;
import com.cakey.cake.dto.CakeInfoDto;
import com.cakey.cake.dto.CakeMainImageDto;
import com.cakey.cake.dto.CakeSelectedInfoDto;
import com.cakey.cake.dto.*;
import com.cakey.cake.repository.CakeRepository;
import com.cakey.caketheme.domain.ThemeName;
import com.cakey.common.exception.NotFoundBaseException;
Expand Down Expand Up @@ -148,4 +145,10 @@ public void isExistCake(final long cakeId) {
throw new NotFoundBaseException();
}
}

//지도뷰 선택 케이크 조회
public CakeSelectedMapDto getCakeSelectedMap(final Long userId, final long cakeId) {
return cakeRepository.getCakeSelectedMap(userId, cakeId).orElseThrow(NotFoundBaseException::new);
}

}
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package com.cakey.cake.repository;

import com.cakey.cake.domain.DayCategory;
import com.cakey.cake.dto.CakeInfoDto;
import com.cakey.cake.dto.CakeMainImageDto;
import com.cakey.cake.dto.CakeSelectedDto;
import com.cakey.cake.dto.CakeSelectedInfoDto;
import com.cakey.cake.dto.*;
import com.cakey.caketheme.domain.ThemeName;
import com.cakey.store.domain.Station;
import com.cakey.store.dto.StoreBySelectedCakeDto;
import com.cakey.store.dto.StoreInfoDto;

import java.util.List;
import java.util.Optional;

public interface CakeRepositoryCustom {
List<CakeMainImageDto> findMainImageByStoreIds(final List<Long> storeIds);
Expand Down Expand Up @@ -78,5 +76,7 @@ List<CakeInfoDto> findPopularCakesLikedByUser(final long userId,
int countCakesByCategoryAndTheme(final DayCategory dayCategory,
final ThemeName theme);


//지도뷰 조회된 디자인 조회
Optional<CakeSelectedMapDto> getCakeSelectedMap(final Long userId,
final long cakeId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

@RequiredArgsConstructor
public class CakeRepositoryCustomImpl implements CakeRepositoryCustom {
Expand All @@ -37,6 +38,7 @@ public class CakeRepositoryCustomImpl implements CakeRepositoryCustom {
QCake cake = QCake.cake;
QStore store = QStore.store;
QCakeLikes cakeLikes = QCakeLikes.cakeLikes;
QStoreLike storeLike = QStoreLike.storeLike;

//가게 메인이미지 조회
@Override
Expand Down Expand Up @@ -136,7 +138,7 @@ public List<CakeInfoDto> findPopularCakesByStation(final Long userId,
.where(cakeLikes.cakeId.eq(cake.id));

/// 좋아요 여부 서브쿼리
final BooleanExpression isLikedExpression = getIsLikedExpression(userId);
final BooleanExpression isLikedExpression = getCakeIsLikedExpression(userId);

/// 역 조건
final BooleanExpression stationCondition = station != Station.ALL
Expand Down Expand Up @@ -498,7 +500,7 @@ public List<CakeInfoDto> findCakesByCategoryAndTheme(final DayCategory dayCatego
cake.storeId,
store.name,
store.station,
getIsLikedExpression(userId), // isLiked 조건
getCakeIsLikedExpression(userId), // isLiked 조건
cake.imageUrl,
likeCountSubQuery, /// 좋아요 개수
cake.id, /// 현재 케이크 ID를 커서로 반환
Expand Down Expand Up @@ -559,7 +561,7 @@ public List<CakeInfoDto> findPopularCakesByCategoryAndTheme(final DayCategory da
store.id,
store.name,
store.station,
getIsLikedExpression(userId), // isLiked 조건
getCakeIsLikedExpression(userId), // isLiked 조건
cake.imageUrl,
cakeLikesOrderExpression, // 좋아요 개수
cake.id,
Expand Down Expand Up @@ -672,7 +674,7 @@ public List<CakeInfoDto> findPopularCakesLikedByUser(final long userId,
store.id,
store.name,
store.station,
getIsLikedExpression(userId), /// isLiked 조건
getCakeIsLikedExpression(userId), /// isLiked 조건
cake.imageUrl,
cakeLikesCountSubQuery, /// 좋아요 개수
cake.id,
Expand Down Expand Up @@ -771,7 +773,7 @@ public List<CakeInfoDto> findCakesLikedByUser(final long userId,
store.id,
store.name,
store.station,
getIsLikedExpression(userId), // isLiked 조건
getCakeIsLikedExpression(userId), // isLiked 조건
cake.imageUrl,
likeCountSubQuery, // 좋아요 개수
cake.id, // 현재 케이크 ID를 반환
Expand Down Expand Up @@ -836,6 +838,24 @@ public int countCakesByCategoryAndTheme(final DayCategory dayCategory, final The
return count != null ? Math.toIntExact(count) : 0;
}

//지도뷰 선택 디자인 조회
@Override
public Optional<CakeSelectedMapDto> getCakeSelectedMap(final Long userId, final long cakeId) {
return Optional.ofNullable(queryFactory
.select(new QCakeSelectedMapDto(
store.id,
store.name,
store.address,
store.station,
getStoreIsLikedExpression(userId),
cake.imageUrl
))
.from(cake)
.join(store).on(cake.storeId.eq(store.id))
.where(cake.id.eq(cakeId))
.fetchOne());
}

private BooleanExpression isLikedByUser(NumberExpression<Long> cakeId, Long userId) {
QCakeLikes cakeLikes = QCakeLikes.cakeLikes;

Expand All @@ -853,7 +873,7 @@ private BooleanExpression isLikedByUser(NumberExpression<Long> cakeId, Long user
}

// 유저의 케이크 좋아요 여부 서브쿼리
private BooleanExpression getIsLikedExpression(final Long userId) {
private BooleanExpression getCakeIsLikedExpression(final Long userId) {
if (userId != null) {
return JPAExpressions.selectOne()
.from(cakeLikes)
Expand All @@ -874,4 +894,17 @@ private BooleanExpression isLikedExpression(final Long userId, final NumberPath<
return Expressions.asBoolean(false);
}
}


//스토어 좋아요 여부 서브쿼리
private BooleanExpression getStoreIsLikedExpression(final Long userId) {
if (userId != null) {
return JPAExpressions.selectOne()
.from(storeLike)
.where(storeLike.storeId.eq(store.id).and(storeLike.userId.eq(userId)))
.exists();
} else {
return Expressions.asBoolean(false);
}
}
}