Skip to content

Commit

Permalink
Fix get problem info api
Browse files Browse the repository at this point in the history
  • Loading branch information
slhmy committed Sep 29, 2023
1 parent 34e360a commit 1e7e290
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
4 changes: 3 additions & 1 deletion src/api/problem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ export namespace ProblemService {

export async function getProblemInfoList() {
let res =
await client.get<ProblemServiceModel.ProblemInfo[]>(`/v1/problem`);
await client.get<ProblemServiceModel.GetProblemInfoResponse>(
`/v1/problem`,
);
if (res.status !== 200) {
throw Error("failed to get problem list");
}
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/problem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const useProblemInfoList = () => {
useEffect(() => {
ProblemService.getProblemInfoList()
.then((res) => {
setProblemList(res);
setProblemList(res.list);
})
.catch((err) => {
console.log(err);
Expand Down
32 changes: 17 additions & 15 deletions src/mocks/rest/problem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,22 @@ Hello! world!
});

export const getProblemInfoList = rest.get("/v1/problem", (req, res, ctx) => {
const response: ProblemServiceModel.ProblemInfo[] = [
{
slug: "hello-world",
title: "Hello World",
tags: [{ slug: "primer", name: "Primer" }],
},
{
slug: "a+b-problem",
title: "A+B Problem",
tags: [
{ slug: "primer", name: "Primer" },
{ slug: "math", name: "Math" },
],
},
];
const response: ProblemServiceModel.GetProblemInfoResponse = {
list: [
{
slug: "hello-world",
title: "Hello World",
tags: [{ slug: "primer", name: "Primer" }],
},
{
slug: "a+b-problem",
title: "A+B Problem",
tags: [
{ slug: "primer", name: "Primer" },
{ slug: "math", name: "Math" },
],
},
],
};
return res(ctx.status(200), ctx.json(response));
});
4 changes: 4 additions & 0 deletions src/typings/problem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ export namespace ProblemServiceModel {
title: string;
tags: AlgorithmTag[];
}

export interface GetProblemInfoResponse {
list: ProblemInfo[];
}
}

0 comments on commit 1e7e290

Please sign in to comment.