Support nextEntry in /series/{id}

This commit is contained in:
Zoe Roux 2025-04-06 19:32:48 +02:00
parent c3abd7c61b
commit 74ee45244b
No known key found for this signature in database
2 changed files with 32 additions and 8 deletions

View File

@ -1,4 +1,13 @@
import { type SQL, and, desc, eq, exists, ne, sql } from "drizzle-orm";
import {
type SQL,
type Subquery,
and,
desc,
eq,
exists,
ne,
sql,
} from "drizzle-orm";
import type { PgSelect } from "drizzle-orm/pg-core";
import { db } from "~/db";
import {
@ -191,7 +200,7 @@ const showRelations = {
}: {
languages: string[];
userId: string;
watchStatusQ: PgSelect<typeof watchlist>;
watchStatusQ: Subquery;
}) => {
const transQ = db
.selectDistinctOn([entryTranslations.pk])
@ -219,7 +228,9 @@ const showRelations = {
.innerJoin(transQ, eq(entries.pk, transQ.pk))
.leftJoin(progressQ, eq(entries.pk, progressQ.entryPk))
.leftJoinLateral(entryVideosQ, sql`true`)
.where(eq(watchStatusQ.nextEntryPk, entries.pk))
.where(
eq((watchStatusQ as unknown as typeof watchlist).nextEntry, entries.pk),
)
.as("nextEntry");
},
};
@ -291,7 +302,11 @@ export async function getShows({
watchStatus: getColumns(watchStatusQ),
...buildRelations(relations, showRelations, { languages, userId }),
...buildRelations(relations, showRelations, {
languages,
userId,
watchStatusQ,
}),
})
.from(shows)
.leftJoin(watchStatusQ, eq(shows.pk, watchStatusQ.showPk))

View File

@ -1,5 +1,6 @@
import { and, eq, sql } from "drizzle-orm";
import { Elysia, t } from "elysia";
import { auth } from "~/auth";
import { prefix } from "~/base";
import { db } from "~/db";
import { shows } from "~/db/schema";
@ -22,12 +23,14 @@ export const series = new Elysia({ prefix: "/series", tags: ["series"] })
serie: Serie,
"serie-translation": SerieTranslation,
})
.use(auth)
.get(
"/:id",
async ({
params: { id },
headers: { "accept-language": languages },
query: { preferOriginal, with: relations },
jwt: { sub },
error,
set,
}) => {
@ -42,6 +45,7 @@ export const series = new Elysia({ prefix: "/series", tags: ["series"] })
fallbackLanguage: langs.includes("*"),
preferOriginal,
relations,
userId: sub,
});
if (!ret) {
return error(404, {
@ -72,10 +76,13 @@ export const series = new Elysia({ prefix: "/series", tags: ["series"] })
preferOriginal: t.Optional(
t.Boolean({ description: desc.preferOriginal }),
),
with: t.Array(t.UnionEnum(["translations", "studios", "firstEntry"]), {
default: [],
description: "Include related resources in the response.",
}),
with: t.Array(
t.UnionEnum(["translations", "studios", "firstEntry", "nextEntry"]),
{
default: [],
description: "Include related resources in the response.",
},
),
}),
headers: t.Object(
{
@ -131,6 +138,7 @@ export const series = new Elysia({ prefix: "/series", tags: ["series"] })
query: { limit, after, query, sort, filter, preferOriginal },
headers: { "accept-language": languages },
request: { url },
jwt: { sub },
}) => {
const langs = processLanguages(languages);
const items = await getShows({
@ -141,6 +149,7 @@ export const series = new Elysia({ prefix: "/series", tags: ["series"] })
filter: and(eq(shows.kind, "serie"), filter),
languages: langs,
preferOriginal,
userId: sub,
});
return createPage(items, { url, sort, limit });
},