mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-07-09 03:04:20 -04:00
Swagger setup
This commit is contained in:
parent
0edf216618
commit
b8b536632d
@ -1,9 +1,10 @@
|
||||
import { Elysia, t } from "elysia";
|
||||
import { Movie } from "../models/movie";
|
||||
import { Movie, MovieTranslation } from "../models/movie";
|
||||
import { db } from "../db";
|
||||
import { shows, showTranslations } from "../db/schema/shows";
|
||||
import { eq, and, sql, or, inArray } from "drizzle-orm";
|
||||
import { getColumns } from "../db/schema/utils";
|
||||
import { bubble } from "../models/examples";
|
||||
|
||||
const translations = db
|
||||
.selectDistinctOn([showTranslations.language])
|
||||
@ -22,7 +23,6 @@ const translations = db
|
||||
const { pk: _, kind, startAir, endAir, ...moviesCol } = getColumns(shows);
|
||||
const { pk, language, ...translationsCol } = getColumns(translations);
|
||||
|
||||
|
||||
const findMovie = db
|
||||
.select({
|
||||
...moviesCol,
|
||||
@ -47,16 +47,29 @@ const findMovie = db
|
||||
export const movies = new Elysia({ prefix: "/movies" })
|
||||
.model({
|
||||
movie: Movie,
|
||||
"movie-translation": MovieTranslation,
|
||||
error: t.Object({}),
|
||||
})
|
||||
.guard({
|
||||
params: t.Object({
|
||||
id: t.String(),
|
||||
id: t.String({
|
||||
description: "The id or slug of the movie to retrieve",
|
||||
examples: [bubble.slug],
|
||||
}),
|
||||
}),
|
||||
response: { 200: "movie", 404: "error" },
|
||||
tags: ["Movies"],
|
||||
})
|
||||
.get("/:id", async ({ params: { id }, error }) => {
|
||||
const ret = await findMovie.execute({ id });
|
||||
if (ret.length !== 1) return error(404, {});
|
||||
return ret[0];
|
||||
});
|
||||
.get(
|
||||
"/:id",
|
||||
async ({ params: { id }, error }) => {
|
||||
const ret = await findMovie.execute({ id });
|
||||
if (ret.length !== 1) return error(404, {});
|
||||
return ret[0];
|
||||
},
|
||||
{
|
||||
detail: {
|
||||
description: "Get a movie by id or slug",
|
||||
},
|
||||
},
|
||||
);
|
||||
|
@ -5,9 +5,12 @@ import { Elysia } from "elysia";
|
||||
import { entries } from "./controllers/entries";
|
||||
import { movies } from "./controllers/movies";
|
||||
import { seasons } from "./controllers/seasons";
|
||||
import { seed } from "./controllers/seed";
|
||||
import { series } from "./controllers/series";
|
||||
import { videos } from "./controllers/videos";
|
||||
import { db } from "./db";
|
||||
import { Image } from "./models/utils";
|
||||
import { comment } from "./utils";
|
||||
|
||||
await migrate(db, { migrationsSchema: "kyoo", migrationsFolder: "./drizzle" });
|
||||
|
||||
@ -33,13 +36,40 @@ if (!secret) {
|
||||
|
||||
const app = new Elysia()
|
||||
.use(jwt({ secret }))
|
||||
.use(swagger())
|
||||
.use(
|
||||
swagger({
|
||||
documentation: {
|
||||
info: {
|
||||
title: "Kyoo",
|
||||
description: comment`
|
||||
Complete API documentation of Kyoo.
|
||||
If you need a route not present here, please make an issue over https://github.com/zoriya/kyoo
|
||||
`,
|
||||
version: "5.0.0",
|
||||
contact: { name: "github", url: "https://github.com/zoriya/kyoo" },
|
||||
license: {
|
||||
name: "GPL-3.0 license",
|
||||
url: "https://github.com/zoriya/Kyoo/blob/master/LICENSE",
|
||||
},
|
||||
},
|
||||
servers: [
|
||||
{
|
||||
url: "https://kyoo.zoriya.dev/api",
|
||||
description: "Kyoo's demo server",
|
||||
},
|
||||
],
|
||||
tags: [{ name: "Movies", description: "Routes about movies" }],
|
||||
},
|
||||
}),
|
||||
)
|
||||
.get("/", () => "Hello Elysia")
|
||||
.model({ image: Image })
|
||||
.use(movies)
|
||||
.use(series)
|
||||
.use(entries)
|
||||
.use(seasons)
|
||||
.use(videos)
|
||||
.use(seed)
|
||||
.listen(3000);
|
||||
|
||||
console.log(`Api running at ${app.server?.hostname}:${app.server?.port}`);
|
||||
|
Loading…
x
Reference in New Issue
Block a user