This document outlines the changes made to connect the React frontend with the FastAPI backend.
- GET /requests/ - List user's requests
- GET /requests/{request_id} - Get specific request
- GET /books/{book_id} - Get specific book
- GET /chats/{chat_id} - Get chat details
- GET /chats/{chat_id}/messages - Get chat messages
- GET /ngo/bulk-request - List NGO bulk requests
- Added
list_user_requests()inrequest_service.py - Added
get_book()inbook_service.py - Added
get_chat()andget_chat_messages()inchat_service.py - Added
list_ngo_requests()inngo_service.py
- Updated CORS to allow frontend origins (localhost:8080, localhost:5173)
- frontend/src/lib/api.ts - Centralized API utilities with authentication
- Includes functions for: books, requests, chats, notes, NGO, feedback, impact, auth
- frontend/src/lib/firebase.ts - Firebase config and auth functions
- frontend/src/contexts/AuthContext.tsx - Auth context provider
- Integrated into main.tsx
- frontend/src/types/api.ts - TypeScript types matching backend schemas
SearchBooks.tsx
- Uses
booksApi.search()to fetch books - Added loading states
- Added error handling
BookDetails.tsx
- Uses
booksApi.getById()to fetch book details - Added loading states
- Updated to use API Book type
RequestBook.tsx
- Uses
booksApi.getById()to fetch book - Uses
requestsApi.create()to submit request - Added authentication check
- Added loading/submitting states
BookCard.tsx
- Updated to use API Book type
- Handles image_urls array instead of single coverImage
The following pages still need to be updated (work in progress):
- RequestStatus.tsx - Use
requestsApi.list()andrequestsApi.getById() - Chat.tsx - Use
chatsApi.getMessages()andchatsApi.sendMessage() - DonateBook.tsx - Use
booksApi.donate()with file uploads - Notes.tsx - Use
notesApi.list()andnotesApi.upload() - StudentImpact.tsx - Use
impactApi.getUserImpact() - NGO pages - Use respective NGO APIs
VITE_API_BASE_URL=http://localhost:8000
VITE_FIREBASE_API_KEY=your_firebase_api_key
VITE_FIREBASE_AUTH_DOMAIN=your_project_id.firebaseapp.com
VITE_FIREBASE_PROJECT_ID=your_project_id
VITE_FIREBASE_STORAGE_BUCKET=your_project_id.appspot.com
VITE_FIREBASE_MESSAGING_SENDER_ID=your_messaging_sender_id
VITE_FIREBASE_APP_ID=your_app_id
FIREBASE_PROJECT_ID=your_project_id
FIREBASE_STORAGE_BUCKET=your_project_id.appspot.com
FIREBASE_SERVICE_ACCOUNT=serviceAccountKey.json
- firebase (for authentication)
- Complete remaining page updates (RequestStatus, Chat, DonateBook, Notes, Impact, NGO pages)
- Add Firebase authentication UI (login/logout)
- Update Index.tsx and NGOLogin.tsx to use Firebase auth
- Add error boundaries
- Test end-to-end flows
- Add loading skeletons for better UX
- Handle offline states
- GET /books/search?class_level=X&board=Y&subject=Z
- GET /books/{book_id}
- POST /books/donate (multipart/form-data)
- GET /requests/
- GET /requests/{request_id}
- POST /requests/ {book_id, donor_uid}
- POST /requests/{request_id}/approve
- POST /requests/{request_id}/complete
- GET /chats/{chat_id}
- GET /chats/{chat_id}/messages
- POST /chats/{chat_id}/message {message}
- GET /notes/?subject=X&class_level=Y
- POST /notes/ (multipart/form-data)
- GET /ngo/bulk-request
- POST /ngo/bulk-request {payload}
- GET /impact/
- POST /auth/bootstrap {role}
- POST /feedback/ {to_uid, ...feedbackData}