mirror of
				https://github.com/mealie-recipes/mealie.git
				synced 2025-10-30 17:53:31 -04:00 
			
		
		
		
	feat(frontend): 🚧 CRUD Functionality
This commit is contained in:
		| @@ -1,10 +1,49 @@ | ||||
| import { ApiRequestInstance } from "~/types/api"; | ||||
|  | ||||
| export class BaseAPIClass { | ||||
|     requests: ApiRequestInstance | ||||
|      | ||||
|     constructor(requests: ApiRequestInstance) { | ||||
|         this.requests = requests; | ||||
|     } | ||||
| export interface CrudAPIInterface { | ||||
|   requests: ApiRequestInstance; | ||||
|  | ||||
|   // Route Properties / Methods | ||||
|   baseRoute: string; | ||||
|   itemRoute(itemId: string): string; | ||||
|  | ||||
|   // Methods | ||||
| } | ||||
|  | ||||
| export abstract class BaseAPIClass<T> implements CrudAPIInterface { | ||||
|   requests: ApiRequestInstance; | ||||
|  | ||||
|   abstract baseRoute: string; | ||||
|   abstract itemRoute(itemId: string): string; | ||||
|  | ||||
|   constructor(requests: ApiRequestInstance) { | ||||
|     this.requests = requests; | ||||
|   } | ||||
|  | ||||
|   async getAll(start = 0, limit = 9999) { | ||||
|     return await this.requests.get<T[]>(this.baseRoute, { | ||||
|       params: { start, limit }, | ||||
|     }); | ||||
|   } | ||||
|  | ||||
|   async getOne(itemId: string) { | ||||
|     return await this.requests.get<T>(this.itemRoute(itemId)); | ||||
|   } | ||||
|  | ||||
|   async createOne(payload: T) { | ||||
|     return await this.requests.post(this.baseRoute, payload); | ||||
|   } | ||||
|    | ||||
|   async updateOne(itemId: string, 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) { | ||||
|     return await this.requests.delete<T>(this.itemRoute(itemId)); | ||||
|   } | ||||
|  | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user