mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-07-21 14:19:41 +02:00
Co-authored-by: Michael Genson <71845777+michael-genson@users.noreply.github.com> Co-authored-by: Kuchenpirat <24235032+Kuchenpirat@users.noreply.github.com>
33 lines
1.5 KiB
TypeScript
33 lines
1.5 KiB
TypeScript
import { BaseCRUDAPIReadOnly } from "~/lib/api/base/base-clients";
|
|
import { route } from "../../base";
|
|
import { Recipe, RecipeSuggestionQuery, RecipeSuggestionResponse } from "~/lib/api/types/recipe";
|
|
import { ApiRequestInstance, PaginationData } from "~/lib/api/types/non-generated";
|
|
import { RecipeSearchQuery } from "../../user/recipes/recipe";
|
|
|
|
const prefix = "/api";
|
|
const exploreGroupSlug = (groupSlug: string | number) => `${prefix}/explore/groups/${groupSlug}`
|
|
|
|
const routes = {
|
|
recipesGroupSlug: (groupSlug: string | number) => `${exploreGroupSlug(groupSlug)}/recipes`,
|
|
recipesGroupSlugRecipeSlug: (groupSlug: string | number, recipeSlug: string | number) => `${exploreGroupSlug(groupSlug)}/recipes/${recipeSlug}`,
|
|
};
|
|
|
|
export class PublicRecipeApi extends BaseCRUDAPIReadOnly<Recipe> {
|
|
constructor(requests: ApiRequestInstance, private readonly groupSlug: string) {
|
|
super(
|
|
requests,
|
|
routes.recipesGroupSlug(groupSlug),
|
|
(itemId: string | number) => routes.recipesGroupSlugRecipeSlug(groupSlug, itemId)
|
|
);
|
|
}
|
|
|
|
async search(rsq: RecipeSearchQuery) {
|
|
return await this.requests.get<PaginationData<Recipe>>(route(routes.recipesGroupSlug(this.groupSlug), rsq));
|
|
}
|
|
|
|
async getSuggestions(q: RecipeSuggestionQuery, foods: string[] | null = null, tools: string[]| null = null) {
|
|
return await this.requests.get<RecipeSuggestionResponse>(
|
|
route(`${routes.recipesGroupSlug(this.groupSlug)}/suggestions`, { ...q, foods, tools })
|
|
);
|
|
}
|
|
}
|