Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/api/facades/plant.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useQueryClient } from '@tanstack/react-query'
import {
getListQueryKey,
list,
getList1QueryKey,
list1,
search,
suggest,
useList,
useList1,
useSearch,
useSuggest as useSuggestGen,
} from '@/api/generated/plant/plant'
Expand All @@ -15,7 +15,7 @@ import type { SuggestPlantRequest } from '@/api/generated/peakdaApi.schemas'
// ─── plain async (이벀트 기반 호좜) ───────────────────────────────────────────

export async function listPlantsApi() {
const res = await list()
const res = await list1()
return res.data.data ?? null
}

Expand All @@ -32,7 +32,7 @@ export async function suggestPlantApi(payload: SuggestPlantRequest) {
// ─── React Query hooks (캐싱 / μƒνƒœ 관리) ────────────────────────────────────

export const usePlants = () =>
useList({ query: { select: (res) => res.data.data ?? null } })
useList1({ query: { select: (res) => res.data.data ?? null } })

export const useSearchPlants = (keyword: string) =>
useSearch(
Expand All @@ -46,7 +46,7 @@ export const useSuggestPlant = () => {
const queryClient = useQueryClient()
return useSuggestGen({
mutation: {
onSuccess: () => queryClient.invalidateQueries({ queryKey: getListQueryKey() }),
onSuccess: () => queryClient.invalidateQueries({ queryKey: getList1QueryKey() }),
},
})
}
44 changes: 44 additions & 0 deletions src/api/facades/seasonal-bloom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import {
calendar,
map,
peak,
useCalendar,
useMap,
usePeak,
} from '@/api/generated/seasonal-bloom/seasonal-bloom'
import type { CalendarParams, MapParams, PeakParams } from '@/api/generated/peakdaApi.schemas'

// μ–Έλž˜ν•‘ κ·œμΉ™: res.data (Orval 래퍼) β†’ res.data.data (λ°±μ—”λ“œ μ‹€μ œ payload)

// bbox λ―Έμ€€λΉ„ μ‹œ ν˜ΈμΆœμ„ 막기 μœ„ν•œ 더미 β€” useBloomMap(null) 이면 enabled:false 둜 μš”μ²­ν•˜μ§€ μ•ŠλŠ”λ‹€.
const EMPTY_BBOX: MapParams = { minLat: 0, maxLat: 0, minLng: 0, maxLng: 0 }

// ─── plain async (이벀트 기반 호좜) ───────────────────────────────────────────

export async function bloomMapApi(params: MapParams) {
const res = await map(params)
return res.data.data ?? null
}

export async function bloomPeakApi(params?: PeakParams) {
const res = await peak(params)
return res.data.data ?? null
}

export async function bloomCalendarApi(params: CalendarParams) {
const res = await calendar(params)
return res.data.data ?? null
}

// ─── React Query hooks (캐싱 / μƒνƒœ 관리) ────────────────────────────────────

export const useBloomMap = (params: MapParams | null) =>
useMap(params ?? EMPTY_BBOX, {
query: { enabled: params !== null, select: (res) => res.data.data ?? null },
})

export const useBloomPeak = (params?: PeakParams) =>
usePeak(params, { query: { select: (res) => res.data.data ?? null } })

export const useBloomCalendar = (params: CalendarParams) =>
useCalendar(params, { query: { select: (res) => res.data.data ?? null } })
68 changes: 68 additions & 0 deletions src/api/facades/spot-favorite.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { useQueryClient } from '@tanstack/react-query'
import {
add,
getListQueryKey,
list,
remove,
updateNotify,
useAdd as useAddGen,
useList,
useRemove as useRemoveGen,
useUpdateNotify as useUpdateNotifyGen,
} from '@/api/generated/spot-favorite/spot-favorite'
import type { UpdateFavoriteNotifyRequest } from '@/api/generated/peakdaApi.schemas'

// μ–Έλž˜ν•‘ κ·œμΉ™: res.data (Orval 래퍼) β†’ res.data.data (λ°±μ—”λ“œ μ‹€μ œ payload)

// 찜 λͺ©λ‘ μΊμ‹œ ν‚€ β€” mutation 성곡 μ‹œ λ¬΄νš¨ν™” λŒ€μƒ
const favoriteListKey = getListQueryKey()

// ─── plain async (이벀트 기반 호좜) ───────────────────────────────────────────

export async function addFavoriteApi(spotId: number) {
const res = await add(spotId)
return res.data.data ?? null
}

export async function removeFavoriteApi(spotId: number) {
await remove(spotId)
}

export async function updateFavoriteNotifyApi(spotId: number, payload: UpdateFavoriteNotifyRequest) {
const res = await updateNotify(spotId, payload)
return res.data.data ?? null
}

export async function favoriteListApi() {
const res = await list()
return res.data.data ?? null
}

// ─── React Query hooks (캐싱 / μƒνƒœ 관리) ────────────────────────────────────

export const useFavoriteList = () =>
useList({ query: { select: (res) => res.data.data ?? null } })

// mutate({ spotId }) ν˜•νƒœλ‘œ 호좜 β€” 성곡 μ‹œ 찜 λͺ©λ‘ μΊμ‹œ λ¬΄νš¨ν™”

export const useAddFavorite = () => {
const queryClient = useQueryClient()
return useAddGen({
mutation: { onSuccess: () => queryClient.invalidateQueries({ queryKey: favoriteListKey }) },
})
}

export const useRemoveFavorite = () => {
const queryClient = useQueryClient()
return useRemoveGen({
mutation: { onSuccess: () => queryClient.invalidateQueries({ queryKey: favoriteListKey }) },
})
}

// mutate({ spotId, data: { enabled } }) ν˜•νƒœλ‘œ 호좜
export const useUpdateFavoriteNotify = () => {
const queryClient = useQueryClient()
return useUpdateNotifyGen({
mutation: { onSuccess: () => queryClient.invalidateQueries({ queryKey: favoriteListKey }) },
})
}
70 changes: 70 additions & 0 deletions src/api/facades/user-follow.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { useQueryClient } from '@tanstack/react-query'
import {
follow,
followers,
followings,
summary,
unfollow,
useFollow as useFollowGen,
useFollowers,
useFollowings,
useSummary,
useUnfollow as useUnfollowGen,
} from '@/api/generated/user-follow/user-follow'
import type { FollowersParams, FollowingsParams } from '@/api/generated/peakdaApi.schemas'

// μ–Έλž˜ν•‘ κ·œμΉ™: res.data (Orval 래퍼) β†’ res.data.data (λ°±μ—”λ“œ μ‹€μ œ payload)

// νŒ”λ‘œμš° λ³€κ²½ μ‹œ λ¬΄νš¨ν™” λŒ€μƒ β€” μ—¬λŸ¬ userId 의 summaryΒ·λͺ©λ‘μ΄ λ™μ‹œμ— λ°”λ€Œλ―€λ‘œ predicate 둜 일괄 μ²˜λ¦¬ν•œλ‹€.
const invalidateFollow = (queryClient: ReturnType<typeof useQueryClient>) =>
queryClient.invalidateQueries({
predicate: (q) => typeof q.queryKey[0] === 'string' && q.queryKey[0].includes('/follow'),
})

// ─── plain async (이벀트 기반 호좜) ───────────────────────────────────────────

export async function followApi(userId: number) {
await follow(userId)
}

export async function unfollowApi(userId: number) {
await unfollow(userId)
}

export async function followingsApi(userId: number, params: FollowingsParams) {
const res = await followings(userId, params)
return res.data.data ?? null
}

export async function followersApi(userId: number, params: FollowersParams) {
const res = await followers(userId, params)
return res.data.data ?? null
}

export async function followSummaryApi(userId: number) {
const res = await summary(userId)
return res.data.data ?? null
}

// ─── React Query hooks (캐싱 / μƒνƒœ 관리) ────────────────────────────────────

export const useFollowSummary = (userId: number) =>
useSummary(userId, { query: { select: (res) => res.data.data ?? null } })

export const useFollowingList = (userId: number, params: FollowingsParams) =>
useFollowings(userId, params, { query: { select: (res) => res.data.data ?? null } })

export const useFollowerList = (userId: number, params: FollowersParams) =>
useFollowers(userId, params, { query: { select: (res) => res.data.data ?? null } })

// mutate({ userId }) ν˜•νƒœλ‘œ 호좜 β€” 성곡 μ‹œ νŒ”λ‘œμš° κ΄€λ ¨ μΊμ‹œ λ¬΄νš¨ν™”

export const useFollow = () => {
const queryClient = useQueryClient()
return useFollowGen({ mutation: { onSuccess: () => invalidateFollow(queryClient) } })
}

export const useUnfollow = () => {
const queryClient = useQueryClient()
return useUnfollowGen({ mutation: { onSuccess: () => invalidateFollow(queryClient) } })
}
Loading
Loading