Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion projects/api/deno.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@trakt/api",
"exports": "./src/index.ts",
"version": "0.1.42",
"version": "0.1.43",
"imports": {
"@anatine/zod-openapi": "npm:@anatine/zod-openapi@^2.2.6",
"@std/testing": "jsr:@std/testing@^1.0.5",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { z } from '../../../_internal/z.ts';

export const monthInReviewParamsSchema = z.object({
year: z.number().int(),
month: z.number().int(),
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { episodeResponseSchema } from '../../../_internal/response/episodeResponseSchema.ts';
import { movieResponseSchema } from '../../../_internal/response/movieResponseSchema.ts';
import { showResponseSchema } from '../../../_internal/response/showResponseSchema.ts';
import { z } from '../../../_internal/z.ts';

const statsSchema = z.object({
total: z.number(),
yearly: z.number(),
monthly: z.number(),
weekly: z.number(),
daily: z.number(),
});

const statsCategoriesSchema = z.object({
minutes: statsSchema,
play_counts: statsSchema,
collected_counts: statsSchema,
ratings_counts: statsSchema,
comments_counts: statsSchema,
lists_counts: statsSchema,
});

const watchedEpisodeSchema = z.object({
type: z.literal('episode'),
watched_at: z.string().datetime(),
episode: episodeResponseSchema,
show: showResponseSchema,
});

const watchedMovieSchema = z.object({
type: z.literal('movie'),
watched_at: z.string().datetime(),
movie: movieResponseSchema,
});

const watchedItemSchema = z.discriminatedUnion('type', [
watchedEpisodeSchema,
watchedMovieSchema,
]);

export const monthInReviewResponseSchema = z.object({
stats: z.object({
all: statsCategoriesSchema,
shows: statsCategoriesSchema,
movies: statsCategoriesSchema,
}),
images: z.object({
cover: z.string(),
story: z.string(),
}),
first_watched: watchedItemSchema,
last_watched: watchedItemSchema,
});
15 changes: 15 additions & 0 deletions projects/api/src/contracts/users/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { avatarRequestSchema } from './_internal/request/avatarRequestSchema.ts'
import { commentOnTypeParamsSchema } from './_internal/request/commentOnTypeParamsSchema.ts';
import { commentsRequestSchema } from './_internal/request/commentsRequestSchema.ts';
import { commentTypeParamsSchema } from './_internal/request/commentTypeParamsSchema.ts';
import { monthInReviewParamsSchema } from './_internal/request/monthInReviewParamsSchema.ts';
import { profileParamsSchema } from './_internal/request/profileParamsSchema.ts';
import { settingsRequestSchema } from './_internal/request/settingsRequestSchema.ts';
import { socialActivityParamsSchema } from './_internal/request/socialActivityParamsSchema.ts';
Expand All @@ -21,6 +22,7 @@ import {
likedCommentResponseSchema,
likedListResponseSchema,
} from './_internal/response/likedItemResponseSchema.ts';
import { monthInReviewResponseSchema } from './_internal/response/monthInReviewResponseSchema.ts';
import { settingsResponseSchema } from './_internal/response/settingsResponseSchema.ts';
import { socialActivityResponseSchema } from './_internal/response/socialActivityResponseSchema.ts';
import { userCommentResponseSchema } from './_internal/response/userCommentResponseSchema.ts';
Expand Down Expand Up @@ -183,6 +185,16 @@ const ENTITY_LEVEL = builder.router({
200: friendResponseSchema.array(),
},
},
month_in_review: {
path: '/mir',
pathParams: profileParamsSchema
.merge(monthInReviewParamsSchema),
query: extendedMediaQuerySchema,
method: 'GET',
responses: {
200: monthInReviewResponseSchema,
},
},
}, {
pathPrefix: '/:id',
});
Expand Down Expand Up @@ -245,3 +257,6 @@ export type UserCommentResponse = z.infer<typeof userCommentResponseSchema>;
export type WatchingResponse = z.infer<typeof watchingResponseSchema>;
export type AvatarRequest = z.infer<typeof avatarRequestSchema>;
export type SettingsRequest = z.infer<typeof settingsRequestSchema>;

export type MonthInReviewParams = z.infer<typeof monthInReviewParamsSchema>;
export type MonthInReviewResponse = z.infer<typeof monthInReviewResponseSchema>;
Loading