-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from GDSC-KNU/Feat/issue-51
Feat/issue 51
- Loading branch information
Showing
7 changed files
with
161 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import axios from 'axios'; | ||
import { UserInfoStore } from '../stores/UserInfoStore'; | ||
|
||
export const MarineApis = { | ||
instance: axios.create({ | ||
baseURL: 'http://localhost:8080/marinelife', | ||
withCredentials: true, | ||
}), | ||
|
||
// 쓰레기 데이터 임시 생성하기 | ||
create: async () => { | ||
try { | ||
const res = await MarineApis.instance.post('/temp-data', { | ||
"marineLifeId": 0, | ||
"userId": 0, | ||
"name": "string", | ||
"latitude": 0, | ||
"longitude": 0 | ||
}); | ||
console.log(res); | ||
return res.data; | ||
} catch (error) { | ||
console.error('Error fetching wastes:', error); | ||
} | ||
}, | ||
|
||
// 업로드하고 획득한 점수 확인하기 | ||
upload: async (formData: FormData) => { | ||
try { | ||
const res = await MarineApis.instance.post('', formData); | ||
console.log(res); | ||
return res.data; | ||
} catch (error) { | ||
alert(`[Can't recognize] Please add a clearer picture`) | ||
throw error; | ||
} | ||
}, | ||
|
||
// 주어진 ID의 해양 생물 정보를 수정 | ||
update: async () => { | ||
try { | ||
const res = await MarineApis.instance.put('',{ | ||
"marineLifeId": 0, | ||
"userId": 0, | ||
"name": "string", | ||
"latitude": 0, | ||
"longitude": 0 | ||
}); | ||
console.log(res); | ||
return res.data; | ||
} catch (error) { | ||
console.error(error); | ||
throw error; | ||
} | ||
}, | ||
|
||
// 사용자가 모은 해양 생물 정보를 조회 | ||
getCollection: async () => { | ||
try { | ||
const res = await MarineApis.instance.get(`/retrieve${UserInfoStore.getState().userId}`); | ||
console.log(res); | ||
return res.data; | ||
} catch (error) { | ||
alert(`[Can't recognize] Please add `) | ||
throw error; | ||
} | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { create } from "zustand"; | ||
import { devtools } from "zustand/middleware"; | ||
|
||
export interface TrashInfo { | ||
plastic: number; | ||
styrofoam: number; | ||
fiber: number; | ||
vinyl: number; | ||
generalWaste: number; | ||
|
||
score: number; | ||
totalScore: number; | ||
|
||
classes: string; | ||
|
||
setPlastic: (plastic: TrashInfo['plastic']) => void; | ||
setStyrofoam: (styrofoam: TrashInfo['styrofoam']) => void; | ||
setFiber: (fiber: TrashInfo['fiber']) => void; | ||
setVinyl: (vinyl: TrashInfo['vinyl']) => void; | ||
setGeneralWaste: (generalWaste: TrashInfo['generalWaste']) => void; | ||
setScore: (score: TrashInfo['score']) => void; | ||
setTotalScore: (totalScore: TrashInfo['totalScore']) => void; | ||
setClasses: (classes: TrashInfo['classes']) => void; | ||
|
||
update: (field: string, value: string) => void; | ||
} | ||
|
||
const createTrashInfoStore = (set) => ({ | ||
plastic: 0, | ||
styrofoam: 0, | ||
fiber: 0, | ||
vinyl: 0, | ||
generalWaste: 0, | ||
score: 0, | ||
totalScore: 0, | ||
classes: '', | ||
|
||
setPlastic: (plastic: TrashInfo['plastic']) => set({ plastic }), | ||
setStyrofoam: (styrofoam: TrashInfo['styrofoam']) => set({ styrofoam }), | ||
setFiber: (fiber: TrashInfo['fiber']) => set({ fiber }), | ||
setVinyl: (vinyl: TrashInfo['vinyl']) => set({ vinyl }), | ||
setGeneralWaste: (generalWaste: TrashInfo['generalWaste']) => set({ generalWaste }), | ||
setScore: (score: TrashInfo['score']) => set({ score }), | ||
setTotalScore: (totalScore: TrashInfo['totalScore']) => set({ totalScore }), | ||
setClasses: (classes: string) => set({ classes }), | ||
|
||
update: (field, value) => set({ [field]: value }), | ||
}); | ||
|
||
let TrashInfoStoreTemp; | ||
|
||
// devtools | ||
if (import.meta.env.DEV) { | ||
TrashInfoStoreTemp = create<TrashInfo>()(devtools(createTrashInfoStore, { name: 'TrashInfo' })); | ||
} else { | ||
TrashInfoStoreTemp = create<TrashInfo>()(createTrashInfoStore); | ||
} | ||
|
||
export const TrashInfoStore = TrashInfoStoreTemp; |