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";
|
2023-09-14 09:01:24 -05:00
|
|
|
import { Recipe } 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";
|
|
|
|
|
|
|
|
const routes = {
|
|
|
|
recipesGroupSlug: (groupSlug: string | number) => `${prefix}/explore/recipes/${groupSlug}`,
|
|
|
|
recipesGroupSlugRecipeSlug: (groupSlug: string | number, recipeSlug: string | number) => `${prefix}/explore/recipes/${groupSlug}/${recipeSlug}`,
|
|
|
|
};
|
|
|
|
|
|
|
|
export class PublicRecipeApi extends BaseCRUDAPIReadOnly<Recipe> {
|
|
|
|
baseRoute = routes.recipesGroupSlug(this.groupSlug);
|
|
|
|
itemRoute = (itemId: string | number) => routes.recipesGroupSlugRecipeSlug(this.groupSlug, itemId);
|
|
|
|
|
|
|
|
constructor(requests: ApiRequestInstance, private readonly groupSlug: string) {
|
|
|
|
super(requests);
|
|
|
|
}
|
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));
|
|
|
|
}
|
2023-09-14 09:01:24 -05:00
|
|
|
}
|