-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add `Semester` and `StudentSemester` entities * Configure a many-to-many relationship between students and semesters * Fix naming for DB tables and columns * Add a name to `Semester` entity * Fix outdated comment * Add DTOs for semesters * Replace `StudentGroupCreateDto` with `AssignStudentDto` This change, in fact, only renames a record so it can be used in other services that require assigninging students to something. * Add validation tests for the semester DTO * Implement semester validation * Implement `AssigningService` and `StudentGroupsService` * Replace typeparams for `IStudentGroupsService` * Add tests for assigning endpoints * Remove `StudentGroup` logic from `GroupsService` * Implement `SemestersService` * Implement `StudentSemestersService` * Add integration tests for semesters endpoints * Implement endpoints for semesters * Fix enrollments display * Configure test data generation for semesters * Fix a test
- Loading branch information
1 parent
32216f2
commit 83f6dc7
Showing
47 changed files
with
3,182 additions
and
420 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; | ||
|
||
namespace EUniversity.Core.Dtos.University; | ||
|
||
[ValidateNever] // Remove data annotations validation | ||
public record SemesterCreateDto(string Name, DateTimeOffset DateFrom, DateTimeOffset DateTo); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
namespace EUniversity.Core.Dtos.University; | ||
|
||
public record SemesterPreviewDto(int Id, string Name, DateTimeOffset DateFrom, DateTimeOffset DateTo); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
namespace EUniversity.Core.Dtos.University; | ||
|
||
public record SemesterViewDto(int Id, string Name, | ||
DateTimeOffset DateFrom, DateTimeOffset DateTo, | ||
IEnumerable<StudentSemesterViewDto> StudentEnrollments); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
using EUniversity.Core.Dtos.Users; | ||
|
||
namespace EUniversity.Core.Dtos.University; | ||
|
||
public record StudentSemesterViewDto(StudentPreviewDto Student, DateTimeOffset EnrollmentDate); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
namespace EUniversity.Core.Models.University; | ||
|
||
/// <summary> | ||
/// An entity that represents a semester. | ||
/// </summary> | ||
public class Semester : IEntity<int>, IHasName | ||
{ | ||
public const int MaxNameLength = 100; | ||
|
||
[Key] | ||
public int Id { get; set; } | ||
/// <summary> | ||
/// Name of the semester. | ||
/// </summary> | ||
[StringLength(MaxNameLength)] | ||
public string Name { get; set; } = null!; | ||
/// <summary> | ||
/// Date when the semester starts. | ||
/// </summary> | ||
public DateTimeOffset DateFrom { get; set; } | ||
/// <summary> | ||
/// Date when the semester ends. | ||
/// </summary> | ||
public DateTimeOffset DateTo { get; set; } | ||
|
||
/// <summary> | ||
/// Navigation property to the students which are part of this semester. | ||
/// </summary> | ||
public ICollection<ApplicationUser> Students { get; set; } = null!; | ||
/// <summary> | ||
/// Navigation property to the student enrollments of this semester. | ||
/// </summary> | ||
public ICollection<StudentSemester> StudentEnrollments { get; set; } = null!; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System.ComponentModel.DataAnnotations.Schema; | ||
|
||
namespace EUniversity.Core.Models.University; | ||
|
||
/// <summary> | ||
/// Represents the entity used for configuring many-to-many relationship | ||
/// between students and semesters. | ||
/// </summary> | ||
public class StudentSemester : IEntity<int> | ||
{ | ||
[Key] | ||
public int Id { get; set; } | ||
|
||
/// <summary> | ||
/// Date when student was added to the semester. | ||
/// </summary> | ||
public DateTimeOffset EnrollmentDate { get; set; } | ||
|
||
/// <summary> | ||
/// Foreign key of the associated student. | ||
/// </summary> | ||
[ForeignKey(nameof(Student))] | ||
public string StudentId { get; set; } = null!; | ||
/// <summary> | ||
/// Foreign key of the associated semester. | ||
/// </summary> | ||
[ForeignKey(nameof(Semester))] | ||
public int SemesterId { get; set; } | ||
|
||
/// <summary> | ||
/// Navigation property for the student associated with this semester. | ||
/// </summary> | ||
public ApplicationUser Student { get; set; } = null!; | ||
/// <summary> | ||
/// Navigation property for the semester that the student is part of. | ||
/// </summary> | ||
public Semester Semester { get; set; } = null!; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using System.Linq.Expressions; | ||
|
||
namespace EUniversity.Core.Services; | ||
|
||
/// <summary> | ||
/// Represents an interface for assigning/unassigning entities in a many-to-many relationship. | ||
/// </summary> | ||
/// <typeparam name="TAssigningEntity">A type of entity that configures a many-to-many relationship.</typeparam> | ||
/// <typeparam name="TId1">A type of the ID of the first entity.</typeparam> | ||
/// <typeparam name="TId2">A type of the ID of the second entity.</typeparam> | ||
public interface IAssigningService<TAssigningEntity, TId1, TId2> | ||
where TAssigningEntity : class | ||
where TId1 : IEquatable<TId1> | ||
where TId2 : IEquatable<TId2> | ||
{ | ||
/// <summary> | ||
/// Gets a predicate that can be used for finding | ||
/// an instance of assigning entity in the database. | ||
/// </summary> | ||
/// <param name="id1">ID of the first entity.</param> | ||
/// <param name="id2">ID of the second entity.</param> | ||
/// <returns> | ||
/// A predicate that can be used for finding | ||
/// an instance of assigning entity in the database. | ||
/// </returns> | ||
public Expression<Func<TAssigningEntity, bool>> AssigningEntityPredicate(TId1 id1, TId2 id2); | ||
|
||
/// <summary> | ||
/// Adds the first entity to the second based on their IDs. | ||
/// </summary> | ||
/// <param name="entity1Id">ID of the first entity.</param> | ||
/// <param name="entity2Id">ID of the second entity.</param> | ||
/// <returns> | ||
/// A task that represents the asynchronous operation. If the first entity was | ||
/// successfully assigned to the second, it returns <see langword="true" />. | ||
/// If the first entity was already assigned to the second, then <see langword="false" /> | ||
/// is returned. | ||
/// </returns> | ||
public Task<bool> AssignAsync(TId1 entity1Id, TId2 entity2Id); | ||
|
||
/// <summary> | ||
/// Unasigns the first entity from the second based on their IDs. | ||
/// </summary> | ||
/// <param name="entity1Id">ID of the first entity.</param> | ||
/// <param name="entity2Id">ID of the second entity.</param> | ||
/// <returns> | ||
/// A task that represents the asynchronous operation. If the first entity was | ||
/// successfully unassigned from the second, it returns <see langword="true" />. | ||
/// If the first entity was not assigned to the second, then <see langword="false" /> | ||
/// is returned. | ||
/// </returns> | ||
public Task<bool> UnassignAsync(TId1 entity1Id, TId2 entity2Id); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using EUniversity.Core.Dtos.University; | ||
using EUniversity.Core.Models.University; | ||
|
||
namespace EUniversity.Core.Services.University; | ||
|
||
public interface ISemestersService : | ||
ICrudService<Semester, int, SemesterPreviewDto, SemesterViewDto, SemesterCreateDto, SemesterCreateDto> | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using EUniversity.Core.Models.University; | ||
|
||
namespace EUniversity.Core.Services.University; | ||
|
||
/// <summary> | ||
/// Represents an interface of the service which configures | ||
/// the 'Students->Groups' many-to-many relationship. | ||
/// </summary> | ||
public interface IStudentGroupsService : IAssigningService<StudentGroup, int, string> | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
using EUniversity.Core.Models.University; | ||
|
||
namespace EUniversity.Core.Services.University; | ||
|
||
public interface IStudentSemestersService : IAssigningService<StudentSemester, int, string> | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using EUniversity.Core.Dtos.University; | ||
using EUniversity.Core.Models.University; | ||
using FluentValidation; | ||
|
||
namespace EUniversity.Core.Validation.University; | ||
|
||
public class SemesterCreateDtoValidator : AbstractValidator<SemesterCreateDto> | ||
{ | ||
public SemesterCreateDtoValidator() | ||
{ | ||
RuleFor(s => s.Name) | ||
.NotEmpty() | ||
.WithErrorCode(ValidationErrorCodes.PropertyRequired) | ||
.WithMessage("Semester name is required"); | ||
RuleFor(s => s.Name) | ||
.MaximumLength(Semester.MaxNameLength) | ||
.WithErrorCode(ValidationErrorCodes.PropertyTooLarge) | ||
.WithMessage($"Semester name cannot exceed {Semester.MaxNameLength} characters"); | ||
|
||
RuleFor(s => s.DateFrom) | ||
.LessThan(s => s.DateTo) | ||
.WithErrorCode(ValidationErrorCodes.InvalidRange) | ||
.WithMessage("The from date must be earlier than the to date"); | ||
RuleFor(s => s.DateTo) | ||
.GreaterThan(DateTimeOffset.Now) | ||
.WithErrorCode(ValidationErrorCodes.InvalidRange) | ||
.WithMessage("The to date must be in the future"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.