Spaces:
Sleeping
Sleeping
| import { API_BASE_URL } from '@/config'; | |
| import apiClient from '@/lib/api/axios-instance'; | |
| import { createHeaders } from '@/lib/api'; | |
| import axios from 'axios'; | |
| export interface Comment { | |
| commentId: number; | |
| entityId: number; | |
| entityType: string; | |
| commentText: string; | |
| userId: number; | |
| createdBy: string | null; | |
| createdAt: string; | |
| updatedBy: string | null; | |
| updatedAt: string | null; | |
| entity: any | null; | |
| } | |
| class CommentsApi { | |
| private baseUrl: string; | |
| constructor() { | |
| this.baseUrl = `/api/Comments`; | |
| } | |
| async getByEntity(entityType: string, entityId: number): Promise<Comment[]> { | |
| try { | |
| const response = await apiClient.get( | |
| `${this.baseUrl}/GetByEntity?entityName=${entityType}&entityId=${entityId}` | |
| ); | |
| return response.data; | |
| } catch (error) { | |
| console.error('Error fetching comments:', error); | |
| throw error; | |
| } | |
| } | |
| async create(comment: Omit<Comment, 'commentId' | 'entity'>): Promise<Comment> { | |
| try { | |
| const response = await apiClient.post(this.baseUrl, { | |
| commentId: 0, | |
| ...comment | |
| }, { | |
| headers: { | |
| 'Content-Type': 'application/json', | |
| } | |
| }); | |
| return response.data; | |
| } catch (error) { | |
| console.error('Error creating comment:', error); | |
| throw error; | |
| } | |
| } | |
| async delete(commentId: number): Promise<void> { | |
| try { | |
| await apiClient.delete(`${this.baseUrl}/${commentId}`); | |
| } catch (error) { | |
| console.error('Error deleting comment:', error); | |
| throw error; | |
| } | |
| } | |
| } | |
| export const commentsApi = new CommentsApi(); | |