From 27e6392de2a51784388651cb30d00cc05eb8babd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=95=88=EC=A0=95=ED=9B=84?= Date: Sun, 21 Jul 2024 23:34:44 +0900 Subject: [PATCH 1/3] fix: user token duration --- .../apimodule/user/application/LoginUseCase.java | 5 +++-- .../apimodule/user/presentation/UserController.java | 9 +++++---- api-module/src/main/resources/application-prod.yml | 4 ++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/api-module/src/main/java/com/likelion/apimodule/user/application/LoginUseCase.java b/api-module/src/main/java/com/likelion/apimodule/user/application/LoginUseCase.java index fd67d3f..f12cf3b 100644 --- a/api-module/src/main/java/com/likelion/apimodule/user/application/LoginUseCase.java +++ b/api-module/src/main/java/com/likelion/apimodule/user/application/LoginUseCase.java @@ -4,6 +4,7 @@ import com.likelion.apimodule.user.dto.KakaoLoginRequest; import com.likelion.coremodule.user.application.KakaoIdTokenDecodeService; import com.likelion.coremodule.user.domain.User; +import com.likelion.coremodule.user.dto.LoginAddResponse; import com.likelion.coremodule.user.dto.LoginResponse; import com.likelion.coremodule.user.dto.OidcDecodePayload; import com.likelion.coremodule.user.repository.UserRepository; @@ -21,14 +22,14 @@ public class LoginUseCase { private final JwtUtil jwtUtil; @Transactional(propagation = Propagation.REQUIRES_NEW) - public LoginResponse kakaoLogin(final KakaoLoginRequest kakaoLoginRequest) { + public LoginAddResponse kakaoLogin(final KakaoLoginRequest kakaoLoginRequest) { // ID 토큰으로 찾아온 유저 정보 final OidcDecodePayload oidcDecodePayload = kakaoIdTokenDecodeService.getPayloadFromIdToken(kakaoLoginRequest.idToken()); final User user = userRepository.findBySubId(oidcDecodePayload.sub()) .orElseGet(() -> createNewKakaoUser(oidcDecodePayload)); - return new LoginResponse(jwtUtil.createJwtAccessToken(oidcDecodePayload.email(), oidcDecodePayload.sub()), + return new LoginAddResponse(user.getName(), jwtUtil.createJwtAccessToken(oidcDecodePayload.email(), oidcDecodePayload.sub()), jwtUtil.createJwtRefreshToken(oidcDecodePayload.email(), oidcDecodePayload.sub())); } diff --git a/api-module/src/main/java/com/likelion/apimodule/user/presentation/UserController.java b/api-module/src/main/java/com/likelion/apimodule/user/presentation/UserController.java index 4bda35b..d0354be 100644 --- a/api-module/src/main/java/com/likelion/apimodule/user/presentation/UserController.java +++ b/api-module/src/main/java/com/likelion/apimodule/user/presentation/UserController.java @@ -4,6 +4,7 @@ import com.likelion.apimodule.user.dto.KakaoLoginRequest; import com.likelion.commonmodule.exception.common.ApplicationResponse; import com.likelion.commonmodule.security.util.AuthConsts; +import com.likelion.coremodule.user.dto.LoginAddResponse; import com.likelion.coremodule.user.dto.LoginResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.responses.ApiResponse; @@ -34,8 +35,8 @@ public class UserController { } ) @Operation(summary = "카카오 로그인 API", description = "카카오 로그인 API입니다.") - public ApplicationResponse kakaoLogin(@Valid @RequestBody KakaoLoginRequest kakaoLoginRequest) { - LoginResponse response = loginUseCase.kakaoLogin(kakaoLoginRequest); + public ApplicationResponse kakaoLogin(@Valid @RequestBody KakaoLoginRequest kakaoLoginRequest) { + LoginAddResponse response = loginUseCase.kakaoLogin(kakaoLoginRequest); return ApplicationResponse.ok(response); } @@ -67,9 +68,9 @@ public ApplicationResponse reissue(@RequestHeader(AuthConsts.REFR ) @Operation(summary = "로그아웃 API", description = "로그아웃 API입니다.") public ApplicationResponse logout(@RequestHeader(AuthConsts.REFRESH_TOKEN_HEADER) String refreshToken, - @RequestParam String name) { + @RequestParam String nickname) { - loginUseCase.logout(refreshToken, name); + loginUseCase.logout(refreshToken, nickname); return ApplicationResponse.ok("로그아웃 되었습니다."); } } diff --git a/api-module/src/main/resources/application-prod.yml b/api-module/src/main/resources/application-prod.yml index e229a55..93ef035 100644 --- a/api-module/src/main/resources/application-prod.yml +++ b/api-module/src/main/resources/application-prod.yml @@ -22,8 +22,8 @@ security: jwt: secret: aGFuZXVtLWZvb2Rnby1qd3Qtc2VjcmV0LWtleQo= token: - access-expiration-time: 86400 - refresh-expiration-time: 604800 + access-expiration-time: 86400000 # 24*60*60*1000 = 1일 + refresh-expiration-time: 604800000 # 7*24*60*60*1000 = 7일 logging: level: From 5d3c09957f605d01ffe85896da03deaa7721a6f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=95=88=EC=A0=95=ED=9B=84?= Date: Sun, 21 Jul 2024 23:35:07 +0900 Subject: [PATCH 2/3] feat: store api --- .github/workflows/cd.yml | 2 +- .../market/application/MarketInfoUseCase.java | 7 ++++-- .../market/presentation/MarketController.java | 22 +++++++++++-------- .../store/application/StoreInfoUseCase.java | 17 +++++++++++--- .../apimodule/store/dto/StoreResponse.java | 9 ++++++++ 5 files changed, 42 insertions(+), 15 deletions(-) create mode 100644 api-module/src/main/java/com/likelion/apimodule/store/dto/StoreResponse.java diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 0e55d1b..3987bdc 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -2,7 +2,7 @@ name: Backend CD # actions 이름 on: push: - branches: [ feat/login-update ] + branches: [ feat/market-info ] jobs: deploy: diff --git a/api-module/src/main/java/com/likelion/apimodule/market/application/MarketInfoUseCase.java b/api-module/src/main/java/com/likelion/apimodule/market/application/MarketInfoUseCase.java index 723ad55..213091b 100644 --- a/api-module/src/main/java/com/likelion/apimodule/market/application/MarketInfoUseCase.java +++ b/api-module/src/main/java/com/likelion/apimodule/market/application/MarketInfoUseCase.java @@ -2,6 +2,7 @@ import com.likelion.apimodule.market.dto.MarketInfo; import com.likelion.apimodule.market.dto.VisitListInfo; +import com.likelion.apimodule.security.util.JwtUtil; import com.likelion.coremodule.VisitList.domain.VisitList; import com.likelion.coremodule.VisitList.service.VisitListQueryService; import com.likelion.coremodule.market.domain.Market; @@ -21,6 +22,7 @@ public class MarketInfoUseCase { private final MarketQueryService marketQueryService; private final VisitListQueryService visitListQueryService; private final StoreQueryService storeQueryService; + private final JwtUtil jwtUtil; public MarketInfo findMarketInfo() { @@ -33,9 +35,10 @@ public MarketInfo findMarketInfo() { market.getContact()); } - public void saveVisitList(Long storeId) { + public void saveVisitList(Long storeId, String accessToken) { - marketQueryService.saveVisitList(storeId); + String email = jwtUtil.getEmail(accessToken); + marketQueryService.saveVisitList(storeId, email); } public List findVisitList() { diff --git a/api-module/src/main/java/com/likelion/apimodule/market/presentation/MarketController.java b/api-module/src/main/java/com/likelion/apimodule/market/presentation/MarketController.java index e62ad50..02e32a2 100644 --- a/api-module/src/main/java/com/likelion/apimodule/market/presentation/MarketController.java +++ b/api-module/src/main/java/com/likelion/apimodule/market/presentation/MarketController.java @@ -4,8 +4,9 @@ import com.likelion.apimodule.market.dto.MarketInfo; import com.likelion.apimodule.market.dto.VisitListInfo; import com.likelion.apimodule.store.application.StoreInfoUseCase; +import com.likelion.apimodule.store.dto.StoreResponse; import com.likelion.commonmodule.exception.common.ApplicationResponse; -import com.likelion.coremodule.store.domain.Store; +import com.likelion.commonmodule.security.util.AuthConsts; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; @@ -26,6 +27,7 @@ public class MarketController { private final MarketInfoUseCase marketInfoUseCase; private final StoreInfoUseCase storeInfoUseCase; + // 시장 정보 @GetMapping("/info") @ApiResponses( value = { @@ -36,7 +38,7 @@ public class MarketController { ) } ) - @Operation(summary = "시장 정보 확인 API", description = "시장 정보 확인 API입니다.") + @Operation(summary = "시장 정보 확인 API", description = "시장 정보 확인 API 입니다.") public ApplicationResponse getMarketInfo() { MarketInfo infos = marketInfoUseCase.findMarketInfo(); @@ -54,10 +56,11 @@ public ApplicationResponse getMarketInfo() { ) } ) - @Operation(summary = "가게 검색 API", description = "가게 검색 API입니다.") - public ApplicationResponse> findStoreByFilter(@RequestParam String search, @RequestParam String category) { + @Operation(summary = "가게 검색 API", description = "가게 검색 API 입니다.") + public ApplicationResponse> findStoreByFilter(@RequestParam(required = false) String search, + @RequestParam(required = false) String category) { - final List storeByFilter = storeInfoUseCase.findStoreByFilter(search, category); + final List storeByFilter = storeInfoUseCase.findStoreByFilter(search, category); return ApplicationResponse.ok(storeByFilter); } @@ -72,10 +75,11 @@ public ApplicationResponse> findStoreByFilter(@RequestParam String s ) } ) - @Operation(summary = "방문 리스트 추가 API", description = "방문 리스트 추가 API입니다.") - public ApplicationResponse saveVisitList(@PathVariable Long storeId) { + @Operation(summary = "방문 리스트 추가 API", description = "방문 리스트 추가 API 입니다.") + public ApplicationResponse saveVisitList(@PathVariable Long storeId, + @RequestHeader(AuthConsts.ACCESS_TOKEN_HEADER) String accessToken) { - marketInfoUseCase.saveVisitList(storeId); + marketInfoUseCase.saveVisitList(storeId, accessToken); return ApplicationResponse.ok("방문 리스트 추가 완료"); } @@ -90,7 +94,7 @@ public ApplicationResponse saveVisitList(@PathVariable Long storeId) { ) } ) - @Operation(summary = "방문 리스트 조회 API", description = "방문 리스트 조회 API입니다.") + @Operation(summary = "방문 리스트 조회 API", description = "방문 리스트 조회 API 입니다.") public ApplicationResponse> findVisitList() { final List visitList = marketInfoUseCase.findVisitList(); diff --git a/api-module/src/main/java/com/likelion/apimodule/store/application/StoreInfoUseCase.java b/api-module/src/main/java/com/likelion/apimodule/store/application/StoreInfoUseCase.java index 61971ca..2f21e68 100644 --- a/api-module/src/main/java/com/likelion/apimodule/store/application/StoreInfoUseCase.java +++ b/api-module/src/main/java/com/likelion/apimodule/store/application/StoreInfoUseCase.java @@ -1,5 +1,6 @@ package com.likelion.apimodule.store.application; +import com.likelion.apimodule.store.dto.StoreResponse; import com.likelion.coremodule.store.domain.Store; import com.likelion.coremodule.store.domain.StoreCategory; import com.likelion.coremodule.store.exception.StoreErrorCode; @@ -8,6 +9,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import java.util.ArrayList; import java.util.List; @Service @@ -16,12 +18,13 @@ public class StoreInfoUseCase { private final StoreQueryService storeQueryService; - public List findStoreByFilter(String search, String category) { + public List findStoreByFilter(String search, String category) { + List response = new ArrayList<>(); List storeList = storeQueryService.findAllStore(); if ((search == null || search.isEmpty()) && (category == null || category.isEmpty())) { - return storeList; + return response; } StoreCategory storeCategory = null; @@ -35,10 +38,18 @@ public List findStoreByFilter(String search, String category) { final StoreCategory finalStoreCategory = storeCategory; - return storeList.stream() + final List list = storeList.stream() .filter(store -> (search == null || search.isEmpty() || store.getName().contains(search))) .filter(store -> (finalStoreCategory == null || store.getCategory() == finalStoreCategory)) .toList(); + + for (Store store : list) { + StoreResponse ex = new StoreResponse(store.getName(), finalStoreCategory, store.getLocation(), store.getOpenHours()); + response.add(ex); + } + + return response; } + } diff --git a/api-module/src/main/java/com/likelion/apimodule/store/dto/StoreResponse.java b/api-module/src/main/java/com/likelion/apimodule/store/dto/StoreResponse.java new file mode 100644 index 0000000..4e78836 --- /dev/null +++ b/api-module/src/main/java/com/likelion/apimodule/store/dto/StoreResponse.java @@ -0,0 +1,9 @@ +package com.likelion.apimodule.store.dto; + +import com.likelion.coremodule.store.domain.StoreCategory; + +public record StoreResponse(String name, + StoreCategory category, + String location, + String openHours) { +} From 94aa73efb496b00ba9cc1ed9f88fb9c280e88fcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=95=88=EC=A0=95=ED=9B=84?= Date: Sun, 21 Jul 2024 23:35:19 +0900 Subject: [PATCH 3/3] feat: store core module --- .../commonmodule/security/util/AuthConsts.java | 1 + .../coremodule/VisitList/domain/VisitList.java | 5 ++--- .../market/service/MarketQueryService.java | 5 +---- .../com/likelion/coremodule/store/domain/Store.java | 1 - .../coremodule/user/dto/LoginAddResponse.java | 12 ++++++++++++ 5 files changed, 16 insertions(+), 8 deletions(-) create mode 100644 core-module/src/main/java/com/likelion/coremodule/user/dto/LoginAddResponse.java diff --git a/common-module/src/main/java/com/likelion/commonmodule/security/util/AuthConsts.java b/common-module/src/main/java/com/likelion/commonmodule/security/util/AuthConsts.java index a4dd65a..a85e408 100644 --- a/common-module/src/main/java/com/likelion/commonmodule/security/util/AuthConsts.java +++ b/common-module/src/main/java/com/likelion/commonmodule/security/util/AuthConsts.java @@ -9,5 +9,6 @@ public class AuthConsts { public static final String AUTHORIZATION = "Authorization"; public static final String EMPTY_HEADER = null; public static final String REFRESH_TOKEN_HEADER = "RefreshToken"; + public static final String ACCESS_TOKEN_HEADER = "AccessToken"; public static final String AUTHENTICATION_TYPE_PREFIX = AUTHENTICATION_TYPE+" "; } diff --git a/core-module/src/main/java/com/likelion/coremodule/VisitList/domain/VisitList.java b/core-module/src/main/java/com/likelion/coremodule/VisitList/domain/VisitList.java index 5871e78..a49dad3 100644 --- a/core-module/src/main/java/com/likelion/coremodule/VisitList/domain/VisitList.java +++ b/core-module/src/main/java/com/likelion/coremodule/VisitList/domain/VisitList.java @@ -1,6 +1,5 @@ package com.likelion.coremodule.VisitList.domain; -import com.likelion.coremodule.market.domain.Market; import com.likelion.coremodule.store.domain.Store; import com.likelion.coremodule.user.domain.User; import jakarta.persistence.*; @@ -18,11 +17,11 @@ public class VisitList { @Column(name = "visit_id") private Long id; - @OneToOne(fetch = FetchType.LAZY) + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "store_id") private Store store; - @OneToOne(fetch = FetchType.LAZY) + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "user_id") private User user; diff --git a/core-module/src/main/java/com/likelion/coremodule/market/service/MarketQueryService.java b/core-module/src/main/java/com/likelion/coremodule/market/service/MarketQueryService.java index 979dcda..a95a333 100644 --- a/core-module/src/main/java/com/likelion/coremodule/market/service/MarketQueryService.java +++ b/core-module/src/main/java/com/likelion/coremodule/market/service/MarketQueryService.java @@ -11,7 +11,6 @@ import com.likelion.coremodule.store.service.StoreQueryService; import com.likelion.coremodule.user.application.UserQueryService; import com.likelion.coremodule.user.domain.User; -import com.likelion.coremodule.user.util.UserUtils; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -28,11 +27,9 @@ public Market findMarket(Long id) { return marketRepository.findById(id).orElseThrow(() -> new MarketException(MarketErrorCode.NO_MARKET_INFO)); } - public void saveVisitList(Long storeId) { + public void saveVisitList(Long storeId, String email) { - String email = UserUtils.getEmailFromAccessUser(); User user = userQueryService.findByEmail(email); - Store store = storeQueryService.findStoreById(storeId); final VisitList visitList = VisitList.builder() diff --git a/core-module/src/main/java/com/likelion/coremodule/store/domain/Store.java b/core-module/src/main/java/com/likelion/coremodule/store/domain/Store.java index 8151c9d..c68e9cf 100644 --- a/core-module/src/main/java/com/likelion/coremodule/store/domain/Store.java +++ b/core-module/src/main/java/com/likelion/coremodule/store/domain/Store.java @@ -6,7 +6,6 @@ @Builder @Getter -@Setter @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor @Entity diff --git a/core-module/src/main/java/com/likelion/coremodule/user/dto/LoginAddResponse.java b/core-module/src/main/java/com/likelion/coremodule/user/dto/LoginAddResponse.java new file mode 100644 index 0000000..f392257 --- /dev/null +++ b/core-module/src/main/java/com/likelion/coremodule/user/dto/LoginAddResponse.java @@ -0,0 +1,12 @@ +package com.likelion.coremodule.user.dto; + +import io.swagger.v3.oas.annotations.media.Schema; + +public record LoginAddResponse( + String nickname, + @Schema(description = "액세스 토큰", example = "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ0ZXN0QGdtYWlsLmNvbSIs", defaultValue = "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ0ZXN0QGdtYWlsLmNvbSIs") + String accessToken, + @Schema(description = "리프레시 토큰", example = "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ0ZXN0QGdtYWlsLmNvbSIs", defaultValue = "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ0ZXN0QGdtYWlsLmNvbSIs") + String refreshToken +) { +}