Add document the beginning of implementation
This commit is contained in:
parent
48ec0e2439
commit
b6669351c4
@ -1,12 +1,16 @@
|
|||||||
using System;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using InternshipSystem.Api.Queries;
|
using InternshipSystem.Api.Queries;
|
||||||
|
using InternshipSystem.Core;
|
||||||
using InternshipSystem.Repository;
|
using InternshipSystem.Repository;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace InternshipSystem.Api.Controllers
|
namespace InternshipSystem.Api.Controllers
|
||||||
{
|
{
|
||||||
|
[ApiController]
|
||||||
|
[Route("document")]
|
||||||
public class DocumentsController : ControllerBase
|
public class DocumentsController : ControllerBase
|
||||||
{
|
{
|
||||||
private InternshipDbContext Context { get; }
|
private InternshipDbContext Context { get; }
|
||||||
@ -30,7 +34,50 @@ namespace InternshipSystem.Api.Controllers
|
|||||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||||
public async Task<ActionResult> AddDocumentToInternship([FromBody] DocumentPublishRequest document) =>
|
public async Task<ActionResult> AddDocumentToInternship([FromBody] DocumentPublishRequest document)
|
||||||
throw new NotImplementedException();
|
{
|
||||||
|
// TODO:
|
||||||
|
// if not authorised then
|
||||||
|
// return Unauthorized();
|
||||||
|
|
||||||
|
// TODO:
|
||||||
|
// is request is valid??
|
||||||
|
// if not then
|
||||||
|
// return BadRequest();
|
||||||
|
|
||||||
|
var studentInternship = await GetCurrentStudentInternship();
|
||||||
|
if (document.Id != null)
|
||||||
|
{
|
||||||
|
var doc = studentInternship.Documentation
|
||||||
|
.Find(d => d.Id == document.Id);
|
||||||
|
if (doc == null)
|
||||||
|
return NotFound();
|
||||||
|
doc.Description = document.Description;
|
||||||
|
doc.Scan = document.Scan;
|
||||||
|
doc.Type = document.Type;
|
||||||
|
doc.State = DocumentState.Submitted;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
studentInternship.Documentation.Add(
|
||||||
|
new Document()
|
||||||
|
{
|
||||||
|
Description = document.Description,
|
||||||
|
Scan = document.Scan,
|
||||||
|
Type = document.Type,
|
||||||
|
State = DocumentState.Submitted
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO: rewrite when authentication will be implemented
|
||||||
|
private async Task<Internship> GetCurrentStudentInternship()
|
||||||
|
{
|
||||||
|
return Context.Editions
|
||||||
|
.FirstAsync().Result
|
||||||
|
.Internships
|
||||||
|
.First();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user