2023-09-14 09:01:24 -05:00
|
|
|
import { BaseCRUDAPIReadOnly } from "~/lib/api/base/base-clients";
|
2023-11-05 19:07:02 -06:00
|
|
|
import { route } from "../../base";
|
2024-12-03 07:27:41 -06:00
|
|
|
import { Recipe, RecipeSuggestionQuery, RecipeSuggestionResponse } from "~/lib/api/types/recipe";
|
2023-11-05 19:07:02 -06:00
|
|
|
import { ApiRequestInstance, PaginationData } from "~/lib/api/types/non-generated";
|
|
|
|
import { RecipeSearchQuery } from "../../user/recipes/recipe";
|
2023-09-14 09:01:24 -05:00
|
|
|
|
|
|
|
const prefix = "/api";
|
2024-08-22 10:14:32 -05:00
|
|
|
const exploreGroupSlug = (groupSlug: string | number) => `${prefix}/explore/groups/${groupSlug}`
|
2023-09-14 09:01:24 -05:00
|
|
|
|
|
|
|
const routes = {
|
2024-08-22 10:14:32 -05:00
|
|
|
recipesGroupSlug: (groupSlug: string | number) => `${exploreGroupSlug(groupSlug)}/recipes`,
|
|
|
|
recipesGroupSlugRecipeSlug: (groupSlug: string | number, recipeSlug: string | number) => `${exploreGroupSlug(groupSlug)}/recipes/${recipeSlug}`,
|
2023-09-14 09:01:24 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
export class PublicRecipeApi extends BaseCRUDAPIReadOnly<Recipe> {
|
|
|
|
constructor(requests: ApiRequestInstance, private readonly groupSlug: string) {
|
2025-06-20 00:09:12 +07:00
|
|
|
super(
|
|
|
|
requests,
|
|
|
|
routes.recipesGroupSlug(groupSlug),
|
|
|
|
(itemId: string | number) => routes.recipesGroupSlugRecipeSlug(groupSlug, itemId)
|
|
|
|
);
|
2023-09-14 09:01:24 -05:00
|
|
|
}
|
2023-11-05 19:07:02 -06:00
|
|
|
|
|
|
|
async search(rsq: RecipeSearchQuery) {
|
|
|
|
return await this.requests.get<PaginationData<Recipe>>(route(routes.recipesGroupSlug(this.groupSlug), rsq));
|
|
|
|
}
|
2024-12-03 07:27:41 -06:00
|
|
|
|
|
|
|
async getSuggestions(q: RecipeSuggestionQuery, foods: string[] | null = null, tools: string[]| null = null) {
|
|
|
|
return await this.requests.get<RecipeSuggestionResponse>(
|
2025-06-20 00:09:12 +07:00
|
|
|
route(`${routes.recipesGroupSlug(this.groupSlug)}/suggestions`, { ...q, foods, tools })
|
2024-12-03 07:27:41 -06:00
|
|
|
);
|
|
|
|
}
|
2023-09-14 09:01:24 -05:00
|
|
|
}
|