feat: add basic problem api
This commit is contained in:
parent
c0acbd6ddc
commit
9dfe9bfe81
@ -15,6 +15,6 @@ const baseQuery = fetchBaseQuery({
|
|||||||
|
|
||||||
export const api = createApi({
|
export const api = createApi({
|
||||||
baseQuery: retry(baseQuery, { maxRetries: 2 }),
|
baseQuery: retry(baseQuery, { maxRetries: 2 }),
|
||||||
tagTypes: ["User", "Status", "Submission"],
|
tagTypes: ["User", "Status", "Submission", "ProblemInfo", "TaskInfo"],
|
||||||
endpoints: () => ({}),
|
endpoints: () => ({}),
|
||||||
});
|
});
|
||||||
|
96
src/app/services/problem.ts
Normal file
96
src/app/services/problem.ts
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
import type { Meta, WithCount, Wrap } from "./base";
|
||||||
|
import type { UserProfile } from "./user";
|
||||||
|
import { api } from "./api";
|
||||||
|
|
||||||
|
export interface RuntimeInfo {
|
||||||
|
MemoryLimit: number;
|
||||||
|
NProcLimit: number;
|
||||||
|
TimeLimit: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface TaskInfo {
|
||||||
|
Languages: {
|
||||||
|
Lang: string;
|
||||||
|
Runtime: {
|
||||||
|
Compile: RuntimeInfo;
|
||||||
|
Run: RuntimeInfo;
|
||||||
|
};
|
||||||
|
}[];
|
||||||
|
Tasks: { Id: number; Points: number }[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ProblemInfo {
|
||||||
|
meta: Meta;
|
||||||
|
title: string;
|
||||||
|
statement: string;
|
||||||
|
tags: { Elements: string[] };
|
||||||
|
provider: UserProfile;
|
||||||
|
is_enabled: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CreateVersionRequest {
|
||||||
|
pid: number;
|
||||||
|
storage_key: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface DetailRequest {
|
||||||
|
pid: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface DetailResponse {
|
||||||
|
context: TaskInfo;
|
||||||
|
problem: ProblemInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SearchRequest {
|
||||||
|
keyword: string;
|
||||||
|
tag: string;
|
||||||
|
offset?: number;
|
||||||
|
limit: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type SearchResponse = WithCount<ProblemInfo>;
|
||||||
|
|
||||||
|
export interface UpdateRequest {
|
||||||
|
pid: number;
|
||||||
|
title: string;
|
||||||
|
statement: string;
|
||||||
|
tags: string[];
|
||||||
|
is_enabled: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface UploadResponse {
|
||||||
|
key: string;
|
||||||
|
url: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const problemApi = api.injectEndpoints({
|
||||||
|
endpoints: (builder) => ({
|
||||||
|
search: builder.query<Wrap<SearchResponse>, SearchRequest>({
|
||||||
|
query: (data: SearchRequest) => ({
|
||||||
|
url: "/problem/search",
|
||||||
|
method: "POST",
|
||||||
|
body: data,
|
||||||
|
}),
|
||||||
|
providesTags: (result) =>
|
||||||
|
result && result.body.count > 0
|
||||||
|
? [
|
||||||
|
...result.body.data.map((p: ProblemInfo) => ({
|
||||||
|
type: "ProblemInfo" as const,
|
||||||
|
id: p.meta.ID,
|
||||||
|
})),
|
||||||
|
{ type: "ProblemInfo", id: "Search" },
|
||||||
|
]
|
||||||
|
: [{ type: "ProblemInfo", id: "Search" }],
|
||||||
|
}),
|
||||||
|
detail: builder.query<Wrap<DetailResponse>, DetailRequest>({
|
||||||
|
query: (data: DetailRequest) => ({
|
||||||
|
url: "/problem/search",
|
||||||
|
method: "POST",
|
||||||
|
body: data,
|
||||||
|
}),
|
||||||
|
providesTags: (result) => (result ? [{ type: "TaskInfo", id: result.body.problem.meta.ID }] : []),
|
||||||
|
}),
|
||||||
|
// TODO: admin endpoints: version, update, upload
|
||||||
|
}),
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user