From d2b32078d3882c61e2f7fefc969ce82f6b6866f7 Mon Sep 17 00:00:00 2001 From: hoon7566 Date: Mon, 7 Mar 2022 13:45:51 +0900 Subject: [PATCH 1/4] =?UTF-8?q?refactor(customer-vue,=20store-service):=20?= =?UTF-8?q?=EC=A6=90=EA=B2=A8=EC=B0=BE=EA=B8=B0=20=EB=A7=A4=EC=9E=A5=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 즐겨찾기 매장 조회 - 즐겨찾기 테스트 데이터 - 페이지 라우팅 체크 로직 --- .../CustomerApigatewayServiceApplication.java | 8 ++ customer-vue/src/api/store.js | 10 +++ customer-vue/src/router/router.js | 41 ++++++---- customer-vue/src/views/HomeView.vue | 76 +++++++++++++++++-- customer-vue/src/views/LoginPage.vue | 2 +- owner-vue/src/views/Category.vue | 2 +- .../storeservice/StoreServiceApplication.java | 12 ++- .../favoritestore/entity/FavoriteStore.java | 11 ++- .../repository/FavoriteStoreRepository.java | 7 ++ .../domain/store/entity/Store.java | 3 + .../repository/StoreRepositoryCustom.java | 64 +++++++++++----- .../domain/store/service/StoreService.java | 3 + .../store/service/StoreServiceImpl.java | 7 ++ .../store/web/StoreCustomerApiController.java | 63 +++++++++++++++ 14 files changed, 266 insertions(+), 43 deletions(-) create mode 100644 store-service/src/main/java/com/justpickup/storeservice/domain/favoritestore/repository/FavoriteStoreRepository.java create mode 100644 store-service/src/main/java/com/justpickup/storeservice/domain/store/web/StoreCustomerApiController.java diff --git a/customer-apigateway-service/src/main/java/com/justpickup/customerapigatewayservice/CustomerApigatewayServiceApplication.java b/customer-apigateway-service/src/main/java/com/justpickup/customerapigatewayservice/CustomerApigatewayServiceApplication.java index 63fab53..a0a5eff 100644 --- a/customer-apigateway-service/src/main/java/com/justpickup/customerapigatewayservice/CustomerApigatewayServiceApplication.java +++ b/customer-apigateway-service/src/main/java/com/justpickup/customerapigatewayservice/CustomerApigatewayServiceApplication.java @@ -1,8 +1,11 @@ package com.justpickup.customerapigatewayservice; +import com.justpickup.customerapigatewayservice.handler.GlobalExceptionHandler; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.web.reactive.error.ErrorWebExceptionHandler; import org.springframework.cloud.netflix.eureka.EnableEurekaClient; +import org.springframework.context.annotation.Bean; @SpringBootApplication @EnableEurekaClient @@ -12,4 +15,9 @@ public class CustomerApigatewayServiceApplication { SpringApplication.run(CustomerApigatewayServiceApplication.class, args); } + @Bean + public ErrorWebExceptionHandler globalExceptionHandler() { + return new GlobalExceptionHandler(); + } + } diff --git a/customer-vue/src/api/store.js b/customer-vue/src/api/store.js index c1a8b8b..4220284 100644 --- a/customer-vue/src/api/store.js +++ b/customer-vue/src/api/store.js @@ -42,4 +42,14 @@ export default { responseType:'json' }) }, + getFavoriteStore(latitude, longitude,){ + const options = { + params: { + latitude: latitude, + longitude: longitude, + } + } + return axios.get(process.env.VUE_APP_CUSTOMER_SERVICE_BASEURL+'/store-service/api/customer/store/favorite',options) + }, + } \ No newline at end of file diff --git a/customer-vue/src/router/router.js b/customer-vue/src/router/router.js index ffc3523..b468abb 100644 --- a/customer-vue/src/router/router.js +++ b/customer-vue/src/router/router.js @@ -1,5 +1,7 @@ import Vue from 'vue'; import VueRouter from 'vue-router'; +import jwt from "@/common/jwt"; +import auth from "@/api/auth"; import HomeLayout from '../views/Layout/HomeLayout.vue'; const ACCESS_TOKEN_NAME = "accessToken"; @@ -7,9 +9,21 @@ const EXPIRED_TIME_NAME = "expiredTime"; Vue.use(VueRouter); -const auth = async function (to, from, next) { - localStorage.setItem(ACCESS_TOKEN_NAME, to.query.accessToken); - localStorage.setItem(EXPIRED_TIME_NAME, to.query.expiredTime) +const authCheck = async function (to, from, next) { + if(to.path==="/login"){ + next(); + return; + } + try { + if (jwt.isExpired()) { + // refresh 호출 + await auth.requestReissue(); + } else { + await auth.requestCheckAccessToken(); + } + } catch (error) { + await router.replace("/login"); + } next(); }; @@ -17,6 +31,7 @@ const routes = [ { path: '/', redirect: 'home', + beforeEnter: authCheck, component: HomeLayout, children: [ { @@ -28,25 +43,23 @@ const routes = [ path: "/search", name: 'search-store', component: () => import('../views/SearchStore') - } - ] - }, - { - path: '/login', - redirect: 'login', - component: HomeLayout, - children: [ + }, { - path: "/login", + path: '/login', name: 'login', component: () => import('../views/LoginPage') - } + }, ] }, + { path: '/auth', name: 'auth', - beforeEnter: auth, + beforeEnter: async function (to, from, next) { + localStorage.setItem(ACCESS_TOKEN_NAME, to.query.accessToken); + localStorage.setItem(EXPIRED_TIME_NAME, to.query.expiredTime) + next(); + }, component: () => import('../views/Layout/AuthSuccess.vue') }, diff --git a/customer-vue/src/views/HomeView.vue b/customer-vue/src/views/HomeView.vue index 55f0e20..45fb5b7 100644 --- a/customer-vue/src/views/HomeView.vue +++ b/customer-vue/src/views/HomeView.vue @@ -1,13 +1,79 @@ diff --git a/customer-vue/src/views/LoginPage.vue b/customer-vue/src/views/LoginPage.vue index 48e640d..74a76eb 100644 --- a/customer-vue/src/views/LoginPage.vue +++ b/customer-vue/src/views/LoginPage.vue @@ -111,7 +111,7 @@ export default { ); }, - } + }, } diff --git a/owner-vue/src/views/Category.vue b/owner-vue/src/views/Category.vue index 799ff17..79861e7 100644 --- a/owner-vue/src/views/Category.vue +++ b/owner-vue/src/views/Category.vue @@ -1,7 +1,7 @@ @@ -39,10 +33,13 @@ export default { }, data(){ return{ - isLoading: true, latitude:0, longitude:0, - favoriteStoreList:[], + favoriteStoreList:{ + data:[], + isActive:'', + + }, } }, async mounted() { @@ -51,9 +48,9 @@ export default { this.longitude = location.longitude; storeApi.getFavoriteStore(this.latitude,this.longitude) .then(response =>{ - this.favoriteStoreList = response.data.data; + this.favoriteStoreList.isActive = 'd-none' + this.favoriteStoreList.data = response.data.data; }); - this.isLoading = false }, methods:{ getLocation: async function() { From 0ae88dba41836ddb9ef8290a8fb37a7bf4ce95b5 Mon Sep 17 00:00:00 2001 From: hoon7566 Date: Mon, 7 Mar 2022 18:49:09 +0900 Subject: [PATCH 4/4] fix(store-service): solve conflict MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 머지 후 error 해결 --- .../domain/store/web/StoreCustomerApiController.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/store-service/src/main/java/com/justpickup/storeservice/domain/store/web/StoreCustomerApiController.java b/store-service/src/main/java/com/justpickup/storeservice/domain/store/web/StoreCustomerApiController.java index ab9dac6..023e30a 100644 --- a/store-service/src/main/java/com/justpickup/storeservice/domain/store/web/StoreCustomerApiController.java +++ b/store-service/src/main/java/com/justpickup/storeservice/domain/store/web/StoreCustomerApiController.java @@ -9,7 +9,6 @@ import lombok.Data; import lombok.NoArgsConstructor; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; - import org.springframework.data.domain.Pageable; import org.springframework.data.domain.SliceImpl; import org.springframework.data.web.PageableDefault; @@ -38,19 +37,19 @@ public class StoreCustomerApiController { List favoriteStore = storeService.findFavoriteStore(condition,Long.parseLong(userId)); - List searchStoreResponse - = favoriteStore.stream().map(SearchStoreResponse::new).collect(Collectors.toList()); + List searchStoreResponse + = favoriteStore.stream().map(FavoriteStoreResponse::new).collect(Collectors.toList()); return ResponseEntity.status(HttpStatus.OK).body(Result.createSuccessResult(searchStoreResponse)); } @Data @NoArgsConstructor - static class SearchStoreResponse { + static class FavoriteStoreResponse { private Long id; private String name; private String distance; - public SearchStoreResponse(SearchStoreResult storeResult) { + public FavoriteStoreResponse(SearchStoreResult storeResult) { this.id = storeResult.getStoreId(); this.name = storeResult.getStoreName(); this.distance = storeResult.convertDistanceToString();