diff --git a/src/service/fortuneAPI.js b/src/service/fortuneAPI.js new file mode 100644 index 0000000..7ec4fb2 --- /dev/null +++ b/src/service/fortuneAPI.js @@ -0,0 +1,43 @@ +import axios from 'axios'; + +export default { + async getFortuneNotification() { + try { + const response = await axios.get( + `${import.meta.env.VITE_APP_SERVER_API_URI}/fortune`, + { + headers: { + 'Content-Type': 'application/json;charset=utf-8', + Authorization: `Bearer ${sessionStorage.getItem('accessToken')}`, + } + } + ); + console.log(response.data); + return response.data; + } catch (error) { + console.error('운세 알림을 불러오는 데 실패했습니다:', error); + throw error; + } + }, + + async activateFortuneNotification(notification) { + try { + const response= await axios.post( + `${import.meta.env.VITE_APP_SERVER_API_URI}/fortune`, + notification, + { + headers: { + 'Content-Type': 'application/json;charset=utf-8', + Authorization: `Bearer ${sessionStorage.getItem('accessToken')}`, + }, + } + ); + console.log(response.data); + } catch (error) { + console.error('운세 알림 활성화/비활성화에 실패했습니다:', error); + alert('알림 활성화/비활성화 실패!'); + location.reload(); + throw error; + } + } +} diff --git a/src/store/index.js b/src/store/index.js index e4c33a4..82565bf 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -8,6 +8,7 @@ import navigationStore from "@/store/modules/navigationStore.js"; import weatherStore from "@/store/modules/weatherStore.js"; import parcelStore from "@/store/modules/parcelStore.js"; import lunchStore from "@/store/modules/lunchStore.js"; +import fortuneStore from "@/store/modules/fortuneStore.js"; export const store = createStore({ modules: { @@ -19,6 +20,7 @@ export const store = createStore({ navigationStore, weatherStore, parcelStore, - lunchStore + lunchStore, + fortuneStore }, }); diff --git a/src/store/modules/fortuneStore.js b/src/store/modules/fortuneStore.js new file mode 100644 index 0000000..aacbac1 --- /dev/null +++ b/src/store/modules/fortuneStore.js @@ -0,0 +1,41 @@ +import fortuneAPI from "@/service/fortuneAPI.js"; + +const state = { + notification: [] +}; + +const mutations = { + setNotification(state, notification) { + state.notification = notification; + } +}; + +const actions = { + async getFortuneNotification({commit}) { + try { + const notification = await fortuneAPI.getFortuneNotification(); + commit('setNotification', notification.data); + } catch (error) { + console.error('알림을 불러오는 데 실패했습니다:', error); + throw error; + } + }, + async activateFortuneNotification({commit, dispatch}, notification) { + try { + await fortuneAPI.activateFortuneNotification(notification); + console.log('알림이 활성화/비활성화 되었습니다.'); + await dispatch('getFortuneNotification'); + } catch (error) { + console.error('알림 활성화/비활성화에 실패했습니다:', error); + throw error; + } + } +}; + + +export default { + namespaced: true, + state, + mutations, + actions +}; diff --git a/src/views/Fortune.vue b/src/views/Fortune.vue new file mode 100644 index 0000000..c01b9b3 --- /dev/null +++ b/src/views/Fortune.vue @@ -0,0 +1,282 @@ + + + + + + + \ No newline at end of file diff --git a/src/views/NotificationList.vue b/src/views/NotificationList.vue index 127cd80..43cf3c8 100644 --- a/src/views/NotificationList.vue +++ b/src/views/NotificationList.vue @@ -1,8 +1,10 @@ \ No newline at end of file