Skip to content

OmarH-creator/Agile-Project

Repository files navigation

Admin Backend Integration

Overview

This feature integrates the frontend Admin Dashboard with the backend Admin Controller REST API to enable persistent storage of student records. Currently, the Admin Dashboard manages student data using local React state, which is lost when the page refreshes. This integration connects the frontend to the Spring Boot backend, allowing student data to be stored in the database and accessed across sessions.

Project Context

Frontend Component: frontend/src/pages/Admin_View/AdminDashboard.jsx
Backend Controller: Backend/backend/src/main/java/com/university/backend/controllers/AdminController.java
API Base URL: http://localhost:8081/api/admin

Features

This integration adds the following capabilities to the Admin Dashboard:

Student Management

  • Create Student - POST request to persist new student records to the database
  • Retrieve Student - GET request to fetch individual student details from the backend
  • Delete Student - DELETE request to remove student records from the database
  • Generate Transcript - GET request to generate formatted transcripts for students

User Experience Improvements

  • Loading Indicators - Visual feedback during API operations
  • Error Handling - User-friendly error messages for network failures and API errors
  • Authentication - JWT token-based authentication for all API requests
  • Data Persistence - Student records survive page refreshes and are accessible across sessions

API Endpoints

The integration uses the following existing backend endpoints:

Method Endpoint Purpose
POST /api/admin/students Create a new student record
GET /api/admin/students/{studentId} Retrieve a specific student
DELETE /api/admin/students/{studentId} Delete a student record
GET /api/admin/students/{studentId}/transcript Generate student transcript

Data Model Mapping

The frontend and backend use slightly different field names. The integration includes transformation functions to handle these differences:

Frontend Field Backend Field Type
code studentId String
cgpa gpa Number
academicHistory completedCourses Array
name name String
email email String
phone phone String
status status String

Architecture

┌─────────────────────────────────────┐
│   Admin Dashboard Component         │
│   (React Frontend)                  │
│                                     │
│  • Student List View                │
│  • Student Detail View              │
│  • Create/Edit Forms                │
│  • API Helper Functions             │
└─────────────────────────────────────┘
              │
              │ HTTP/JSON (fetch API)
              │ JWT Authentication
              ▼
┌─────────────────────────────────────┐
│   Admin Controller                  │
│   (Spring Boot Backend)             │
│                                     │
│  • Request Validation               │
│  • Business Logic                   │
│  • Database Operations              │
└─────────────────────────────────────┘
              │
              ▼
┌─────────────────────────────────────┐
│   Database (JPA Repository)         │
└─────────────────────────────────────┘

Implementation Status

Completed

  • ✅ Requirements document
  • ✅ Design document
  • ✅ Implementation task list

Pending Implementation

  • ⏳ API helper functions (createStudent, getStudent, deleteStudent, getTranscript)
  • ⏳ Data transformation functions (toBackendFormat, toFrontendFormat)
  • ⏳ Loading state management
  • ⏳ Error handling and display
  • ⏳ Form submission integration
  • ⏳ Student selection integration
  • ⏳ Transcript generation UI
  • ⏳ Initial data loading from backend

Getting Started

Prerequisites

  1. Backend Running: Ensure the Spring Boot backend is running on http://localhost:8081
  2. Database: Verify the database is accessible and properly configured
  3. Authentication: Ensure you can log in and obtain a valid JWT token
  4. CORS: Backend must allow requests from the frontend origin

Key Design Decisions

1. Inline API Functions

API functions are defined within AdminDashboard.jsx rather than a separate module, following the existing pattern in frontend/src/auth/login.js.

2. Data Transformation Layer

Transformation functions handle field name differences between frontend and backend, providing clean separation and making future changes easier.

3. Error Handling

Uses try-catch blocks with user-friendly error messages, maintaining UI stability during errors and providing clear feedback.

4. State Update Strategy

Local state is updated only after successful backend operations to ensure data consistency and avoid rollback complexity.

5. No Optimistic Updates

The implementation does not use optimistic updates due to potential backend validation failures. UI updates occur after backend confirmation.

Error Handling

The integration handles the following error scenarios:

Error Type HTTP Status User Message
Network Failure N/A "Connection failed. Please check your network."
Not Found 404 "Student not found."
Validation Error 400 Backend error message displayed
Server Error 500 "Server error occurred. Please try again."
Duplicate Student 400 "Student with this ID already exists."

Authentication

All API requests include JWT authentication:

const token = localStorage.getItem('token');
headers: {
  'Content-Type': 'application/json',
  'Authorization': `Bearer ${token}`
}

The token is obtained during login and stored in localStorage. If the token is missing or invalid, API requests will fail with a 401 Unauthorized error.

Known Limitations

  1. No Edit Endpoint: The backend Admin Controller does not have a PUT endpoint for updating students. Edit functionality remains local-only until the backend is updated.

  2. No Bulk Operations: The current implementation handles one student at a time. Bulk operations are not supported.

  3. No Pagination: All students are loaded at once. For large datasets, pagination should be implemented in the future.

  4. No Real-time Updates: Changes made by other users are not reflected until the page is refreshed.

Future Enhancements

  1. Update Student Endpoint: Add PUT endpoint to backend for updating student records
  2. Bulk Operations: Support creating, updating, or deleting multiple students at once
  3. Pagination: Implement server-side pagination for better performance with large datasets
  4. Search on Backend: Move search and filtering to backend for improved performance
  5. Caching: Implement client-side caching to reduce API calls
  6. Optimistic Updates: Update UI immediately and rollback on failure
  7. Real-time Sync: Use WebSockets for live data synchronization
  8. Offline Support: Cache data for offline access

Troubleshooting

"Connection failed" Error

  • Verify backend is running on http://localhost:8081
  • Check CORS configuration in backend
  • Verify network connectivity

"Unauthorized" Error

  • Ensure you're logged in
  • Check that JWT token exists in localStorage
  • Verify token hasn't expired

"Student not found" Error

  • Verify student ID is correct
  • Check that student exists in database
  • Ensure database connection is working

Data Not Persisting

  • Verify backend is saving to database
  • Check database connection settings
  • Review backend logs for errors

Related Documentation

  • Backend Controller: Backend/backend/src/main/java/com/university/backend/controllers/AdminController.java
  • Frontend Component: frontend/src/pages/Admin_View/AdminDashboard.jsx

Support

For questions or issues:

  1. Review the design document for technical details
  2. Check the requirements document for expected behavior
  3. Consult the backend AdminController source code
  4. Review the existing authentication pattern in frontend/src/auth/login.js

Contributing

When implementing this feature:

  1. Follow the task list in sequential order
  2. Test each feature before moving to the next
  3. Maintain the existing UI and user experience
  4. Use the existing code patterns (especially from login.js)
  5. Add comments explaining complex logic
  6. Handle all error cases gracefully

License

This is part of the University Management System project.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •