Spaces:
Sleeping
Sleeping
Download frontend-backup/src/services/api.ts from edichat/edi.chat.test: direct link, hf CLI and curl.
- Browser
- Download file 15.7 kB
-
https://huggingface.co/spaces/edichat/edi.chat.test/resolve/main/frontend-backup/src/services/api.ts
- Command line
-
hf download hf://spaces/edichat/edi.chat.test/frontend-backup/src/services/api.ts
-
curl -L -o api.ts https://huggingface.co/spaces/edichat/edi.chat.test/resolve/main/frontend-backup/src/services/api.ts
15.7 kB
| import axios, { AxiosInstance, AxiosResponse } from 'axios'; | |
| import { | |
| User, | |
| LoginRequest, | |
| ChatRequest, | |
| ChatResponse, | |
| Conversation, | |
| ApiResponse, | |
| LoginResponse, | |
| FacultyDashboard, | |
| ClassRoster, | |
| StudentAnalytics, | |
| KnowledgeResult, | |
| QuickResponse | |
| } from '../types'; | |
| class ApiClient { | |
| private client: AxiosInstance; | |
| constructor() { | |
| this.client = axios.create({ | |
| baseURL: process.env.REACT_APP_API_URL || '/api', | |
| timeout: 30000, | |
| headers: { | |
| 'Content-Type': 'application/json', | |
| }, | |
| }); | |
| // Request interceptor to add auth token | |
| this.client.interceptors.request.use( | |
| (config) => { | |
| const token = localStorage.getItem('uga-chat-token'); | |
| if (token) { | |
| config.headers.Authorization = `Bearer ${token}`; | |
| } | |
| return config; | |
| }, | |
| (error) => { | |
| return Promise.reject(error); | |
| } | |
| ); | |
| // Response interceptor to handle auth errors | |
| this.client.interceptors.response.use( | |
| (response) => response, | |
| (error) => { | |
| if (error.response?.status === 401) { | |
| localStorage.removeItem('uga-chat-token'); | |
| window.location.href = '/login'; | |
| } | |
| return Promise.reject(error); | |
| } | |
| ); | |
| } | |
| private async handleResponse<T>(promise: Promise<AxiosResponse<T>>): Promise<T> { | |
| try { | |
| const response = await promise; | |
| return response.data; | |
| } catch (error: any) { | |
| const message = error.response?.data?.error || error.message || 'An error occurred'; | |
| throw new Error(message); | |
| } | |
| } | |
| } | |
| const apiClient = new ApiClient(); | |
| // Auth API | |
| export const authAPI = { | |
| login: (credentials: LoginRequest): Promise<ApiResponse<LoginResponse>> => | |
| apiClient['handleResponse'](apiClient['client'].post('/auth/login', credentials)), | |
| loginWithMyID: (credentials: LoginRequest): Promise<ApiResponse<LoginResponse>> => | |
| apiClient['handleResponse'](apiClient['client'].post('/auth/login/myid', credentials)), | |
| logout: (): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].post('/auth/logout')), | |
| getProfile: (): Promise<ApiResponse<User>> => | |
| apiClient['handleResponse'](apiClient['client'].get('/auth/me')), | |
| updateProfile: (data: Partial<User>): Promise<ApiResponse<User>> => | |
| apiClient['handleResponse'](apiClient['client'].put('/auth/profile', data)), | |
| changePassword: (currentPassword: string, newPassword: string): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].post('/auth/change-password', { | |
| currentPassword, | |
| newPassword, | |
| })), | |
| }; | |
| // Chat API | |
| export const chatAPI = { | |
| sendMessage: (request: ChatRequest): Promise<ApiResponse<ChatResponse>> => | |
| apiClient['handleResponse'](apiClient['client'].post('/chat/message', request)), | |
| getConversations: (params?: { page?: number; limit?: number; category?: string }): Promise<ApiResponse<{ conversations: Conversation[] }>> => | |
| apiClient['handleResponse'](apiClient['client'].get('/chat/conversations', { params })), | |
| getConversation: (conversationId: string): Promise<ApiResponse<Conversation>> => | |
| apiClient['handleResponse'](apiClient['client'].get(`/chat/conversations/${conversationId}`)), | |
| deleteConversation: (conversationId: string): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].delete(`/chat/conversations/${conversationId}`)), | |
| rateConversation: (conversationId: string, rating: number, feedback?: string): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].post(`/chat/conversations/${conversationId}/rate`, { | |
| rating, | |
| feedback, | |
| })), | |
| getQuickResponses: (): Promise<ApiResponse<QuickResponse[]>> => | |
| apiClient['handleResponse'](apiClient['client'].get('/chat/quick-responses')), | |
| // Student endpoints | |
| getStudentCourses: (): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].get('/chat/student/courses')), | |
| getStudentGrades: (semester?: string): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].get('/chat/student/grades', { | |
| params: { semester }, | |
| })), | |
| getStudentSchedule: (): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].get('/chat/student/schedule')), | |
| getRegistrationInfo: (): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].get('/chat/student/registration')), | |
| getFinancialAidInfo: (): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].get('/chat/student/financial-aid')), | |
| getHousingInfo: (): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].get('/chat/student/housing')), | |
| getMealPlanInfo: (): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].get('/chat/student/meal-plans')), | |
| getBillingInfo: (): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].get('/chat/student/billing')), | |
| }; | |
| // Faculty API | |
| export const facultyAPI = { | |
| getDashboard: (): Promise<ApiResponse<FacultyDashboard>> => | |
| apiClient['handleResponse'](apiClient['client'].get('/faculty/dashboard')), | |
| getClassRoster: (courseId: string, semester?: string): Promise<ApiResponse<ClassRoster>> => | |
| apiClient['handleResponse'](apiClient['client'].get(`/faculty/courses/${courseId}/roster`, { | |
| params: { semester }, | |
| })), | |
| submitGrades: (courseId: string, grades: any[], semester?: string): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].post(`/faculty/courses/${courseId}/grades`, { | |
| grades, | |
| semester, | |
| })), | |
| getStudentAnalytics: (courseId: string, semester?: string, type?: string): Promise<ApiResponse<StudentAnalytics>> => | |
| apiClient['handleResponse'](apiClient['client'].get(`/faculty/courses/${courseId}/analytics`, { | |
| params: { semester, type }, | |
| })), | |
| getCourseContent: (courseId: string): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].get(`/faculty/courses/${courseId}/content`)), | |
| createAnnouncement: (courseId: string, title: string, content: string, priority?: string): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].post(`/faculty/courses/${courseId}/announcements`, { | |
| title, | |
| content, | |
| priority, | |
| })), | |
| createAssignment: (courseId: string, assignment: any): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].post(`/faculty/courses/${courseId}/assignments`, assignment)), | |
| getStudentProfile: (courseId: string, studentId: string): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].get(`/faculty/courses/${courseId}/students/${studentId}/profile`)), | |
| getAttendance: (courseId: string, params?: any): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].get(`/faculty/courses/${courseId}/attendance`, { params })), | |
| recordAttendance: (courseId: string, date: string, attendance: any[]): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].post(`/faculty/courses/${courseId}/attendance`, { | |
| date, | |
| attendance, | |
| })), | |
| getResources: (): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].get('/faculty/resources')), | |
| exportGrades: (courseId: string, format: 'csv' | 'xlsx' = 'csv'): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].get(`/faculty/courses/${courseId}/export/grades`, { | |
| params: { format }, | |
| })), | |
| getAnalytics: (courseId?: string): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].get('/faculty/analytics', { | |
| params: { courseId }, | |
| })), | |
| }; | |
| // UGA API | |
| export const ugaAPI = { | |
| searchKnowledge: (query: string, category: string = 'all'): Promise<ApiResponse<{ results: KnowledgeResult[] }>> => | |
| apiClient['handleResponse'](apiClient['client'].get('/uga/knowledge/search', { | |
| params: { q: query, category }, | |
| })), | |
| getCampusBuildings: (): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].get('/uga/campus/buildings')), | |
| getDiningOptions: (): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].get('/uga/campus/dining')), | |
| getRecreationFacilities: (): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].get('/uga/campus/recreation')), | |
| getStudentOrganizations: (): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].get('/uga/studentlife/organizations')), | |
| getUGATraditions: (): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].get('/uga/studentlife/traditions')), | |
| getAthensNeighborhoods: (): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].get('/uga/athens/neighborhoods')), | |
| getEmergencyInfo: (): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].get('/uga/safety/emergency')), | |
| }; | |
| // User API | |
| export const userAPI = { | |
| updatePreferences: (preferences: any): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].put('/user/preferences', preferences)), | |
| getStats: (): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].get('/user/stats')), | |
| getConversationsSummary: (params?: any): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].get('/user/conversations/summary', { params })), | |
| getPreferences: (): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].get('/user/preferences')), | |
| }; | |
| // Knowledge Base API | |
| export const knowledgeAPI = { | |
| getArticles: (category?: string): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].get('/knowledge/articles', { params: { category } })), | |
| searchArticles: (query: string): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].get('/knowledge/search', { params: { q: query } })), | |
| getCategories: (): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].get('/knowledge/categories')), | |
| getArticle: (id: string): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].get(`/knowledge/articles/${id}`)), | |
| rateArticle: (id: string, rating: number): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].post(`/knowledge/articles/${id}/rate`, { rating })), | |
| suggestEdit: (id: string, suggestion: string): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].post(`/knowledge/articles/${id}/suggest`, { suggestion })), | |
| getBookmarkedArticles: (): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].get('/knowledge/bookmarks')), | |
| toggleBookmark: (articleId: string): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].post(`/knowledge/articles/${articleId}/bookmark`)), | |
| trackArticleView: (articleId: string): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].post(`/knowledge/articles/${articleId}/view`)), | |
| submitFeedback: (articleId: string, helpful: boolean): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].post(`/knowledge/articles/${articleId}/feedback`, { helpful })), | |
| }; | |
| // Settings API | |
| export const settingsAPI = { | |
| getSettings: (): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].get('/user/settings')), | |
| updateSettings: (settings: any): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].put('/user/settings', settings)), | |
| resetSettings: (): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].post('/user/settings/reset')), | |
| exportData: (): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].get('/user/data/export')), | |
| deleteAccount: (): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].delete('/user/account')), | |
| }; | |
| // Student Services API | |
| export const studentAPI = { | |
| getCourses: (): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].get('/student/courses')), | |
| getGrades: (semester?: string): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].get('/student/grades', { params: { semester } })), | |
| getSchedule: (): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].get('/student/schedule')), | |
| getRegistrationStatus: (): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].get('/student/registration/status')), | |
| getFinancialInfo: (): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].get('/student/financial')), | |
| getHousingInfo: (): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].get('/student/housing')), | |
| getMealPlan: (): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].get('/student/meal-plan')), | |
| getMealPlanInfo: (): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].get('/student/meal-plan')), | |
| getBilling: (): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].get('/student/billing')), | |
| registerCourse: (courseId: string): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].post('/student/courses/register', { courseId })), | |
| dropCourse: (courseId: string): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].post('/student/courses/drop', { courseId })), | |
| }; | |
| // Documents API | |
| export const documentsAPI = { | |
| getUpcomingDueDates: (days: number = 30): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].get('/documents/due-dates/upcoming', { params: { days } })), | |
| getDocuments: (params?: any): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].get('/documents', { params })), | |
| uploadDocument: (formData: FormData): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].post('/documents/upload', formData, { | |
| headers: { 'Content-Type': 'multipart/form-data' } | |
| })), | |
| deleteDocument: (documentId: string): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].delete(`/documents/${documentId}`)), | |
| exportCalendar: (params?: any): Promise<any> => | |
| apiClient['client'].get('/documents/calendar/export', { | |
| params, | |
| responseType: 'blob' | |
| }), | |
| }; | |
| // Dining API | |
| export const diningAPI = { | |
| getMenus: (params?: { location?: string; date?: string }): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].get('/dining/menus', { params })), | |
| getFilteredMenus: (params?: { | |
| dietary?: string; | |
| exclude?: string; | |
| station?: string; | |
| mealType?: string; | |
| location?: string; | |
| date?: string | |
| }): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].get('/dining/menus/filtered', { params })), | |
| searchMenuItems: (params: { q: string; date?: string }): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].get('/dining/search', { params })), | |
| getDiningHours: (): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].get('/dining/hours')), | |
| getDiningLocations: (): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].get('/dining/locations')), | |
| getDietarySummary: (params?: { date?: string }): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].get('/dining/dietary-summary', { params })), | |
| getMenuForDate: (location: string, date: string): Promise<ApiResponse> => | |
| apiClient['handleResponse'](apiClient['client'].get(`/dining/menus/${location}/${date}`)), | |
| }; | |
| export default apiClient; |