This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import { apiRequest } from "@/lib/api/api-service";
|
||||
import { ApiResponse } from "@/types/api-response";
|
||||
import type { AnalyzeMatchesDto, AnalysisResultDto, AnalysisHistoryDto } from "./types";
|
||||
|
||||
/**
|
||||
* Analysis Service
|
||||
* Backend: /api/analysis/*
|
||||
*/
|
||||
|
||||
const analyzeMatches = (dto: AnalyzeMatchesDto) => {
|
||||
return apiRequest<ApiResponse<AnalysisResultDto>>({
|
||||
url: "/analysis/analyze",
|
||||
client: "core",
|
||||
method: "post",
|
||||
data: dto,
|
||||
});
|
||||
};
|
||||
|
||||
const getHistory = () => {
|
||||
return apiRequest<ApiResponse<AnalysisHistoryDto>>({
|
||||
url: "/analysis/history",
|
||||
client: "core",
|
||||
method: "get",
|
||||
});
|
||||
};
|
||||
|
||||
export const analysisService = {
|
||||
analyzeMatches,
|
||||
getHistory,
|
||||
};
|
||||
@@ -0,0 +1,24 @@
|
||||
// ========================
|
||||
// Request DTOs
|
||||
// ========================
|
||||
|
||||
export interface AnalyzeMatchesDto {
|
||||
matchIds: string[];
|
||||
}
|
||||
|
||||
// ========================
|
||||
// Response DTOs
|
||||
// ========================
|
||||
|
||||
export interface AnalysisResultDto {
|
||||
id: string;
|
||||
matchIds: string[];
|
||||
result: Record<string, unknown>;
|
||||
createdAt: string;
|
||||
[key: string]: unknown;
|
||||
}
|
||||
|
||||
export interface AnalysisHistoryDto {
|
||||
analyses: AnalysisResultDto[];
|
||||
total: number;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import { useQuery, useMutation } from "@tanstack/react-query";
|
||||
import { analysisService } from "./service";
|
||||
import type { AnalyzeMatchesDto } from "./types";
|
||||
|
||||
export const AnalysisQueryKeys = {
|
||||
all: ["analysis"] as const,
|
||||
history: () => [...AnalysisQueryKeys.all, "history"] as const,
|
||||
};
|
||||
|
||||
export const useAnalyzeMatches = () => {
|
||||
return useMutation({
|
||||
mutationFn: (dto: AnalyzeMatchesDto) => analysisService.analyzeMatches(dto),
|
||||
});
|
||||
};
|
||||
|
||||
export const useAnalysisHistory = () => {
|
||||
return useQuery({
|
||||
queryKey: AnalysisQueryKeys.history(),
|
||||
queryFn: () => analysisService.getHistory(),
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user