Skip to content

DevloperAkash007/University

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.java
  • ProfessorRepository.java
  • ProfessorJpaService.java
  • ProfessorJpaRepository.java
  • Professor.java
  • CourseController.java
  • CourseRepository.java
  • CourseJpaService.java
  • CourseJpaRepository.java
  • Course.java
  • StudentController.java
  • StudentRepository.java
  • StudentJpaService.java
  • StudentJpaRepository.java
  • Student.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**

Professor Table

Columns Type
id INTEGER (Primary Key, Auto Increment)
name TEXT
department TEXT

Course Table

Columns Type
id INTEGER (Primary Key, Auto Increment)
name TEXT
credits INTEGER
professorId INTEGER (Foreign Key)

Student Table

Columns Type
id INTEGER (Primary Key, Auto Increment)
name TEXT
email TEXT

Junction Table

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**

Professor Data

id name department
1 John Smith Computer Science
2 Mary Johnson Physics
3 David Lee Mathematics

Course Data

id name credits professorId
1 Introduction to Programming 3 1
2 Quantum Mechanics 4 2
3 Calculus 4 3

Student Data

id name email
1 Alice Johnson alice@example.com
2 Bob Davis bob@example.com
3 Eva Wilson eva@example.com

Junction Table

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.

Completion Instructions

  • Professor.java: The Professor class should contain the following attributes.

    Attribute Type
    professorId int
    professorName String
    department String
  • ProfessorRepository.java: Create an interface containing 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 the JpaRepository interface.

  • Course.java: The Course class should contain the following attributes.

    Attribute Type
    courseId int
    courseName String
    credits String
    professor Professor
    students List<Student>
  • CourseRepository.java: Create an interface containing 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 the JpaRepository interface.

  • Student.java: The Student class should contain the following attributes.

    Attribute Type
    studentId int
    studentName String
    email String
    courses List<Course>
  • StudentRepository.java: Create an interface containing 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 the JpaRepository interface.

Implement the following APIs.

**API 1: GET /professors**

Path: /professors

Method: GET

Description:

Returns a list of all professors in the professor table.

Response

[
    {
        "professorId": 1,
        "professorName": "John Smith",
        "department": "Computer Science"
    },
    ...
]
**API 2: POST /professors**

Path: /professors

Method: POST

Description:

Creates a new professor in the professor table. The professorId is auto-incremented.

Request

{
    "professorName": "Mark Willam",
    "department": "Mathematics"
}

Response

{
    "professorId": 4,
    "professorName": "Mark Willam",
    "department": "Mathematics"
}
**API 3: GET /professors/{professorId}**

Path: /professors/{professorId}

Method: GET

Description:

Returns a professor based on the professorId. If the given professorId is not found in the professor table, raise ResponseStatusException with HttpStatus.NOT_FOUND.

Success Response

{
    "professorId": 1,
    "professorName": "John Smith",
    "department": "Computer Science"
}
**API 4: PUT /professors/{professorId}**

Path: /professors/{professorId}

Method: PUT

Description:

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.

Request

{
    "professorName": "Mark Williams"
}

Success Response

{
    "professorId": 4,
    "professorName": "Mark Williams",
    "department": "Mathematics"
}
**API 5: DELETE /professors/{professorId}**

Path: /professors/{professorId}

Method: DELETE

Description:

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.

Sample Course object when its corresponding professor is deleted

{
    "courseId": 1,
    "courseName": "Introduction to Programming",
    "credits": 3,
    "professor": null
}
**API 6: GET /professors/{professorId}/courses**

Path: /professors/{professorId}/courses

Method: GET

Description:

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.

Success Response

[
    {
        "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**

Path: /courses

Method: GET

Description:

Returns a list of all courses in the course table.

Response

[
    {
        "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**

Path: /courses

Method: POST

Description:

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.

Request

{
    "courseName": "Statistics",
    "credits": 5,
    "professor": {
        "professorId": 3
    },
    "students": [
        {
            "studentId": 2
        },
        {
            "studentId": 3
        }
    ]
}

Response

{
    "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}**

Path: /courses/{courseId}

Method: GET

Description:

Returns a course based on the courseId. If the given courseId is not found in the course table, raise ResponseStatusException with HttpStatus.NOT_FOUND.

Success Response

{
    "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}**

Path: /courses/{courseId}

Method: PUT

Description:

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.

Request

{
    "credits": 4,
    "professor": {
        "professorId": 4
    },
    "students": [
        {
            "studentId": 1
        },
        {
            "studentId": 3
        }
    ]
}

Success Response

{
    "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}**

Path: /courses/{courseId}

Method: DELETE

Description:

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**

Path: /courses/{courseId}/professor

Method: GET

Description:

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.

Success Response

{
    "professorId": 1,
    "professorName": "John Smith",
    "department": "Computer Science"
}
**API 13: GET /courses/{courseId}/students**

Path: /courses/{courseId}/students

Method: GET

Description:

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.

Success Response

[
    {
        "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**

Path: /students

Method: GET

Description:

Returns a list of all students in the student table.

Response

[
    {
        "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**

Path: /students

Method: POST

Description:

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.

Request

{
    "studentName": "Harley Hoies",
    "email": "harley@example.com",
    "courses": [
        {
            "courseId": 2
        },
        {
            "courseId": 4
        }
    ]
}

Success Response

{
    "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}**

Path: /students/{studentId}

Method: GET

Description:

Returns a student based on the studentId. If the given studentId is not found in the student table, raise ResponseStatusException with HttpStatus.NOT_FOUND.

Success Response

{
    "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}**

Path: /students/{studentId}

Method: PUT

Description:

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.

Request

{
    "studentName": "Harley Homes",
    "courses": [
        {
            "courseId": 3
        },
        {
            "courseId": 4
        }
    ]
}

Success Response

{
    "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}**

Path: /students/{studentId}

Method: DELETE

Description:

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**

Path: /students/{studentId}/courses

Method: GET

Description:

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.

Success Response

[
    {
        "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

About

No description or website provided.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages