[as] feat: 'dcrag-to' API 구현
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
import { client } from "@/shared/api";
|
||||
import { ENDPOINT } from "@/shared/config";
|
||||
|
||||
import type {
|
||||
DcRagApiToService,
|
||||
DcRagCommonResponseDto,
|
||||
DcRagDraftGenerateResponseDto,
|
||||
DcRagDraftStatusResponseDto,
|
||||
} from "../model/dcrag-to-interface";
|
||||
import type {
|
||||
DcRagCostVerifyRequestDto,
|
||||
DcRagDocumentTransferRequestDto,
|
||||
DcRagDraftGenerateRequestDto,
|
||||
} from "../model/dcrag-to-payload-schema";
|
||||
|
||||
const BASE = ENDPOINT.AS_SERVICE.DCRAG_TO;
|
||||
|
||||
async function requestDocumentTransfer(
|
||||
body: DcRagDocumentTransferRequestDto,
|
||||
): Promise<DcRagCommonResponseDto> {
|
||||
const response = await client.post<DcRagCommonResponseDto>(`${BASE}/documents/transfer`, body);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
async function requestDraftGeneration(
|
||||
body: DcRagDraftGenerateRequestDto,
|
||||
): Promise<DcRagDraftGenerateResponseDto> {
|
||||
const response = await client.post<DcRagDraftGenerateResponseDto>(
|
||||
`${BASE}/documents/draft/generate`,
|
||||
body,
|
||||
);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
async function getDraftGenerationStatus(crtDmndUuid: string): Promise<DcRagDraftStatusResponseDto> {
|
||||
const response = await client.get<DcRagDraftStatusResponseDto>(
|
||||
`${BASE}/documents/draft/status/${crtDmndUuid}`,
|
||||
);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
async function requestCostVerification(
|
||||
body: DcRagCostVerifyRequestDto,
|
||||
): Promise<DcRagCommonResponseDto> {
|
||||
const response = await client.post<DcRagCommonResponseDto>(`${BASE}/documents/cost/verify`, body);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export const dcRagApiToService = {
|
||||
requestDocumentTransfer,
|
||||
requestDraftGeneration,
|
||||
getDraftGenerationStatus,
|
||||
requestCostVerification,
|
||||
} satisfies DcRagApiToService;
|
||||
@@ -0,0 +1,70 @@
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
|
||||
import { ENDPOINT } from "@/shared/config";
|
||||
|
||||
import type { DcRagDraftStatusResponseDto } from "../model/dcrag-to-interface";
|
||||
import type {
|
||||
DcRagCostVerifyRequestDto,
|
||||
DcRagDocumentTransferRequestDto,
|
||||
DcRagDraftGenerateRequestDto,
|
||||
} from "../model/dcrag-to-payload-schema";
|
||||
|
||||
import { dcRagApiToService } from "./dcrag-to-service";
|
||||
|
||||
export const dcRagApiToBaseKey = [ENDPOINT.AS_SERVICE.DCRAG_TO] as const;
|
||||
|
||||
const DRAFT_STATUS_POLL_INTERVAL_MS = 5_000;
|
||||
|
||||
function isDraftGenerationSettled(data: DcRagDraftStatusResponseDto | undefined): boolean {
|
||||
if (!data) return false;
|
||||
if (data.status === "COMPLETED" || data.status === "FAILED") return true;
|
||||
return data.events?.some((event) => event.eventType === "COMPLETED") ?? false;
|
||||
}
|
||||
|
||||
export function useDraftGenerationStatus(crtDmndUuid: string | null | undefined) {
|
||||
return useQuery({
|
||||
queryKey: [...dcRagApiToBaseKey, "getDraftGenerationStatus", crtDmndUuid],
|
||||
queryFn: () => dcRagApiToService.getDraftGenerationStatus(crtDmndUuid!),
|
||||
enabled: Boolean(crtDmndUuid),
|
||||
refetchInterval: (query) =>
|
||||
isDraftGenerationSettled(query.state.data) ? false : DRAFT_STATUS_POLL_INTERVAL_MS,
|
||||
});
|
||||
}
|
||||
|
||||
export function useRequestDocumentTransfer() {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (body: DcRagDocumentTransferRequestDto) =>
|
||||
dcRagApiToService.requestDocumentTransfer(body),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: dcRagApiToBaseKey });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useRequestDraftGeneration() {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (body: DcRagDraftGenerateRequestDto) =>
|
||||
dcRagApiToService.requestDraftGeneration(body),
|
||||
onSuccess: (_data, body) => {
|
||||
queryClient.invalidateQueries({ queryKey: dcRagApiToBaseKey });
|
||||
if (body.crtDmndUuid) {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: [...dcRagApiToBaseKey, "getDraftGenerationStatus", body.crtDmndUuid],
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useRequestCostVerification() {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (body: DcRagCostVerifyRequestDto) =>
|
||||
dcRagApiToService.requestCostVerification(body),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: dcRagApiToBaseKey });
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
export { dcRagApiToService } from "./api/dcrag-to-service";
|
||||
export { dcRagApiToBaseKey } from "./api/queries";
|
||||
export {
|
||||
useDraftGenerationStatus,
|
||||
useRequestCostVerification,
|
||||
useRequestDocumentTransfer,
|
||||
useRequestDraftGeneration,
|
||||
} from "./api/queries";
|
||||
export type {
|
||||
DcRagApiToService,
|
||||
DcRagCommonResponseDto,
|
||||
DcRagDraftGenerateResponseDto,
|
||||
DcRagDraftStatusResponseDto,
|
||||
EventInfoDto,
|
||||
} from "./model/dcrag-to-interface";
|
||||
export type {
|
||||
DcRagCostVerifyRequestDto,
|
||||
DcRagDocumentTransferRequestDto,
|
||||
DcRagDraftGenerateRequestDto,
|
||||
DcRagFileInfoDto,
|
||||
} from "./model/dcrag-to-payload-schema";
|
||||
export {
|
||||
dcRagCostVerifyRequestSchema,
|
||||
dcRagDocumentTransferRequestSchema,
|
||||
dcRagDraftGenerateRequestSchema,
|
||||
dcRagFileInfoSchema,
|
||||
} from "./model/dcrag-to-payload-schema";
|
||||
@@ -0,0 +1,52 @@
|
||||
import type {
|
||||
DcRagCostVerifyRequestDto,
|
||||
DcRagDocumentTransferRequestDto,
|
||||
DcRagDraftGenerateRequestDto,
|
||||
} from "./dcrag-to-payload-schema";
|
||||
|
||||
/** 백엔드 DcRagCommonResponseDto */
|
||||
export interface DcRagCommonResponseDto {
|
||||
resultCode?: string;
|
||||
message?: string;
|
||||
requestId?: string;
|
||||
}
|
||||
|
||||
/** 백엔드 DcRagDraftGenerateResponseDto */
|
||||
export interface DcRagDraftGenerateResponseDto {
|
||||
resultCode?: string;
|
||||
message?: string;
|
||||
crtDmndUuid?: string;
|
||||
/** R:생성요청, I:생성중, C:생성완료, F:생성실패 */
|
||||
crtSttsComCd?: "R" | "I" | "C" | "F";
|
||||
requestId?: string;
|
||||
estimatedMinutes?: number;
|
||||
}
|
||||
|
||||
/** 백엔드 DcRagDraftStatusResponseDto.EventInfoDto */
|
||||
export interface EventInfoDto {
|
||||
eventType?: string;
|
||||
eventMessage?: string;
|
||||
occurredDt?: string;
|
||||
}
|
||||
|
||||
/** 백엔드 DcRagDraftStatusResponseDto */
|
||||
export interface DcRagDraftStatusResponseDto {
|
||||
crtDmndUuid?: string;
|
||||
status?: "REQUESTED" | "DOWNLOADING" | "ANALYZING" | "GENERATING" | "COMPLETED" | "FAILED";
|
||||
statusName?: string;
|
||||
progressPercent?: number;
|
||||
events?: EventInfoDto[];
|
||||
startedDt?: string;
|
||||
estimatedCompletionDt?: string;
|
||||
errorMessage?: string;
|
||||
}
|
||||
|
||||
/** Controller public 메서드명·시그니처와 동일 */
|
||||
export interface DcRagApiToService {
|
||||
requestDocumentTransfer(body: DcRagDocumentTransferRequestDto): Promise<DcRagCommonResponseDto>;
|
||||
requestDraftGeneration(
|
||||
body: DcRagDraftGenerateRequestDto,
|
||||
): Promise<DcRagDraftGenerateResponseDto>;
|
||||
getDraftGenerationStatus(crtDmndUuid: string): Promise<DcRagDraftStatusResponseDto>;
|
||||
requestCostVerification(body: DcRagCostVerifyRequestDto): Promise<DcRagCommonResponseDto>;
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
import { z } from "zod";
|
||||
|
||||
/** 백엔드 DcRagFileInfoDto */
|
||||
export const dcRagFileInfoSchema = z.object({
|
||||
fileId: z.string().optional(),
|
||||
fileGroupId: z.string().optional(),
|
||||
fileName: z.string().optional(),
|
||||
physicalPath: z.string().optional(),
|
||||
downloadUrl: z.string().optional(),
|
||||
fileSize: z.number().optional(),
|
||||
esntlAtchFileId: z.string().optional(),
|
||||
esntlAtchFileNm: z.string().optional(),
|
||||
});
|
||||
|
||||
/** 백엔드 DcRagDocumentTransferRequestDto */
|
||||
export const dcRagDocumentTransferRequestSchema = z.object({
|
||||
fnrsCnsltnDocNo: z.string(),
|
||||
taskSeComCd: z.string().optional(),
|
||||
taskSeCdNm: z.string().optional(),
|
||||
essentialFiles: z.array(dcRagFileInfoSchema).optional(),
|
||||
etcFiles: z.array(dcRagFileInfoSchema).optional(),
|
||||
callbackUrl: z.string().optional(),
|
||||
});
|
||||
|
||||
/** 백엔드 DcRagDraftGenerateRequestDto */
|
||||
export const dcRagDraftGenerateRequestSchema = z.object({
|
||||
fnrsCnsltnDocNo: z.string(),
|
||||
pwrkCnsltnDocNo: z.string(),
|
||||
crtDmndUuid: z.string().optional(),
|
||||
essentialFiles: z.array(dcRagFileInfoSchema).optional(),
|
||||
etcFiles: z.array(dcRagFileInfoSchema).optional(),
|
||||
rqstrUuid: z.string().optional(),
|
||||
callbackUrl: z.string().optional(),
|
||||
});
|
||||
|
||||
/** 백엔드 DcRagCostVerifyRequestDto */
|
||||
export const dcRagCostVerifyRequestSchema = z.object({
|
||||
fnrsCnsltnDocNo: z.string(),
|
||||
pwrkCnsltnDocNo: z.string(),
|
||||
});
|
||||
|
||||
export type DcRagFileInfoDto = z.infer<typeof dcRagFileInfoSchema>;
|
||||
export type DcRagDocumentTransferRequestDto = z.infer<typeof dcRagDocumentTransferRequestSchema>;
|
||||
export type DcRagDraftGenerateRequestDto = z.infer<typeof dcRagDraftGenerateRequestSchema>;
|
||||
export type DcRagCostVerifyRequestDto = z.infer<typeof dcRagCostVerifyRequestSchema>;
|
||||
@@ -25,6 +25,7 @@ export const ENDPOINT = {
|
||||
DESIGN_CNSTN_RVW_OPNN: "/as-service/api/v1/design-cnstn-rvw-opnn",
|
||||
SEWER_BSC_PLAN: "/as-service/api/v1/sewer-bsc-plans",
|
||||
DASHBOARD: "/as-service/api/v1/dashboard",
|
||||
DCRAG_TO: "/as-service/api/v1/dcrag-to",
|
||||
},
|
||||
USER_SERVICE: {
|
||||
LOGIN: "/user-service/login",
|
||||
|
||||
Reference in New Issue
Block a user