Add /staff routes

This commit is contained in:
Zoe Roux 2025-03-09 19:26:47 +01:00
parent bcec4c31d1
commit 8d7d5f3e7e
No known key found for this signature in database
4 changed files with 99 additions and 2 deletions

View File

@ -0,0 +1,94 @@
import { sql } from "drizzle-orm";
import Elysia, { t } from "elysia";
import { db } from "~/db";
import { staff } from "~/db/schema/staff";
import { KError } from "~/models/error";
import { Role, Staff } from "~/models/staff";
import { Filter, Page, Sort } from "~/models/utils";
import { desc } from "~/models/utils/descriptions";
export const staffH = new Elysia({ tags: ["staff"] })
.model({
staff: Staff,
role: Role,
})
.get(
"/staff/:id",
async ({ params: { id }, error, set }) => {
throw new Error();
},
{
detail: {
description: "Get a staff member by id or slug.",
},
params: t.Object({
id: t.String({
description: "The id or slug of the staff to retrieve.",
example: "hiroyuki-sawano",
}),
}),
response: {
200: "staff",
404: {
...KError,
description: "No staff found with the given id or slug.",
},
},
},
)
.get(
"/staff/random",
async ({ error, redirect }) => {
const [member] = await db
.select({ slug: staff.slug })
.from(staff)
.orderBy(sql`random()`)
.limit(1);
if (!member)
return error(404, {
status: 404,
message: "No staff in the database.",
});
return redirect(`/staff/${member.slug}`);
},
{
detail: {
description: "Get a random staff member.",
},
response: {
302: t.Void({
description:
"Redirected to the [/staff/{id}](#tag/staff/GET/staff/{id}) route.",
}),
404: {
...KError,
description: "No staff in the database.",
},
},
},
)
.get(
"/staff",
async ({ query: { limit, after, query }, request: { url } }) => {
throw new Error();
},
{
detail: {
description: "Get all staff members known by kyoo.",
},
query: t.Object({
query: t.Optional(t.String({ description: desc.query })),
limit: t.Integer({
minimum: 1,
maximum: 250,
default: 50,
description: "Max page size.",
}),
after: t.Optional(t.String({ description: desc.after })),
}),
response: {
200: Page(Staff),
422: KError,
},
},
);

View File

@ -156,7 +156,7 @@ export const studiosH = new Elysia({ prefix: "/studios", tags: ["studios"] })
},
params: t.Object({
id: t.String({
description: "The id or slug of the collection to retrieve.",
description: "The id or slug of the studio to retrieve.",
example: "mappa",
}),
}),
@ -173,7 +173,7 @@ export const studiosH = new Elysia({ prefix: "/studios", tags: ["studios"] })
200: "studio",
404: {
...KError,
description: "No collection found with the given id or slug.",
description: "No studio found with the given id or slug.",
},
422: KError,
},

View File

@ -6,6 +6,7 @@ import { collections } from "./controllers/shows/collections";
import { movies } from "./controllers/shows/movies";
import { series } from "./controllers/shows/series";
import { showsH } from "./controllers/shows/shows";
import { staffH } from "./controllers/staff";
import { studiosH } from "./controllers/studios";
import { videosH } from "./controllers/videos";
import type { KError } from "./models/error";
@ -54,4 +55,5 @@ export const app = new Elysia()
.use(seasonsH)
.use(videosH)
.use(studiosH)
.use(staffH)
.use(seed);

View File

@ -64,6 +64,7 @@ app
`,
},
{ name: "studios", description: "Routes about studios" },
{ name: "staff", description: "Routes about staff & roles" },
],
},
}),