mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-05-31 04:05:33 -04:00
refactor(frontend): ♻️ update API folder structure
This commit is contained in:
parent
9b79b82c4d
commit
a94b9d504f
21
frontend/api/admin-api.ts
Normal file
21
frontend/api/admin-api.ts
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import { AdminAboutAPI } from "./admin/admin-about";
|
||||||
|
import { AdminTaskAPI } from "./admin/admin-tasks";
|
||||||
|
import { ApiRequestInstance } from "~/types/api";
|
||||||
|
|
||||||
|
export class AdminAPI {
|
||||||
|
private static instance: AdminAPI;
|
||||||
|
public about: AdminAboutAPI;
|
||||||
|
public serverTasks: AdminTaskAPI;
|
||||||
|
|
||||||
|
constructor(requests: ApiRequestInstance) {
|
||||||
|
if (AdminAPI.instance instanceof AdminAPI) {
|
||||||
|
return AdminAPI.instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.about = new AdminAboutAPI(requests);
|
||||||
|
this.serverTasks = new AdminTaskAPI(requests);
|
||||||
|
|
||||||
|
Object.freeze(this);
|
||||||
|
AdminAPI.instance = this;
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
import { BaseAPI } from "./_base";
|
import { BaseAPI } from "../_base";
|
||||||
|
|
||||||
const prefix = "/api";
|
const prefix = "/api";
|
||||||
|
|
18
frontend/api/admin/admin-tasks.ts
Normal file
18
frontend/api/admin/admin-tasks.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import { BaseAPI } from "../_base";
|
||||||
|
import { ServerTask } from "~/api/types/server-task";
|
||||||
|
|
||||||
|
const prefix = "/api";
|
||||||
|
|
||||||
|
const routes = {
|
||||||
|
base: `${prefix}/admin/server-tasks`,
|
||||||
|
};
|
||||||
|
|
||||||
|
export class AdminTaskAPI extends BaseAPI {
|
||||||
|
async testTask() {
|
||||||
|
return await this.requests.post<ServerTask>(`${routes.base}`, {});
|
||||||
|
}
|
||||||
|
|
||||||
|
async getAll() {
|
||||||
|
return await this.requests.get<ServerTask[]>(routes.base);
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
import { BaseAPI } from "./_base";
|
import { BaseAPI } from "../_base";
|
||||||
|
|
||||||
export interface BackupOptions {
|
export interface BackupOptions {
|
||||||
recipes?: boolean;
|
recipes?: boolean;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { BaseCRUDAPI } from "./_base";
|
import { BaseCRUDAPI } from "../_base";
|
||||||
import { Recipe } from "~/types/api-types/recipe";
|
import { Recipe } from "~/types/api-types/recipe";
|
||||||
|
|
||||||
const prefix = "/api";
|
const prefix = "/api";
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { BaseAPI } from "./_base";
|
import { BaseAPI } from "../_base";
|
||||||
|
|
||||||
const routes = {
|
const routes = {
|
||||||
base: "/api/admin/email",
|
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 EventCategory = "general" | "recipe" | "backup" | "scheduled" | "migration" | "group" | "user";
|
||||||
export type DeclaredTypes = "General" | "Discord" | "Gotify" | "Pushover" | "Home Assistant";
|
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";
|
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 { Category } from "./categories";
|
||||||
import { CategoryBase } from "~/types/api-types/recipe";
|
import { CategoryBase } from "~/types/api-types/recipe";
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { BaseCRUDAPI } from "./_base";
|
import { BaseCRUDAPI } from "../_base";
|
||||||
|
|
||||||
const prefix = "/api";
|
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";
|
const prefix = "/api";
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { BaseCRUDAPI } from "./_base";
|
import { BaseCRUDAPI } from "../_base";
|
||||||
import { GroupInDB, UserOut } from "~/types/api-types/user";
|
import { GroupInDB, UserOut } from "~/types/api-types/user";
|
||||||
|
|
||||||
const prefix = "/api";
|
const prefix = "/api";
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { BaseAPI } from "./_base";
|
import { BaseAPI } from "../_base";
|
||||||
|
|
||||||
interface BasePayload {
|
interface BasePayload {
|
||||||
recipes: string[];
|
recipes: string[];
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { BaseCRUDAPI } from "./_base";
|
import { BaseCRUDAPI } from "../_base";
|
||||||
|
|
||||||
const prefix = "/api";
|
const prefix = "/api";
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { BaseCRUDAPI } from "./_base";
|
import { BaseCRUDAPI } from "../_base";
|
||||||
|
|
||||||
const prefix = "/api";
|
const prefix = "/api";
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { BaseCRUDAPI } from "./_base";
|
import { BaseCRUDAPI } from "../_base";
|
||||||
import { Recipe, CreateRecipe } from "~/types/api-types/recipe";
|
import { Recipe, CreateRecipe } from "~/types/api-types/recipe";
|
||||||
|
|
||||||
const prefix = "/api";
|
const prefix = "/api";
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { BaseCRUDAPI } from "./_base";
|
import { BaseCRUDAPI } from "../_base";
|
||||||
import { Recipe } from "~/types/api-types/admin";
|
import { Recipe } from "~/types/api-types/admin";
|
||||||
|
|
||||||
const prefix = "/api";
|
const prefix = "/api";
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { BaseAPI } from "./_base";
|
import { BaseAPI } from "../_base";
|
||||||
|
|
||||||
export class UploadFile extends BaseAPI {
|
export class UploadFile extends BaseAPI {
|
||||||
file(url: string, fileObject: any) {
|
file(url: string, fileObject: any) {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { BaseAPI } from "./_base";
|
import { BaseAPI } from "../_base";
|
||||||
|
|
||||||
export interface RegisterPayload {
|
export interface RegisterPayload {
|
||||||
group: string;
|
group: string;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { BaseCRUDAPI } from "./_base";
|
import { BaseCRUDAPI } from "../_base";
|
||||||
import { UserIn, UserOut } from "~/types/api-types/user";
|
import { UserIn, UserOut } from "~/types/api-types/user";
|
||||||
|
|
||||||
// Interfaces
|
// Interfaces
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { BaseAPI } from "./_base";
|
import { BaseAPI } from "../_base";
|
||||||
|
|
||||||
const prefix = "/api";
|
const prefix = "/api";
|
||||||
|
|
||||||
|
@ -12,29 +12,14 @@ import { FoodAPI } from "./class-interfaces/recipe-foods";
|
|||||||
import { UnitAPI } from "./class-interfaces/recipe-units";
|
import { UnitAPI } from "./class-interfaces/recipe-units";
|
||||||
import { CookbookAPI } from "./class-interfaces/group-cookbooks";
|
import { CookbookAPI } from "./class-interfaces/group-cookbooks";
|
||||||
import { WebhooksAPI } from "./class-interfaces/group-webhooks";
|
import { WebhooksAPI } from "./class-interfaces/group-webhooks";
|
||||||
import { AdminAboutAPI } from "./class-interfaces/admin-about";
|
|
||||||
import { RegisterAPI } from "./class-interfaces/user-registration";
|
import { RegisterAPI } from "./class-interfaces/user-registration";
|
||||||
import { MealPlanAPI } from "./class-interfaces/group-mealplan";
|
import { MealPlanAPI } from "./class-interfaces/group-mealplan";
|
||||||
import { EmailAPI } from "./class-interfaces/email";
|
import { EmailAPI } from "./class-interfaces/email";
|
||||||
import { BulkActionsAPI } from "./class-interfaces/recipe-bulk-actions";
|
import { BulkActionsAPI } from "./class-interfaces/recipe-bulk-actions";
|
||||||
|
import { GroupServerTaskAPI } from "./class-interfaces/group-tasks";
|
||||||
|
import { AdminAPI } from "./admin-api";
|
||||||
import { ApiRequestInstance } from "~/types/api";
|
import { ApiRequestInstance } from "~/types/api";
|
||||||
|
|
||||||
class AdminAPI {
|
|
||||||
private static instance: AdminAPI;
|
|
||||||
public about: AdminAboutAPI;
|
|
||||||
|
|
||||||
constructor(requests: ApiRequestInstance) {
|
|
||||||
if (AdminAPI.instance instanceof AdminAPI) {
|
|
||||||
return AdminAPI.instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.about = new AdminAboutAPI(requests);
|
|
||||||
|
|
||||||
Object.freeze(this);
|
|
||||||
AdminAPI.instance = this;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class Api {
|
class Api {
|
||||||
private static instance: Api;
|
private static instance: Api;
|
||||||
public recipes: RecipeAPI;
|
public recipes: RecipeAPI;
|
||||||
@ -54,6 +39,7 @@ class Api {
|
|||||||
public mealplans: MealPlanAPI;
|
public mealplans: MealPlanAPI;
|
||||||
public email: EmailAPI;
|
public email: EmailAPI;
|
||||||
public bulk: BulkActionsAPI;
|
public bulk: BulkActionsAPI;
|
||||||
|
public grouperServerTasks: GroupServerTaskAPI;
|
||||||
|
|
||||||
// Utils
|
// Utils
|
||||||
public upload: UploadFile;
|
public upload: UploadFile;
|
||||||
@ -77,6 +63,7 @@ class Api {
|
|||||||
this.groupWebhooks = new WebhooksAPI(requests);
|
this.groupWebhooks = new WebhooksAPI(requests);
|
||||||
this.register = new RegisterAPI(requests);
|
this.register = new RegisterAPI(requests);
|
||||||
this.mealplans = new MealPlanAPI(requests);
|
this.mealplans = new MealPlanAPI(requests);
|
||||||
|
this.grouperServerTasks = new GroupServerTaskAPI(requests);
|
||||||
|
|
||||||
// Admin
|
// Admin
|
||||||
this.events = new EventsAPI(requests);
|
this.events = new EventsAPI(requests);
|
||||||
|
8
frontend/api/types/server-task.ts
Normal file
8
frontend/api/types/server-task.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
export interface ServerTask {
|
||||||
|
id: number;
|
||||||
|
groupId: number;
|
||||||
|
callback: string;
|
||||||
|
createdAt: string;
|
||||||
|
status: string;
|
||||||
|
log: string;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user