-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem.admin.controller.ts
More file actions
66 lines (55 loc) · 2.39 KB
/
Copy pathproblem.admin.controller.ts
File metadata and controls
66 lines (55 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { BaseController } from "../base.controller";
import { type IProblemAdminService } from "../../services/problems/problem.admin.service";
import { type ICradle } from "../../libs/awilix-container";
import { type ControllerRequest } from "../../types/infrastructure/hono.types";
import {
type CreateAdminProblemPayload,
type UpdateAdminProblemPayload,
} from "../../types/problems/problem.admin.types";
import { ApiResponse } from "../../utils/api-response";
export class ProblemAdminController extends BaseController {
private readonly problemAdminService: IProblemAdminService;
constructor(cradle: ICradle) {
super(cradle);
this.problemAdminService = cradle.problemAdminService;
}
async getAllPaginated(
req: ControllerRequest<never, never, { page?: number; limit?: number; search?: string }>
): Promise<any> {
const { page = 1, limit = 20, search } = req.query;
const result = await this.problemAdminService.getAllPaginated(page, limit, search);
return ApiResponse.paginated(result.data, {
totalItems: result.total,
itemCount: result.data.length,
perPage: limit,
totalPages: Math.ceil(result.total / limit),
currentPage: page,
});
}
async createProblem(req: ControllerRequest<CreateAdminProblemPayload>): Promise<any> {
return this.problemAdminService.createProblem(req.body);
}
async updateProblem(req: ControllerRequest<UpdateAdminProblemPayload, { id: string }>): Promise<any> {
return this.problemAdminService.updateProblem(req.params.id, req.body);
}
async deleteProblem(req: ControllerRequest<never, { id: string }>): Promise<{ success: boolean }> {
await this.problemAdminService.deleteProblem(req.params.id);
return { success: true };
}
async getProblemById(req: ControllerRequest<never, { id: string }>): Promise<any> {
return this.problemAdminService.getProblemById(req.params.id);
}
async getProblemTests(req: ControllerRequest<never, { id: string }>): Promise<any> {
return this.problemAdminService.getProblemTests(req.params.id);
}
async updateProblemTests(req: ControllerRequest<any, { id: string }>): Promise<any> {
return this.problemAdminService.updateProblemTests({
problem_id: req.params.id,
type: req.body.type,
cases: req.body.cases,
});
}
async getStats(req: ControllerRequest<never>): Promise<any> {
return this.problemAdminService.getStats();
}
}