diff --git a/src/InternshipSystem.Api/Controllers/DocumentManagementController.cs b/src/InternshipSystem.Api/Controllers/DocumentManagementController.cs index d48e21a..326cac8 100644 --- a/src/InternshipSystem.Api/Controllers/DocumentManagementController.cs +++ b/src/InternshipSystem.Api/Controllers/DocumentManagementController.cs @@ -23,7 +23,7 @@ namespace InternshipSystem.Api.Controllers Context = context; } - [HttpDelete("delete/{documentId}")] + [HttpDelete("{documentId}/delete")] [Authorize(Policy = Policies.IsOverseer)] public async Task DeleteDocument(long documentId, CancellationToken ct) { @@ -43,7 +43,7 @@ namespace InternshipSystem.Api.Controllers return Ok(); } - [HttpPut("accept/{documentId}")] + [HttpPut("{documentId}/accept")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status404NotFound)] @@ -75,7 +75,7 @@ namespace InternshipSystem.Api.Controllers return Ok(); } - [HttpPut("reject/{documentId}")] + [HttpPut("{documentId}/reject")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status404NotFound)] diff --git a/src/InternshipSystem.Api/Controllers/InternshipManagementController.cs b/src/InternshipSystem.Api/Controllers/InternshipManagementController.cs index 2b7309a..d04049c 100644 --- a/src/InternshipSystem.Api/Controllers/InternshipManagementController.cs +++ b/src/InternshipSystem.Api/Controllers/InternshipManagementController.cs @@ -94,12 +94,54 @@ namespace InternshipSystem.Api.Controllers return Ok(internship); } - [HttpPut("accept/{internshipId}")] + [HttpGet("{internshipId}/status")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status404NotFound)] [Authorize(Policy = Policies.IsOverseer)] - public async Task AcceptInternship(long internshipId, [FromBody] string comment, CancellationToken token) + public async Task GetInternshipStatus(long internshipId, CancellationToken token) + { + var internship = await Context.Internships + .Include(i => i.InternshipRegistration) + .Include(i => i.Report) + .Include(i => i.Documentation) + .FirstOrDefaultAsync(i => i.Id.Equals(internshipId), token); + + if (internship == null) + { + return NotFound(); + } + + return new JsonResult(new { Errors = internship.ValidateStatus() }); + } + + [HttpPut("{internshipId}/grade")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [Authorize(Policy = Policies.IsOverseer)] + public async Task GradeInternship(long internshipId, [FromBody] float grade, CancellationToken token) + { + var internship = await Context.Internships + .FirstOrDefaultAsync(i => i.Id.Equals(internshipId), token); + + if (internship == null) + { + return NotFound(); + } + + internship.Grade = grade; + await Context.SaveChangesAsync(token); + + return new JsonResult(new { Errors = internship.ValidateStatus() }); + } + + [HttpPut("{internshipId}/registration/accept")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [Authorize(Policy = Policies.IsOverseer)] + public async Task AcceptInternshipRegistration(long internshipId, [FromBody] string comment, CancellationToken token) { var internship = await Context.Internships .Include(i => i.InternshipRegistration) @@ -118,12 +160,12 @@ namespace InternshipSystem.Api.Controllers return Ok(); } - [HttpPut("reject/{internshipId}")] + [HttpPut("{internshipId}/registration/reject")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status404NotFound)] [Authorize(Policy = Policies.IsOverseer)] - public async Task RejectInternship(long internshipId, [FromBody] string comment, CancellationToken token) + public async Task RejectInternshipRegistration(long internshipId, [FromBody] string comment, CancellationToken token) { var internship = await Context.Internships .Include(i => i.InternshipRegistration) diff --git a/src/InternshipSystem.Core/Entity/Internship/Internship.cs b/src/InternshipSystem.Core/Entity/Internship/Internship.cs index d03aab3..3daecaa 100644 --- a/src/InternshipSystem.Core/Entity/Internship/Internship.cs +++ b/src/InternshipSystem.Core/Entity/Internship/Internship.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using FluentValidation; using InternshipSystem.Core.ValueObject; namespace InternshipSystem.Core.Entity.Internship @@ -75,5 +76,30 @@ namespace InternshipSystem.Core.Entity.Internship Documentation.Remove(doc); } } + + public IEnumerable ValidateStatus() + { + var validator = new Validator(); + + var result = validator.Validate(this); + + return result.ToErrorDescription(); + } + + private class Validator : AbstractValidator + { + public Validator() + { + RuleFor(i => i.Report) + .Must(r => r.State == DocumentState.Accepted) + .WithMessage("error.report.not_accepted"); + RuleFor(i => i.InternshipRegistration) + .Must(r => r.State == DocumentState.Accepted) + .WithMessage("error.registration.not_accepted"); + RuleForEach(i => i.Documentation) + .Must(d => d.State == DocumentState.Accepted) + .WithMessage("error.documentation.not_accepted"); + } + } } } \ No newline at end of file