51 lines
2.1 KiB
C#
51 lines
2.1 KiB
C#
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using InternshipSystem.Api.Queries;
|
|
using InternshipSystem.Api.Security;
|
|
using InternshipSystem.Api.Services;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace InternshipSystem.Api.Controllers
|
|
{
|
|
[ApiController]
|
|
[Route("document")]
|
|
public class DocumentsController : ControllerBase
|
|
{
|
|
private readonly IInternshipService _internshipService;
|
|
|
|
public DocumentsController(IInternshipService internshipService)
|
|
{
|
|
_internshipService = internshipService;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Fill out required document,
|
|
/// </summary>
|
|
/// <param name="documentRequest">Documents Scan and description, and Id of filled document</param>
|
|
/// <response code="200">If change was successfully registered</response>
|
|
/// <response code="400">If the provided query was malformed</response>
|
|
/// <response code="404">Id doesn't match any required document</response>
|
|
/// <response code="401">This action is only available for authorized student registered for current edition</response>
|
|
[HttpPost]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
[Authorize(Policy = Policies.RegisteredOnly)]
|
|
public async Task<ActionResult> AddDocumentToInternship([FromBody] DocumentPublishRequest documentRequest,
|
|
[FromServices] User user, CancellationToken cancellationToken)
|
|
{
|
|
var validator = new DocumentPublishRequest.Validator();
|
|
var validationResult = await validator.ValidateAsync(documentRequest, cancellationToken);
|
|
|
|
if (!validationResult.IsValid)
|
|
{
|
|
return BadRequest(validationResult.ToString());
|
|
}
|
|
|
|
return await _internshipService.AddDocumentToInternship(documentRequest, user, cancellationToken);
|
|
}
|
|
}
|
|
} |