diff --git a/src/apis/product/ProductClient.ts b/src/apis/product/ProductClient.ts index 1e1336d5..a746596b 100644 --- a/src/apis/product/ProductClient.ts +++ b/src/apis/product/ProductClient.ts @@ -3,6 +3,7 @@ import { defaultAxiosInstance } from '@/apis/utils' import type { ReadCacheProductListResponse, ReadProductDetailResponse, + ReadProductSearchResponse, ReadProductSliceResponse } from '@/apis/product/ProductDto' import { openInternalServerErrorNotification } from '@/utils/Toast' @@ -11,6 +12,32 @@ import { warningModal } from '@/utils/Modal' const PRODUCT_SERVICE_PREFIX: string = '/product-service' const PRODUCT_PREFIX: string = '/products' +export const searchProducts = async (query: string): Promise => { + try { + const { data } = await defaultAxiosInstance.get( + `${PRODUCT_SERVICE_PREFIX}${PRODUCT_PREFIX}/search`, + { + params: { query: query } + } + ) + return data + } catch (error) { + if (error instanceof AxiosError) { + if (error.response) { + if (error.response.status >= 400 && error.response.status < 500) { + await warningModal('알림', error.response.data.message) + console.error(`Client Error=${error.response.data.message}`) + } + if (error.response.status >= 500) { + openInternalServerErrorNotification() + console.error('Internal Server Error') + } + } + } + throw error + } +} + export const getProductSlice = async ( brandId: number | null, categoryId: number | null, diff --git a/src/apis/product/ProductDto.ts b/src/apis/product/ProductDto.ts index d23a6e37..57b58b85 100644 --- a/src/apis/product/ProductDto.ts +++ b/src/apis/product/ProductDto.ts @@ -3,6 +3,10 @@ export interface ReadProductSliceResponse { productResponses: ReadProductResponse[] } +export interface ReadProductSearchResponse { + productResponses: ReadProductResponse[] +} + export interface ExtendedReadProductResponse extends ReadProductResponse { categoryId: number } diff --git a/src/components/HeaderComponent.vue b/src/components/HeaderComponent.vue index 8f6b8869..c37c34b3 100644 --- a/src/components/HeaderComponent.vue +++ b/src/components/HeaderComponent.vue @@ -17,7 +17,6 @@ const notificationStore = useNotificationStore() const { notifications, unreadNotificationCount } = storeToRefs(notificationStore) const memberStore = useMemberStore() -// const { } = storeToRefs(memberStore) const categoryStore = useCategoryStore() const brandStore = useBrandStore() @@ -46,7 +45,7 @@ const routeSearch = () => { if (searchQuery.value === null) { infoModal('알림', '검색 키워드를 입력해주세요.') } else { - window.location.href = `/product-list?query=${searchQuery.value}` + window.location.href = `/product-search?query=${searchQuery.value}` searchQuery.value = null } } @@ -275,4 +274,4 @@ onMounted(async () => { \ No newline at end of file + diff --git a/src/components/SpinnerComponent.vue b/src/components/SpinnerComponent.vue new file mode 100644 index 00000000..4e2353ab --- /dev/null +++ b/src/components/SpinnerComponent.vue @@ -0,0 +1,26 @@ + + + + + diff --git a/src/router/index.ts b/src/router/index.ts index 0c020b4b..34353963 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -26,6 +26,11 @@ const router = createRouter({ name: 'productList', component: () => import('@/views/ProductListView.vue') }, + { + path: '/product-search', + name: 'productSearch', + component: () => import('@/views/ProductSearchView.vue') + }, { path: '/products/:id', name: 'productDetails', @@ -223,8 +228,8 @@ router.beforeEach((to, from, next) => { }) const isLoggedIn = () => { - const token = localStorage.getItem('accessToken') - return !!token + const token = localStorage.getItem('accessToken') + return !!token } export default router diff --git a/src/views/ProductListView.vue b/src/views/ProductListView.vue index 010c16cb..d31ea827 100644 --- a/src/views/ProductListView.vue +++ b/src/views/ProductListView.vue @@ -36,10 +36,6 @@ const initData = async () => { categoryId.value = Number(route.query.category) } - if (route.query.query) { - query.value = String(route.query.query) - } - const response: ReadProductSliceResponse = await getProductSlice( brandId.value, categoryId.value, @@ -643,4 +639,4 @@ const getProductMaxDiscountPercentage = (product: ReadProductResponse) => { width: 10vw; height: 19.5vh; } - \ No newline at end of file + diff --git a/src/views/ProductSearchView.vue b/src/views/ProductSearchView.vue new file mode 100644 index 00000000..a7cfcdc2 --- /dev/null +++ b/src/views/ProductSearchView.vue @@ -0,0 +1,264 @@ + + + + +