mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
Add /staff routes
This commit is contained in:
parent
bcec4c31d1
commit
8d7d5f3e7e
94
api/src/controllers/staff.ts
Normal file
94
api/src/controllers/staff.ts
Normal 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,
|
||||
},
|
||||
},
|
||||
);
|
@ -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,
|
||||
},
|
||||
|
@ -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);
|
||||
|
@ -64,6 +64,7 @@ app
|
||||
`,
|
||||
},
|
||||
{ name: "studios", description: "Routes about studios" },
|
||||
{ name: "staff", description: "Routes about staff & roles" },
|
||||
],
|
||||
},
|
||||
}),
|
||||
|
Loading…
x
Reference in New Issue
Block a user