temp release
This commit is contained in:
parent
de983127a3
commit
56546a7777
@ -8,7 +8,7 @@ const getApiUrls = () => {
|
|||||||
GATEWAY_URL: config.GATEWAY_URL || 'http://20.1.2.3',
|
GATEWAY_URL: config.GATEWAY_URL || 'http://20.1.2.3',
|
||||||
AUTH_URL: 'http://localhost:8081/api/auth',
|
AUTH_URL: 'http://localhost:8081/api/auth',
|
||||||
MEMBER_URL: 'http://localhost:8081/api/member',
|
MEMBER_URL: 'http://localhost:8081/api/member',
|
||||||
STORE_URL: config.STORE_URL || 'http://20.1.2.3/api/store',
|
STORE_URL: config.STORE_URL || 'http://localhost:8082/api/store',
|
||||||
CONTENT_URL: config.CONTENT_URL || 'http://20.1.2.3/api/content',
|
CONTENT_URL: config.CONTENT_URL || 'http://20.1.2.3/api/content',
|
||||||
MENU_URL: config.MENU_URL || 'http://20.1.2.3/api/menu',
|
MENU_URL: config.MENU_URL || 'http://20.1.2.3/api/menu',
|
||||||
SALES_URL: config.SALES_URL || 'http://20.1.2.3/api/sales',
|
SALES_URL: config.SALES_URL || 'http://20.1.2.3/api/sales',
|
||||||
|
|||||||
@ -1,285 +1,153 @@
|
|||||||
//* src/store/index.js
|
//* src/store/index.js - Store 스토어 수정 (매장 조회 부분)
|
||||||
/**
|
|
||||||
* Pinia 스토어 설정
|
|
||||||
* 전역 상태 관리
|
|
||||||
*/
|
|
||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
import authService from '@/services/auth'
|
// 매장 스토어에 추가할 fetchStoreInfo 메서드
|
||||||
import storeService from '@/services/store'
|
|
||||||
|
|
||||||
// 인증 스토어
|
|
||||||
export const useAuthStore = defineStore('auth', {
|
|
||||||
state: () => ({
|
|
||||||
user: null,
|
|
||||||
token: localStorage.getItem('token'),
|
|
||||||
refreshToken: localStorage.getItem('refreshToken'),
|
|
||||||
isAuthenticated: false
|
|
||||||
}),
|
|
||||||
|
|
||||||
getters: {
|
|
||||||
getUserInfo: (state) => state.user,
|
|
||||||
isLoggedIn: (state) => state.isAuthenticated && !!state.token
|
|
||||||
},
|
|
||||||
|
|
||||||
actions: {
|
|
||||||
async login(credentials) {
|
|
||||||
try {
|
|
||||||
const response = await authService.login(credentials)
|
|
||||||
this.setAuth(response.data)
|
|
||||||
return response
|
|
||||||
} catch (error) {
|
|
||||||
this.clearAuth()
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
async register(userData) {
|
|
||||||
try {
|
|
||||||
const response = await authService.register(userData)
|
|
||||||
return response
|
|
||||||
} catch (error) {
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
async logout() {
|
|
||||||
try {
|
|
||||||
if (this.token) {
|
|
||||||
await authService.logout()
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error('로그아웃 오류:', error)
|
|
||||||
} finally {
|
|
||||||
this.clearAuth()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
async refreshUserInfo() {
|
|
||||||
try {
|
|
||||||
const response = await authService.getUserInfo()
|
|
||||||
this.user = response.data
|
|
||||||
this.isAuthenticated = true
|
|
||||||
return response
|
|
||||||
} catch (error) {
|
|
||||||
this.clearAuth()
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
setAuth(authData) {
|
|
||||||
this.user = authData.user
|
|
||||||
this.token = authData.accessToken
|
|
||||||
this.refreshToken = authData.refreshToken
|
|
||||||
this.isAuthenticated = true
|
|
||||||
|
|
||||||
localStorage.setItem('token', authData.accessToken)
|
|
||||||
localStorage.setItem('refreshToken', authData.refreshToken)
|
|
||||||
},
|
|
||||||
|
|
||||||
clearAuth() {
|
|
||||||
this.user = null
|
|
||||||
this.token = null
|
|
||||||
this.refreshToken = null
|
|
||||||
this.isAuthenticated = false
|
|
||||||
|
|
||||||
localStorage.removeItem('token')
|
|
||||||
localStorage.removeItem('refreshToken')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// 앱 전역 스토어
|
|
||||||
export const useAppStore = defineStore('app', {
|
|
||||||
state: () => ({
|
|
||||||
loading: false,
|
|
||||||
snackbar: {
|
|
||||||
show: false,
|
|
||||||
message: '',
|
|
||||||
color: 'success',
|
|
||||||
timeout: 3000
|
|
||||||
},
|
|
||||||
notifications: [],
|
|
||||||
notificationCount: 0
|
|
||||||
}),
|
|
||||||
|
|
||||||
actions: {
|
|
||||||
setLoading(status) {
|
|
||||||
this.loading = status
|
|
||||||
},
|
|
||||||
|
|
||||||
showSnackbar(message, color = 'success', timeout = 3000) {
|
|
||||||
this.snackbar = {
|
|
||||||
show: true,
|
|
||||||
message,
|
|
||||||
color,
|
|
||||||
timeout
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
hideSnackbar() {
|
|
||||||
this.snackbar.show = false
|
|
||||||
},
|
|
||||||
|
|
||||||
addNotification(notification) {
|
|
||||||
this.notifications.unshift({
|
|
||||||
id: Date.now(),
|
|
||||||
timestamp: new Date(),
|
|
||||||
...notification
|
|
||||||
})
|
|
||||||
this.notificationCount = this.notifications.length
|
|
||||||
},
|
|
||||||
|
|
||||||
clearNotifications() {
|
|
||||||
this.notifications = []
|
|
||||||
this.notificationCount = 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// 매장 스토어
|
|
||||||
export const useStoreStore = defineStore('store', {
|
export const useStoreStore = defineStore('store', {
|
||||||
state: () => ({
|
state: () => ({
|
||||||
storeInfo: null,
|
storeInfo: null,
|
||||||
loading: false
|
|
||||||
}),
|
|
||||||
|
|
||||||
getters: {
|
|
||||||
hasStoreInfo: (state) => !!state.storeInfo
|
|
||||||
},
|
|
||||||
|
|
||||||
actions: {
|
|
||||||
setStoreInfo(storeInfo) {
|
|
||||||
this.storeInfo = storeInfo
|
|
||||||
},
|
|
||||||
|
|
||||||
async fetchStoreInfo() {
|
|
||||||
try {
|
|
||||||
this.loading = true
|
|
||||||
const response = await storeService.getStore() // getStoreInfo가 아닌 getStore
|
|
||||||
this.storeInfo = response.data
|
|
||||||
return response
|
|
||||||
} catch (error) {
|
|
||||||
throw error
|
|
||||||
} finally {
|
|
||||||
this.loading = false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
async registerStore(storeData) {
|
|
||||||
try {
|
|
||||||
this.loading = true
|
|
||||||
const response = await storeService.registerStore(storeData)
|
|
||||||
this.storeInfo = response.data
|
|
||||||
return response
|
|
||||||
} catch (error) {
|
|
||||||
throw error
|
|
||||||
} finally {
|
|
||||||
this.loading = false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
async updateStore(storeId, storeData) {
|
|
||||||
try {
|
|
||||||
this.loading = true
|
|
||||||
const response = await storeService.updateStore(storeId, storeData)
|
|
||||||
this.storeInfo = response.data
|
|
||||||
return response
|
|
||||||
} catch (error) {
|
|
||||||
throw error
|
|
||||||
} finally {
|
|
||||||
this.loading = false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
async createStoreInfo(storeData) {
|
|
||||||
try {
|
|
||||||
this.loading = true
|
|
||||||
const response = await storeService.createStoreInfo(storeData)
|
|
||||||
this.storeInfo = response.data
|
|
||||||
return response
|
|
||||||
} catch (error) {
|
|
||||||
throw error
|
|
||||||
} finally {
|
|
||||||
this.loading = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// 메뉴 스토어
|
|
||||||
export const useMenuStore = defineStore('menu', {
|
|
||||||
state: () => ({
|
|
||||||
menus: [],
|
|
||||||
loading: false,
|
loading: false,
|
||||||
totalCount: 0
|
error: null
|
||||||
}),
|
}),
|
||||||
|
|
||||||
getters: {
|
getters: {
|
||||||
getMenuById: (state) => (id) => {
|
hasStoreInfo: (state) => !!state.storeInfo,
|
||||||
return state.menus.find(menu => menu.id === id)
|
isLoading: (state) => state.loading
|
||||||
},
|
|
||||||
|
|
||||||
getMenusByCategory: (state) => (category) => {
|
|
||||||
return state.menus.filter(menu => menu.category === category)
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
async fetchMenus() {
|
/**
|
||||||
try {
|
* 매장 정보 조회
|
||||||
this.loading = true
|
*/
|
||||||
const response = await storeService.getMenus()
|
async fetchStoreInfo() {
|
||||||
this.menus = response.data
|
console.log('=== Store 스토어: 매장 정보 조회 시작 ===')
|
||||||
this.totalCount = response.data.length
|
this.loading = true
|
||||||
return response
|
this.error = null
|
||||||
} catch (error) {
|
|
||||||
throw error
|
|
||||||
} finally {
|
|
||||||
this.loading = false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
async createMenu(menuData) {
|
|
||||||
try {
|
try {
|
||||||
this.loading = true
|
// 스토어 서비스 임포트
|
||||||
const response = await storeService.createMenu(menuData)
|
const { storeService } = await import('@/services/store')
|
||||||
this.menus.push(response.data)
|
|
||||||
this.totalCount++
|
|
||||||
return response
|
|
||||||
} catch (error) {
|
|
||||||
throw error
|
|
||||||
} finally {
|
|
||||||
this.loading = false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
async updateMenu(menuId, menuData) {
|
console.log('매장 정보 API 호출')
|
||||||
try {
|
const result = await storeService.getStore()
|
||||||
this.loading = true
|
|
||||||
const response = await storeService.updateMenu(menuId, menuData)
|
console.log('=== Store 스토어: API 응답 분석 ===')
|
||||||
const index = this.menus.findIndex(menu => menu.id === menuId)
|
console.log('Result:', result)
|
||||||
if (index !== -1) {
|
console.log('Result.success:', result.success)
|
||||||
this.menus[index] = response.data
|
console.log('Result.data:', result.data)
|
||||||
|
console.log('Result.message:', result.message)
|
||||||
|
|
||||||
|
if (result.success && result.data) {
|
||||||
|
// 매장 정보가 있는 경우
|
||||||
|
console.log('✅ 매장 정보 설정:', result.data)
|
||||||
|
this.storeInfo = result.data
|
||||||
|
return { success: true, data: result.data }
|
||||||
|
} else {
|
||||||
|
// 매장이 없거나 조회 실패한 경우
|
||||||
|
console.log('⚠️ 매장 정보 없음 또는 조회 실패')
|
||||||
|
this.storeInfo = null
|
||||||
|
|
||||||
|
if (result.message === '등록된 매장이 없습니다') {
|
||||||
|
return { success: false, message: '등록된 매장이 없습니다' }
|
||||||
|
} else {
|
||||||
|
return { success: false, message: result.message || '매장 정보 조회에 실패했습니다' }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return response
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw error
|
console.error('=== Store 스토어: 매장 정보 조회 실패 ===')
|
||||||
|
console.error('Error:', error)
|
||||||
|
|
||||||
|
this.error = error.message
|
||||||
|
this.storeInfo = null
|
||||||
|
|
||||||
|
// HTTP 상태 코드별 처리
|
||||||
|
if (error.response?.status === 404) {
|
||||||
|
return { success: false, message: '등록된 매장이 없습니다' }
|
||||||
|
}
|
||||||
|
|
||||||
|
if (error.response?.status >= 500) {
|
||||||
|
return { success: false, message: '서버 오류가 발생했습니다. 잠시 후 다시 시도해주세요.' }
|
||||||
|
}
|
||||||
|
|
||||||
|
if (error.response?.status === 401) {
|
||||||
|
return { success: false, message: '로그인이 필요합니다' }
|
||||||
|
}
|
||||||
|
|
||||||
|
return { success: false, message: error.message || '매장 정보 조회에 실패했습니다' }
|
||||||
} finally {
|
} finally {
|
||||||
this.loading = false
|
this.loading = false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
async deleteMenu(menuId) {
|
/**
|
||||||
|
* 매장 등록
|
||||||
|
*/
|
||||||
|
async registerStore(storeData) {
|
||||||
|
console.log('매장 등록 시작:', storeData)
|
||||||
|
this.loading = true
|
||||||
|
this.error = null
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.loading = true
|
const { storeService } = await import('@/services/store')
|
||||||
await storeService.deleteMenu(menuId)
|
|
||||||
this.menus = this.menus.filter(menu => menu.id !== menuId)
|
const result = await storeService.registerStore(storeData)
|
||||||
this.totalCount--
|
|
||||||
|
console.log('매장 등록 결과:', result)
|
||||||
|
|
||||||
|
if (result.success) {
|
||||||
|
// 등록 성공 후 매장 정보 다시 조회
|
||||||
|
await this.fetchStoreInfo()
|
||||||
|
return result
|
||||||
|
} else {
|
||||||
|
this.error = result.message
|
||||||
|
return result
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw error
|
console.error('매장 등록 실패:', error)
|
||||||
|
this.error = error.message
|
||||||
|
return { success: false, message: error.message || '매장 등록에 실패했습니다' }
|
||||||
} finally {
|
} finally {
|
||||||
this.loading = false
|
this.loading = false
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 매장 정보 수정
|
||||||
|
*/
|
||||||
|
async updateStore(storeId, storeData) {
|
||||||
|
console.log('매장 정보 수정 시작:', { storeId, storeData })
|
||||||
|
this.loading = true
|
||||||
|
this.error = null
|
||||||
|
|
||||||
|
try {
|
||||||
|
const { storeService } = await import('@/services/store')
|
||||||
|
|
||||||
|
const result = await storeService.updateStore(storeId, storeData)
|
||||||
|
|
||||||
|
console.log('매장 수정 결과:', result)
|
||||||
|
|
||||||
|
if (result.success) {
|
||||||
|
// 수정 성공 후 매장 정보 다시 조회
|
||||||
|
await this.fetchStoreInfo()
|
||||||
|
return result
|
||||||
|
} else {
|
||||||
|
this.error = result.message
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('매장 수정 실패:', error)
|
||||||
|
this.error = error.message
|
||||||
|
return { success: false, message: error.message || '매장 수정에 실패했습니다' }
|
||||||
|
} finally {
|
||||||
|
this.loading = false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 매장 정보 초기화
|
||||||
|
*/
|
||||||
|
clearStoreInfo() {
|
||||||
|
this.storeInfo = null
|
||||||
|
this.error = null
|
||||||
|
this.loading = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -1,202 +1,266 @@
|
|||||||
//* src/store/store.js 수정 - 기존 구조 유지하고 API 연동만 추가
|
//* src/services/store.js - 백엔드 API 연동 수정
|
||||||
import { defineStore } from 'pinia'
|
import { storeApi, handleApiError, formatSuccessResponse } from './api.js'
|
||||||
import { ref, computed } from 'vue'
|
|
||||||
import storeService from '@/services/store'
|
|
||||||
|
|
||||||
export const useStoreStore = defineStore('store', () => {
|
|
||||||
// 기존 상태들 유지
|
|
||||||
const storeInfo = ref(null)
|
|
||||||
const menus = ref([])
|
|
||||||
const salesData = ref(null)
|
|
||||||
const isLoading = ref(false)
|
|
||||||
|
|
||||||
// 기존 computed 속성들 유지
|
|
||||||
const hasStoreInfo = computed(() => !!storeInfo.value)
|
|
||||||
const menuCount = computed(() => menus.value?.length || 0)
|
|
||||||
|
|
||||||
// fetchStoreInfo를 실제 API 호출로 수정
|
|
||||||
const fetchStoreInfo = async () => {
|
|
||||||
if (import.meta.env.DEV) {
|
|
||||||
console.log('개발 모드: 매장 정보 API 호출 건너뛰기')
|
|
||||||
return { success: true }
|
|
||||||
}
|
|
||||||
|
|
||||||
isLoading.value = true
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 매장 관련 API 서비스
|
||||||
|
* 백엔드 Store Controller와 연동 (포트 8082)
|
||||||
|
*/
|
||||||
|
class StoreService {
|
||||||
|
/**
|
||||||
|
* 매장 등록 (STR-015: 매장 등록)
|
||||||
|
* @param {Object} storeData - 매장 정보
|
||||||
|
* @returns {Promise<Object>} 매장 등록 결과
|
||||||
|
*/
|
||||||
|
async registerStore(storeData) {
|
||||||
try {
|
try {
|
||||||
const result = await storeService.getStore()
|
console.log('매장 등록 API 호출 - 요청 데이터:', storeData)
|
||||||
|
|
||||||
if (result.success) {
|
// 백엔드 StoreCreateRequest에 맞는 형태로 변환
|
||||||
storeInfo.value = result.data
|
const requestData = {
|
||||||
return { success: true }
|
storeName: storeData.storeName,
|
||||||
|
businessType: storeData.businessType,
|
||||||
|
address: storeData.address,
|
||||||
|
phoneNumber: storeData.phoneNumber,
|
||||||
|
businessHours: storeData.businessHours || `${storeData.openTime}-${storeData.closeTime}`,
|
||||||
|
closedDays: Array.isArray(storeData.holidays) ? storeData.holidays.join(',') : storeData.closedDays,
|
||||||
|
seatCount: parseInt(storeData.seatCount) || 0,
|
||||||
|
snsAccounts: {
|
||||||
|
instagram: storeData.instagramUrl || '',
|
||||||
|
blog: storeData.blogUrl || ''
|
||||||
|
},
|
||||||
|
description: storeData.description || ''
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('백엔드 전송 데이터:', requestData)
|
||||||
|
|
||||||
|
const response = await storeApi.post('/register', requestData)
|
||||||
|
|
||||||
|
console.log('매장 등록 API 응답:', response.data)
|
||||||
|
|
||||||
|
// 백엔드 응답 구조에 맞게 처리
|
||||||
|
if (response.data.status === 200 || response.data.message?.includes('성공')) {
|
||||||
|
return formatSuccessResponse(response.data.data, response.data.message || '매장이 등록되었습니다.')
|
||||||
} else {
|
} else {
|
||||||
console.warn('매장 정보 조회 실패:', result.message)
|
throw new Error(response.data.message || '매장 등록에 실패했습니다.')
|
||||||
return { success: false, error: result.message }
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.warn('매장 정보 조회 실패:', error)
|
console.error('매장 등록 실패:', error)
|
||||||
return { success: false, error: '네트워크 오류가 발생했습니다.' }
|
return handleApiError(error)
|
||||||
} finally {
|
|
||||||
isLoading.value = false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// saveStoreInfo를 실제 API 호출로 수정
|
/**
|
||||||
const saveStoreInfo = async (storeData) => {
|
* 매장 정보 조회 (STR-005: 매장 정보 관리)
|
||||||
isLoading.value = true
|
* @returns {Promise<Object>} 매장 정보
|
||||||
|
*/
|
||||||
|
async getStore() {
|
||||||
try {
|
try {
|
||||||
let result
|
console.log('매장 정보 조회 API 호출')
|
||||||
if (storeInfo.value) {
|
|
||||||
// 기존 매장 정보 수정
|
|
||||||
result = await storeService.updateStore(storeData)
|
|
||||||
} else {
|
|
||||||
// 새 매장 등록
|
|
||||||
result = await storeService.registerStore(storeData)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result.success) {
|
const response = await storeApi.get('/')
|
||||||
storeInfo.value = result.data
|
|
||||||
return { success: true, message: '매장 정보가 저장되었습니다.' }
|
console.log('매장 정보 조회 API 응답:', response.data)
|
||||||
|
|
||||||
|
// 백엔드 응답 구조에 맞게 처리
|
||||||
|
if (response.data.status === 200 && response.data.data) {
|
||||||
|
return formatSuccessResponse(response.data.data, '매장 정보를 조회했습니다.')
|
||||||
|
} else if (response.data.data === null) {
|
||||||
|
// 매장이 없는 경우
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: '등록된 매장이 없습니다',
|
||||||
|
data: null
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return { success: false, error: result.message }
|
throw new Error(response.data.message || '매장 정보를 찾을 수 없습니다.')
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return { success: false, error: '네트워크 오류가 발생했습니다.' }
|
console.error('매장 정보 조회 실패:', error)
|
||||||
} finally {
|
|
||||||
isLoading.value = false
|
// 404 오류 처리 (매장이 없음)
|
||||||
|
if (error.response?.status === 404) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: '등록된 매장이 없습니다',
|
||||||
|
data: null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 500 오류 처리 (서버 내부 오류)
|
||||||
|
if (error.response?.status === 500) {
|
||||||
|
console.error('서버 내부 오류 - 백엔드 로그 확인 필요:', error.response?.data)
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: '서버 오류가 발생했습니다. 관리자에게 문의하세요.',
|
||||||
|
data: null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return handleApiError(error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// fetchMenus를 실제 API 호출로 수정
|
/**
|
||||||
const fetchMenus = async () => {
|
* 매장 정보 수정 (STR-010: 매장 수정)
|
||||||
if (!storeInfo.value?.storeId) {
|
* @param {number} storeId - 매장 ID (현재는 사용하지 않음 - JWT에서 사용자 확인)
|
||||||
console.warn('매장 ID가 없어 메뉴를 조회할 수 없습니다.')
|
* @param {Object} storeData - 수정할 매장 정보
|
||||||
return { success: false, error: '매장 정보가 필요합니다.' }
|
* @returns {Promise<Object>} 매장 수정 결과
|
||||||
}
|
*/
|
||||||
|
async updateStore(storeId, storeData) {
|
||||||
isLoading.value = true
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await storeService.getMenus(storeInfo.value.storeId)
|
console.log('매장 정보 수정 API 호출 - 요청 데이터:', storeData)
|
||||||
|
|
||||||
if (result.success) {
|
// 백엔드 StoreUpdateRequest에 맞는 형태로 변환
|
||||||
menus.value = result.data
|
const requestData = {
|
||||||
return { success: true }
|
storeName: storeData.storeName,
|
||||||
|
businessType: storeData.businessType,
|
||||||
|
address: storeData.address,
|
||||||
|
phoneNumber: storeData.phoneNumber,
|
||||||
|
businessHours: storeData.businessHours || `${storeData.openTime}-${storeData.closeTime}`,
|
||||||
|
closedDays: Array.isArray(storeData.holidays) ? storeData.holidays.join(',') : storeData.closedDays,
|
||||||
|
seatCount: parseInt(storeData.seatCount) || 0,
|
||||||
|
snsAccounts: {
|
||||||
|
instagram: storeData.instagramUrl || '',
|
||||||
|
blog: storeData.blogUrl || ''
|
||||||
|
},
|
||||||
|
description: storeData.description || ''
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('백엔드 전송 데이터:', requestData)
|
||||||
|
|
||||||
|
// PUT 요청 (storeId는 JWT에서 추출하므로 URL에 포함하지 않음)
|
||||||
|
const response = await storeApi.put('/', requestData)
|
||||||
|
|
||||||
|
console.log('매장 정보 수정 API 응답:', response.data)
|
||||||
|
|
||||||
|
if (response.data.status === 200 || response.data.message?.includes('성공')) {
|
||||||
|
return formatSuccessResponse(response.data.data, response.data.message || '매장 정보가 수정되었습니다.')
|
||||||
} else {
|
} else {
|
||||||
return { success: false, error: result.message }
|
throw new Error(response.data.message || '매장 정보 수정에 실패했습니다.')
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return { success: false, error: '네트워크 오류가 발생했습니다.' }
|
console.error('매장 정보 수정 실패:', error)
|
||||||
} finally {
|
return handleApiError(error)
|
||||||
isLoading.value = false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 메뉴 관련 메서드들 API 연동 추가
|
/**
|
||||||
const saveMenu = async (menuData) => {
|
* 매출 정보 조회 (STR-020: 대시보드)
|
||||||
isLoading.value = true
|
* @param {string} period - 조회 기간 (today, week, month, year)
|
||||||
|
* @returns {Promise<Object>} 매출 정보
|
||||||
|
*/
|
||||||
|
async getSales(period = 'today') {
|
||||||
try {
|
try {
|
||||||
const result = await storeService.registerMenu(menuData)
|
// 현재는 목업 데이터 반환 (추후 실제 API 연동 시 수정)
|
||||||
|
const mockSalesData = {
|
||||||
if (result.success) {
|
todaySales: 150000,
|
||||||
// 메뉴 목록 새로고침
|
yesterdaySales: 120000,
|
||||||
await fetchMenus()
|
changeRate: 25.0,
|
||||||
return { success: true, message: '메뉴가 등록되었습니다.' }
|
monthlyTarget: 3000000,
|
||||||
} else {
|
achievementRate: 45.2
|
||||||
return { success: false, error: result.message }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return formatSuccessResponse(mockSalesData, '매출 정보를 조회했습니다.')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return { success: false, error: '네트워크 오류가 발생했습니다.' }
|
return handleApiError(error)
|
||||||
} finally {
|
|
||||||
isLoading.value = false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const updateMenu = async (menuId, menuData) => {
|
/**
|
||||||
isLoading.value = true
|
* 메뉴 등록 (STR-030: 메뉴 등록)
|
||||||
|
* @param {Object} menuData - 메뉴 정보
|
||||||
|
* @returns {Promise<Object>} 메뉴 등록 결과
|
||||||
|
*/
|
||||||
|
async registerMenu(menuData) {
|
||||||
try {
|
try {
|
||||||
const result = await storeService.updateMenu(menuId, menuData)
|
// 현재는 목업 처리 (추후 실제 API 연동 시 수정)
|
||||||
|
console.log('메뉴 등록 - 목업 처리:', menuData)
|
||||||
|
|
||||||
if (result.success) {
|
const mockMenuResponse = {
|
||||||
// 메뉴 목록 새로고침
|
id: Date.now(),
|
||||||
await fetchMenus()
|
...menuData,
|
||||||
return { success: true, message: '메뉴가 수정되었습니다.' }
|
createdAt: new Date().toISOString()
|
||||||
} else {
|
|
||||||
return { success: false, error: result.message }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return formatSuccessResponse(mockMenuResponse, '메뉴가 등록되었습니다.')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return { success: false, error: '네트워크 오류가 발생했습니다.' }
|
return handleApiError(error)
|
||||||
} finally {
|
|
||||||
isLoading.value = false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const deleteMenu = async (menuId) => {
|
/**
|
||||||
isLoading.value = true
|
* 메뉴 목록 조회 (STR-025: 메뉴 조회)
|
||||||
|
* @returns {Promise<Object>} 메뉴 목록
|
||||||
|
*/
|
||||||
|
async getMenus() {
|
||||||
try {
|
try {
|
||||||
const result = await storeService.deleteMenu(menuId)
|
// 현재는 목업 데이터 반환 (추후 실제 API 연동 시 수정)
|
||||||
|
const mockMenus = [
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
name: '김치찌개',
|
||||||
|
category: '찌개',
|
||||||
|
price: 8000,
|
||||||
|
description: '푸짐한 김치찌개',
|
||||||
|
imageUrl: '/images/menu-placeholder.png',
|
||||||
|
isPopular: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 2,
|
||||||
|
name: '제육볶음',
|
||||||
|
category: '볶음',
|
||||||
|
price: 12000,
|
||||||
|
description: '매콤한 제육볶음',
|
||||||
|
imageUrl: '/images/menu-placeholder.png',
|
||||||
|
isRecommended: true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
if (result.success) {
|
return formatSuccessResponse(mockMenus, '메뉴 목록을 조회했습니다.')
|
||||||
// 메뉴 목록 새로고침
|
|
||||||
await fetchMenus()
|
|
||||||
return { success: true, message: '메뉴가 삭제되었습니다.' }
|
|
||||||
} else {
|
|
||||||
return { success: false, error: result.message }
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return { success: false, error: '네트워크 오류가 발생했습니다.' }
|
return handleApiError(error)
|
||||||
} finally {
|
|
||||||
isLoading.value = false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 매출 정보 조회 추가
|
/**
|
||||||
const fetchSalesData = async () => {
|
* 메뉴 수정 (STR-035: 메뉴 수정)
|
||||||
if (!storeInfo.value?.storeId) {
|
* @param {number} menuId - 메뉴 ID
|
||||||
return { success: false, error: '매장 정보가 필요합니다.' }
|
* @param {Object} menuData - 수정할 메뉴 정보
|
||||||
}
|
* @returns {Promise<Object>} 메뉴 수정 결과
|
||||||
|
*/
|
||||||
isLoading.value = true
|
async updateMenu(menuId, menuData) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await storeService.getSales(storeInfo.value.storeId)
|
// 현재는 목업 처리 (추후 실제 API 연동 시 수정)
|
||||||
|
console.log('메뉴 수정 - 목업 처리:', { menuId, menuData })
|
||||||
|
|
||||||
if (result.success) {
|
const mockMenuResponse = {
|
||||||
salesData.value = result.data
|
id: menuId,
|
||||||
return { success: true }
|
...menuData,
|
||||||
} else {
|
updatedAt: new Date().toISOString()
|
||||||
return { success: false, error: result.message }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return formatSuccessResponse(mockMenuResponse, '메뉴가 수정되었습니다.')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return { success: false, error: '네트워크 오류가 발생했습니다.' }
|
return handleApiError(error)
|
||||||
} finally {
|
|
||||||
isLoading.value = false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
/**
|
||||||
// 상태
|
* 메뉴 삭제 (STR-040: 메뉴 삭제)
|
||||||
storeInfo,
|
* @param {number} menuId - 삭제할 메뉴 ID
|
||||||
menus,
|
* @returns {Promise<Object>} 메뉴 삭제 결과
|
||||||
salesData,
|
*/
|
||||||
isLoading,
|
async deleteMenu(menuId) {
|
||||||
|
try {
|
||||||
|
// 현재는 목업 처리 (추후 실제 API 연동 시 수정)
|
||||||
|
console.log('메뉴 삭제 - 목업 처리:', menuId)
|
||||||
|
|
||||||
// 컴퓨티드
|
return formatSuccessResponse(null, '메뉴가 삭제되었습니다.')
|
||||||
hasStoreInfo,
|
} catch (error) {
|
||||||
menuCount,
|
return handleApiError(error)
|
||||||
|
}
|
||||||
// 메서드
|
|
||||||
fetchStoreInfo,
|
|
||||||
saveStoreInfo,
|
|
||||||
fetchMenus,
|
|
||||||
saveMenu,
|
|
||||||
updateMenu,
|
|
||||||
deleteMenu,
|
|
||||||
fetchSalesData
|
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
|
export const storeService = new StoreService()
|
||||||
|
export default storeService
|
||||||
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user