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/search with gpt #270

Merged
merged 2 commits into from
Jan 24, 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
27 changes: 27 additions & 0 deletions src/apis/product/ProductClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { defaultAxiosInstance } from '@/apis/utils'
import type {
ReadCacheProductListResponse,
ReadProductDetailResponse,
ReadProductSearchResponse,
ReadProductSliceResponse
} from '@/apis/product/ProductDto'
import { openInternalServerErrorNotification } from '@/utils/Toast'
Expand All @@ -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<ReadProductSearchResponse> => {
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,
Expand Down
4 changes: 4 additions & 0 deletions src/apis/product/ProductDto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ export interface ReadProductSliceResponse {
productResponses: ReadProductResponse[]
}

export interface ReadProductSearchResponse {
productResponses: ReadProductResponse[]
}

export interface ExtendedReadProductResponse extends ReadProductResponse {
categoryId: number
}
Expand Down
5 changes: 2 additions & 3 deletions src/components/HeaderComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const notificationStore = useNotificationStore()
const { notifications, unreadNotificationCount } = storeToRefs(notificationStore)

const memberStore = useMemberStore()
// const { } = storeToRefs(memberStore)
const categoryStore = useCategoryStore()
const brandStore = useBrandStore()

Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -275,4 +274,4 @@ onMounted(async () => {

<style scoped>
@import '@/assets/header.css';
</style>
</style>
26 changes: 26 additions & 0 deletions src/components/SpinnerComponent.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<script setup lang="ts"></script>

<template>
<div class="spinner" />
</template>

<style scoped>
.spinner {
border: 16px solid #f3f3f3;
border-top: 16px solid #c22727;
border-radius: 50%;
width: 120px;
height: 120px;
animation: spin 2s linear infinite;
background-color: rgba(0, 0, 0, 0.1);
}

@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
</style>
9 changes: 7 additions & 2 deletions src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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
6 changes: 1 addition & 5 deletions src/views/ProductListView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -643,4 +639,4 @@ const getProductMaxDiscountPercentage = (product: ReadProductResponse) => {
width: 10vw;
height: 19.5vh;
}
</style>
</style>
Loading
Loading