diff --git a/api/src/controllers/seed/index.ts b/api/src/controllers/seed/index.ts index 776dc4f1..11de1774 100644 --- a/api/src/controllers/seed/index.ts +++ b/api/src/controllers/seed/index.ts @@ -11,12 +11,24 @@ export const seed = new Elysia() }) .post( "/movies", - async ({ body }) => { - return await seedMovie(body); + async ({ body, error }) => { + const { status, ...ret } = await seedMovie(body); + return error(status === "created" ? 201 : 200, ret); }, { body: "seed-movie", - response: { 200: "seed-movie-response", 400: "error" }, - tags: ["movies"], + response: { + 200: { + ...SeedMovieResponse, + description: "Existing movie edited/updated.", + }, + 201: { ...SeedMovieResponse, description: "Created a new movie." }, + 400: "error", + }, + detail: { + tags: ["movies"], + description: + "Create a movie & all related metadata. Can also link videos.", + }, }, ); diff --git a/api/src/controllers/seed/movies.ts b/api/src/controllers/seed/movies.ts index f2420277..e7cd3308 100644 --- a/api/src/controllers/seed/movies.ts +++ b/api/src/controllers/seed/movies.ts @@ -11,7 +11,6 @@ import { } from "~/db/schema"; import { conflictUpdateAllExcept } from "~/db/schema/utils"; import type { SeedMovie } from "~/models/movie"; -import { Resource } from "~/models/utils"; import { processOptImage } from "./images"; import { guessNextRefresh } from "./refresh"; @@ -19,17 +18,18 @@ type Show = typeof shows.$inferInsert; type ShowTrans = typeof showTranslations.$inferInsert; type Entry = typeof entries.$inferInsert; -export const SeedMovieResponse = t.Intersect([ - Resource, - t.Object({ - videos: t.Array(t.Object({ slug: t.String({ format: "slug" }) })), - }), -]); +export const SeedMovieResponse = t.Object({ + id: t.String({ format: "uuid" }), + slug: t.String({ format: "slug", examples: ["bubble"] }), + videos: t.Array( + t.Object({ slug: t.String({ format: "slug", examples: ["bubble-v2"] }) }), + ), +}); export type SeedMovieResponse = typeof SeedMovieResponse.static; export const seedMovie = async ( seed: SeedMovie, -): Promise => { +): Promise => { const { translations, videos: vids, ...bMovie } = seed; const ret = await db.transaction(async (tx) => { @@ -139,6 +139,7 @@ export const seedMovie = async ( } return { + status: ret.updated ? "updated" : "created", id: ret.id, slug: ret.slug, videos: retVideos, diff --git a/api/src/index.ts b/api/src/index.ts index 92dabc75..00f1b082 100644 --- a/api/src/index.ts +++ b/api/src/index.ts @@ -73,7 +73,6 @@ const app = new Elysia() }, }), ) - .get("/", () => "Hello Elysia") .model({ image: Image }) .use(movies) .use(series)