From efbb3de68c7c52550e32e79fddc1f23c53a689e6 Mon Sep 17 00:00:00 2001 From: Ingyu Song Date: Mon, 15 Apr 2024 15:58:52 +0900 Subject: [PATCH] =?UTF-8?q?:sparkles:=20feat:=20=EC=98=A4=EB=8A=98?= =?UTF-8?q?=EC=9D=98=20=EC=9A=B4=EC=84=B8=20=EC=95=8C=EB=A6=BC=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/service/fortuneAPI.js | 43 +++++ src/store/index.js | 4 +- src/store/modules/fortuneStore.js | 41 +++++ src/views/Fortune.vue | 282 ++++++++++++++++++++++++++++++ src/views/NotificationList.vue | 2 + 5 files changed, 371 insertions(+), 1 deletion(-) create mode 100644 src/service/fortuneAPI.js create mode 100644 src/store/modules/fortuneStore.js create mode 100644 src/views/Fortune.vue 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