Student Management API Documentation
Overview
This project implements a RESTful API for managing student data. It provides endpoints to create, retrieve, update, and delete student records, along with specific methods for searching and modifying student tasks based on various criteria.
Key Features
1. Student Creation
- Endpoint:
POST /api/students/create - Description: Allows users to create a new student entry.
- Process:
- Accepts a JSON body representing the student.
- Checks if a student with the same
usernamealready exists to prevent duplicate records. - Stores the new student record in the database.
- Sample Request Body:
{ "name": "Srinivas Nampalli", "username": "srininampalli", "tableNumber": 4, "course": "CSA", "tasks": ["Task 1", "Task 2"], "trimester": 1, "period": 3 } - Response Codes:
200 OKon successful creation400 Bad Requestif a duplicate student exists
2. Retrieve All Students
- Endpoint:
GET /api/students/all - Description: Fetches a list of all students.
- Process: Directly retrieves all student records from the database.
- Response Example:
[ { "id": 1, "name": "Srinivas Nampalli", "username": "srininampalli", "tableNumber": 4, "course": "CSA", "tasks": ["Task 1", "Task 2"], "trimester": 1, "period": 3 }, { "id": 2, "name": "Aditya Samavedam", "username": "adityasamavedam", "tableNumber": 4, "course": "CSA", "tasks": ["Task 1", "Task 2"], "trimester": 1, "period": 3 }, { "id": 3, "name": "Nitin Balaji", "username": "nitinsandiego", "tableNumber": 4, "course": "CSA", "tasks": ["Task 1", "Task 2"], "trimester": 1, "period": 3 } ]
3. Retrieve Student by Criteria
- Endpoint:
GET /api/students/find - Description: Finds a student by matching
name,course,trimester, andperiod. - Process:
- Queries the database to match a student’s criteria.
- Query Parameters:
name,course,trimester,period - Response Example:
{ "id": 1, "name": "Srinivas Nampalli", "username": "srininampalli", "tableNumber": 4, "course": "CSA", "tasks": ["Task 1", "Task 2"], "trimester": 1, "period": 3 }
4. Retrieve Team by Table
- Endpoint:
GET /api/students/findteam - Description: Finds a group of students seated at the same table in a given
course,trimester,period, andtable. - Query Parameters:
course,trimester,period,table - Response Example:
[ { "id": 1, "name": "Srinivas Nampalli", "username": "srininampalli", "tableNumber": 4, "course": "CSA", "tasks": ["Task 1", "Task 2"], "trimester": 1, "period": 3 }, { "id": 2, "name": "Aditya Samavedam", "username": "adityasamavedam", "tableNumber": 4, "course": "CSA", "tasks": ["Task 1", "Task 2"], "trimester": 1, "period": 3 }, { "id": 3, "name": "Nitin Balaji", "username": "nitinsandiego", "tableNumber": 4, "course": "CSA", "tasks": ["Task 1", "Task 2"], "trimester": 1, "period": 3 } ]
5. Retrieve Students by Period
- Endpoint:
GET /api/students/findperiod - Description: Finds all students for a specific
course,trimester, andperiod. - Query Parameters:
course,trimester,period - Response Example:
[ { "id": 1, "name": "Srinivas Nampalli", "username": "srininampalli", "tableNumber": 4, "course": "CSA", "tasks": ["Task 1", "Task 2"], "trimester": 1, "period": 3 }, ... ]
6. Update Tasks for a Student
- Endpoint:
POST /api/students/updatetasks - Description: Updates the task list for a student identified by
username. - Process:
- Accepts
usernameand newtasksarray in the request body. - Updates the
tasksfield for the student in the database.
- Accepts
- Sample Request Body:
{ "username": "srininampalli", "tasks": ["Task 1 - Completed", "Task 2"] } - Response Codes:
200 OKon successful update404 Not Foundif the student doesn’t exist
7. Delete Student by Username
- Endpoint:
DELETE /api/students/delete - Description: Deletes a student based on their
username. - Process:
- Locates the student by
usernameand deletes them from the database.
- Locates the student by
- Query Parameter:
username - Response Example:
{ "message": "Student with username 'srininampalli' has been deleted." }
8. Mark Task as Completed
- Endpoint:
POST /api/students/completeTask - Description: Marks a specific task as completed for a student identified by
username. - Process:
- Locates the student by
username. - Finds the specified
taskand marks it as completed by appending “ - Completed” to the task name.
- Locates the student by
- Query Parameters:
username,task - Response Example:
{ "id": 1, "name": "Srinivas Nampalli", "username": "srininampalli", "tasks": ["Task 1 - Completed", "Task 2"], ... }
Summary of Changes and Additions
- Controller Methods: Added methods for all CRUD operations and specific queries (retrieve by criteria, find team, update tasks, etc.).
- Student Service: Centralized business logic for student operations, such as creation, deletion, and task updates.
- JPA Repository: Extended with custom query methods:
findByNameCourseTrimesterPeriod- Finds students based on detailed criteria.findTeam- Retrieves students based ontable,course,trimester, andperiod.findPeriod- Retrieves students based oncourse,trimester, andperiod.
Testing and Troubleshooting
To ensure the API functions correctly:
- Testing: Use tools like Postman or curl to send HTTP requests to each endpoint.
- Error Handling: Implemented error handling in the service layer to avoid duplicates and handle missing students with appropriate status codes (
400for bad requests,404for not found, etc.). - Transaction Management: Some methods, such as marking a task as completed, are marked
@Transactionalto maintain data consistency.