v0.1.17 - 목표 패널 및 D-DAY 선택 추가

This commit is contained in:
2026-04-21 18:37:06 +09:00
parent 440f0f46a1
commit 4355185203
11 changed files with 429 additions and 21 deletions

49
src/lib/goalsApi.js Normal file
View File

@@ -0,0 +1,49 @@
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL ?? 'http://localhost:3001'
function buildHeaders(token) {
return {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
}
}
async function request(path, { method = 'GET', token, body } = {}) {
const response = await fetch(`${API_BASE_URL}${path}`, {
method,
headers: buildHeaders(token),
body: body ? JSON.stringify(body) : undefined,
})
const data = await response.json().catch(() => ({}))
if (!response.ok) {
throw new Error(data.message || '목표 데이터를 처리하지 못했습니다.')
}
return data
}
export async function fetchGoals(token, { query = '', status = 'active' } = {}) {
const searchParams = new URLSearchParams()
if (query) {
searchParams.set('query', query)
}
if (status) {
searchParams.set('status', status)
}
const queryString = searchParams.toString()
return request(`/api/goals${queryString ? `?${queryString}` : ''}`, {
token,
})
}
export async function createGoal(token, payload) {
return request('/api/goals', {
method: 'POST',
token,
body: payload,
})
}