Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/market info #9

Merged
merged 3 commits into from
Jul 21, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Backend CD # actions 이름

on:
push:
branches: [ feat/login-update ]
branches: [ feat/market-info ]

jobs:
deploy:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {

Expand All @@ -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<VisitListInfo> findVisitList() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,6 +27,7 @@ public class MarketController {
private final MarketInfoUseCase marketInfoUseCase;
private final StoreInfoUseCase storeInfoUseCase;

// μ‹œμž₯ 정보
@GetMapping("/info")
@ApiResponses(
value = {
Expand All @@ -36,7 +38,7 @@ public class MarketController {
)
}
)
@Operation(summary = "μ‹œμž₯ 정보 확인 API", description = "μ‹œμž₯ 정보 확인 APIμž…λ‹ˆλ‹€.")
@Operation(summary = "μ‹œμž₯ 정보 확인 API", description = "μ‹œμž₯ 정보 확인 API μž…λ‹ˆλ‹€.")
public ApplicationResponse<MarketInfo> getMarketInfo() {

MarketInfo infos = marketInfoUseCase.findMarketInfo();
Expand All @@ -54,10 +56,11 @@ public ApplicationResponse<MarketInfo> getMarketInfo() {
)
}
)
@Operation(summary = "κ°€κ²Œ 검색 API", description = "κ°€κ²Œ 검색 APIμž…λ‹ˆλ‹€.")
public ApplicationResponse<List<Store>> findStoreByFilter(@RequestParam String search, @RequestParam String category) {
@Operation(summary = "κ°€κ²Œ 검색 API", description = "κ°€κ²Œ 검색 API μž…λ‹ˆλ‹€.")
public ApplicationResponse<List<StoreResponse>> findStoreByFilter(@RequestParam(required = false) String search,
@RequestParam(required = false) String category) {

final List<Store> storeByFilter = storeInfoUseCase.findStoreByFilter(search, category);
final List<StoreResponse> storeByFilter = storeInfoUseCase.findStoreByFilter(search, category);
return ApplicationResponse.ok(storeByFilter);
}

Expand All @@ -72,10 +75,11 @@ public ApplicationResponse<List<Store>> findStoreByFilter(@RequestParam String s
)
}
)
@Operation(summary = "λ°©λ¬Έ 리슀트 μΆ”κ°€ API", description = "λ°©λ¬Έ 리슀트 μΆ”κ°€ APIμž…λ‹ˆλ‹€.")
public ApplicationResponse<String> saveVisitList(@PathVariable Long storeId) {
@Operation(summary = "λ°©λ¬Έ 리슀트 μΆ”κ°€ API", description = "λ°©λ¬Έ 리슀트 μΆ”κ°€ API μž…λ‹ˆλ‹€.")
public ApplicationResponse<String> saveVisitList(@PathVariable Long storeId,
@RequestHeader(AuthConsts.ACCESS_TOKEN_HEADER) String accessToken) {

marketInfoUseCase.saveVisitList(storeId);
marketInfoUseCase.saveVisitList(storeId, accessToken);
return ApplicationResponse.ok("λ°©λ¬Έ 리슀트 μΆ”κ°€ μ™„λ£Œ");
}

Expand All @@ -90,7 +94,7 @@ public ApplicationResponse<String> saveVisitList(@PathVariable Long storeId) {
)
}
)
@Operation(summary = "λ°©λ¬Έ 리슀트 쑰회 API", description = "λ°©λ¬Έ 리슀트 쑰회 APIμž…λ‹ˆλ‹€.")
@Operation(summary = "λ°©λ¬Έ 리슀트 쑰회 API", description = "λ°©λ¬Έ 리슀트 쑰회 API μž…λ‹ˆλ‹€.")
public ApplicationResponse<List<VisitListInfo>> findVisitList() {

final List<VisitListInfo> visitList = marketInfoUseCase.findVisitList();
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -8,6 +9,7 @@
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

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

@Service
Expand All @@ -16,12 +18,13 @@ public class StoreInfoUseCase {

private final StoreQueryService storeQueryService;

public List<Store> findStoreByFilter(String search, String category) {
public List<StoreResponse> findStoreByFilter(String search, String category) {

List<StoreResponse> response = new ArrayList<>();
List<Store> storeList = storeQueryService.findAllStore();

if ((search == null || search.isEmpty()) && (category == null || category.isEmpty())) {
return storeList;
return response;
}

StoreCategory storeCategory = null;
Expand All @@ -35,10 +38,18 @@ public List<Store> findStoreByFilter(String search, String category) {

final StoreCategory finalStoreCategory = storeCategory;

return storeList.stream()
final List<Store> 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;
}


}
Original file line number Diff line number Diff line change
@@ -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) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -34,8 +35,8 @@ public class UserController {
}
)
@Operation(summary = "카카였 둜그인 API", description = "카카였 둜그인 APIμž…λ‹ˆλ‹€.")
public ApplicationResponse<LoginResponse> kakaoLogin(@Valid @RequestBody KakaoLoginRequest kakaoLoginRequest) {
LoginResponse response = loginUseCase.kakaoLogin(kakaoLoginRequest);
public ApplicationResponse<LoginAddResponse> kakaoLogin(@Valid @RequestBody KakaoLoginRequest kakaoLoginRequest) {
LoginAddResponse response = loginUseCase.kakaoLogin(kakaoLoginRequest);
return ApplicationResponse.ok(response);
}

Expand Down Expand Up @@ -67,9 +68,9 @@ public ApplicationResponse<LoginResponse> reissue(@RequestHeader(AuthConsts.REFR
)
@Operation(summary = "λ‘œκ·Έμ•„μ›ƒ API", description = "λ‘œκ·Έμ•„μ›ƒ APIμž…λ‹ˆλ‹€.")
public ApplicationResponse<String> 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("λ‘œκ·Έμ•„μ›ƒ λ˜μ—ˆμŠ΅λ‹ˆλ‹€.");
}
}
4 changes: 2 additions & 2 deletions api-module/src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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+" ";
}
Original file line number Diff line number Diff line change
@@ -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.*;
Expand All @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

@Builder
@Getter
@Setter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
@Entity
Expand Down
Original file line number Diff line number Diff line change
@@ -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
) {
}
Loading