In this project, we will build a Spring Boot application named 'University'. The 'University' platform is designed to connect professors, courses, and students. Users can easily navigate through the platform to discover which courses are offered by specific professors and which students are enrolled in a particular course.
The main entities to be considered for this application are Professor, Course, and Student. The Course entity has a Many-to-One relationship with the Professor indicating that each course is taught by a specific professor. Additionally, the Course entity shares a Many-to-Many relationship with the Student, showing that a course can have multiple enrolled students, and a student can be enrolled in multiple courses.
**Implementation Files**
Use these files to complete the implementation:
ProfessorController.javaProfessorRepository.javaProfessorJpaService.javaProfessorJpaRepository.javaProfessor.javaCourseController.javaCourseRepository.javaCourseJpaService.javaCourseJpaRepository.javaCourse.javaStudentController.javaStudentRepository.javaStudentJpaService.javaStudentJpaRepository.javaStudent.java
Create a database that contains four tables professor, student, course, and course_student using the given database schema.
You can refer to this session, for creating a database.
Create the SQL files and compose accurate queries to run the application. Inaccurate SQL files will result in test case failures.
**Database Schema**
| Columns | Type |
|---|---|
| id | INTEGER (Primary Key, Auto Increment) |
| name | TEXT |
| department | TEXT |
| Columns | Type |
|---|---|
| id | INTEGER (Primary Key, Auto Increment) |
| name | TEXT |
| credits | INTEGER |
| professorId | INTEGER (Foreign Key) |
| Columns | Type |
|---|---|
| id | INTEGER (Primary Key, Auto Increment) |
| name | TEXT |
| TEXT |
| Columns | Type |
|---|---|
| studentId | INTEGER (Primary Key, Foreign Key) |
| courseId | INTEGER (Primary Key, Foreign Key) |
You can use the given sample data to populate the tables.
**Sample Data**
| id | name | department |
|---|---|---|
| 1 | John Smith | Computer Science |
| 2 | Mary Johnson | Physics |
| 3 | David Lee | Mathematics |
| id | name | credits | professorId |
|---|---|---|---|
| 1 | Introduction to Programming | 3 | 1 |
| 2 | Quantum Mechanics | 4 | 2 |
| 3 | Calculus | 4 | 3 |
| id | name | |
|---|---|---|
| 1 | Alice Johnson | alice@example.com |
| 2 | Bob Davis | bob@example.com |
| 3 | Eva Wilson | eva@example.com |
| courseId | studentId |
|---|---|
| 1 | 1 |
| 1 | 2 |
| 2 | 2 |
| 2 | 3 |
| 3 | 1 |
| 3 | 3 |
Use only professor, student, course, and course_student as the table names in your code.
-
Professor.java: TheProfessorclass should contain the following attributes.Attribute Type professorId int professorName String department String -
ProfessorRepository.java: Create aninterfacecontaining the required methods. -
ProfessorJpaService.java: Update the service class with logic for managing professor data. -
ProfessorController.java: Create the controller class to handle HTTP requests. -
ProfessorJpaRepository.java: Create an interface that implements theJpaRepositoryinterface. -
Course.java: TheCourseclass should contain the following attributes.Attribute Type courseId int courseName String credits String professor Professor students List<Student> -
CourseRepository.java: Create aninterfacecontaining the required methods. -
CourseJpaService.java: Update the service class with logic for managing course data. -
CourseController.java: Create the controller class to handle HTTP requests. -
CourseJpaRepository.java: Create an interface that implements theJpaRepositoryinterface. -
Student.java: TheStudentclass should contain the following attributes.Attribute Type studentId int studentName String email String courses List<Course> -
StudentRepository.java: Create aninterfacecontaining the required methods. -
StudentJpaService.java: Update the service class with logic for managing student data. -
StudentController.java: Create the controller class to handle HTTP requests. -
StudentJpaRepository.java: Create an interface that implements theJpaRepositoryinterface.
Implement the following APIs.
**API 1: GET /professors**
Returns a list of all professors in the professor table.
[
{
"professorId": 1,
"professorName": "John Smith",
"department": "Computer Science"
},
...
]**API 2: POST /professors**
Creates a new professor in the professor table. The professorId is auto-incremented.
{
"professorName": "Mark Willam",
"department": "Mathematics"
}{
"professorId": 4,
"professorName": "Mark Willam",
"department": "Mathematics"
}**API 3: GET /professors/{professorId}**
Returns a professor based on the professorId. If the given professorId is not found in the professor table, raise ResponseStatusException with HttpStatus.NOT_FOUND.
{
"professorId": 1,
"professorName": "John Smith",
"department": "Computer Science"
}**API 4: PUT /professors/{professorId}**
Updates the details of a professor based on the professorId and returns the updated professor details. If the given professorId is not found in the professor table, raise ResponseStatusException with HttpStatus.NOT_FOUND.
{
"professorName": "Mark Williams"
}{
"professorId": 4,
"professorName": "Mark Williams",
"department": "Mathematics"
}**API 5: DELETE /professors/{professorId}**
Deletes a professor from the professor table based on the professorId and returns the status code 204(raise ResponseStatusException with HttpStatus.NO_CONTENT). Also, remove the association between the professor and the courses by replacing the professorId in the course table with null.
If the given professorId is not found in the professor table, raise ResponseStatusException with HttpStatus.NOT_FOUND.
{
"courseId": 1,
"courseName": "Introduction to Programming",
"credits": 3,
"professor": null
}**API 6: GET /professors/{professorId}/courses**
Returns the courses of a professor based on the professorId. If the given professorId is not found in the professor table, raise ResponseStatusException with HttpStatus.NOT_FOUND.
[
{
"courseId": 1,
"courseName": "Introduction to Programming",
"credits": 3,
"professor": {
"professorId": 1,
"professorName": "John Smith",
"department": "Computer Science"
},
"students": [
{
"studentId": 1,
"studentName": "Alice Johnson",
"email": "alice@example.com"
},
{
"studentId": 2,
"studentName": "Bob Davis",
"email": "bob@example.com"
}
]
}
]**API 7: GET /courses**
Returns a list of all courses in the course table.
[
{
"courseId": 1,
"courseName": "Introduction to Programming",
"credits": 3,
"professor": {
"professorId": 1,
"professorName": "John Smith",
"department": "Computer Science"
},
"students": [
{
"studentId": 1,
"studentName": "Alice Johnson",
"email": "alice@example.com"
},
{
"studentId": 2,
"studentName": "Bob Davis",
"email": "bob@example.com"
}
]
},
...
]**API 8: POST /courses**
Creates a new course in the course table. Also, create an association between the course and students in the course_student table based on the studentIds provided in the students field and an association between the course and the professor based on the professorId of the professor field. The courseId is auto-incremented.
{
"courseName": "Statistics",
"credits": 5,
"professor": {
"professorId": 3
},
"students": [
{
"studentId": 2
},
{
"studentId": 3
}
]
}{
"courseId": 4,
"courseName": "Statistics",
"credits": 5,
"professor": {
"professorId": 3,
"professorName": "David Lee",
"department": "Mathematics"
},
"students": [
{
"studentId": 2,
"studentName": "Bob Davis",
"email": "bob@example.com"
},
{
"studentId": 3,
"studentName": "Eva Wilson",
"email": "eva@example.com"
}
]
}**API 9: GET /courses/{courseId}**
Returns a course based on the courseId. If the given courseId is not found in the course table, raise ResponseStatusException with HttpStatus.NOT_FOUND.
{
"courseId": 1,
"courseName": "Introduction to Programming",
"credits": 3,
"professor": {
"professorId": 1,
"professorName": "John Smith",
"department": "Computer Science"
},
"students": [
{
"studentId": 1,
"studentName": "Alice Johnson",
"email": "alice@example.com"
},
{
"studentId": 2,
"studentName": "Bob Davis",
"email": "bob@example.com"
}
]
}**API 10: PUT /courses/{courseId}**
Updates the details of a course based on the courseId and returns the updated course details. Also update the associations between the course and students, if the students field is provided and the association between the course and the professor based on the professorId, if the professor field is provided. If the given courseId is not found in the course table, raise ResponseStatusException with HttpStatus.NOT_FOUND.
{
"credits": 4,
"professor": {
"professorId": 4
},
"students": [
{
"studentId": 1
},
{
"studentId": 3
}
]
}{
"courseId": 4,
"courseName": "Statistics",
"credits": 4,
"professor": {
"professorId": 4,
"professorName": "Mark Williams",
"department": "Mathematics"
},
"students": [
{
"studentId": 1,
"studentName": "Alice Johnson",
"email": "alice@example.com"
},
{
"studentId": 3,
"studentName": "Eva Wilson",
"email": "eva@example.com"
}
]
}**API 11: DELETE /courses/{courseId}**
Deletes a course from the course table and its associations from the course_student table based on the courseId and returns the status code 204(raise ResponseStatusException with HttpStatus.NO_CONTENT). If the given courseId is not found in the course table, raise ResponseStatusException with HttpStatus.NOT_FOUND.
**API 12: GET /courses/{courseId}/professor**
Returns a professor of the course based on the courseId. If the given courseId is not found in the course table, raise ResponseStatusException with HttpStatus.NOT_FOUND.
{
"professorId": 1,
"professorName": "John Smith",
"department": "Computer Science"
}**API 13: GET /courses/{courseId}/students**
Returns all students associated with the course based on the courseId. If the given courseId is not found in the course table, raise ResponseStatusException with HttpStatus.NOT_FOUND.
[
{
"studentId": 1,
"studentName": "Alice Johnson",
"email": "alice@example.com",
"courses": [
{
"courseId": 1,
"courseName": "Introduction to Programming",
"credits": 3,
"professor": {
"professorId": 1,
"professorName": "John Smith",
"department": "Computer Science"
}
},
{
"courseId": 3,
"courseName": "Calculus",
"credits": 4,
"professor": {
"professorId": 3,
"professorName": "David Lee",
"department": "Mathematics"
}
},
{
"courseId": 4,
"courseName": "Statistics",
"credits": 4,
"professor": {
"professorId": 4,
"professorName": "Mark Williams",
"department": "Mathematics"
}
}
]
},
{
"studentId": 2,
"studentName": "Bob Davis",
"email": "bob@example.com",
"courses": [
{
"courseId": 1,
"courseName": "Introduction to Programming",
"credits": 3,
"professor": {
"professorId": 1,
"professorName": "John Smith",
"department": "Computer Science"
}
},
{
"courseId": 2,
"courseName": "Quantum Mechanics",
"credits": 4,
"professor": {
"professorId": 2,
"professorName": "Mary Johnson",
"department": "Physics"
}
}
]
}
]**API 14: GET /students**
Returns a list of all students in the student table.
[
{
"studentId": 1,
"studentName": "Alice Johnson",
"email": "alice@example.com",
"courses": [
{
"courseId": 1,
"courseName": "Introduction to Programming",
"credits": 3,
"professor": {
"professorId": 1,
"professorName": "John Smith",
"department": "Computer Science"
}
},
{
"courseId": 3,
"courseName": "Calculus",
"credits": 4,
"professor": {
"professorId": 3,
"professorName": "David Lee",
"department": "Mathematics"
}
},
{
"courseId": 4,
"courseName": "Statistics",
"credits": 4,
"professor": {
"professorId": 4,
"professorName": "Mark Williams",
"department": "Mathematics"
}
}
]
},
...
]**API 15: POST /students**
Creates a new student in the student table, if all the courseIds in the courses field exist in the course table. Also, create an association between the student and courses in the course_student table. The studentId is auto-incremented. If any given courseId is not found in the course table, raise ResponseStatusException with HttpStatus.BAD_REQUEST.
{
"studentName": "Harley Hoies",
"email": "harley@example.com",
"courses": [
{
"courseId": 2
},
{
"courseId": 4
}
]
}{
"studentId": 4,
"studentName": "Harley Hoies",
"email": "harley@example.com",
"courses": [
{
"courseId": 2,
"courseName": "Quantum Mechanics",
"credits": 4,
"professor": {
"professorId": 2,
"professorName": "Mary Johnson",
"department": "Physics"
}
},
{
"courseId": 4,
"courseName": "Statistics",
"credits": 4,
"professor": {
"professorId": 4,
"professorName": "Mark Williams",
"department": "Mathematics"
}
}
]
}**API 16: GET /students/{studentId}**
Returns a student based on the studentId. If the given studentId is not found in the student table, raise ResponseStatusException with HttpStatus.NOT_FOUND.
{
"studentId": 1,
"studentName": "Alice Johnson",
"email": "alice@example.com",
"courses": [
{
"courseId": 1,
"courseName": "Introduction to Programming",
"credits": 3,
"professor": {
"professorId": 1,
"professorName": "John Smith",
"department": "Computer Science"
}
},
{
"courseId": 3,
"courseName": "Calculus",
"credits": 4,
"professor": {
"professorId": 3,
"professorName": "David Lee",
"department": "Mathematics"
}
},
{
"courseId": 4,
"courseName": "Statistics",
"credits": 4,
"professor": {
"professorId": 4,
"professorName": "Mark Williams",
"department": "Mathematics"
}
}
]
}**API 17: PUT /students/{studentId}**
Updates the details of a student based on the studentId and returns the updated student details. Also update the associations between the student and courses, if the courses field is provided. If the given studentId is not found in the student table, raise ResponseStatusException with HttpStatus.NOT_FOUND. If any given courseId is not found in the course table, raise ResponseStatusException with HttpStatus.BAD_REQUEST.
{
"studentName": "Harley Homes",
"courses": [
{
"courseId": 3
},
{
"courseId": 4
}
]
}{
"studentId": 4,
"studentName": "Harley Homes",
"email": "harley@example.com",
"courses": [
{
"courseId": 3,
"courseName": "Calculus",
"credits": 4,
"professor": {
"professorId": 3,
"professorName": "David Lee",
"department": "Mathematics"
}
},
{
"courseId": 4,
"courseName": "Statistics",
"credits": 4,
"professor": {
"professorId": 4,
"professorName": "Mark Williams",
"department": "Mathematics"
}
}
]
}**API 18: DELETE /students/{studentId}**
Deletes a student from the student table and its associations from the course_student table based on the studentId and returns the status code 204(raise ResponseStatusException with HttpStatus.NO_CONTENT). If the given studentId is not found in the student table, raise ResponseStatusException with HttpStatus.NOT_FOUND.
**API 19: GET /students/{studentId}/courses**
Returns all courses associated with the student based on the studentId. If the given studentId is not found in the student table, raise ResponseStatusException with HttpStatus.NOT_FOUND.
[
{
"courseId": 1,
"courseName": "Introduction to Programming",
"credits": 3,
"professor": {
"professorId": 1,
"professorName": "John Smith",
"department": "Computer Science"
},
"students": [
{
"studentId": 1,
"studentName": "Alice Johnson",
"email": "alice@example.com"
},
{
"studentId": 2,
"studentName": "Bob Davis",
"email": "bob@example.com"
}
]
},
{
"courseId": 4,
"courseName": "Statistics",
"credits": 4,
"professor": {
"professorId": 4,
"professorName": "Mark Williams",
"department": "Mathematics"
},
"students": [
{
"studentId": 1,
"studentName": "Alice Johnson",
"email": "alice@example.com"
},
{
"studentId": 3,
"studentName": "Eva Wilson",
"email": "eva@example.com"
},
{
"studentId": 4,
"studentName": "Harley Homes",
"email": "harley@example.com"
}
]
},
{
"courseId": 3,
"courseName": "Calculus",
"credits": 4,
"professor": {
"professorId": 3,
"professorName": "David Lee",
"department": "Mathematics"
},
"students": [
{
"studentId": 1,
"studentName": "Alice Johnson",
"email": "alice@example.com"
},
{
"studentId": 3,
"studentName": "Eva Wilson",
"email": "eva@example.com"
},
{
"studentId": 4,
"studentName": "Harley Homes",
"email": "harley@example.com"
}
]
}
]Do not modify the code in UniversityApplication.java