add api operator
This commit is contained in:
1 parent
99d7a4a2d6
commit
0c72b4c53e
5 files changed
+83
-5
No files matched your search
@@ -0,0 +1,2 @@
|
||||
export * from '../service/models';
|
||||
export * from '../service/operator';
|
||||
@@ -0,0 +1,20 @@
|
||||
export interface IApi {
|
||||
id: string;
|
||||
alias: string;
|
||||
title?: string;
|
||||
description?: string;
|
||||
tags?: string[];
|
||||
endpoint?: string;
|
||||
isFree?: boolean;
|
||||
swaggerConfiguration?: string;
|
||||
service?: string;
|
||||
createdAt?: string;
|
||||
updatedAt?: string;
|
||||
}
|
||||
|
||||
export interface IApiListResponse {
|
||||
count: number;
|
||||
items: IApi[];
|
||||
}
|
||||
|
||||
export type IApiDetailResponse = IApi;
|
||||
@@ -0,0 +1,41 @@
|
||||
import { AxiosResponse } from 'axios';
|
||||
import { decamelizeKeys } from 'humps';
|
||||
import { httpClient } from '../instance';
|
||||
import { IApi, IApiDetailResponse, IApiListResponse } from '../api/models';
|
||||
|
||||
export interface IApiQuery {
|
||||
limit: number;
|
||||
offset: number;
|
||||
}
|
||||
|
||||
class ApiOperator {
|
||||
key = 'apis';
|
||||
|
||||
async getAll(query: IApiQuery): Promise<AxiosResponse<IApiListResponse>> {
|
||||
return await httpClient.get(`/${this.key}/`, {
|
||||
params: decamelizeKeys(query)
|
||||
});
|
||||
}
|
||||
|
||||
async get(id: string): Promise<AxiosResponse<IApiDetailResponse>> {
|
||||
return await httpClient.get(`/${this.key}/${id}`);
|
||||
}
|
||||
|
||||
async create(data: IApi): Promise<AxiosResponse<IApiDetailResponse>> {
|
||||
return await httpClient.post(`/${this.key}/`, data);
|
||||
}
|
||||
|
||||
async update(id: string, data: IApi): Promise<AxiosResponse<IApiDetailResponse>> {
|
||||
return await httpClient.put(`/${this.key}/${id}`, data);
|
||||
}
|
||||
|
||||
async delete(id: string): Promise<AxiosResponse<null>> {
|
||||
return await httpClient.delete(`/${this.key}/${id}`);
|
||||
}
|
||||
|
||||
async getAllForService(serviceId: string): Promise<AxiosResponse<IApiListResponse>> {
|
||||
return await httpClient.get(`/services/${serviceId}/${this.key}/`);
|
||||
}
|
||||
}
|
||||
|
||||
export const apiOperator = new ApiOperator();
|
||||
@@ -3,3 +3,4 @@ export * from './application';
|
||||
export * from './auth';
|
||||
export * from './service';
|
||||
export * from './user';
|
||||
export * from './api';
|
||||
@@ -100,9 +100,12 @@ import { defineComponent } from 'vue';
|
||||
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
|
||||
import { ERROR_CODE_DUPLICATION } from '@/constants';
|
||||
import { ElForm, ElMessage } from 'element-plus';
|
||||
import { apiOperator } from '@/operators/api/operator';
|
||||
import { IApi, IApiListResponse } from '@/operators/api/models';
|
||||
|
||||
interface IData {
|
||||
service: IService | undefined;
|
||||
apis: IApi[];
|
||||
application: IApplication | undefined;
|
||||
loading: boolean;
|
||||
activeTab: string;
|
||||
@@ -116,6 +119,7 @@ export default defineComponent({
|
||||
data(): IData {
|
||||
return {
|
||||
service: undefined,
|
||||
apis: [],
|
||||
application: undefined,
|
||||
loading: false,
|
||||
activeTab: 'introduction'
|
||||
@@ -127,13 +131,23 @@ export default defineComponent({
|
||||
}
|
||||
},
|
||||
async mounted() {
|
||||
this.loading = true;
|
||||
serviceOperator.get(this.id).then(({ data: data }: { data: IServiceDetailResponse }) => {
|
||||
this.service = data;
|
||||
this.loading = false;
|
||||
});
|
||||
this.onFetchService();
|
||||
this.onFetchApis();
|
||||
},
|
||||
methods: {
|
||||
onFetchService() {
|
||||
this.loading = true;
|
||||
serviceOperator.get(this.id).then(({ data: data }: { data: IServiceDetailResponse }) => {
|
||||
this.service = data;
|
||||
this.loading = false;
|
||||
});
|
||||
},
|
||||
onFetchApis() {
|
||||
this.loading = true;
|
||||
apiOperator.getAllForService(this.id).then(({ data: data }: { data: IApiListResponse }) => {
|
||||
this.apis = data.items;
|
||||
});
|
||||
},
|
||||
onApply() {
|
||||
applicationOperator
|
||||
.create({
|
||||
|
||||
Reference in new issue
Block a user