Download src/api/closetApi.ts from Jessedbrown/daisy-client: direct link, hf CLI and curl.
- Browser
- Download file 1.4 kB
-
https://huggingface.co/Jessedbrown/daisy-client/resolve/main/src/api/closetApi.ts
- Command line
-
hf download hf://Jessedbrown/daisy-client/src/api/closetApi.ts
-
curl -L -o closetApi.ts https://huggingface.co/Jessedbrown/daisy-client/resolve/main/src/api/closetApi.ts
1.4 kB
| import { BackendApiResponse, ClosetItem, NewClosetItem } from '@/types'; | |
| import { apiClient } from './client'; | |
| // Utility function to create FormData from closet item | |
| const createItemFormData = (item: Partial<NewClosetItem>): FormData => { | |
| const formData = new FormData(); | |
| if (item.name) formData.append('name', item.name); | |
| if (item.brand) formData.append('brand', item.brand); | |
| if (item.category) formData.append('category', item.category); | |
| if (item.imageFile) { | |
| formData.append('image', item.imageFile); | |
| } | |
| return formData; | |
| }; | |
| export const closetApi = { | |
| // Get all closet items with optional filters | |
| getItems: async (params?: { | |
| q?: string; | |
| sortBy?: string; | |
| }): Promise<ClosetItem[]> => { | |
| const response = await apiClient.get<BackendApiResponse<ClosetItem[]>>( | |
| '/closet', | |
| { params } | |
| ); | |
| return response.data.data; | |
| }, | |
| // Create new closet item | |
| createItem: async (item: NewClosetItem): Promise<ClosetItem> => { | |
| const formData = createItemFormData(item); | |
| const response = await apiClient.post<BackendApiResponse<ClosetItem>>( | |
| '/closet', | |
| formData, | |
| { | |
| headers: { | |
| 'Content-Type': 'multipart/form-data', | |
| }, | |
| } | |
| ); | |
| return response.data.data; | |
| }, | |
| // Delete closet item | |
| deleteItem: async (id: string): Promise<void> => { | |
| await apiClient.delete(`/closet/${id}`); | |
| }, | |
| }; | |