diff --git a/StudentModule.Application/Handlers/StudentHandlres/CreateStudentCommandHandler.cs b/StudentModule.Application/Handlers/StudentHandlres/CreateStudentCommandHandler.cs index 5709700..20abc8f 100644 --- a/StudentModule.Application/Handlers/StudentHandlres/CreateStudentCommandHandler.cs +++ b/StudentModule.Application/Handlers/StudentHandlres/CreateStudentCommandHandler.cs @@ -49,6 +49,7 @@ public async Task Handle(CreateStudentCommand request, CancellationT Phone = request.Phone, IsHeadMan = request.IsHeadMan, Status = request.Status, + InternshipStatus = request.InternshipStatus, GroupId = request.GroupId, Group = group }; diff --git a/StudentModule.Application/Handlers/StudentHandlres/CreateStudentFromExelCommandHandler.cs b/StudentModule.Application/Handlers/StudentHandlres/CreateStudentFromExelCommandHandler.cs index 496ade8..11ffd62 100644 --- a/StudentModule.Application/Handlers/StudentHandlres/CreateStudentFromExelCommandHandler.cs +++ b/StudentModule.Application/Handlers/StudentHandlres/CreateStudentFromExelCommandHandler.cs @@ -50,6 +50,7 @@ public async Task Handle(CreateStudentFromExelCommand request, Cance Phone = null, IsHeadMan = false, Status = StudentStatus.InProcess, + InternshipStatus = StudentInternshipStatus.Candidate, GroupId = group.Id, Group = group }; diff --git a/StudentModule.Application/Handlers/StudentHandlres/EditStudentInternshupStatusCommandHandler.cs b/StudentModule.Application/Handlers/StudentHandlres/EditStudentInternshupStatusCommandHandler.cs new file mode 100644 index 0000000..c67d1bf --- /dev/null +++ b/StudentModule.Application/Handlers/StudentHandlres/EditStudentInternshupStatusCommandHandler.cs @@ -0,0 +1,35 @@ +using MediatR; +using Shared.Domain.Exceptions; +using StudentModule.Contracts.Commands.StudentCommands; +using StudentModule.Contracts.DTOs; +using StudentModule.Contracts.Repositories; +using UserModule.Contracts.Repositories; + +namespace StudentModule.Application.Handlers.StudentHandlres +{ + public class EditStudentInternshipStatusCommandHandler : IRequestHandler + { + private readonly IStudentRepository _studentRepository; + private readonly IUserRepository _userRepository; + + public EditStudentInternshipStatusCommandHandler(IStudentRepository studentRepository, IUserRepository userRepository) + { + _studentRepository = studentRepository; + _userRepository = userRepository; + } + public async Task Handle(EditStudentInternshipStatusCommand request, CancellationToken cancellationToken) + { + var student = await _studentRepository.GetStudentByIdAsync(request.Id) + ?? throw new NotFound("Student not found"); + + var user = await _userRepository.GetByIdAsync(student.UserId); + + + student.InternshipStatus = request.Status; + await _studentRepository.UpdateAsync(student); + + student.User = user; + return new StudentDto(student); + } + } +} diff --git a/StudentModule.Contracts/Commands/StudentCommands/CreateStudentCommand.cs b/StudentModule.Contracts/Commands/StudentCommands/CreateStudentCommand.cs index a10eb4f..ef57245 100644 --- a/StudentModule.Contracts/Commands/StudentCommands/CreateStudentCommand.cs +++ b/StudentModule.Contracts/Commands/StudentCommands/CreateStudentCommand.cs @@ -18,6 +18,7 @@ public record CreateStudentCommand : IRequest public string Phone { get; set; } public bool IsHeadMan { get; set; } public StudentStatus Status { get; set; } + public StudentInternshipStatus InternshipStatus { get; set; } public Guid GroupId { get; set; } } } diff --git a/StudentModule.Contracts/Commands/StudentCommands/EditStudentInternshipStatusCommand.cs b/StudentModule.Contracts/Commands/StudentCommands/EditStudentInternshipStatusCommand.cs new file mode 100644 index 0000000..21fa065 --- /dev/null +++ b/StudentModule.Contracts/Commands/StudentCommands/EditStudentInternshipStatusCommand.cs @@ -0,0 +1,17 @@ +using MediatR; +using StudentModule.Contracts.DTOs; +using StudentModule.Domain.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StudentModule.Contracts.Commands.StudentCommands +{ + public record EditStudentInternshipStatusCommand : IRequest + { + public Guid Id { get; set; } + public StudentInternshipStatus Status { get; set; } + } +} diff --git a/StudentModule.Contracts/DTOs/StudentDto.cs b/StudentModule.Contracts/DTOs/StudentDto.cs index c037b83..f90c9d0 100644 --- a/StudentModule.Contracts/DTOs/StudentDto.cs +++ b/StudentModule.Contracts/DTOs/StudentDto.cs @@ -1,13 +1,6 @@ using StudentModule.Domain.Entities; using StudentModule.Domain.Enums; -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations.Schema; -using System.Linq; -using System.Text; -using System.Text.RegularExpressions; -using System.Threading.Tasks; -using UserModule.Domain.Entities; + namespace StudentModule.Contracts.DTOs { @@ -21,6 +14,7 @@ public class StudentDto public string Phone { get; set; } public bool IsHeadMan { get; set; } public StudentStatus Status { get; set; } + public StudentInternshipStatus InternshipStatus { get; set; } public int? GroupNumber { get; set; } public int? Course { get; set; } @@ -32,6 +26,7 @@ public StudentDto(StudentEntity student) Middlename = student.Middlename; Phone = student.Phone; Status = student.Status; + InternshipStatus = student.InternshipStatus; IsHeadMan = student.IsHeadMan; Name = student.User.Name; Surname = student.User.Surname; diff --git a/StudentModule.Controllers/Controllers/StudentController.cs b/StudentModule.Controllers/Controllers/StudentController.cs index 9a75565..d295dd3 100644 --- a/StudentModule.Controllers/Controllers/StudentController.cs +++ b/StudentModule.Controllers/Controllers/StudentController.cs @@ -24,7 +24,7 @@ public StudentController(IMediator mediator) [HttpPost] [Route("create")] - //[Authorize(Roles = "Dean")] + [Authorize(Roles = "DeanMember")] public async Task CreateStudent(CreateStudentCommand command) { return Ok(await _mediator.Send(command)); @@ -32,12 +32,28 @@ public async Task CreateStudent(CreateStudentCommand command) [HttpPatch] [Route("edit-student-status")] - //todo уточнить кто имеет прао менять статус студента + [Authorize(Roles = "DeanMember")] public async Task EditStudentStatus(EditStudentStatusCommand command) { return Ok(await _mediator.Send(command)); } + [HttpPatch] + [Route("edit-student-internship-status")] + [Authorize(Roles = "DeanMember")] + public async Task EditStudentInternshipStatus(EditStudentInternshipStatusCommand command) + { + return Ok(await _mediator.Send(command)); + } + + [HttpPut] + [Route("edit-student")] + [Authorize(Roles = "DeanMember")] + public async Task EditStudent(EditStudentCommand command) + { + return Ok(await _mediator.Send(command)); + } + [HttpPatch] [Route("edit-student-group")] [Authorize(Roles = "DeanMember")] diff --git a/StudentModule.Domain/Entities/StudentEntity.cs b/StudentModule.Domain/Entities/StudentEntity.cs index 827f890..dc9f0c8 100644 --- a/StudentModule.Domain/Entities/StudentEntity.cs +++ b/StudentModule.Domain/Entities/StudentEntity.cs @@ -14,6 +14,7 @@ public class StudentEntity : BaseEntity public string? Phone { get; set; } public bool IsHeadMan { get; set; } public StudentStatus Status { get; set; } + public StudentInternshipStatus InternshipStatus { get; set; } public Guid GroupId { get; set; } public GroupEntity Group { get; set; } diff --git a/StudentModule.Domain/Enums/StudentInternshipStatus.cs b/StudentModule.Domain/Enums/StudentInternshipStatus.cs new file mode 100644 index 0000000..6d901ca --- /dev/null +++ b/StudentModule.Domain/Enums/StudentInternshipStatus.cs @@ -0,0 +1,11 @@ + + +namespace StudentModule.Domain.Enums +{ + public enum StudentInternshipStatus + { + Small, + Candidate, + Intern + } +} diff --git a/StudentModule.Infrastructure/Migrations/20250529104555_InternshipStatus.Designer.cs b/StudentModule.Infrastructure/Migrations/20250529104555_InternshipStatus.Designer.cs new file mode 100644 index 0000000..51f4556 --- /dev/null +++ b/StudentModule.Infrastructure/Migrations/20250529104555_InternshipStatus.Designer.cs @@ -0,0 +1,147 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using StudentModule.Infrastructure; + +#nullable disable + +namespace StudentModule.Infrastructure.Migrations +{ + [DbContext(typeof(StudentModuleDbContext))] + [Migration("20250529104555_InternshipStatus")] + partial class InternshipStatus + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "9.0.5") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("StudentModule.Domain.Entities.GroupEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("GroupNumber") + .HasColumnType("integer"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("StreamId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("StreamId"); + + b.ToTable("Groups"); + }); + + modelBuilder.Entity("StudentModule.Domain.Entities.StreamEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Course") + .HasColumnType("integer"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("StreamNumber") + .HasColumnType("integer"); + + b.Property("Year") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Streams"); + }); + + modelBuilder.Entity("StudentModule.Domain.Entities.StudentEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("GroupId") + .HasColumnType("uuid"); + + b.Property("InternshipStatus") + .HasColumnType("integer"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("IsHeadMan") + .HasColumnType("boolean"); + + b.Property("Middlename") + .HasColumnType("text"); + + b.Property("Phone") + .HasColumnType("text"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("GroupId"); + + b.ToTable("SStudents"); + }); + + modelBuilder.Entity("StudentModule.Domain.Entities.GroupEntity", b => + { + b.HasOne("StudentModule.Domain.Entities.StreamEntity", "Stream") + .WithMany("Groups") + .HasForeignKey("StreamId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Stream"); + }); + + modelBuilder.Entity("StudentModule.Domain.Entities.StudentEntity", b => + { + b.HasOne("StudentModule.Domain.Entities.GroupEntity", "Group") + .WithMany("Students") + .HasForeignKey("GroupId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Group"); + }); + + modelBuilder.Entity("StudentModule.Domain.Entities.GroupEntity", b => + { + b.Navigation("Students"); + }); + + modelBuilder.Entity("StudentModule.Domain.Entities.StreamEntity", b => + { + b.Navigation("Groups"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/StudentModule.Infrastructure/Migrations/20250529104555_InternshipStatus.cs b/StudentModule.Infrastructure/Migrations/20250529104555_InternshipStatus.cs new file mode 100644 index 0000000..14239b4 --- /dev/null +++ b/StudentModule.Infrastructure/Migrations/20250529104555_InternshipStatus.cs @@ -0,0 +1,29 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace StudentModule.Infrastructure.Migrations +{ + /// + public partial class InternshipStatus : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "InternshipStatus", + table: "SStudents", + type: "integer", + nullable: false, + defaultValue: 0); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "InternshipStatus", + table: "SStudents"); + } + } +} diff --git a/StudentModule.Infrastructure/Migrations/StudentModuleDbContextModelSnapshot.cs b/StudentModule.Infrastructure/Migrations/StudentModuleDbContextModelSnapshot.cs index 7d09a5e..dd99126 100644 --- a/StudentModule.Infrastructure/Migrations/StudentModuleDbContextModelSnapshot.cs +++ b/StudentModule.Infrastructure/Migrations/StudentModuleDbContextModelSnapshot.cs @@ -79,6 +79,9 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("GroupId") .HasColumnType("uuid"); + b.Property("InternshipStatus") + .HasColumnType("integer"); + b.Property("IsDeleted") .HasColumnType("boolean");