MVP
This commit is contained in:
@@ -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;
|
||||
};
|
||||
Reference in New Issue
Block a user