From 0c72b4c53ecd9b863acbe22b3a2758b4e49b2548 Mon Sep 17 00:00:00 2001 From: AceDataCloud Date: Fri, 6 Jan 2023 23:00:16 +0800 Subject: [PATCH] add api operator --- src/operators/api/index.ts | 2 ++ src/operators/api/models.ts | 20 +++++++++++++++++ src/operators/api/operator.ts | 41 +++++++++++++++++++++++++++++++++++ src/operators/index.ts | 1 + src/pages/service/Detail.vue | 24 +++++++++++++++----- 5 files changed, 83 insertions(+), 5 deletions(-) create mode 100644 src/operators/api/index.ts create mode 100644 src/operators/api/models.ts create mode 100644 src/operators/api/operator.ts diff --git a/src/operators/api/index.ts b/src/operators/api/index.ts new file mode 100644 index 00000000..5477b79c --- /dev/null +++ b/src/operators/api/index.ts @@ -0,0 +1,2 @@ +export * from '../service/models'; +export * from '../service/operator'; diff --git a/src/operators/api/models.ts b/src/operators/api/models.ts new file mode 100644 index 00000000..6bdfeb57 --- /dev/null +++ b/src/operators/api/models.ts @@ -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; diff --git a/src/operators/api/operator.ts b/src/operators/api/operator.ts new file mode 100644 index 00000000..f1651fb5 --- /dev/null +++ b/src/operators/api/operator.ts @@ -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> { + return await httpClient.get(`/${this.key}/`, { + params: decamelizeKeys(query) + }); + } + + async get(id: string): Promise> { + return await httpClient.get(`/${this.key}/${id}`); + } + + async create(data: IApi): Promise> { + return await httpClient.post(`/${this.key}/`, data); + } + + async update(id: string, data: IApi): Promise> { + return await httpClient.put(`/${this.key}/${id}`, data); + } + + async delete(id: string): Promise> { + return await httpClient.delete(`/${this.key}/${id}`); + } + + async getAllForService(serviceId: string): Promise> { + return await httpClient.get(`/services/${serviceId}/${this.key}/`); + } +} + +export const apiOperator = new ApiOperator(); diff --git a/src/operators/index.ts b/src/operators/index.ts index a4c8bf29..c76685ec 100644 --- a/src/operators/index.ts +++ b/src/operators/index.ts @@ -3,3 +3,4 @@ export * from './application'; export * from './auth'; export * from './service'; export * from './user'; +export * from './api'; diff --git a/src/pages/service/Detail.vue b/src/pages/service/Detail.vue index 271d1bcb..d4db9053 100644 --- a/src/pages/service/Detail.vue +++ b/src/pages/service/Detail.vue @@ -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({