56 lines
2.2 KiB
C#
56 lines
2.2 KiB
C#
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using InternshipSystem.Api.Security;
|
|
using InternshipSystem.Core.Entity.Internship;
|
|
using InternshipSystem.Repository;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace InternshipSystem.Api.Controllers
|
|
{
|
|
[ApiController]
|
|
[Route("internship")]
|
|
public class InternshipController : ControllerBase
|
|
{
|
|
private readonly InternshipDbContext _context;
|
|
|
|
public InternshipController(InternshipDbContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get internship for current edition
|
|
/// </summary>
|
|
/// <response code="200">If current internship returned successfully</response>
|
|
/// <response code="401">This action is only available for authorized student registered for current edition</response>
|
|
[HttpGet]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
[Authorize(Policy = Policies.RegisteredOnly)]
|
|
public async Task<ActionResult<Internship>> GetCurrentEditionInternship([FromServices] User user, CancellationToken cancellationToken)
|
|
{
|
|
var edition = await _context.Editions
|
|
.FindAsync(user.EditionId);
|
|
|
|
var internship = await _context.Entry(edition)
|
|
.Collection(e => e.Internships)
|
|
.Query()
|
|
.Include(i => i.Student)
|
|
.Include(i => i.InternshipRegistration)
|
|
.Include(i => i.InternshipRegistration.Company)
|
|
.Include(i => i.InternshipRegistration.BranchAddress)
|
|
.Include(i => i.InternshipRegistration.Type)
|
|
.Include(i => i.InternshipRegistration.Subjects)
|
|
.ThenInclude(subject => subject.Subject)
|
|
.Include(i => i.Report)
|
|
.Include(i => i.Documentation)
|
|
.SingleAsync(i => i.Student.Id == user.PersonNumber, cancellationToken);
|
|
|
|
return Ok(internship);
|
|
}
|
|
}
|
|
} |