basic structure for webapi
This commit is contained in:
parent
ee42625d66
commit
7ded4a21bb
12 changed files with 554 additions and 62 deletions
|
@ -131,6 +131,7 @@ export const useNavigationStore = defineStore("navigation", {
|
|||
main: [
|
||||
...(abilityStore.can("read", "user", "user") ? [{ key: "user", title: "Benutzer" }] : []),
|
||||
...(abilityStore.can("read", "user", "role") ? [{ key: "role", title: "Rollen" }] : []),
|
||||
...(abilityStore.can("read", "user", "webapi") ? [{ key: "webapi", title: "Webapi-Token" }] : []),
|
||||
],
|
||||
},
|
||||
} as navigationModel;
|
||||
|
|
|
@ -1,57 +0,0 @@
|
|||
import { defineStore } from "pinia";
|
||||
import type { ApiViewModel } from "@/viewmodels/admin/user/api.models";
|
||||
import { http } from "@/serverCom";
|
||||
import type { PermissionObject } from "@/types/permissionTypes";
|
||||
import type { AxiosResponse } from "axios";
|
||||
|
||||
export const useApiStore = defineStore("api", {
|
||||
state: () => {
|
||||
return {
|
||||
apis: [] as Array<ApiViewModel>,
|
||||
loading: null as null | "loading" | "success" | "failed",
|
||||
};
|
||||
},
|
||||
actions: {
|
||||
fetchApis() {
|
||||
this.loading = "loading";
|
||||
http
|
||||
.get("/admin/api")
|
||||
.then((result) => {
|
||||
this.apis = result.data;
|
||||
this.loading = "success";
|
||||
})
|
||||
.catch((err) => {
|
||||
this.loading = "failed";
|
||||
});
|
||||
},
|
||||
fetchApiById(id: number): Promise<AxiosResponse<any, any>> {
|
||||
return http.get(`/admin/api/${id}`);
|
||||
},
|
||||
async createApi(api: string): Promise<AxiosResponse<any, any>> {
|
||||
const result = await http.post("/admin/api", {
|
||||
api: api,
|
||||
});
|
||||
this.fetchApis();
|
||||
return result;
|
||||
},
|
||||
async updateActiveApi(id: number, api: string): Promise<AxiosResponse<any, any>> {
|
||||
const result = await http.patch(`/admin/api/${id}`, {
|
||||
api: api,
|
||||
});
|
||||
this.fetchApis();
|
||||
return result;
|
||||
},
|
||||
async updateActiveApiPermissions(api: number, permission: PermissionObject): Promise<AxiosResponse<any, any>> {
|
||||
const result = await http.patch(`/admin/api/${api}/permissions`, {
|
||||
permissions: permission,
|
||||
});
|
||||
this.fetchApis();
|
||||
return result;
|
||||
},
|
||||
async deleteApi(api: number): Promise<AxiosResponse<any, any>> {
|
||||
const result = await http.delete(`/admin/api/${api}`);
|
||||
this.fetchApis();
|
||||
return result;
|
||||
},
|
||||
},
|
||||
});
|
60
src/stores/admin/user/webapi.ts
Normal file
60
src/stores/admin/user/webapi.ts
Normal file
|
@ -0,0 +1,60 @@
|
|||
import { defineStore } from "pinia";
|
||||
import type { WebapiViewModel } from "@/viewmodels/admin/user/webapi.models";
|
||||
import { http } from "@/serverCom";
|
||||
import type { PermissionObject } from "@/types/permissionTypes";
|
||||
import type { AxiosResponse } from "axios";
|
||||
|
||||
export const useWebapiStore = defineStore("webapi", {
|
||||
state: () => {
|
||||
return {
|
||||
webapis: [] as Array<WebapiViewModel>,
|
||||
loading: null as null | "loading" | "success" | "failed",
|
||||
};
|
||||
},
|
||||
actions: {
|
||||
fetchWebapis() {
|
||||
this.loading = "loading";
|
||||
http
|
||||
.get("/admin/webapi")
|
||||
.then((result) => {
|
||||
this.webapis = result.data;
|
||||
this.loading = "success";
|
||||
})
|
||||
.catch((err) => {
|
||||
this.loading = "failed";
|
||||
});
|
||||
},
|
||||
fetchWebapiById(id: number): Promise<AxiosResponse<any, any>> {
|
||||
return http.get(`/admin/webapi/${id}`);
|
||||
},
|
||||
async createWebapi(webapi: string): Promise<AxiosResponse<any, any>> {
|
||||
const result = await http.post("/admin/webapi", {
|
||||
webapi: webapi,
|
||||
});
|
||||
this.fetchWebapis();
|
||||
return result;
|
||||
},
|
||||
async updateActiveWebapi(id: number, webapi: string): Promise<AxiosResponse<any, any>> {
|
||||
const result = await http.patch(`/admin/webapi/${id}`, {
|
||||
webapi: webapi,
|
||||
});
|
||||
this.fetchWebapis();
|
||||
return result;
|
||||
},
|
||||
async updateActiveWebapiPermissions(
|
||||
webapi: number,
|
||||
permission: PermissionObject
|
||||
): Promise<AxiosResponse<any, any>> {
|
||||
const result = await http.patch(`/admin/webapi/${webapi}/permissions`, {
|
||||
permissions: permission,
|
||||
});
|
||||
this.fetchWebapis();
|
||||
return result;
|
||||
},
|
||||
async deleteWebapi(webapi: number): Promise<AxiosResponse<any, any>> {
|
||||
const result = await http.delete(`/admin/webapi/${webapi}`);
|
||||
this.fetchWebapis();
|
||||
return result;
|
||||
},
|
||||
},
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue