feat(frontend): TanStack Query 기반 apis 레이어 추가
- auth/negotiation 도메인별 api/keys/queries/mutations/type 5파일 구조 - axios 인스턴스: access token 주입, 434 만료 시 refresh 자동 재발급(단일 비행) 후 원요청 재시도, 433/435/1203(TOKEN_REVOKED) 시 세션 종료 처리 - HTTP 200 + result.success=false 비즈니스 에러를 ApiError 로 변환, 에러코드별 한국어 메시지 맵(getApiErrorMessage) 제공 - 토큰 localStorage 저장소(tokenStorage) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
2480a47efe
commit
a867daa98f
16 files changed
+629
No files matched your search
@@ -0,0 +1,6 @@
|
||||
// 협상 API 모듈 공개 표면.
|
||||
export { negotiationApi } from './negotiation.api'
|
||||
export { negotiationKeys } from './negotiation.keys'
|
||||
export { useSessionListQuery } from './negotiation.queries'
|
||||
export { useParticipateMutation, useRejectMutation } from './negotiation.mutations'
|
||||
export * from './negotiation.type'
|
||||
@@ -0,0 +1,34 @@
|
||||
// 협상 엔드포인트 호출 함수 (순수 HTTP 레이어, React 의존 없음).
|
||||
import { http } from '@/apis/http'
|
||||
import type {
|
||||
ParticipateResponse,
|
||||
RejectRequest,
|
||||
RejectResponse,
|
||||
SessionListParams,
|
||||
SessionListResponse,
|
||||
} from './negotiation.type'
|
||||
|
||||
export const negotiationApi = {
|
||||
/** GET /v1/negotiation/sessions — 로그인 공급사의 협상 세션 목록(필터/정렬/페이지) */
|
||||
getSessions: async (params: SessionListParams = {}): Promise<SessionListResponse> => {
|
||||
const res = await http.get<SessionListResponse>('/v1/negotiation/sessions', { params })
|
||||
return res.data
|
||||
},
|
||||
|
||||
/** POST /v1/negotiation/sessions/{id}/participate — 협상 세션 참여 */
|
||||
participate: async (sessionId: string): Promise<ParticipateResponse> => {
|
||||
const res = await http.post<ParticipateResponse>(
|
||||
`/v1/negotiation/sessions/${sessionId}/participate`,
|
||||
)
|
||||
return res.data
|
||||
},
|
||||
|
||||
/** POST /v1/negotiation/sessions/{id}/reject — 협상 세션 거부 */
|
||||
reject: async (sessionId: string, body: RejectRequest): Promise<RejectResponse> => {
|
||||
const res = await http.post<RejectResponse>(
|
||||
`/v1/negotiation/sessions/${sessionId}/reject`,
|
||||
body,
|
||||
)
|
||||
return res.data
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// 협상 도메인의 TanStack Query 키 팩토리.
|
||||
import type { SessionListParams } from './negotiation.type'
|
||||
|
||||
export const negotiationKeys = {
|
||||
all: ['negotiation'] as const,
|
||||
sessions: () => [...negotiationKeys.all, 'sessions'] as const,
|
||||
sessionList: (params: SessionListParams) => [...negotiationKeys.sessions(), params] as const,
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// 협상 도메인의 변경(useMutation) 훅.
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import { negotiationApi } from './negotiation.api'
|
||||
import { negotiationKeys } from './negotiation.keys'
|
||||
import type { RejectRequest } from './negotiation.type'
|
||||
|
||||
/**
|
||||
* 협상 세션 참여: 성공 시 세션 목록 캐시를 무효화해 상태를 갱신한다.
|
||||
*/
|
||||
export function useParticipateMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: (sessionId: string) => negotiationApi.participate(sessionId),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: negotiationKeys.sessions() })
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 협상 세션 거부: 성공 시 세션 목록 캐시를 무효화한다.
|
||||
*/
|
||||
export function useRejectMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: ({ sessionId, request }: { sessionId: string; request: RejectRequest }) =>
|
||||
negotiationApi.reject(sessionId, request),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: negotiationKeys.sessions() })
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// 협상 도메인의 조회(useQuery) 훅.
|
||||
import { keepPreviousData, useQuery } from '@tanstack/react-query'
|
||||
import { negotiationApi } from './negotiation.api'
|
||||
import { negotiationKeys } from './negotiation.keys'
|
||||
import type { SessionListParams } from './negotiation.type'
|
||||
|
||||
/**
|
||||
* 협상 세션 목록 조회.
|
||||
* 페이지 전환 시 이전 데이터를 유지해 깜빡임을 줄인다.
|
||||
*/
|
||||
export function useSessionListQuery(params: SessionListParams = {}) {
|
||||
return useQuery({
|
||||
queryKey: negotiationKeys.sessionList(params),
|
||||
queryFn: () => negotiationApi.getSessions(params),
|
||||
placeholderData: keepPreviousData,
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
// 협상 API 의 요청/응답 타입 + 코드값 enum.
|
||||
// 와이어 포맷은 백엔드(snake_case)를 그대로 미러링한다.
|
||||
import type { ApiResult } from '@/apis/types'
|
||||
|
||||
/** 협상 세션 상태 (negotiation.sessions.status) */
|
||||
export const SessionStatus = {
|
||||
CREATED: 1, // 협상생성(참여대기)
|
||||
IN_PROGRESS: 2, // 협상중
|
||||
DONE: 3, // 협상완료
|
||||
NOT_PARTICIPATED: 4, // 미참여(마감)
|
||||
REJECTED: 5, // 협상거부
|
||||
} as const
|
||||
export type SessionStatus = (typeof SessionStatus)[keyof typeof SessionStatus]
|
||||
|
||||
export const SESSION_STATUS_LABEL: Record<SessionStatus, string> = {
|
||||
[SessionStatus.CREATED]: '협상생성',
|
||||
[SessionStatus.IN_PROGRESS]: '협상중',
|
||||
[SessionStatus.DONE]: '협상완료',
|
||||
[SessionStatus.NOT_PARTICIPATED]: '미참여',
|
||||
[SessionStatus.REJECTED]: '협상거부',
|
||||
}
|
||||
|
||||
/** 견적 타입 (negotiation.sessions.qt_type) */
|
||||
export const QtType = {
|
||||
RENEGO: 1, // 재협상(1:1)
|
||||
REQUOTE: 2, // 재견적(1:N)
|
||||
} as const
|
||||
export type QtType = (typeof QtType)[keyof typeof QtType]
|
||||
|
||||
export const QT_TYPE_LABEL: Record<QtType, string> = {
|
||||
[QtType.RENEGO]: '재협상',
|
||||
[QtType.REQUOTE]: '재견적',
|
||||
}
|
||||
|
||||
// --- 세션 목록 (GET /v1/negotiation/sessions) ----------------------------
|
||||
export interface SessionListParams {
|
||||
status?: number // SessionStatus 코드 필터
|
||||
qt_type?: number // QtType 코드 필터
|
||||
order?: 'asc' | 'desc' // 마감(qt_end_time) 정렬, asc=임박순
|
||||
page?: number
|
||||
page_size?: number
|
||||
}
|
||||
|
||||
export interface SessionListItem {
|
||||
session_id: string
|
||||
session_status: number
|
||||
qt_type: number
|
||||
qt_number: string
|
||||
qt_end_time: string // ISO 8601 마감 시각
|
||||
item_code: string
|
||||
item_name: string
|
||||
model_name: string
|
||||
maker_name: string
|
||||
}
|
||||
|
||||
export interface SessionListResponse {
|
||||
result: ApiResult
|
||||
items: SessionListItem[]
|
||||
total: number
|
||||
page: number
|
||||
page_size: number
|
||||
}
|
||||
|
||||
// --- 참여 (POST /v1/negotiation/sessions/{id}/participate) ----------------
|
||||
export interface ParticipateResponse {
|
||||
result: ApiResult
|
||||
session_id: string
|
||||
}
|
||||
|
||||
// --- 거부 (POST /v1/negotiation/sessions/{id}/reject) ---------------------
|
||||
// reject_reason: 프리셋(단종/품절) 라벨 또는 '기타' 직접 입력 텍스트.
|
||||
// (백엔드 sessions.reject_reason 컬럼에 대응. 엔드포인트는 백엔드 추가 예정)
|
||||
export interface RejectRequest {
|
||||
reject_reason: string
|
||||
}
|
||||
|
||||
export interface RejectResponse {
|
||||
result: ApiResult
|
||||
session_id: string
|
||||
}
|
||||
Reference in new issue
Block a user