Skip to content

Commit

Permalink
merge : 디자인 좋아요 하기 - #46
Browse files Browse the repository at this point in the history
[FEAT] 디자인 좋아요 하기 - #46
  • Loading branch information
lreowy authored Jan 16, 2025
2 parents ab949b8 + f234dbb commit 1041ec6
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ public ResponseEntity<BaseResponse<?>> getPopularCakesByStationStore(

@GetMapping("/lank")
public ResponseEntity<BaseResponse<?>> getLankCakesByStationStore(@RequestHeader(required = false) final Long userId) {
return ApiResponseUtil.success(SuccessCode.OK, cakeService.getCakeByPopularity(userId));
return ApiResponseUtil.success(SuccessCode.OK, cakeService.getCakeByLank(userId));
}

@PostMapping("/likes/{cakeId}")
public ResponseEntity<BaseResponse<?>> postCakeLike(
@PathVariable(value = "cakeId") final Long cakeId,
@RequestHeader final Long userId
) {
cakeService.postCakeLike(cakeId, userId);
return ApiResponseUtil.success(SuccessCode.OK);
}
}
22 changes: 20 additions & 2 deletions cakey-api/src/main/java/com/cakey/cake/service/CakeService.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package com.cakey.cake.service;

import com.cakey.cake.domain.Cake;
import com.cakey.cake.dto.CakeByPopularityDto;
import com.cakey.cake.dto.CakeInfo;
import com.cakey.cake.dto.CakeInfoDto;
import com.cakey.cake.dto.CakeListByPopularityRes;
import com.cakey.cake.dto.CakesLatestByStationStoreRes;
import com.cakey.cake.dto.CakesPopularByStationStoreRes;
import com.cakey.cake.facade.CakeFacade;
import com.cakey.cakelike.domain.CakeLikes;
import com.cakey.cakelike.facade.CakeLikesFacade;
import com.cakey.common.exception.NotFoundException;
import com.cakey.exception.CakeyApiException;
import com.cakey.store.domain.Station;
import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import org.apache.tomcat.util.digester.AbstractObjectCreationFactory;
import org.springframework.stereotype.Service;
Expand All @@ -20,6 +25,7 @@
@RequiredArgsConstructor
public class CakeService {
private final CakeFacade cakeFacade;
private final CakeLikesFacade cakeLikesFacade;

//해당역 스토어의 케이크들 조회(최신순)
public CakesLatestByStationStoreRes getLatestCakesByStationStore(final Long userId,
Expand Down Expand Up @@ -93,8 +99,20 @@ public CakesPopularByStationStoreRes getPopularCakesByStationStore(final Long us
return CakesPopularByStationStoreRes.from(nextLikesCursor, nextCakeIdCursor, totalCakeCount, isLastData, cakes);
}

public CakeListByPopularityRes getCakeByPopularity(final Long userId) {
List<CakeByPopularityDto> cakeByPopularityDtos = cakeFacade.findCakeByPopularity(userId);
public CakeListByPopularityRes getCakeByLank(final Long userId) {
List<CakeByPopularityDto> cakeByPopularityDtos = cakeFacade.findCakeByLank(userId);
return new CakeListByPopularityRes(cakeByPopularityDtos);
}

@Transactional
public void postCakeLike(final Long cakeId, final Long userId) {
Cake cake = cakeFacade.findById(cakeId);
if (!cakeLikesFacade.existsCakeLikesByCakeIdAndUserId(cakeId, userId)) {
CakeLikes cakeLikes = CakeLikes.createCakeLikes(cakeId, userId);
cakeLikesFacade.saveCakeLikes(cakeLikes);
} else {
//todo: 추후 구체적인 예외 처리
throw new RuntimeException("Cake like already exists");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public ResponseEntity<BaseResponse<?>> getStoreInformation(@PathVariable("storeI
}

@GetMapping("/lank")
public ResponseEntity<BaseResponse<?>> getStorePopularity(){
return ApiResponseUtil.success(SuccessCode.OK, storeService.getStoreByPopularity());
public ResponseEntity<BaseResponse<?>> getStoreByLank(){
return ApiResponseUtil.success(SuccessCode.OK, storeService.getStoreByLank());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ public StoreDetailInfoRes getStoreDetailInfo(final long storeId) {
}
}

public StoreListByPopularityRes getStoreByPopularity() {
final List<StoreByPopularityDto> storeByPopularityDtoList = storeFacade.findStoreListByPopularity();
public StoreListByPopularityRes getStoreByLank() {
final List<StoreByPopularityDto> storeByPopularityDtoList = storeFacade.findStoreListByLank();
return new StoreListByPopularityRes(storeByPopularityDtoList);
}
}
12 changes: 7 additions & 5 deletions cakey-domain/src/main/java/com/cakey/cake/facade/CakeFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,17 @@ public List<Cake> findAllByStoreId(final Long storeId) {
return cakeRetriever.findAllByStoreId(storeId);
}

public List<CakeByPopularityDto> findCakeByLank(final Long userId) {
return cakeRetriever.findCakesByLank(userId);
}

public Cake findById(final Long cakeId) {
return cakeRetriever.findById(cakeId);
}
//찜한 디자인(케이크) 조회(최신순)
public List<CakeInfoDto> findLatestLikedCakesByUser(final Long userId,
final Long cakeIdCursor,
final int size) {
return cakeRetriever.findLatestLikedCakesByUser(userId, cakeIdCursor, size);
}

public List<CakeByPopularityDto> findCakeByPopularity(final Long userId) {
return cakeRetriever.findCakesByPopularity(userId);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.cakey.cake.dto.CakeInfoDto;
import com.cakey.cake.dto.CakeMainImageDto;
import com.cakey.cake.repository.CakeRepository;
import com.cakey.common.exception.NotFoundException;
import com.cakey.store.domain.Station;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -40,15 +41,20 @@ public List<CakeInfoDto> findPopularCakesByStation(final Long userId,
return cakeRepository.findPopularCakesByStation(userId, station, likesCursor, cakeIdCursor, size);
}


public List<CakeByPopularityDto> findCakesByLank(final Long userId) {
return cakeRepository.findCakesByLank(userId);
}

public Cake findById(final Long cakeId) {
return cakeRepository.findById(cakeId)
.orElseThrow(() -> new NotFoundException());
}
//찜한 디자인(케이크) 조회(최신순)
List<CakeInfoDto> findLatestLikedCakesByUser(final Long userId,
final Long cakeIdCursor,
final int size) {
public List<CakeInfoDto> findLatestLikedCakesByUser (final Long userId,
final Long cakeIdCursor,
final int size) {
return cakeRepository.findLatestLikedCakesByUser(userId, cakeIdCursor, size);
}
public List<CakeByPopularityDto> findCakesByPopularity(final Long userId) {
return cakeRepository.findCakesByPopularity(userId);

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ public interface CakeRepository extends JpaRepository<Cake, Long>, CakeRepositor
"JOIN Store s ON c.storeId = s.id " +
"GROUP BY c.id, c.storeId, c.imageUrl, s.name, s.station " +
"ORDER BY COUNT(cl.id) DESC, c.id ASC LIMIT 10")
List<CakeByPopularityDto> findCakesByPopularity(@Param("userId") Long userId);
List<CakeByPopularityDto> findCakesByLank(@Param("userId") Long userId);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.cakey.cakelike.facade;

import com.cakey.cakelike.domain.CakeLikes;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

Expand All @@ -12,6 +13,10 @@ public boolean existsCakeLikesByCakeIdAndUserId(Long cakeId, Long userId) {
return cakeLikesRetriever.existsCakeLikesByCakeIdAndUserId(cakeId, userId);
}

public void saveCakeLikes(CakeLikes cakeLikes) {
cakeLikesRetriever.saveCakeLikes(cakeLikes);
}

public int countByUserId(final Long userId) {
return cakeLikesRetriever.countByUserId(userId);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.cakey.cakelike.facade;

import com.cakey.cakelike.domain.CakeLikes;
import com.cakey.cakelike.repository.CakeLikesRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
Expand All @@ -13,8 +14,11 @@ public boolean existsCakeLikesByCakeIdAndUserId(Long cakeId, Long userId) {
return cakeLikesRepository.existsByCakeIdAndUserId(cakeId, userId);
}

public void saveCakeLikes(CakeLikes cakeLikes) {
cakeLikesRepository.save(cakeLikes);
}

public int countByUserId(final Long userId) {
return cakeLikesRepository.countByUserId(userId);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public StoreDetailInfoDto findStoreDetailInfo(final Long storeId) {
return new StoreDetailInfoDto(store.getAddress(), store.getPhone());
}

public List<StoreByPopularityDto> findStoreListByPopularity() {
return storeRetriever.findStoreListByPopularity();
public List<StoreByPopularityDto> findStoreListByLank() {
return storeRetriever.findStoreListByLank();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public Store findById(final Long storeId) {
.orElseThrow(() -> new NotFoundException());
}

public List<StoreByPopularityDto> findStoreListByPopularity(){
public List<StoreByPopularityDto> findStoreListByLank(){
return storeRepository.findStoresByLikeCount();
}
}

0 comments on commit 1041ec6

Please sign in to comment.