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; } /// /// Fill out required document, /// /// Documents Scan and description, and Id of filled document /// /// If change was successfully registered /// If the provided query was malformed /// Id doesn't match any required document /// This action is only available for authorized student registered for current edition [HttpPost] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status404NotFound)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [Authorize(Policy = Policies.RegisteredOnly)] public async Task AddDocumentToInternship([FromBody] DocumentPublishRequest documentRequest, CancellationToken cancellationToken) { var validator = new DocumentPublishRequest.Validator(); var validationResult = await validator.ValidateAsync(documentRequest, cancellationToken); if (!validationResult.IsValid) { return BadRequest(validationResult.ToString()); } var personNumber = long.Parse(User.FindFirst(InternshipClaims.PersonNumber).Value); return await _internshipService.AddDocumentToInternship(documentRequest, personNumber, cancellationToken); } } }