Spaces:
Sleeping
Sleeping
| import { Feature, FeatureCreateRequest, FeatureUpdateRequest } from '../types'; | |
| import apiClient from '@/lib/api/axios-instance'; | |
| import { createHeaders } from '@/lib/api'; | |
| import { API_BASE_URL } from '../config'; | |
| import axios from 'axios'; | |
| // Feature API service | |
| export const featureApi = { | |
| getAll: async (): Promise<Feature[]> => { | |
| const response = await apiClient.get(`/api/Feature`); | |
| if (!response.data) { | |
| throw new Error('Failed to fetch features'); | |
| } | |
| return response.data; | |
| }, | |
| getById: async (id: number): Promise<Feature> => { | |
| const response = await apiClient.get(`/api/Feature/${id}`); | |
| if (!response.data) { | |
| throw new Error(`Failed to fetch feature with ID ${id}`); | |
| } | |
| return response.data; | |
| }, | |
| create: async (feature: FeatureCreateRequest): Promise<Feature> => { | |
| const response = await apiClient.post(`/api/Feature`, feature); | |
| if (!response.data) { | |
| throw new Error('Failed to create feature'); | |
| } | |
| return response.data; | |
| }, | |
| update: async (id: number, feature: FeatureUpdateRequest): Promise<void> => { | |
| const response = await apiClient.put(`/api/Feature/${id}`, feature); | |
| if (!response.status || response.status >= 400) { | |
| throw new Error(`Failed to update feature with ID ${id}`); | |
| } | |
| }, | |
| delete: async (id: number): Promise<void> => { | |
| const response = await apiClient.delete(`/api/Feature/${id}`); | |
| if (!response.status || response.status >= 400) { | |
| throw new Error(`Failed to delete feature with ID ${id}`); | |
| } | |
| }, | |
| }; |