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();
|
||||
Reference in new issue
Block a user