50 lines
1.2 KiB
TypeScript
50 lines
1.2 KiB
TypeScript
import { ApiClient } from './ApiClient';
|
|
import { API_BASE_URLS } from './config';
|
|
|
|
export class TemplateServiceClient {
|
|
private client: ApiClient;
|
|
|
|
constructor() {
|
|
this.client = new ApiClient(API_BASE_URLS.template);
|
|
}
|
|
|
|
async saveTemplate(data: {
|
|
name: string;
|
|
description: string;
|
|
chart_configs: any[];
|
|
layout: any[];
|
|
theme: string;
|
|
}): Promise<any> {
|
|
return this.client.post<any>('/api/v1/templates', data);
|
|
}
|
|
|
|
async listTemplates(): Promise<any[]> {
|
|
return this.client.get<any[]>('/templates');
|
|
}
|
|
|
|
async getTemplate(id: string): Promise<any> {
|
|
return this.client.get<any>(`/templates/${encodeURIComponent(id)}`);
|
|
}
|
|
|
|
async updateTemplate(id: string, data: any): Promise<any> {
|
|
return this.client.put<any>(
|
|
`/templates/${encodeURIComponent(id)}`,
|
|
data,
|
|
);
|
|
}
|
|
|
|
async deleteTemplate(id: string): Promise<void> {
|
|
return this.client.delete(`/templates/${encodeURIComponent(id)}`);
|
|
}
|
|
|
|
async importTemplate(json: string): Promise<any> {
|
|
return this.client.post<any>('/templates/import', JSON.parse(json));
|
|
}
|
|
|
|
async exportTemplate(id: string): Promise<any> {
|
|
return this.client.get<any>(
|
|
`/templates/${encodeURIComponent(id)}/export`,
|
|
);
|
|
}
|
|
}
|