Skip to content

Commit 2e63903

Browse files
committed
feat(user): add support for getting mir stats
1 parent 2025305 commit 2e63903

3 files changed

Lines changed: 74 additions & 0 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { z } from '../../../_internal/z.ts';
2+
3+
export const monthInReviewParamsSchema = z.object({
4+
year: z.number().int(),
5+
month: z.number().int(),
6+
});
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { episodeResponseSchema } from '../../../_internal/response/episodeResponseSchema.ts';
2+
import { movieResponseSchema } from '../../../_internal/response/movieResponseSchema.ts';
3+
import { showResponseSchema } from '../../../_internal/response/showResponseSchema.ts';
4+
import { z } from '../../../_internal/z.ts';
5+
6+
const statsSchema = z.object({
7+
total: z.number(),
8+
yearly: z.number(),
9+
monthly: z.number(),
10+
weekly: z.number(),
11+
daily: z.number(),
12+
});
13+
14+
const statsCategoriesSchema = z.object({
15+
minutes: statsSchema,
16+
play_counts: statsSchema,
17+
collected_counts: statsSchema,
18+
ratings_counts: statsSchema,
19+
comments_counts: statsSchema,
20+
lists_counts: statsSchema,
21+
});
22+
23+
const watchedEpisodeSchema = z.object({
24+
type: z.literal('episode'),
25+
watched_at: z.string().datetime(),
26+
episode: episodeResponseSchema,
27+
show: showResponseSchema,
28+
});
29+
30+
const watchedMovieSchema = z.object({
31+
type: z.literal('movie'),
32+
watched_at: z.string().datetime(),
33+
movie: movieResponseSchema,
34+
});
35+
36+
const watchedItemSchema = z.discriminatedUnion('type', [
37+
watchedEpisodeSchema,
38+
watchedMovieSchema,
39+
]);
40+
41+
export const monthInReviewResponseSchema = z.object({
42+
stats: z.object({
43+
all: statsCategoriesSchema,
44+
shows: statsCategoriesSchema,
45+
movies: statsCategoriesSchema,
46+
}),
47+
images: z.object({
48+
cover: z.string(),
49+
story: z.string(),
50+
}),
51+
first_watched: watchedItemSchema,
52+
last_watched: watchedItemSchema,
53+
});

projects/api/src/contracts/users/index.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { avatarRequestSchema } from './_internal/request/avatarRequestSchema.ts'
1010
import { commentOnTypeParamsSchema } from './_internal/request/commentOnTypeParamsSchema.ts';
1111
import { commentsRequestSchema } from './_internal/request/commentsRequestSchema.ts';
1212
import { commentTypeParamsSchema } from './_internal/request/commentTypeParamsSchema.ts';
13+
import { monthInReviewParamsSchema } from './_internal/request/monthInReviewParamsSchema.ts';
1314
import { profileParamsSchema } from './_internal/request/profileParamsSchema.ts';
1415
import { settingsRequestSchema } from './_internal/request/settingsRequestSchema.ts';
1516
import { socialActivityParamsSchema } from './_internal/request/socialActivityParamsSchema.ts';
@@ -21,6 +22,7 @@ import {
2122
likedCommentResponseSchema,
2223
likedListResponseSchema,
2324
} from './_internal/response/likedItemResponseSchema.ts';
25+
import { monthInReviewResponseSchema } from './_internal/response/monthInReviewResponseSchema.ts';
2426
import { settingsResponseSchema } from './_internal/response/settingsResponseSchema.ts';
2527
import { socialActivityResponseSchema } from './_internal/response/socialActivityResponseSchema.ts';
2628
import { userCommentResponseSchema } from './_internal/response/userCommentResponseSchema.ts';
@@ -183,6 +185,16 @@ const ENTITY_LEVEL = builder.router({
183185
200: friendResponseSchema.array(),
184186
},
185187
},
188+
month_in_review: {
189+
path: '/mir',
190+
pathParams: profileParamsSchema
191+
.merge(monthInReviewParamsSchema),
192+
query: extendedMediaQuerySchema,
193+
method: 'GET',
194+
responses: {
195+
200: monthInReviewResponseSchema,
196+
},
197+
},
186198
}, {
187199
pathPrefix: '/:id',
188200
});
@@ -245,3 +257,6 @@ export type UserCommentResponse = z.infer<typeof userCommentResponseSchema>;
245257
export type WatchingResponse = z.infer<typeof watchingResponseSchema>;
246258
export type AvatarRequest = z.infer<typeof avatarRequestSchema>;
247259
export type SettingsRequest = z.infer<typeof settingsRequestSchema>;
260+
261+
export type MonthInReviewParams = z.infer<typeof monthInReviewParamsSchema>;
262+
export type MonthInReviewResponse = z.infer<typeof monthInReviewResponseSchema>;

0 commit comments

Comments
 (0)