From eaf39cab8f9cfae34d0adb44258d6c0567c71013 Mon Sep 17 00:00:00 2001 From: zzizan Date: Tue, 27 May 2025 01:04:55 +0700 Subject: [PATCH 1/6] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BF=D0=BE=D0=BB=D1=83=D1=87=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=20=D1=81=D1=82=D1=83=D0=B4=D0=B5=D0=BD=D1=82?= =?UTF-8?q?=D0=B0=20=D0=BF=D0=BE=20=D1=82=D0=BE=D0=BA=D0=B5=D0=BD=D1=83=20?= =?UTF-8?q?+=20=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=BF=D0=BE=20?= =?UTF-8?q?=D0=B7=D0=B0=D1=8F=D0=B2=D0=BA=D0=B0=D0=BC=20=D1=84=D1=80=D0=BE?= =?UTF-8?q?=D0=BD=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GroupHandlers/GetGroupsQueryHandler.cs | 25 +++------------ .../StreamHandlers/GetStreamQueryHandler.cs | 20 ++---------- .../StreamHandlers/GetStreamsQueryHandler.cs | 16 ++-------- .../GetStudentHimselfQueryHandler.cs | 32 +++++++++++++++++++ .../StudentQueries/GetStudentHimselfQuery.cs | 15 +++++++++ .../Repositories/IStudentRepository.cs | 1 + .../Controllers/GroupController.cs | 3 +- .../Controllers/StreamController.cs | 3 +- .../Controllers/StudentController.cs | 10 +++--- .../Repositories/StudentRepository.cs | 7 ++++ 10 files changed, 74 insertions(+), 58 deletions(-) create mode 100644 StudentModule.Application/Handlers/StudentHandlres/GetStudentHimselfQueryHandler.cs create mode 100644 StudentModule.Contracts/Queries/StudentQueries/GetStudentHimselfQuery.cs diff --git a/StudentModule.Application/Handlers/GroupHandlers/GetGroupsQueryHandler.cs b/StudentModule.Application/Handlers/GroupHandlers/GetGroupsQueryHandler.cs index a383ac8..3e73fc7 100644 --- a/StudentModule.Application/Handlers/GroupHandlers/GetGroupsQueryHandler.cs +++ b/StudentModule.Application/Handlers/GroupHandlers/GetGroupsQueryHandler.cs @@ -9,37 +9,22 @@ namespace StudentModule.Application.Handlers.GroupHandlers public class GetGroupsQueryHandler : IRequestHandler> { private readonly IGroupRepository _groupRepository; - private readonly IUserRepository _userRepository; - public GetGroupsQueryHandler(IGroupRepository groupRepository, IUserRepository userRepository) + public GetGroupsQueryHandler(IGroupRepository groupRepository) { _groupRepository = groupRepository; - _userRepository = userRepository; } public async Task> Handle(GetGroupsQuery request, CancellationToken cancellationToken) { var groups = await _groupRepository.GetGroupAsync(); - var groupDtos = new List(); - var studentDtos = new List(); - + var groupsDto = new List(groups.Count); + foreach (var group in groups) { - studentDtos = new List(); - foreach (var student in group.Students) - { - var user = await _userRepository.GetByIdAsync(student.UserId); - student.User = user; - studentDtos.Add(new StudentDto(student)); - } - - var groupDto = new GroupDto(group) - { - Students = studentDtos - }; - groupDtos.Add(groupDto); + groupsDto.Add(new GroupDto(group)); } - return groupDtos; + return groupsDto; } } } diff --git a/StudentModule.Application/Handlers/StreamHandlers/GetStreamQueryHandler.cs b/StudentModule.Application/Handlers/StreamHandlers/GetStreamQueryHandler.cs index b4feca1..4cec16b 100644 --- a/StudentModule.Application/Handlers/StreamHandlers/GetStreamQueryHandler.cs +++ b/StudentModule.Application/Handlers/StreamHandlers/GetStreamQueryHandler.cs @@ -10,12 +10,10 @@ namespace StudentModule.Application.Handlers.StreamHandlers { public class GetStreamQueryHandler : IRequestHandler { - private readonly IUserRepository _userRepository; private readonly IStreamRepository _streamRepository; - public GetStreamQueryHandler(IUserRepository userRepository, IStreamRepository streamRepository) + public GetStreamQueryHandler(IStreamRepository streamRepository) { - _userRepository = userRepository; _streamRepository = streamRepository; } @@ -25,25 +23,13 @@ public async Task Handle(GetStreamQuery request, CancellationToken ca ?? throw new NotFound("Stream not found"); var groups = new List(); - var students = new List(); foreach (var group in stream.Groups) { - students = new List(); - foreach (var student in group.Students) - { - var user = await _userRepository.GetByIdAsync(student.UserId); - student.User = user; - students.Add(new StudentDto(student)); - } - - var groupDto = new GroupDto(group); - groupDto.Students = students; - groups.Add(groupDto); + groups.Add(new GroupDto(group)); } - var streamDto = new StreamDto(stream); - streamDto.groups = groups; + var streamDto = new StreamDto(stream) { groups = groups}; return streamDto; } diff --git a/StudentModule.Application/Handlers/StreamHandlers/GetStreamsQueryHandler.cs b/StudentModule.Application/Handlers/StreamHandlers/GetStreamsQueryHandler.cs index 4513693..cbc197d 100644 --- a/StudentModule.Application/Handlers/StreamHandlers/GetStreamsQueryHandler.cs +++ b/StudentModule.Application/Handlers/StreamHandlers/GetStreamsQueryHandler.cs @@ -25,28 +25,16 @@ public async Task> Handle(GetStreamsQuery request, CancellationT List streamDtos = new List(); List groupDtos = new List(); - List studentDtos = new List(); foreach (var stream in streams) { groupDtos = new List(); foreach (var group in stream.Groups) { - studentDtos = new List(); - foreach (var student in group.Students) - { - var user = await _userRepository.GetByIdAsync(student.UserId); - student.User = user; - studentDtos.Add(new StudentDto(student)); - } - - var groupDto = new GroupDto(group); - groupDto.Students = studentDtos; - groupDtos.Add(groupDto); + groupDtos.Add(new GroupDto(group)); } - var streamDto = new StreamDto(stream); - streamDto.groups = groupDtos; + var streamDto = new StreamDto(stream) { groups = groupDtos }; streamDtos.Add(streamDto); } diff --git a/StudentModule.Application/Handlers/StudentHandlres/GetStudentHimselfQueryHandler.cs b/StudentModule.Application/Handlers/StudentHandlres/GetStudentHimselfQueryHandler.cs new file mode 100644 index 0000000..2ab7455 --- /dev/null +++ b/StudentModule.Application/Handlers/StudentHandlres/GetStudentHimselfQueryHandler.cs @@ -0,0 +1,32 @@ +using MediatR; +using Shared.Domain.Exceptions; +using StudentModule.Contracts.DTOs; +using StudentModule.Contracts.Queries.StudentQueries; +using StudentModule.Contracts.Repositories; +using UserModule.Contracts.Repositories; + +namespace StudentModule.Application.Handlers.StudentHandlres +{ + public class GetStudentHimselfQueryHandler : IRequestHandler + { + private readonly IStudentRepository _studentRepository; + private readonly IUserRepository _userRepository; + + public GetStudentHimselfQueryHandler(IStudentRepository studentRepository, IUserRepository userRepository) + { + _studentRepository = studentRepository; + _userRepository = userRepository; + } + + public async Task Handle(GetStudentHimselfQuery request, CancellationToken cancellationToken) + { + var user = await _userRepository.GetByIdAsync(request.userId) + ?? throw new NotFound("User not found"); + + var student = await _studentRepository.GetStudentByUserIdAsync(request.userId); + + student.User = user; + return new StudentDto(student); + } + } +} diff --git a/StudentModule.Contracts/Queries/StudentQueries/GetStudentHimselfQuery.cs b/StudentModule.Contracts/Queries/StudentQueries/GetStudentHimselfQuery.cs new file mode 100644 index 0000000..5872d91 --- /dev/null +++ b/StudentModule.Contracts/Queries/StudentQueries/GetStudentHimselfQuery.cs @@ -0,0 +1,15 @@ +using MediatR; +using StudentModule.Contracts.DTOs; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StudentModule.Contracts.Queries.StudentQueries +{ + public record GetStudentHimselfQuery : IRequest + { + public Guid userId { get; set; } + } +} diff --git a/StudentModule.Contracts/Repositories/IStudentRepository.cs b/StudentModule.Contracts/Repositories/IStudentRepository.cs index 1e6924a..e71e707 100644 --- a/StudentModule.Contracts/Repositories/IStudentRepository.cs +++ b/StudentModule.Contracts/Repositories/IStudentRepository.cs @@ -7,5 +7,6 @@ public interface IStudentRepository : IBaseEntityRepository { Task> GetStudentsByGroup(int groupNumber); Task GetStudentByIdAsync(Guid id); + Task GetStudentByUserIdAsync(Guid id); } } diff --git a/StudentModule.Controllers/Controllers/GroupController.cs b/StudentModule.Controllers/Controllers/GroupController.cs index d21a6d0..481f33e 100644 --- a/StudentModule.Controllers/Controllers/GroupController.cs +++ b/StudentModule.Controllers/Controllers/GroupController.cs @@ -1,4 +1,5 @@ using MediatR; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using StudentModule.Contracts.Commands.GroupCommands; using StudentModule.Contracts.Queries.GroupQueries; @@ -8,7 +9,7 @@ namespace StudentModule.Controllers.Controllers { [ApiController] [Route("api/groups/")] - //[Authorize(Roles = "Dean")] + [Authorize(Roles = "Dean")] public class GroupController : ControllerBase { private readonly IMediator _mediator; diff --git a/StudentModule.Controllers/Controllers/StreamController.cs b/StudentModule.Controllers/Controllers/StreamController.cs index 7cb256d..78fa7c4 100644 --- a/StudentModule.Controllers/Controllers/StreamController.cs +++ b/StudentModule.Controllers/Controllers/StreamController.cs @@ -1,4 +1,5 @@ using MediatR; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using StudentModule.Contracts.Commands.StreamCommands; using StudentModule.Contracts.Queries.StreamQueries; @@ -8,7 +9,7 @@ namespace StudentModule.Controllers.Controllers { [ApiController] [Route("api/streams/")] - //[Authorize(Roles = "Dean")] + [Authorize(Roles = "Dean")] public class StreamController : ControllerBase { private readonly IMediator _mediator; diff --git a/StudentModule.Controllers/Controllers/StudentController.cs b/StudentModule.Controllers/Controllers/StudentController.cs index d663e87..537b76a 100644 --- a/StudentModule.Controllers/Controllers/StudentController.cs +++ b/StudentModule.Controllers/Controllers/StudentController.cs @@ -38,7 +38,7 @@ public async Task EditStudentStatus(EditStudentStatusCommand comm [HttpPatch] [Route("edit-student-group")] - //[Authorize(Roles = "Dean")] + [Authorize(Roles = "Dean")] public async Task EditStudentGroup(EditStudentGroupCommand command) { return Ok(await _mediator.Send(command)); @@ -46,7 +46,7 @@ public async Task EditStudentGroup(EditStudentGroupCommand comman [HttpGet] [Route("get-students-by-group/{groupId}")] - //[Authorize(Roles = "Dean")] + [Authorize(Roles = "Dean")] public async Task GetStudentsByGroup([FromRoute] Guid groupId) { var query = new GetStudentsFromGroupQuery() { GroupId = groupId }; @@ -55,7 +55,7 @@ public async Task GetStudentsByGroup([FromRoute] Guid groupId) [HttpGet] [Route("get-students-by-stream/{streamId}")] - //[Authorize(Roles = "Dean")] + [Authorize(Roles = "Dean")] public async Task GetStudentsByStream([FromRoute] Guid streamId) { var query = new GetStudentsFromStreamQuery() { streamId = streamId }; @@ -64,7 +64,7 @@ public async Task GetStudentsByStream([FromRoute] Guid streamId) [HttpGet] [Route("get-student/{id}")] - //[Authorize(Roles = "Dean")] + [Authorize(Roles = "Dean")] public async Task GetStudentForDean([FromRoute] Guid id) { var query = new GetStudentQuery() { id = id }; @@ -80,7 +80,7 @@ public async Task GetStudent() if (userId != null) { - var query = new GetStudentQuery() { id = new Guid(userId) }; + var query = new GetStudentHimselfQuery() { userId = new Guid(userId) }; return Ok(await _mediator.Send(query)); } diff --git a/StudentModule.Persistence/Repositories/StudentRepository.cs b/StudentModule.Persistence/Repositories/StudentRepository.cs index 06d0106..e32aff3 100644 --- a/StudentModule.Persistence/Repositories/StudentRepository.cs +++ b/StudentModule.Persistence/Repositories/StudentRepository.cs @@ -23,5 +23,12 @@ public Task GetStudentByIdAsync(Guid id) return student; } + + public Task GetStudentByUserIdAsync(Guid id) + { + var student = context.SStudents.FirstOrDefaultAsync(s => s.UserId == id); + + return student; + } } } \ No newline at end of file From 46aa811c7eb74db5ab3723dde89b3d83650364a6 Mon Sep 17 00:00:00 2001 From: zzizan Date: Tue, 27 May 2025 01:08:37 +0700 Subject: [PATCH 2/6] =?UTF-8?q?=D0=B5=D1=89=D0=B5=20=D0=BE=D0=B4=D0=B8?= =?UTF-8?q?=D0=BD=20=D1=84=D0=B8=D0=BA=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- StudentModule.Controllers/Controllers/StudentController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/StudentModule.Controllers/Controllers/StudentController.cs b/StudentModule.Controllers/Controllers/StudentController.cs index 537b76a..0286771 100644 --- a/StudentModule.Controllers/Controllers/StudentController.cs +++ b/StudentModule.Controllers/Controllers/StudentController.cs @@ -76,7 +76,7 @@ public async Task GetStudentForDean([FromRoute] Guid id) [Authorize] public async Task GetStudent() { - var userId = User.FindFirst("UserId")?.Value; + var userId = User.Claims.First().Value.ToString(); if (userId != null) { From f066eb8d8403030c04cd25558c6386cf63e9972a Mon Sep 17 00:00:00 2001 From: zzizan Date: Tue, 27 May 2025 13:57:44 +0700 Subject: [PATCH 3/6] =?UTF-8?q?=D1=84=D0=B8=D0=BA=D1=81=20=D1=81=D0=BE?= =?UTF-8?q?=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8=D1=8F=20=D0=B0=D1=81=D0=BF=D1=8E?= =?UTF-8?q?=D0=B7=D0=B5=D1=80=D0=B0,=20=D0=B2=D0=BE=D0=B7=D0=B2=D1=80?= =?UTF-8?q?=D0=B0=D1=89=D0=B0=D0=B5=D0=BC=D1=8B=D1=85=20=D0=BF=D1=80=D0=B8?= =?UTF-8?q?=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BD=D0=B5=20=D1=80=D0=BE=D0=BB?= =?UTF-8?q?=D0=B5=D0=B9,=20=D0=B8=D0=BD=D1=84=D0=BE=D1=80=D0=BC=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D0=B8=20=D0=BE=20=D1=81=D1=82=D1=83=D0=B4=D0=B5?= =?UTF-8?q?=D0=BD=D1=82=D0=B5=20=D0=BF=D0=BE=20=D1=82=D0=BE=D0=BA=D0=B5?= =?UTF-8?q?=D0=BD=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Handler/CreateAspNetUserHandler.cs | 1 + AuthModule.Application/Handler/LoginHandler.cs | 14 +++++++++++--- AuthModule.Contracts/Model/LoginResponseDTO.cs | 3 ++- .../Controllers/StudentController.cs | 15 ++++++--------- .../StudentModule.Controllers.csproj | 1 + .../Repositories/StudentRepository.cs | 5 ++++- 6 files changed, 25 insertions(+), 14 deletions(-) diff --git a/AuthModule.Application/Handler/CreateAspNetUserHandler.cs b/AuthModule.Application/Handler/CreateAspNetUserHandler.cs index 74319cc..d98e0a1 100644 --- a/AuthModule.Application/Handler/CreateAspNetUserHandler.cs +++ b/AuthModule.Application/Handler/CreateAspNetUserHandler.cs @@ -35,6 +35,7 @@ public async Task Handle(CreateAspNetUserQuery request, Cancellatio Id = Guid.NewGuid(), Login = genNewAspNetUserDto.Login, Password = _hashService.GetHash(sha256Hash, genNewAspNetUserDto.Password), + UserId = genNewAspNetUserDto.UserId }); await _context.SaveChangesAsync(cancellationToken); diff --git a/AuthModule.Application/Handler/LoginHandler.cs b/AuthModule.Application/Handler/LoginHandler.cs index d562688..8f65de9 100644 --- a/AuthModule.Application/Handler/LoginHandler.cs +++ b/AuthModule.Application/Handler/LoginHandler.cs @@ -13,6 +13,7 @@ using Shared.Domain.Exceptions; using UserModule.Contracts.Repositories; using UserInfrastructure; +using UserModule.Domain.Enums; namespace AuthModel.Service.Handler; @@ -51,12 +52,17 @@ public async Task Handle(LoginDTO request, CancellationToken c await _context.SaveChangesAsync(cancellationToken); var roles = await _roleRepository.GetRolesByUserIdAsync(user.UserId.Value); + var roleNames = new List(roles.Count); + foreach (var role in roles) + { + roleNames.Add(role.RoleName); + } return new LoginResponseDTO { AccessToken = accessToken.ToString(), RefreshToken = refreshToken, - Roles = roles + Roles = roleNames }; } @@ -68,13 +74,15 @@ private async Task GenerateAccessToken(AspNetUser user) var claims = new List { new Claim("UserId", user.UserId.ToString()) }; - + var roles = await _roleRepository.GetRolesByUserIdAsync(user.UserId.Value); foreach (var role in roles) { claims.Add(new Claim(ClaimTypes.Role, role.RoleName.ToString())); + + role.Users = null; } - + var tokenDescriptor = new SecurityTokenDescriptor { Subject = new ClaimsIdentity(claims), diff --git a/AuthModule.Contracts/Model/LoginResponseDTO.cs b/AuthModule.Contracts/Model/LoginResponseDTO.cs index 8d5a933..4b7bd78 100644 --- a/AuthModule.Contracts/Model/LoginResponseDTO.cs +++ b/AuthModule.Contracts/Model/LoginResponseDTO.cs @@ -1,4 +1,5 @@ using UserModule.Domain.Entities; +using UserModule.Domain.Enums; namespace AuthModule.Contracts.Model; @@ -6,5 +7,5 @@ public class LoginResponseDTO { public string AccessToken { get; set; } public string RefreshToken { get; set; } - public List Roles { get; set; } + public List Roles { get; set; } } \ No newline at end of file diff --git a/StudentModule.Controllers/Controllers/StudentController.cs b/StudentModule.Controllers/Controllers/StudentController.cs index 0286771..45e0b1f 100644 --- a/StudentModule.Controllers/Controllers/StudentController.cs +++ b/StudentModule.Controllers/Controllers/StudentController.cs @@ -6,11 +6,13 @@ using StudentModule.Contracts.Commands.StudentCommands; using StudentModule.Contracts.Queries.StudentQueries; using System.Security.Claims; +using UserModule.Persistence; namespace StudentModule.Controllers.Controllers { [ApiController] + [Authorize] [Route("api/student/")] public class StudentController : ControllerBase { @@ -73,18 +75,13 @@ public async Task GetStudentForDean([FromRoute] Guid id) [HttpGet] [Route("get-student")] - [Authorize] + [Authorize(Roles = "Student")] public async Task GetStudent() { - var userId = User.Claims.First().Value.ToString(); + var userId = User.GetUserId(); - if (userId != null) - { - var query = new GetStudentHimselfQuery() { userId = new Guid(userId) }; - return Ok(await _mediator.Send(query)); - } - - else { throw new BadRequest("Invalid UserId"); } + var query = new GetStudentHimselfQuery() { userId = userId }; + return Ok(await _mediator.Send(query)); } } } diff --git a/StudentModule.Controllers/StudentModule.Controllers.csproj b/StudentModule.Controllers/StudentModule.Controllers.csproj index 7918149..37f1107 100644 --- a/StudentModule.Controllers/StudentModule.Controllers.csproj +++ b/StudentModule.Controllers/StudentModule.Controllers.csproj @@ -18,6 +18,7 @@ + diff --git a/StudentModule.Persistence/Repositories/StudentRepository.cs b/StudentModule.Persistence/Repositories/StudentRepository.cs index e32aff3..331046e 100644 --- a/StudentModule.Persistence/Repositories/StudentRepository.cs +++ b/StudentModule.Persistence/Repositories/StudentRepository.cs @@ -26,7 +26,10 @@ public Task GetStudentByIdAsync(Guid id) public Task GetStudentByUserIdAsync(Guid id) { - var student = context.SStudents.FirstOrDefaultAsync(s => s.UserId == id); + var student = context.SStudents + .Include(s => s.Group) + .ThenInclude(g => g.Stream) + .FirstOrDefaultAsync(s => s.UserId == id); return student; } From 01790ef15ee82f36930d1213efac841ca0a561d4 Mon Sep 17 00:00:00 2001 From: zzizan Date: Wed, 28 May 2025 11:16:17 +0700 Subject: [PATCH 4/6] students from exel --- .../Handler/UploadExcelHandler.cs | 2 +- AuthModule.Contracts/Model/ExcelStudentDTO.cs | 4 +- .../CreateStudentCommandHandler.cs | 2 - .../CreateStudentFromExelCommandHandler.cs | 65 ++++++++ .../EditStudentCommandHandler.cs | 45 ++++++ .../StudentModule.Application.csproj | 1 + .../CreateStudentFromExelCommand.cs | 11 ++ .../StudentCommands/EditStudentCommand.cs | 17 +++ .../Repositories/IGroupRepository.cs | 1 + .../StudentModule.Contracts.csproj | 1 + .../Controllers/StudentController.cs | 8 +- .../Entities/StudentEntity.cs | 2 +- .../20250527150145_PhoneFix.Designer.cs | 144 ++++++++++++++++++ .../Migrations/20250527150145_PhoneFix.cs | 36 +++++ .../StudentModuleDbContextModelSnapshot.cs | 3 +- .../Repositories/GroupRepository.cs | 8 + 16 files changed, 339 insertions(+), 11 deletions(-) create mode 100644 StudentModule.Application/Handlers/StudentHandlres/CreateStudentFromExelCommandHandler.cs create mode 100644 StudentModule.Application/Handlers/StudentHandlres/EditStudentCommandHandler.cs create mode 100644 StudentModule.Contracts/Commands/StudentCommands/CreateStudentFromExelCommand.cs create mode 100644 StudentModule.Contracts/Commands/StudentCommands/EditStudentCommand.cs create mode 100644 StudentModule.Infrastructure/Migrations/20250527150145_PhoneFix.Designer.cs create mode 100644 StudentModule.Infrastructure/Migrations/20250527150145_PhoneFix.cs diff --git a/AuthModule.Application/Handler/UploadExcelHandler.cs b/AuthModule.Application/Handler/UploadExcelHandler.cs index 9aa0163..942a191 100644 --- a/AuthModule.Application/Handler/UploadExcelHandler.cs +++ b/AuthModule.Application/Handler/UploadExcelHandler.cs @@ -50,7 +50,7 @@ public async Task> Handle(UploadExcelDTO request, Cancella students.Add(new ExcelStudentDTO { - FIO = fio, + //FIO = fio, Email = email, Group = group }); diff --git a/AuthModule.Contracts/Model/ExcelStudentDTO.cs b/AuthModule.Contracts/Model/ExcelStudentDTO.cs index 415a7c2..0fc469e 100644 --- a/AuthModule.Contracts/Model/ExcelStudentDTO.cs +++ b/AuthModule.Contracts/Model/ExcelStudentDTO.cs @@ -2,7 +2,9 @@ namespace AuthModule.Contracts.Model; public class ExcelStudentDTO { - public string FIO { get; set; } + public string Name { get; set; } + public string Surname { get; set; } + public string Middleame { get; set; } public string Email { get; set; } public string Group { get; set; } } \ No newline at end of file diff --git a/StudentModule.Application/Handlers/StudentHandlres/CreateStudentCommandHandler.cs b/StudentModule.Application/Handlers/StudentHandlres/CreateStudentCommandHandler.cs index 909366a..5709700 100644 --- a/StudentModule.Application/Handlers/StudentHandlres/CreateStudentCommandHandler.cs +++ b/StudentModule.Application/Handlers/StudentHandlres/CreateStudentCommandHandler.cs @@ -5,10 +5,8 @@ using StudentModule.Contracts.Repositories; using StudentModule.Domain.Entities; using UserModule.Contracts.Commands; -using UserModule.Contracts.Repositories; using UserModule.Domain.Entities; using UserModule.Domain.Enums; -using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database; namespace StudentModule.Application.Handlers.StudentHandlres { diff --git a/StudentModule.Application/Handlers/StudentHandlres/CreateStudentFromExelCommandHandler.cs b/StudentModule.Application/Handlers/StudentHandlres/CreateStudentFromExelCommandHandler.cs new file mode 100644 index 0000000..496ade8 --- /dev/null +++ b/StudentModule.Application/Handlers/StudentHandlres/CreateStudentFromExelCommandHandler.cs @@ -0,0 +1,65 @@ +using MediatR; +using Shared.Domain.Exceptions; +using StudentModule.Contracts.Commands.StudentCommands; +using StudentModule.Contracts.DTOs; +using StudentModule.Contracts.Repositories; +using StudentModule.Domain.Entities; +using StudentModule.Domain.Enums; +using UserModule.Contracts.Commands; +using UserModule.Contracts.DTOs.Requests; +using UserModule.Domain.Entities; +using UserModule.Domain.Enums; + +namespace StudentModule.Application.Handlers.StudentHandlres +{ + public class CreateStudentFromExelCommandHandler : IRequestHandler + { + private readonly IStudentRepository _studentRepository; + private readonly IGroupRepository _groupRepository; + private readonly IStreamRepository _streamRepository; + private readonly IMediator _mediator; + + public CreateStudentFromExelCommandHandler(IStudentRepository studentRepository, IGroupRepository groupRepository, IMediator mediator, IStreamRepository streamRepository) + { + _studentRepository = studentRepository; + _groupRepository = groupRepository; + _mediator = mediator; + _streamRepository = streamRepository; + } + public async Task Handle(CreateStudentFromExelCommand request, CancellationToken cancellationToken) + { + UserRequest userRequest = new UserRequest() + { + name = request.ExelStudentDto.Name, + surname = request.ExelStudentDto.Surname, + email = request.ExelStudentDto.Email + }; + + User user = await _mediator.Send(new CreateUserCommand(userRequest)); + + user = await _mediator.Send(new AddUserRoleCommand(user.Id, RoleName.Student)); + + var group = await _groupRepository.GetGroupByNumberAsync(int.Parse(request.ExelStudentDto.Group)) + ?? throw new NotFound("Group not found"); + + StudentEntity student = new StudentEntity() + { + UserId = user.Id, + User = user, + Middlename = request.ExelStudentDto.Middleтame, + Phone = null, + IsHeadMan = false, + Status = StudentStatus.InProcess, + GroupId = group.Id, + Group = group + }; + + await _studentRepository.AddAsync(student); + + var stream = await _streamRepository.GetByIdAsync(group.StreamId); + student.Group.Stream = stream; + + return new StudentDto(student); + } + } +} diff --git a/StudentModule.Application/Handlers/StudentHandlres/EditStudentCommandHandler.cs b/StudentModule.Application/Handlers/StudentHandlres/EditStudentCommandHandler.cs new file mode 100644 index 0000000..44422ab --- /dev/null +++ b/StudentModule.Application/Handlers/StudentHandlres/EditStudentCommandHandler.cs @@ -0,0 +1,45 @@ +using MediatR; +using Shared.Domain.Exceptions; +using StudentModule.Contracts.Commands.StudentCommands; +using StudentModule.Contracts.DTOs; +using StudentModule.Contracts.Repositories; +using UserModule.Contracts.Commands; +using UserModule.Contracts.DTOs.Requests; + +namespace StudentModule.Application.Handlers.StudentHandlres +{ + public class EditStudentCommandHandler : IRequestHandler + { + private readonly IStudentRepository _studentRepository; + private readonly IMediator _mediator; + + public EditStudentCommandHandler(IStudentRepository studentRepository, IMediator mediator) + { + _studentRepository = studentRepository; + _mediator = mediator; + } + + public async Task Handle(EditStudentCommand request, CancellationToken cancellationToken) + { + var student = await _studentRepository.GetStudentByIdAsync(request.studentId) + ?? throw new NotFound("Student not found"); + + var userRequest = new UserRequest() + { + name = request.name, + surname = request.surnamename, + email = request.email + }; + + var editUserCommand = new EditUserCommand(student.UserId, userRequest); + var user = await _mediator.Send(editUserCommand); + + student.Middlename = request.middlename; + student.Phone = request.phone; + student.IsHeadMan = request.isHeadMan; + student.User = user; + + return new StudentDto(student); + } + } +} diff --git a/StudentModule.Application/StudentModule.Application.csproj b/StudentModule.Application/StudentModule.Application.csproj index 879f8df..710cec7 100644 --- a/StudentModule.Application/StudentModule.Application.csproj +++ b/StudentModule.Application/StudentModule.Application.csproj @@ -7,6 +7,7 @@ + diff --git a/StudentModule.Contracts/Commands/StudentCommands/CreateStudentFromExelCommand.cs b/StudentModule.Contracts/Commands/StudentCommands/CreateStudentFromExelCommand.cs new file mode 100644 index 0000000..9971913 --- /dev/null +++ b/StudentModule.Contracts/Commands/StudentCommands/CreateStudentFromExelCommand.cs @@ -0,0 +1,11 @@ +using AuthModule.Contracts.Model; +using MediatR; +using StudentModule.Contracts.DTOs; + +namespace StudentModule.Contracts.Commands.StudentCommands +{ + public record CreateStudentFromExelCommand : IRequest + { + public ExcelStudentDTO ExelStudentDto { get; set; } + } +} diff --git a/StudentModule.Contracts/Commands/StudentCommands/EditStudentCommand.cs b/StudentModule.Contracts/Commands/StudentCommands/EditStudentCommand.cs new file mode 100644 index 0000000..e2328d7 --- /dev/null +++ b/StudentModule.Contracts/Commands/StudentCommands/EditStudentCommand.cs @@ -0,0 +1,17 @@ +using MediatR; +using StudentModule.Contracts.DTOs; + +namespace StudentModule.Contracts.Commands.StudentCommands +{ + public record EditStudentCommand : IRequest + { + public Guid studentId { get; set; } + public string name { get; set; } + public string surnamename { get; set; } + public string middlename { get; set; } + public string email { get; set; } + public string phone { get; set; } + public bool isHeadMan { get; set; } + } +} + diff --git a/StudentModule.Contracts/Repositories/IGroupRepository.cs b/StudentModule.Contracts/Repositories/IGroupRepository.cs index b0313c5..856da03 100644 --- a/StudentModule.Contracts/Repositories/IGroupRepository.cs +++ b/StudentModule.Contracts/Repositories/IGroupRepository.cs @@ -12,6 +12,7 @@ public interface IGroupRepository : IBaseEntityRepository { Task> GetGroupAsync(); Task GetGroupByIdAsync(Guid id); + Task GetGroupByNumberAsync(int number); Task IsGroupWithNumderExistsAsync(int number); } } diff --git a/StudentModule.Contracts/StudentModule.Contracts.csproj b/StudentModule.Contracts/StudentModule.Contracts.csproj index 55e1ac3..b2a9acb 100644 --- a/StudentModule.Contracts/StudentModule.Contracts.csproj +++ b/StudentModule.Contracts/StudentModule.Contracts.csproj @@ -11,6 +11,7 @@ + diff --git a/StudentModule.Controllers/Controllers/StudentController.cs b/StudentModule.Controllers/Controllers/StudentController.cs index 45e0b1f..9a75565 100644 --- a/StudentModule.Controllers/Controllers/StudentController.cs +++ b/StudentModule.Controllers/Controllers/StudentController.cs @@ -40,7 +40,7 @@ public async Task EditStudentStatus(EditStudentStatusCommand comm [HttpPatch] [Route("edit-student-group")] - [Authorize(Roles = "Dean")] + [Authorize(Roles = "DeanMember")] public async Task EditStudentGroup(EditStudentGroupCommand command) { return Ok(await _mediator.Send(command)); @@ -48,7 +48,7 @@ public async Task EditStudentGroup(EditStudentGroupCommand comman [HttpGet] [Route("get-students-by-group/{groupId}")] - [Authorize(Roles = "Dean")] + [Authorize(Roles = "DeanMember")] public async Task GetStudentsByGroup([FromRoute] Guid groupId) { var query = new GetStudentsFromGroupQuery() { GroupId = groupId }; @@ -57,7 +57,7 @@ public async Task GetStudentsByGroup([FromRoute] Guid groupId) [HttpGet] [Route("get-students-by-stream/{streamId}")] - [Authorize(Roles = "Dean")] + [Authorize(Roles = "DeanMember")] public async Task GetStudentsByStream([FromRoute] Guid streamId) { var query = new GetStudentsFromStreamQuery() { streamId = streamId }; @@ -66,7 +66,7 @@ public async Task GetStudentsByStream([FromRoute] Guid streamId) [HttpGet] [Route("get-student/{id}")] - [Authorize(Roles = "Dean")] + [Authorize(Roles = "DeanMember")] public async Task GetStudentForDean([FromRoute] Guid id) { var query = new GetStudentQuery() { id = id }; diff --git a/StudentModule.Domain/Entities/StudentEntity.cs b/StudentModule.Domain/Entities/StudentEntity.cs index 70ffe68..827f890 100644 --- a/StudentModule.Domain/Entities/StudentEntity.cs +++ b/StudentModule.Domain/Entities/StudentEntity.cs @@ -11,7 +11,7 @@ public class StudentEntity : BaseEntity [NotMapped] public User User { get; set; } public string? Middlename { get; set; } - public string Phone { get; set; } + public string? Phone { get; set; } public bool IsHeadMan { get; set; } public StudentStatus Status { get; set; } diff --git a/StudentModule.Infrastructure/Migrations/20250527150145_PhoneFix.Designer.cs b/StudentModule.Infrastructure/Migrations/20250527150145_PhoneFix.Designer.cs new file mode 100644 index 0000000..b29dffd --- /dev/null +++ b/StudentModule.Infrastructure/Migrations/20250527150145_PhoneFix.Designer.cs @@ -0,0 +1,144 @@ +// +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("20250527150145_PhoneFix")] + partial class PhoneFix + { + /// + 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("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/20250527150145_PhoneFix.cs b/StudentModule.Infrastructure/Migrations/20250527150145_PhoneFix.cs new file mode 100644 index 0000000..5750a45 --- /dev/null +++ b/StudentModule.Infrastructure/Migrations/20250527150145_PhoneFix.cs @@ -0,0 +1,36 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace StudentModule.Infrastructure.Migrations +{ + /// + public partial class PhoneFix : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "Phone", + table: "SStudents", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "text"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "Phone", + table: "SStudents", + type: "text", + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + } + } +} diff --git a/StudentModule.Infrastructure/Migrations/StudentModuleDbContextModelSnapshot.cs b/StudentModule.Infrastructure/Migrations/StudentModuleDbContextModelSnapshot.cs index 1b4cf99..7d09a5e 100644 --- a/StudentModule.Infrastructure/Migrations/StudentModuleDbContextModelSnapshot.cs +++ b/StudentModule.Infrastructure/Migrations/StudentModuleDbContextModelSnapshot.cs @@ -17,7 +17,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "9.0.4") + .HasAnnotation("ProductVersion", "9.0.5") .HasAnnotation("Relational:MaxIdentifierLength", 63); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); @@ -89,7 +89,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasColumnType("text"); b.Property("Phone") - .IsRequired() .HasColumnType("text"); b.Property("Status") diff --git a/StudentModule.Persistence/Repositories/GroupRepository.cs b/StudentModule.Persistence/Repositories/GroupRepository.cs index 89fd542..c5370e0 100644 --- a/StudentModule.Persistence/Repositories/GroupRepository.cs +++ b/StudentModule.Persistence/Repositories/GroupRepository.cs @@ -34,6 +34,14 @@ public async Task GetGroupByIdAsync(Guid id) return group; } + public async Task GetGroupByNumberAsync(int number) + { + var group = await context.Groups + .FirstOrDefaultAsync(g => g.GroupNumber == number); + + return group; + } + public async Task IsGroupWithNumderExistsAsync(int number) { return await context.Groups.AnyAsync(s => s.GroupNumber == number); From 9b9df099d0eb3e4935bc8b26e75110edc04616c0 Mon Sep 17 00:00:00 2001 From: zzizan Date: Thu, 29 May 2025 17:47:02 +0700 Subject: [PATCH 5/6] internship status --- .../CreateStudentCommandHandler.cs | 1 + .../CreateStudentFromExelCommandHandler.cs | 1 + ...itStudentInternshupStatusCommandHandler.cs | 35 +++++ .../StudentCommands/CreateStudentCommand.cs | 1 + .../EditStudentInternshipStatusCommand.cs | 17 ++ StudentModule.Contracts/DTOs/StudentDto.cs | 11 +- .../Controllers/StudentController.cs | 20 ++- .../Entities/StudentEntity.cs | 1 + .../Enums/StudentInternshipStatus.cs | 11 ++ ...0250529104555_InternshipStatus.Designer.cs | 147 ++++++++++++++++++ .../20250529104555_InternshipStatus.cs | 29 ++++ .../StudentModuleDbContextModelSnapshot.cs | 3 + 12 files changed, 267 insertions(+), 10 deletions(-) create mode 100644 StudentModule.Application/Handlers/StudentHandlres/EditStudentInternshupStatusCommandHandler.cs create mode 100644 StudentModule.Contracts/Commands/StudentCommands/EditStudentInternshipStatusCommand.cs create mode 100644 StudentModule.Domain/Enums/StudentInternshipStatus.cs create mode 100644 StudentModule.Infrastructure/Migrations/20250529104555_InternshipStatus.Designer.cs create mode 100644 StudentModule.Infrastructure/Migrations/20250529104555_InternshipStatus.cs 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..f289c18 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)); + } + + [HttpPatch] + [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"); From 6733877a3460fa483fd5afdb70a3f58eff5d672e Mon Sep 17 00:00:00 2001 From: zzizan Date: Thu, 29 May 2025 17:54:23 +0700 Subject: [PATCH 6/6] small fix --- StudentModule.Controllers/Controllers/StudentController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/StudentModule.Controllers/Controllers/StudentController.cs b/StudentModule.Controllers/Controllers/StudentController.cs index f289c18..d295dd3 100644 --- a/StudentModule.Controllers/Controllers/StudentController.cs +++ b/StudentModule.Controllers/Controllers/StudentController.cs @@ -46,7 +46,7 @@ public async Task EditStudentInternshipStatus(EditStudentInternsh return Ok(await _mediator.Send(command)); } - [HttpPatch] + [HttpPut] [Route("edit-student")] [Authorize(Roles = "DeanMember")] public async Task EditStudent(EditStudentCommand command)