A Spring Boot REST API for calculating Cumulative Grade Point Average (CGPA) based on course records.
- Create, read, update, and delete course records
- Automatic grade-to-grade-point conversion
- Calculate overall CGPA across all semesters
- Calculate semester-specific GPA
- Filter courses by semester
| Grade | Grade Points |
|---|---|
| A | 5 |
| B | 4 |
| C | 3 |
| D | 2 |
| E | 1 |
| F | 0 |
CGPA = (Sum of (Unit × Grade Point)) / (Sum of Units)
- Java 17
- Spring Boot 3.1.5
- Spring Data JPA
- Lombok
- Maven
rest-grpc-demo/
│
├── pom.xml
│
└── src/
└── main/
├── java/
│ └── com/
│ └── example/
│ ├── Application.java
│ │
│ └── cgpa/
│ ├── model/
│ │ └── CourseRecord.java
│ │
│ ├── repository/
│ │ └── CourseRecordRepository.java
│ │
│ ├── dto/
│ │ └── CGPAResponse.java
│ │
│ ├── service/
│ │ └── CourseRecordService.java
│ │
│ └── controller/
│ └── CourseRecordController.java
│
└── resources/
└── application.properties
- Java 17 or higher
- Maven 3.6+
Install "mvn" on Ubuntu(WSL):
sudo apt update
sudo apt install maven - #this is the namme of the package
# Check the Version for confirmation
mvn -version# Build the project
mvn clean install
# Run the application
mvn spring-boot:runThe application will start on http://localhost:8080
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/courses |
Create a new course record |
| GET | /api/courses |
Get all course records |
| GET | /api/courses/{id} |
Get course record by ID |
| GET | /api/courses/semester/{semester} |
Get courses by semester |
| PUT | /api/courses/{id} |
Update a course record |
| DELETE | /api/courses/{id} |
Delete a course record |
| GET | /api/courses/cgpa |
Calculate overall CGPA |
| GET | /api/courses/cgpa/semester/{semester} |
Calculate semester GPA |
curl -X POST http://localhost:8080/api/courses \
-H "Content-Type: application/json" \
-d '{
"semester": "Fall 2024",
"courseName": "Data Structures",
"unit": 3,
"grade": "A"
}'Request Body:
{
"semester": "Fall 2024",
"courseName": "Data Structures",
"unit": 3,
"grade": "A"
}Response:
{
"id": 1,
"semester": "Fall 2024",
"courseName": "Data Structures",
"unit": 3,
"grade": "A",
"gradePoint": 5
}curl http://localhost:8080/api/coursesResponse:
[
{
"id": 1,
"semester": "Fall 2024",
"courseName": "Data Structures",
"unit": 3,
"grade": "A",
"gradePoint": 5
},
{
"id": 2,
"semester": "Fall 2024",
"courseName": "Algorithms",
"unit": 4,
"grade": "B",
"gradePoint": 4
}
]curl http://localhost:8080/api/courses/cgpaResponse:
{
"cgpa": 4.43,
"totalUnits": 7,
"totalGradePoints": 31,
"semester": null
}curl http://localhost:8080/api/courses/cgpa/semester/Fall%202024Response:
{
"cgpa": 4.43,
"totalUnits": 7,
"totalGradePoints": 31,
"semester": "Fall 2024"
}curl http://localhost:8080/api/courses/semester/Fall%202024curl -X PUT http://localhost:8080/api/courses/1 \
-H "Content-Type: application/json" \
-d '{
"semester": "Fall 2024",
"courseName": "Advanced Data Structures",
"unit": 4,
"grade": "A"
}'curl -X DELETE http://localhost:8080/api/courses/1Create multiple course records to test CGPA calculation:
# Course 1
curl -X POST http://localhost:8080/api/courses \
-H "Content-Type: application/json" \
-d '{"semester": "Fall 2024", "courseName": "Data Structures", "unit": 3, "grade": "A"}'
# Course 2
curl -X POST http://localhost:8080/api/courses \
-H "Content-Type: application/json" \
-d '{"semester": "Fall 2024", "courseName": "Algorithms", "unit": 4, "grade": "B"}'
# Course 3
curl -X POST http://localhost:8080/api/courses \
-H "Content-Type: application/json" \
-d '{"semester": "Spring 2025", "courseName": "Database Systems", "unit": 3, "grade": "A"}'
# Calculate overall CGPA
curl http://localhost:8080/api/courses/cgpaThe API includes validation for:
- Unit must be a positive number
- Course name is required
- Semester is required
- Grade must be one of: A, B, C, D, E, F
This project is open source and available under the MIT License.
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.