This commit is contained in:
Zimeng Xiong
2025-11-21 19:18:07 -08:00
parent 35734936b3
commit 4e8beae0ee
66 changed files with 21548 additions and 315 deletions
+61
View File
@@ -0,0 +1,61 @@
import axios from 'axios';
import type { Drawing, Collection } from '../types';
export const API_URL = import.meta.env.VITE_API_URL || '/api';
export const api = axios.create({
baseURL: API_URL,
});
export const getDrawings = async (search?: string, collectionId?: string | null) => {
const params: any = {};
if (search) params.search = search;
if (collectionId !== undefined) params.collectionId = collectionId === null ? 'null' : collectionId;
const response = await api.get<Drawing[]>('/drawings', { params });
return response.data;
};
export const getDrawing = async (id: string) => {
const response = await api.get<Drawing>(`/drawings/${id}`);
return response.data;
};
export const createDrawing = async (name?: string, collectionId?: string | null) => {
const response = await api.post<{ id: string }>('/drawings', { name, collectionId });
return response.data;
};
export const updateDrawing = async (id: string, data: Partial<Drawing>) => {
const response = await api.put<{ success: true }>(`/drawings/${id}`, data);
return response.data;
};
export const deleteDrawing = async (id: string) => {
const response = await api.delete<{ success: true }>(`/drawings/${id}`);
return response.data;
};
export const duplicateDrawing = async (id: string) => {
const response = await api.post<{ id: string }>(`/drawings/${id}/duplicate`);
return response.data;
};
export const getCollections = async () => {
const response = await api.get<Collection[]>('/collections');
return response.data;
};
export const createCollection = async (name: string) => {
const response = await api.post<Collection>('/collections', { name });
return response.data;
};
export const updateCollection = async (id: string, name: string) => {
const response = await api.put<{ success: true }>(`/collections/${id}`, { name });
return response.data;
};
export const deleteCollection = async (id: string) => {
const response = await api.delete<{ success: true }>(`/collections/${id}`);
return response.data;
};