feat: create routes to load popular titles
This commit is contained in:
@@ -2,28 +2,27 @@ import { graphql } from "gql.tada";
|
||||
import { GraphQLClient } from "graphql-request";
|
||||
|
||||
import { sleep } from "~/libs/sleep";
|
||||
import { HomeTitleFragment } from "~/types/title/homeTitle";
|
||||
|
||||
const SearchQuery = graphql(`
|
||||
query Search($query: String!, $page: Int!, $limit: Int!) {
|
||||
Page(page: $page, perPage: $limit) {
|
||||
media(search: $query, type: ANIME, sort: [POPULARITY_DESC, SCORE_DESC]) {
|
||||
id
|
||||
title {
|
||||
userPreferred
|
||||
english
|
||||
const SearchQuery = graphql(
|
||||
`
|
||||
query Search($query: String!, $page: Int!, $limit: Int!) {
|
||||
Page(page: $page, perPage: $limit) {
|
||||
media(
|
||||
search: $query
|
||||
type: ANIME
|
||||
sort: [POPULARITY_DESC, SCORE_DESC]
|
||||
) {
|
||||
...HomeTitle
|
||||
}
|
||||
coverImage {
|
||||
extraLarge
|
||||
large
|
||||
medium
|
||||
pageInfo {
|
||||
hasNextPage
|
||||
}
|
||||
}
|
||||
pageInfo {
|
||||
hasNextPage
|
||||
}
|
||||
}
|
||||
}
|
||||
`);
|
||||
`,
|
||||
[HomeTitleFragment],
|
||||
);
|
||||
|
||||
export async function fetchSearchResultsFromAnilist(
|
||||
query: string,
|
||||
|
||||
@@ -2,9 +2,9 @@ import { OpenAPIHono, createRoute, z } from "@hono/zod-openapi";
|
||||
|
||||
import { fetchFromMultipleSources } from "~/libs/fetchFromMultipleSources";
|
||||
import { PaginatedResponseSchema } from "~/types/schema";
|
||||
import { HomeTitle } from "~/types/title/homeTitle";
|
||||
|
||||
import { fetchSearchResultsFromAnilist } from "./anilist";
|
||||
import { SearchResult } from "./searchResult";
|
||||
|
||||
const app = new OpenAPIHono();
|
||||
|
||||
@@ -25,7 +25,7 @@ const route = createRoute({
|
||||
200: {
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: PaginatedResponseSchema(SearchResult),
|
||||
schema: PaginatedResponseSchema(HomeTitle),
|
||||
},
|
||||
},
|
||||
description: "Returns a list of paginated results for the query",
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
import { z } from "@hono/zod-openapi";
|
||||
|
||||
export type SearchResult = z.infer<typeof SearchResult>;
|
||||
export const SearchResult = z.object({
|
||||
id: z.number().openapi({ type: "integer", format: "int64" }),
|
||||
title: z.nullable(z.string()),
|
||||
coverImage: z.nullable(
|
||||
z.object({
|
||||
medium: z.nullable(z.string()).optional(),
|
||||
large: z.nullable(z.string()).optional(),
|
||||
extraLarge: z.nullable(z.string()).optional(),
|
||||
}),
|
||||
),
|
||||
});
|
||||
Reference in New Issue
Block a user