Skip to content

Commit

Permalink
merge : 스토어 상세 디자인 조회 구현 - #29
Browse files Browse the repository at this point in the history
[FEAT] 스토어 상세 디자인 조회 구현 - #29
  • Loading branch information
lreowy authored Jan 15, 2025
2 parents 75ed589 + 0393f8b commit 065360a
Show file tree
Hide file tree
Showing 12 changed files with 136 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,16 @@ public ResponseEntity<BaseResponse<?>> getAllStation() {
storeService.getAllStation());
}

//스토어 카카오 오픈채팅 링크 조회
@GetMapping("/{storeId}/kakaoLink")
public ResponseEntity<BaseResponse<?>> getKakaoLink(@PathVariable("storeId") final Long storeId) {
return ApiResponseUtil.success(SuccessCode.OK,
storeService.getStoreKakaoLink(storeId));
}

@GetMapping("/{storeId}/design")
public ResponseEntity<BaseResponse<?>> getAllDesign(@PathVariable("storeId") final Long storeId,
@RequestHeader(required = false) final Long userId) {
return ApiResponseUtil.success(SuccessCode.OK, storeService.getStoreAllDesign(storeId, userId));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.cakey.store.dto;

import java.util.List;

public record StoreDetailAllDesignRes(
List<StoreDetailDesign> storeDesignDtoList
){
public StoreDetailAllDesignRes from(final List<StoreDetailDesign> storeDesignDtoList) {
return new StoreDetailAllDesignRes(storeDesignDtoList);
}
}
23 changes: 23 additions & 0 deletions cakey-api/src/main/java/com/cakey/store/dto/StoreDetailDesign.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.cakey.store.dto;

import lombok.AccessLevel;
import lombok.Builder;

@Builder(access = AccessLevel.PRIVATE)
public record StoreDetailDesign(
long cakeId,
String imageUrl,
boolean isLiked
) {
public static StoreDetailDesign of(final long cakeId,
final String imageUrl,
final boolean isLiked) {
return StoreDetailDesign.builder()
.cakeId(cakeId)
.imageUrl(imageUrl)
.isLiked(isLiked)
.build();
}


}
31 changes: 29 additions & 2 deletions cakey-api/src/main/java/com/cakey/store/service/StoreService.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.cakey.store.service;

import com.cakey.cake.domain.Cake;
import com.cakey.cake.dto.CakeMainImageDto;
import com.cakey.cake.facade.CakeFacade;
import com.cakey.cake.repository.CakeRepository;
import com.cakey.cakelike.facade.CakeLikesFacade;
import com.cakey.cakelike.repository.CakeLikesRepository;
import com.cakey.common.exception.NotFoundException;
import com.cakey.store.domain.Station;
import com.cakey.store.dto.*;
import com.cakey.store.facade.StoreFacade;
import com.cakey.user.dto.UserInfoDto;
import com.cakey.user.dto.UserInfoRes;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

Expand All @@ -22,6 +24,7 @@ public class StoreService {

private final StoreFacade storeFacade;
private final CakeFacade cakeFacade;
private final CakeLikesFacade cakeLikesFacade;

public List<StoreCoordinate> getStoreCoordinateList(final Station station) {
final List<StoreCoordianteDto> storeCoordianteDtoList = storeFacade.findCoordinatesByStation(station);
Expand Down Expand Up @@ -146,4 +149,28 @@ public StoreKakaoLinkRes getStoreKakaoLink(final Long storeId) {
}
return new StoreKakaoLinkRes(storeKakaoLinkDto.kakaoLink());
}

public StoreDetailAllDesignRes getStoreAllDesign(final long storeId, final Long userId) {
// 케이크 조회
// 스토어 ID로 케이크 리스트 조회
final List<Cake> cakes = cakeFacade.findAllByStoreId(storeId);

//좋아요 상태 설정
List<StoreDetailDesign> designs = cakes.stream()
.map(cake -> {
boolean isLiked = false;
if (userId != null) {
// userId가 null이 아니면 좋아요 상태 조회
isLiked = cakeLikesFacade.existsCakeLikesByCakeIdAndUserId(cake.getId(), userId);
} else {
//userId 없으면 좋아요 전체 false
isLiked = false;
}
// StoreDetailDesign 생성
return StoreDetailDesign.of(cake.getId(), cake.getImageUrl(), isLiked);
})
.collect(Collectors.toList());

return new StoreDetailAllDesignRes(designs);
}
}
13 changes: 13 additions & 0 deletions cakey-domain/src/main/java/com/cakey/cake/dto/CakeDesignDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.cakey.cake.dto;

public record CakeDesignDto(
long cakeId,
String cakeImageUrl,
boolean isLiked
) {
public CakeDesignDto(long cakeId, String cakeImageUrl, boolean isLiked) {
this.cakeId = cakeId;
this.cakeImageUrl = cakeImageUrl;
this.isLiked = isLiked;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.cakey.cake.facade;

import com.cakey.cake.domain.Cake;
import com.cakey.cake.dto.CakeMainImageDto;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -27,4 +28,8 @@ public Map<Long, List<CakeMainImageDto>> getMainImageMap(final List<Long> storeI
return cakeMainImageDtos.stream()
.collect(Collectors.groupingBy(CakeMainImageDto::getStoreId));
}

public List<Cake> findAllByStoreId(final Long storeId) {
return cakeRetriever.findAllByStoreId(storeId);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.cakey.cake.facade;

import com.cakey.cake.domain.Cake;
import com.cakey.cake.dto.CakeDesignDto;
import com.cakey.cake.dto.CakeMainImageDto;
import com.cakey.cake.repository.CakeRepository;
import lombok.RequiredArgsConstructor;
Expand All @@ -16,4 +18,8 @@ public List<CakeMainImageDto> findMainImageByStoreIds(final List<Long> storeIds)
return cakeRepository.findMainImageByStoreIds(storeIds);
}

public List<Cake> findAllByStoreId(final Long storeId) {
return cakeRepository.findAllByStoreId(storeId);
}

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

import com.cakey.cake.domain.Cake;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface CakeRepository extends JpaRepository<Cake, Long>, CakeRepositoryCustom {
@Query("SELECT c FROM Cake c WHERE c.storeId = :storeId ORDER BY c.id DESC")
List<Cake> findAllByStoreId(@Param("storeId") final long storeId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.cakey.cakelike.facade;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class CakeLikesFacade {
private final CakeLikesRetriever cakeLikesRetriever;

public boolean existsCakeLikesByCakeIdAndUserId(Long cakeId, Long userId) {
return cakeLikesRetriever.existsCakeLikesByCakeIdAndUserId(cakeId, userId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.cakey.cakelike.facade;

import com.cakey.cakelike.repository.CakeLikesRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class CakeLikesRetriever {
private final CakeLikesRepository cakeLikesRepository;

public boolean existsCakeLikesByCakeIdAndUserId(Long cakeId, Long userId) {
return cakeLikesRepository.existsByCakeIdAndUserId(cakeId, userId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.cakey.cakelike.repository;

import com.cakey.cakelike.domain.CakeLikes;
import org.springframework.data.jpa.repository.JpaRepository;

public interface CakeLikesRepository extends JpaRepository<CakeLikes, Long> {
boolean existsByCakeIdAndUserId(final Long cakeId, final Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,4 @@ public interface StoreRepository extends JpaRepository<Store, Long>, StoreReposi
// 특정 지하철역의 스토어 개수
@Query("SELECT COUNT(s) FROM Store s WHERE s.station = :stationName")
int countStoresByStation(Station stationName);

Optional<Store> findById(Long storeId);
}

0 comments on commit 065360a

Please sign in to comment.