Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public async Task<StudentDto> Handle(CreateStudentCommand request, CancellationT
Phone = request.Phone,
IsHeadMan = request.IsHeadMan,
Status = request.Status,
InternshipStatus = request.InternshipStatus,
GroupId = request.GroupId,
Group = group
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public async Task<StudentDto> Handle(CreateStudentFromExelCommand request, Cance
Phone = null,
IsHeadMan = false,
Status = StudentStatus.InProcess,
InternshipStatus = StudentInternshipStatus.Candidate,
GroupId = group.Id,
Group = group
};
Expand Down
Original file line number Diff line number Diff line change
@@ -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<EditStudentInternshipStatusCommand, StudentDto>
{
private readonly IStudentRepository _studentRepository;
private readonly IUserRepository _userRepository;

public EditStudentInternshipStatusCommandHandler(IStudentRepository studentRepository, IUserRepository userRepository)
{
_studentRepository = studentRepository;
_userRepository = userRepository;
}
public async Task<StudentDto> 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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public record CreateStudentCommand : IRequest<StudentDto>
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; }
}
}
Original file line number Diff line number Diff line change
@@ -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<StudentDto>
{
public Guid Id { get; set; }
public StudentInternshipStatus Status { get; set; }
}
}
11 changes: 3 additions & 8 deletions StudentModule.Contracts/DTOs/StudentDto.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -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; }

Expand All @@ -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;
Expand Down
20 changes: 18 additions & 2 deletions StudentModule.Controllers/Controllers/StudentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,36 @@ public StudentController(IMediator mediator)

[HttpPost]
[Route("create")]
//[Authorize(Roles = "Dean")]
[Authorize(Roles = "DeanMember")]
public async Task<IActionResult> CreateStudent(CreateStudentCommand command)
{
return Ok(await _mediator.Send(command));
}

[HttpPatch]
[Route("edit-student-status")]
//todo уточнить кто имеет прао менять статус студента
[Authorize(Roles = "DeanMember")]
public async Task<IActionResult> EditStudentStatus(EditStudentStatusCommand command)
{
return Ok(await _mediator.Send(command));
}

[HttpPatch]
[Route("edit-student-internship-status")]
[Authorize(Roles = "DeanMember")]
public async Task<IActionResult> EditStudentInternshipStatus(EditStudentInternshipStatusCommand command)
{
return Ok(await _mediator.Send(command));
}

[HttpPut]
[Route("edit-student")]
[Authorize(Roles = "DeanMember")]
public async Task<IActionResult> EditStudent(EditStudentCommand command)
{
return Ok(await _mediator.Send(command));
}

[HttpPatch]
[Route("edit-student-group")]
[Authorize(Roles = "DeanMember")]
Expand Down
1 change: 1 addition & 0 deletions StudentModule.Domain/Entities/StudentEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
11 changes: 11 additions & 0 deletions StudentModule.Domain/Enums/StudentInternshipStatus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@


namespace StudentModule.Domain.Enums
{
public enum StudentInternshipStatus
{
Small,
Candidate,
Intern
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace StudentModule.Infrastructure.Migrations
{
/// <inheritdoc />
public partial class InternshipStatus : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
name: "InternshipStatus",
table: "SStudents",
type: "integer",
nullable: false,
defaultValue: 0);
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "InternshipStatus",
table: "SStudents");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Property<Guid>("GroupId")
.HasColumnType("uuid");

b.Property<int>("InternshipStatus")
.HasColumnType("integer");

b.Property<bool>("IsDeleted")
.HasColumnType("boolean");

Expand Down