mirror of
https://github.com/hay-kot/mealie.git
synced 2025-07-08 05:51:50 -07:00
refactor(frontend): ♻️ rewrite search componenets to typescript
This commit is contained in:
parent
1981e191be
commit
bde885dc84
25 changed files with 826 additions and 113 deletions
45
frontend/api/class-interfaces/categories.ts
Normal file
45
frontend/api/class-interfaces/categories.ts
Normal file
|
@ -0,0 +1,45 @@
|
|||
import { BaseCRUDAPI } from "./_base";
|
||||
|
||||
const prefix = "/api";
|
||||
|
||||
export interface Category {
|
||||
name: string;
|
||||
id: number;
|
||||
slug: string;
|
||||
}
|
||||
|
||||
export interface CreateCategory {
|
||||
name: string;
|
||||
}
|
||||
|
||||
const routes = {
|
||||
categories: `${prefix}/categories`,
|
||||
categoriesEmpty: `${prefix}/categories/empty`,
|
||||
|
||||
categoriesCategory: (category: string) => `${prefix}/categories/${category}`,
|
||||
};
|
||||
|
||||
export class CategoriesAPI extends BaseCRUDAPI<Category, CreateCategory> {
|
||||
baseRoute: string = routes.categories;
|
||||
itemRoute = routes.categoriesCategory;
|
||||
|
||||
/** Returns a list of categories that do not contain any recipes
|
||||
*/
|
||||
async getEmptyCategories() {
|
||||
return await this.requests.get(routes.categoriesEmpty);
|
||||
}
|
||||
|
||||
/** Returns a list of recipes associated with the provided category.
|
||||
*/
|
||||
async getAllRecipesByCategory(category: string) {
|
||||
return await this.requests.get(routes.categoriesCategory(category));
|
||||
}
|
||||
|
||||
/** Removes a recipe category from the database. Deleting a
|
||||
* category does not impact a recipe. The category will be removed
|
||||
* from any recipes that contain it
|
||||
*/
|
||||
async deleteRecipeCategory(category: string) {
|
||||
return await this.requests.delete(routes.categoriesCategory(category));
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue