This is a sample API, using Clean Architecture, CQRS and Microsoft .NET 7.
We are using some Functional Programing paradigms, concepts such as:
Maybe<T>
- to avoid Nulls with the Maybe TypeResult
- to handle failures and Input Errors in a Functional Way
The application is an API for a student management system. Here's the domain model of this system. This is the main class in our model, Student. It consists of a name, email, collection of enrollments, and a collection of disenrollment comments. A student can have up to two enrollments in courses. Each enrollment has a grade: either A, B, C, D, or F. Whenever the user deletes an enrollment, he or she must specify the reason why the student wants to discontinue taking this course. It means that when you create an enrollment, you must specify the student's grade, and when you delete one, you have to type in the comment from the student. The API exposes the standard CRUD operations: the standard create, read, update, and delete.
We have 3 repositories, and we are using the unit of work pattern:
StudentRepository
CourseRepository
EnrollmenttRepository
Courses endpoints
- GET
/Courses
- returns all courses - POST
/Courses
- creates a new course - GET
/Courses/{id}
- returns a course by id - GET
/Courses/GetByName/{name}
- returns a course by name - DELETE
/Courses/{id}
- deletes a course by id
Enrollments endpoints
- GET
/Enrollments
- returns all enrollments
Students endpoints
- GET
/students
- returns all students - POST
/students
- creates a new student - DELETE
/students/{id}
- deletes a student by id - PUT
/students/{id}
- updates a student by id - POST
/students/{id}/enrollments
- adds a student to a course - PUT
/students/{id}/enrollments/{enrollmentNumber}
- updates a student with a course - POST
/students/{id}/enrollments/{enrollmentNumber}/deletion
- deletes a student from a course
Student
Id
should not be nullName
should not be emptyEmail
should not be empty
Enrollment
Id
should not be nullStudent
should not be emptyCourse
should not be emptyGrade
should not be empty
Course
Id
should not be nullName
should not be emptyCredits
should not be null
This demo application uses the following technologies:
- .NET 7
- C# 11
- ASP.NET Core MVC 7.0
- EF Core 7.0
- Rider 2022
- SQL Server 2022
- MediatR 11.1
- Fluent Validation 11.2
- Bogus 34.0