File size: 4,793 Bytes
3d23b0f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import { FastifyRequest, FastifyReply } from 'fastify';
import * as service from './service';
import type {
    UserQuery,
    StatusQuery,
    ProblemsetQuery,
    RecentActionsQuery,
    ContestQuery,
    StandingsQuery,
    ContestStatusQuery,
    BlogEntryQuery,
    RecentStatusQuery
} from './types';

export async function getUserRatingHandler(
    request: FastifyRequest<{ Querystring: UserQuery }>,
    reply: FastifyReply
) {
    const { username } = request.query;
    const data = await service.getUserRating(username);
    return reply.send(data);
}

export async function getContestHistoryHandler(
    request: FastifyRequest<{ Querystring: UserQuery }>,
    reply: FastifyReply
) {
    const { username } = request.query;
    const data = await service.getContestHistory(username);
    return reply.send(data);
}

export async function getUserStatusHandler(
    request: FastifyRequest<{ Querystring: StatusQuery }>,
    reply: FastifyReply
) {
    const { username, from = 1, count = 10 } = request.query;
    const data = await service.getUserStatus(username, Number(from), Number(count));
    return reply.send(data);
}

export async function getUserBlogsHandler(
    request: FastifyRequest<{ Querystring: UserQuery }>,
    reply: FastifyReply
) {
    const { username } = request.query;
    const data = await service.getUserBlogs(username);
    return reply.send(data);
}

export async function getSolvedProblemsHandler(
    request: FastifyRequest<{ Querystring: UserQuery }>,
    reply: FastifyReply
) {
    const { username } = request.query;
    const data = await service.getSolvedProblems(username);
    return reply.send(data);
}

export async function getContestsHandler(
    request: FastifyRequest<{ Querystring: { gym?: boolean } }>,
    reply: FastifyReply
) {
    const { gym = false } = request.query;
    const data = await service.getContests(gym);
    return reply.send(data);
}

export async function getRecentActionsHandler(
    request: FastifyRequest<{ Querystring: RecentActionsQuery }>,
    reply: FastifyReply
) {
    const { maxCount = 20 } = request.query;
    const data = await service.getRecentActions(Number(maxCount));
    return reply.send(data);
}

export async function getProblemsHandler(
    request: FastifyRequest<{ Querystring: ProblemsetQuery }>,
    reply: FastifyReply
) {
    const { tags } = request.query;
    const data = await service.getProblems(tags);
    return reply.send(data);
}

export async function getContestStandingsHandler(
    request: FastifyRequest<{ Querystring: StandingsQuery }>,
    reply: FastifyReply
) {
    const { contestId, from, count, handles, room, showUnofficial } = request.query;
    const data = await service.getContestStandings(
        Number(contestId),
        from ? Number(from) : undefined,
        count ? Number(count) : undefined,
        handles,
        room ? Number(room) : undefined,
        showUnofficial
    );
    return reply.send(data);
}

export async function getContestRatingChangesHandler(
    request: FastifyRequest<{ Querystring: ContestQuery }>,
    reply: FastifyReply
) {
    const { contestId } = request.query;
    const data = await service.getContestRatingChanges(Number(contestId));
    return reply.send(data);
}

export async function getContestHacksHandler(
    request: FastifyRequest<{ Querystring: ContestQuery }>,
    reply: FastifyReply
) {
    const { contestId } = request.query;
    const data = await service.getContestHacks(Number(contestId));
    return reply.send(data);
}

export async function getContestStatusHandler(
    request: FastifyRequest<{ Querystring: ContestStatusQuery }>,
    reply: FastifyReply
) {
    const { contestId, handle, from, count } = request.query;
    const data = await service.getContestStatus(
        Number(contestId),
        handle,
        from ? Number(from) : undefined,
        count ? Number(count) : undefined
    );
    return reply.send(data);
}

export async function getProblemsetRecentStatusHandler(
    request: FastifyRequest<{ Querystring: RecentStatusQuery }>,
    reply: FastifyReply
) {
    const { count = 10 } = request.query;
    const data = await service.getProblemsetRecentStatus(Number(count));
    return reply.send(data);
}

export async function getBlogEntryHandler(
    request: FastifyRequest<{ Querystring: BlogEntryQuery }>,
    reply: FastifyReply
) {
    const { blogEntryId } = request.query;
    const data = await service.getBlogEntry(Number(blogEntryId));
    return reply.send(data);
}

export async function getBlogCommentsHandler(
    request: FastifyRequest<{ Querystring: BlogEntryQuery }>,
    reply: FastifyReply
) {
    const { blogEntryId } = request.query;
    const data = await service.getBlogComments(Number(blogEntryId));
    return reply.send(data);
}