mirror of
				https://github.com/mealie-recipes/mealie.git
				synced 2025-10-31 10:13:32 -04:00 
			
		
		
		
	refactor(frontend): ♻️ update API folder structure
This commit is contained in:
		| @@ -1,60 +0,0 @@ | ||||
| import { ApiRequestInstance } from "~/types/api"; | ||||
|  | ||||
| export interface CrudAPIInterface { | ||||
|   requests: ApiRequestInstance; | ||||
|  | ||||
|   // Route Properties / Methods | ||||
|   baseRoute: string; | ||||
|   itemRoute(itemId: string | number): string; | ||||
|  | ||||
|   // Methods | ||||
| } | ||||
|  | ||||
| export interface CrudAPIMethodsInterface { | ||||
|   // CRUD Methods | ||||
|   getAll(): any; | ||||
|   createOne(): any; | ||||
|   getOne(): any; | ||||
|   updateOne(): any; | ||||
|   patchOne(): any; | ||||
|   deleteOne(): any; | ||||
| } | ||||
|  | ||||
| export abstract class BaseAPI { | ||||
|   requests: ApiRequestInstance; | ||||
|  | ||||
|   constructor(requests: ApiRequestInstance) { | ||||
|     this.requests = requests; | ||||
|   } | ||||
| } | ||||
|  | ||||
| export abstract class BaseCRUDAPI<T, U> extends BaseAPI implements CrudAPIInterface { | ||||
|   abstract baseRoute: string; | ||||
|   abstract itemRoute(itemId: string | number): string; | ||||
|  | ||||
|   async getAll(start = 0, limit = 9999, params = {}) { | ||||
|     return await this.requests.get<T[]>(this.baseRoute, { | ||||
|       params: { start, limit, ...params }, | ||||
|     }); | ||||
|   } | ||||
|  | ||||
|   async createOne(payload: U) { | ||||
|     return await this.requests.post<T>(this.baseRoute, payload); | ||||
|   } | ||||
|  | ||||
|   async getOne(itemId: string | number) { | ||||
|     return await this.requests.get<T>(this.itemRoute(itemId)); | ||||
|   } | ||||
|  | ||||
|   async updateOne(itemId: string | number, payload: T) { | ||||
|     return await this.requests.put<T>(this.itemRoute(itemId), payload); | ||||
|   } | ||||
|  | ||||
|   async patchOne(itemId: string, payload: T) { | ||||
|     return await this.requests.patch(this.itemRoute(itemId), payload); | ||||
|   } | ||||
|  | ||||
|   async deleteOne(itemId: string | number) { | ||||
|     return await this.requests.delete<T>(this.itemRoute(itemId)); | ||||
|   } | ||||
| } | ||||
| @@ -1,47 +0,0 @@ | ||||
| import { BaseAPI } from "./_base"; | ||||
|  | ||||
| const prefix = "/api"; | ||||
|  | ||||
| const routes = { | ||||
|   about: `${prefix}/admin/about`, | ||||
|   aboutStatistics: `${prefix}/admin/about/statistics`, | ||||
|   check: `${prefix}/admin/about/check`, | ||||
| }; | ||||
|  | ||||
| export interface AdminAboutInfo { | ||||
|   production: boolean; | ||||
|   version: string; | ||||
|   demoStatus: boolean; | ||||
|   apiPort: number; | ||||
|   apiDocs: boolean; | ||||
|   dbType: string; | ||||
|   dbUrl: string; | ||||
|   defaultGroup: string; | ||||
| } | ||||
|  | ||||
| export interface AdminStatistics { | ||||
|   totalRecipes: number; | ||||
|   totalUsers: number; | ||||
|   totalGroups: number; | ||||
|   uncategorizedRecipes: number; | ||||
|   untaggedRecipes: number; | ||||
| } | ||||
|  | ||||
| export interface CheckAppConfig { | ||||
|   emailReady: boolean; | ||||
|   baseUrlSet: boolean; | ||||
| } | ||||
|  | ||||
| export class AdminAboutAPI extends BaseAPI { | ||||
|   async about() { | ||||
|     return await this.requests.get<AdminAboutInfo>(routes.about); | ||||
|   } | ||||
|  | ||||
|   async statistics() { | ||||
|     return await this.requests.get(routes.aboutStatistics); | ||||
|   } | ||||
|  | ||||
|   async checkApp() { | ||||
|     return await this.requests.get<CheckAppConfig>(routes.check); | ||||
|   } | ||||
| } | ||||
| @@ -1,4 +1,4 @@ | ||||
| import { BaseAPI } from "./_base"; | ||||
| import { BaseAPI } from "../_base"; | ||||
|  | ||||
| export interface BackupOptions { | ||||
|   recipes?: boolean; | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| import { BaseCRUDAPI } from "./_base"; | ||||
| import { BaseCRUDAPI } from "../_base"; | ||||
| import { Recipe } from "~/types/api-types/recipe"; | ||||
|  | ||||
| const prefix = "/api"; | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| import { BaseAPI } from "./_base"; | ||||
| import { BaseAPI } from "../_base"; | ||||
|  | ||||
| const routes = { | ||||
|   base: "/api/admin/email", | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| import { BaseCRUDAPI } from "./_base"; | ||||
| import { BaseCRUDAPI } from "../_base"; | ||||
|  | ||||
| export type EventCategory = "general" | "recipe" | "backup" | "scheduled" | "migration" | "group" | "user"; | ||||
| export type DeclaredTypes = "General" | "Discord" | "Gotify" | "Pushover" | "Home Assistant"; | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| import { BaseAPI } from "./_base"; | ||||
| import { BaseAPI } from "../_base"; | ||||
|  | ||||
| export type EventCategory = "general" | "recipe" | "backup" | "scheduled" | "migration" | "group" | "user"; | ||||
|  | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| import { BaseCRUDAPI } from "./_base"; | ||||
| import { BaseCRUDAPI } from "../_base"; | ||||
| import { Category } from "./categories"; | ||||
| import { CategoryBase } from "~/types/api-types/recipe"; | ||||
|  | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| import { BaseCRUDAPI } from "./_base"; | ||||
| import { BaseCRUDAPI } from "../_base"; | ||||
|  | ||||
| const prefix = "/api"; | ||||
|  | ||||
|   | ||||
							
								
								
									
										13
									
								
								frontend/api/class-interfaces/group-tasks.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								frontend/api/class-interfaces/group-tasks.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,13 @@ | ||||
| import { BaseAPI } from "../_base"; | ||||
| import { ServerTask } from "~/api/types/server-task"; | ||||
| const prefix = "/api"; | ||||
|  | ||||
| const routes = { | ||||
|   base: `${prefix}/groups/server-tasks`, | ||||
| }; | ||||
|  | ||||
| export class GroupServerTaskAPI extends BaseAPI { | ||||
|   async getAll() { | ||||
|     return await this.requests.get<ServerTask[]>(routes.base); | ||||
|   } | ||||
| } | ||||
| @@ -1,4 +1,4 @@ | ||||
| import { BaseCRUDAPI } from "./_base"; | ||||
| import { BaseCRUDAPI } from "../_base"; | ||||
|  | ||||
| const prefix = "/api"; | ||||
|  | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| import { BaseCRUDAPI } from "./_base"; | ||||
| import { BaseCRUDAPI } from "../_base"; | ||||
| import { GroupInDB, UserOut } from "~/types/api-types/user"; | ||||
|  | ||||
| const prefix = "/api"; | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| import { BaseAPI } from "./_base"; | ||||
| import { BaseAPI } from "../_base"; | ||||
|  | ||||
| interface BasePayload { | ||||
|   recipes: string[]; | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| import { BaseCRUDAPI } from "./_base"; | ||||
| import { BaseCRUDAPI } from "../_base"; | ||||
|  | ||||
| const prefix = "/api"; | ||||
|  | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| import { BaseCRUDAPI } from "./_base"; | ||||
| import { BaseCRUDAPI } from "../_base"; | ||||
|  | ||||
| const prefix = "/api"; | ||||
|  | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| import { BaseCRUDAPI } from "./_base"; | ||||
| import { BaseCRUDAPI } from "../_base"; | ||||
| import { Recipe, CreateRecipe } from "~/types/api-types/recipe"; | ||||
|  | ||||
| const prefix = "/api"; | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| import { BaseCRUDAPI } from "./_base"; | ||||
| import { BaseCRUDAPI } from "../_base"; | ||||
| import { Recipe } from "~/types/api-types/admin"; | ||||
|  | ||||
| const prefix = "/api"; | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| import { BaseAPI } from "./_base"; | ||||
| import { BaseAPI } from "../_base"; | ||||
|  | ||||
| export class UploadFile extends BaseAPI { | ||||
|   file(url: string, fileObject: any) { | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| import { BaseAPI } from "./_base"; | ||||
| import { BaseAPI } from "../_base"; | ||||
|  | ||||
| export interface RegisterPayload { | ||||
|   group: string; | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| import { BaseCRUDAPI } from "./_base"; | ||||
| import { BaseCRUDAPI } from "../_base"; | ||||
| import { UserIn, UserOut } from "~/types/api-types/user"; | ||||
|  | ||||
| // Interfaces | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| import { BaseAPI } from "./_base"; | ||||
| import { BaseAPI } from "../_base"; | ||||
|  | ||||
| const prefix = "/api"; | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user