Skip to content

Commit

Permalink
merge: 코드 정리, 배포 log - #140
Browse files Browse the repository at this point in the history
[REFAC] 코드 정리, 배포 log  - #140
  • Loading branch information
sjk4618 authored Jan 23, 2025
2 parents 4b36830 + b23be53 commit c1c01bf
Show file tree
Hide file tree
Showing 28 changed files with 148 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.cakey.store.facade.StoreFacade;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.stream.Collectors;
Expand All @@ -25,6 +26,7 @@ public class CakeService {
private final StoreFacade storeFacade;

//해당역 스토어의 케이크들 조회(최신순)
@Transactional(readOnly = true)
public CakesLatestListRes getLatestCakesByStationStore(final Long userId,
final Station station,
final Long cakeIdCursor,
Expand Down Expand Up @@ -61,6 +63,7 @@ public CakesLatestListRes getLatestCakesByStationStore(final Long userId,
}

//해당역 디자인(케이크) 조회(인기순)
@Transactional(readOnly = true)
public CakesPopularListRes getPopularCakesByStationStore(final Long userId,
final Station station,
final Integer cakeLikesCursor,
Expand Down Expand Up @@ -110,6 +113,7 @@ public CakeListByPopularityRes getCakeByRank(final Long userId) {


//선택한 디자인(케이크) 조회
@Transactional(readOnly = true)
public CakeSelectedRes getSelectedCakes(final Long cakeId,
final DayCategory dayCategory,
final ThemeName theme,
Expand Down Expand Up @@ -155,6 +159,7 @@ public CakeSelectedRes getSelectedCakes(final Long cakeId,
}

//디자인 둘러보기 조회(최신순)
@Transactional(readOnly = true)
public CakesLatestListRes findCakesByCategoryAndTheme(final DayCategory dayCategory,
final ThemeName theme,
final Long userId,
Expand Down Expand Up @@ -193,6 +198,7 @@ public CakesLatestListRes findCakesByCategoryAndTheme(final DayCategory dayCateg
}

//디자인 둘러보기 조회(인기순)
@Transactional(readOnly = true)
public CakesPopularListRes getPopularCakesByCategoryAndTheme(final DayCategory dayCategory,
final ThemeName themeName,
final Long userId,
Expand Down Expand Up @@ -233,6 +239,7 @@ public CakesPopularListRes getPopularCakesByCategoryAndTheme(final DayCategory d
}

//찜한 스토어들 디자인 조회(최신순)
@Transactional(readOnly = true)
public CakesLatestListRes getLatestCakeByStoreLiked(final long userId,
final Long cakeIdCursor,
final int size) {
Expand Down Expand Up @@ -267,6 +274,7 @@ public CakesLatestListRes getLatestCakeByStoreLiked(final long userId,
}

//찜한 스토어들 디자인 조회(인기순)
@Transactional(readOnly = true)
public CakesPopularListRes getPopularCakeByStoreLiked(final long userId,
final Long cakeIdCursor,
final Integer cakeLikesCursor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@
import com.cakey.cakelikes.dto.CakeLikedLatestRes;
import com.cakey.cakelikes.dto.CakeLikedPopularRes;
import com.cakey.common.exception.NotFoundBaseException;
import jakarta.transaction.Transactional;
import com.cakey.store.exception.StoreConflictBaseException;
import com.cakey.store.exception.StoreErrorCode;
import com.cakey.user.facade.UserFacade;
import lombok.RequiredArgsConstructor;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.stream.Collectors;
Expand All @@ -25,9 +29,11 @@ public class CakeLikesService {

private final CakeFacade cakeFacade;
private final CakeLikesFacade cakeLikesFacade;
private final UserFacade userFacade;
private final CakeLikesRemover cakeLikesRemover;

//찜한 디자인(케이크) 조회(최신순)
@Transactional(readOnly = true)
public CakeLikedLatestRes getLatestCakeLikedByUser(final long userId,
final Long cakeIdCursor,
final Integer size) {
Expand Down Expand Up @@ -65,6 +71,7 @@ public CakeLikedLatestRes getLatestCakeLikedByUser(final long userId,
}

//찜한 디자인(케이크) 조회(인기순)
@Transactional(readOnly = true)
public CakeLikedPopularRes getPopularLikedCakesByUser(final long userId,
final Long cakeIdCursor,
final Integer cakeLikesCursor,
Expand Down Expand Up @@ -103,21 +110,21 @@ public CakeLikedPopularRes getPopularLikedCakesByUser(final long userId,
}



//케이크 좋아요 등록
@Transactional
public void postCakeLike(final long cakeId, final long userId) {
try {
final Cake cake = cakeFacade.findById(cakeId);
cakeFacade.isExistCake(cakeId);
} catch (NotFoundBaseException e) {
throw new CakeyNotFoundException(CakeErrorCode.CAKE_NOT_FOUND_ENTITY);
}

if (!cakeLikesFacade.existsCakeLikesByCakeIdAndUserId(cakeId, userId)) {
try {
final CakeLikes cakeLikes = CakeLikes.createCakeLikes(cakeId, userId);
cakeLikesFacade.saveCakeLikes(cakeLikes);
} else {
throw new CakeyNotFoundException(CakeErrorCode.CAKE_LIKES_CONFLICT);
} catch (DataIntegrityViolationException e) {
throw new StoreConflictBaseException(StoreErrorCode.STORE_LIKES_CONFLICT);
}

}

//케이크 좋아요 취소
Expand Down
5 changes: 0 additions & 5 deletions cakey-api/src/main/java/com/cakey/common/Constant.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package com.cakey.common.filter;

import com.cakey.common.Constant;
import com.cakey.Constants;
import com.cakey.common.response.ApiResponseUtil;
import com.cakey.jwt.auth.JwtProvider;
import com.cakey.jwt.auth.UserAuthentication;
import com.cakey.jwt.auth.JwtValidationType;
import com.cakey.rescode.ErrorBaseCode;
import com.cakey.rescode.ErrorCode;
import com.cakey.user.exception.UserBadRequestException;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.servlet.FilterChain;
Expand All @@ -20,7 +18,6 @@

import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -78,7 +75,7 @@ protected void doFilterInternal(
final ErrorBaseCode errorCode = ErrorBaseCode.UNAUTHORIZED;

response.setContentType(MediaType.APPLICATION_JSON_VALUE);
response.setCharacterEncoding(Constant.CHARACTER_TYPE);
response.setCharacterEncoding(Constants.CHARACTER_TYPE);
response.setStatus(errorCode.getHttpStatus().value()); // HTTP 상태 코드 401 설정

// `ApiResponseUtil.failure`를 이용해 응답 작성
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -60,6 +61,7 @@ public List<StoreCoordinate> getStoreCoordinateList(final Station station) {
}

//지하철역 스토어 리스트 조회(인기순)
@Transactional(readOnly = true)
public StoreInfoListBylikesRes getStoreInfoListByStationAndLikes(final Long userId,
final Station station,
final Integer likesCursor,
Expand Down Expand Up @@ -101,6 +103,7 @@ public StoreInfoListBylikesRes getStoreInfoListByStationAndLikes(final Long user
}

//지하철역 스토어 리스트 조회(최신순)
@Transactional(readOnly = true)
public StoreInfoListByLatestRes getStoreInfoListByStationAndLatest(final Long userId,
final Station station,
final Long storeIdCursor,
Expand Down Expand Up @@ -186,6 +189,7 @@ public StoreKakaoLinkRes getStoreKakaoLink(final long storeId) {
return new StoreKakaoLinkRes(storeKakaoLinkDto.kakaoLink());
}

@Transactional(readOnly = true)
public StoreDetailAllDesignRes getStoreAllDesign(final long storeId, final Long userId) {

final List<Cake> cakes;
Expand Down Expand Up @@ -216,6 +220,7 @@ public StoreDetailAllDesignRes getStoreAllDesign(final long storeId, final Long
return new StoreDetailAllDesignRes(designs);
}

@Transactional(readOnly = true)
public StoreAllSizeAndTasteRes getStoreSizeAndTaste(final long storeId) {
final List<SizeDto> sizeList;
try {
Expand All @@ -226,6 +231,7 @@ public StoreAllSizeAndTasteRes getStoreSizeAndTaste(final long storeId) {
return StoreAllSizeAndTasteRes.of(sizeList, storeFacade.findTaste(storeId).taste());
}

@Transactional(readOnly = true)
public StoreDetailInfoRes getStoreDetailInfo(final long storeId) {
final StoreDetailInfoDto storeDetailInfoDto;
final StoreOperationTimeDto storeOperationTimeDto;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
import com.cakey.store.exception.StoreErrorCode;
import com.cakey.store.exception.StoreNotfoundException;
import com.cakey.store.facade.StoreFacade;
import com.cakey.storelike.domain.StoreLike;
import com.cakey.storelike.facade.StoreLikeFacade;
import com.cakey.storelikes.dto.StoreLatestLikedByUserRes;
import com.cakey.storelikes.dto.StorePopularityLikedByUserRes;
import lombok.RequiredArgsConstructor;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;
Expand All @@ -32,6 +34,7 @@ public class StoreLikesService {
private final StoreLikeFacade storeLikeFacade;

//찜한 스토어 조회(최신순)
@Transactional(readOnly = true)
public StoreLatestLikedByUserRes getLatestStoreLikesByUser(final long userId,
final Long storeIdCursor,
final int size) {
Expand Down Expand Up @@ -71,6 +74,7 @@ public StoreLatestLikedByUserRes getLatestStoreLikesByUser(final long userId,
}

//찜한 스토어 조회(인기순)
@Transactional(readOnly = true)
public StorePopularityLikedByUserRes getPopularityStoreByUserLikes(final long userId,
final Integer likesCursor,
final Long storeIdCursor,
Expand Down Expand Up @@ -158,20 +162,31 @@ public List<StoreCoordinate> getLikedStoreCoordinatesByUserId(final long userId)
}

//스토어 좋아요 등록
@Transactional
public void postStoreLikes(final long userId, final long storeId) {
final StoreLike newStoreLikes;
try {
storeLikeFacade.saveStoreLikes(userId, storeId);
storeFacade.isExistStore(storeId);
} catch (NotFoundBaseException e) {
throw new StoreNotfoundException(StoreErrorCode.STORE_NOT_FOUND_ENTITY);
}
try {
newStoreLikes = StoreLike.createStoreLike(storeId, userId);
storeLikeFacade.saveStoreLikes(newStoreLikes);
} catch (DataIntegrityViolationException e) {
throw new StoreConflictBaseException(StoreErrorCode.STORE_LIKES_CONFLICT);
}
}

//스토어 좋아요 취소
@Transactional
public void deleteStoreLikes(final long userId, final long storeId) {
final StoreLike storeLike;
try {
storeLikeFacade.deleteStoreLikes(userId, storeId);
storeLike = storeLikeFacade.findStoreLikesByUserIdAndStoreId(userId, storeId);
} catch (NotFoundBaseException e) {
throw new StoreNotfoundException(StoreErrorCode.STORE_LIKES_NOT_FOUND_ENTITY);
}
storeLikeFacade.deleteStoreLikes(storeLike);
}
}
11 changes: 6 additions & 5 deletions cakey-api/src/main/java/com/cakey/user/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,14 @@ public LoginSuccessRes login(

//로그아웃
public void logout(final long userId, final HttpServletResponse response) {
if(userRetriever.isExistById(userId)) {
deleteAccessCookie(response);
deleteRefreshCookie(response);
deleteRefreshToken(userId);
} else {
try {
userFacade.isExistById(userId);
} catch (NotFoundBaseException e) {
throw new UserNotFoundException(UserErrorCode.USER_NOT_FOUND);
}
deleteAccessCookie(response);
deleteRefreshCookie(response);
deleteRefreshToken(userId);
}

@CacheEvict(value = "refresh")
Expand Down
2 changes: 1 addition & 1 deletion cakey-api/src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<totalSizeCap>3GB</totalSizeCap>
</rollingPolicy>
</appender>
<root level="DEBUG">
<root level="ERROR">
<appender-ref ref="DEVROLLFILE"/>
</root>
</springProfile>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.cakey.client.kakao.api;

import com.cakey.Constants;
import com.cakey.client.dto.KakaoUserInfoDto;
import com.cakey.client.kakao.api.dto.KakaoAccessTokenRes;
import com.cakey.client.kakao.api.dto.KakaoUserDto;
Expand All @@ -21,7 +22,6 @@ public class KakaoSocialService {
private final KakaoApiClient kakaoApiClient;
private final KakaoAuthApiClient kakaoAuthApiClient;

private static final String AUTH_CODE = "authorization_code";

@Value("${kakao.clientId}")
private String clientId;
Expand All @@ -46,7 +46,7 @@ private String getOAuth2Authentication(
final String redirectUri
) {
final KakaoAccessTokenRes response = kakaoAuthApiClient.getOAuth2AccessToken(
AUTH_CODE,
Constants.AUTHCODE,
clientId,
redirectUri,
authorizationCode
Expand All @@ -59,7 +59,7 @@ private KakaoUserDto getUserInfo(
final String accessToken,
final String contentType
) {
return kakaoApiClient.getUserInformation("Bearer " + accessToken, contentType);
return kakaoApiClient.getUserInformation(Constants.BEARER + accessToken, contentType);
}

private KakaoUserInfoDto getLoginDto(
Expand Down
8 changes: 8 additions & 0 deletions cakey-common/src/main/java/com/cakey/Constants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.cakey;

public abstract class Constants {
public static final String CHARACTER_TYPE = "utf-8";
public static final String BEARER = "Bearer ";
public static final String AUTHCODE = "authorization_code";

}
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,10 @@ public int countAllDesignsLikedByUser(final Long userId) {
return cakeRetriever.countAllDesignsLikedByUser(userId);
}

//케이크 존재여부
public void isExistCake(final long cakeId) {
cakeRetriever.isExistCake(cakeId);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.cakey.store.domain.Station;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

Expand Down Expand Up @@ -48,6 +49,7 @@ public List<CakeInfoDto> findPopularCakesByStation(final Long userId,
return cakeRepository.findPopularCakesByStation(userId, station, likesCursor, cakeIdCursor, size);
}

@Transactional(readOnly = true)
public List<CakeByPopularityDto> findCakesByRank(final Long userId) {
final List<CakeByPopularityDto> cakeByPopularityDtos = cakeRepository.findCakesByRank(userId);
if (cakeByPopularityDtos.isEmpty()) {
Expand Down Expand Up @@ -139,6 +141,11 @@ public int countAllDesignsLikedByUser(final Long userId) {
return cakeRepository.countAllDesignsLikedByUser(userId);
}



//케이크 존재여부
public void isExistCake(final long cakeId) {
boolean isCakeExist = cakeRepository.existsById(cakeId);
if (!isCakeExist) {
throw new NotFoundBaseException();
}
}
}
Loading

0 comments on commit c1c01bf

Please sign in to comment.