feat/random #65
@ -38,6 +38,7 @@ namespace InternshipSystem.Api.Controllers
|
|||||||
public async Task<ActionResult<IReadOnlyCollection<Company>>> SearchByNameAsync([FromQuery] CompanySearchQuery searchQuery, CancellationToken cancellationToken) =>
|
public async Task<ActionResult<IReadOnlyCollection<Company>>> SearchByNameAsync([FromQuery] CompanySearchQuery searchQuery, CancellationToken cancellationToken) =>
|
||||||
await Context.Companies
|
await Context.Companies
|
||||||
.Where(c => c.Name.ToLower().Contains(searchQuery.Name.ToLower()))
|
.Where(c => c.Name.ToLower().Contains(searchQuery.Name.ToLower()))
|
||||||
|
.Where(c => c.Provider == 0)
|
||||||
.OrderBy(o => o.Name)
|
.OrderBy(o => o.Name)
|
||||||
.Skip(searchQuery.Page * searchQuery.PerPage)
|
.Skip(searchQuery.Page * searchQuery.PerPage)
|
||||||
.Take(searchQuery.PerPage)
|
.Take(searchQuery.PerPage)
|
||||||
@ -62,6 +63,7 @@ namespace InternshipSystem.Api.Controllers
|
|||||||
.Collection(c => c.Branches)
|
.Collection(c => c.Branches)
|
||||||
.Query()
|
.Query()
|
||||||
.Where(office => office.Address.City.ToLower().Contains(searchQuery.City.ToLower()))
|
.Where(office => office.Address.City.ToLower().Contains(searchQuery.City.ToLower()))
|
||||||
|
.Where(office => office.Provider == 0)
|
||||||
.Skip(searchQuery.Page * searchQuery.PerPage)
|
.Skip(searchQuery.Page * searchQuery.PerPage)
|
||||||
.Take(searchQuery.PerPage)
|
.Take(searchQuery.PerPage)
|
||||||
.ToListAsync(token);
|
.ToListAsync(token);
|
||||||
|
@ -6,6 +6,7 @@ using System.Threading.Tasks;
|
|||||||
using InternshipSystem.Api.Queries;
|
using InternshipSystem.Api.Queries;
|
||||||
using InternshipSystem.Api.Security;
|
using InternshipSystem.Api.Security;
|
||||||
using InternshipSystem.Api.Service;
|
using InternshipSystem.Api.Service;
|
||||||
|
using InternshipSystem.Core;
|
||||||
using InternshipSystem.Repository;
|
using InternshipSystem.Repository;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
@ -85,10 +86,17 @@ namespace InternshipSystem.Api.Controllers
|
|||||||
await _context.Entry(edition)
|
await _context.Entry(edition)
|
||||||
.Collection(e => e.Internships)
|
.Collection(e => e.Internships)
|
||||||
.Query()
|
.Query()
|
||||||
.Include(i => i.Documentation)
|
|
||||||
.FirstAsync(i => i.Student.Id == user.PersonNumber, cancellationToken);
|
.FirstAsync(i => i.Student.Id == user.PersonNumber, cancellationToken);
|
||||||
|
|
||||||
internship.UpdateDocumentScan(documentId, memoryStream.ToArray());
|
var document = await _context.Entry(internship)
|
||||||
|
.Collection(i => i.Documentation)
|
||||||
|
.Query()
|
||||||
|
.FirstOrDefaultAsync(d => d.Id == documentId, cancellationToken);
|
||||||
|
|
||||||
|
document.Scan = memoryStream.ToArray();
|
||||||
|
document.State = DocumentState.Submitted;
|
||||||
|
|
||||||
|
await _context.SaveChangesAsync(cancellationToken);
|
||||||
|
|
||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
@ -103,10 +111,14 @@ namespace InternshipSystem.Api.Controllers
|
|||||||
await _context.Entry(edition)
|
await _context.Entry(edition)
|
||||||
.Collection(e => e.Internships)
|
.Collection(e => e.Internships)
|
||||||
.Query()
|
.Query()
|
||||||
.Include(i => i.Documentation)
|
|
||||||
.FirstAsync(i => i.Student.Id == user.PersonNumber, cancellationToken);
|
.FirstAsync(i => i.Student.Id == user.PersonNumber, cancellationToken);
|
||||||
|
|
||||||
var document = internship.Documentation.First(d => d.Id == documentId);
|
var document =
|
||||||
|
await _context.Entry(internship)
|
||||||
|
.Collection(i => i.Documentation)
|
||||||
|
.Query()
|
||||||
|
.FirstOrDefaultAsync(d => d.Id == documentId, cancellationToken);
|
||||||
|
|
||||||
var stream = new MemoryStream(document.Scan);
|
var stream = new MemoryStream(document.Scan);
|
||||||
|
|
||||||
return File(stream, "application/pdf");
|
return File(stream, "application/pdf");
|
||||||
|
54
src/InternshipSystem.Api/Controllers/InternshipController.cs
Normal file
54
src/InternshipSystem.Api/Controllers/InternshipController.cs
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
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.Report)
|
||||||
|
.Include(i => i.Documentation)
|
||||||
|
.SingleAsync(i => i.Student.Id == user.PersonNumber, cancellationToken);
|
||||||
|
|
||||||
|
return Ok(internship);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -7,13 +7,13 @@ using InternshipSystem.Api.Security;
|
|||||||
using InternshipSystem.Api.UseCases;
|
using InternshipSystem.Api.UseCases;
|
||||||
using InternshipSystem.Repository;
|
using InternshipSystem.Repository;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using InternshipSystem.Core.Entity.Internship;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace InternshipSystem.Api.Controllers
|
namespace InternshipSystem.Api.Controllers
|
||||||
{
|
{
|
||||||
|
[ApiController]
|
||||||
[Route("internshipRegistration")]
|
[Route("internshipRegistration")]
|
||||||
public class InternshipRegistrationController : ControllerBase
|
public class InternshipRegistrationController : ControllerBase
|
||||||
{
|
{
|
||||||
@ -81,38 +81,6 @@ namespace InternshipSystem.Api.Controllers
|
|||||||
{
|
{
|
||||||
return BadRequest(e.Message);
|
return BadRequest(e.Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <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.Report)
|
|
||||||
.Include(i => i.Approvals)
|
|
||||||
.Include(i => i.Documentation)
|
|
||||||
.SingleAsync(i => i.Student.Id == user.PersonNumber, cancellationToken);
|
|
||||||
|
|
||||||
return Ok(internship);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -6,16 +6,11 @@ namespace InternshipSystem.Api.Queries
|
|||||||
{
|
{
|
||||||
public class DocumentPublishRequest
|
public class DocumentPublishRequest
|
||||||
{
|
{
|
||||||
public long? Id { get; set; }
|
|
||||||
public string Description { get; set; }
|
public string Description { get; set; }
|
||||||
public DocumentType Type { get; set; }
|
public DocumentType Type { get; set; }
|
||||||
|
|
||||||
public class Validator : AbstractValidator<DocumentPublishRequest>
|
public class Validator : AbstractValidator<DocumentPublishRequest>
|
||||||
{
|
{
|
||||||
public Validator()
|
|
||||||
{
|
|
||||||
RuleFor(document => document.Type).NotEmpty();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -17,6 +17,7 @@ using Microsoft.Extensions.DependencyInjection;
|
|||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using Microsoft.OpenApi.Models;
|
using Microsoft.OpenApi.Models;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Converters;
|
||||||
|
|
||||||
namespace InternshipSystem.Api
|
namespace InternshipSystem.Api
|
||||||
{
|
{
|
||||||
@ -57,7 +58,11 @@ namespace InternshipSystem.Api
|
|||||||
options.IncludeXmlComments(xmlPath);
|
options.IncludeXmlComments(xmlPath);
|
||||||
})
|
})
|
||||||
.AddControllers(o => { o.ModelBinderProviders.Insert(0, new UserBinderProvider()); })
|
.AddControllers(o => { o.ModelBinderProviders.Insert(0, new UserBinderProvider()); })
|
||||||
.AddNewtonsoftJson(options => options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore);
|
.AddNewtonsoftJson(options =>
|
||||||
|
{
|
||||||
|
options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
|
||||||
|
options.SerializerSettings.Converters.Add(new StringEnumConverter());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||||
|
@ -10,7 +10,6 @@ namespace InternshipSystem.Core.Entity.Internship
|
|||||||
public Student Student { get; set; }
|
public Student Student { get; set; }
|
||||||
public InternshipRegistration InternshipRegistration { get; set; }
|
public InternshipRegistration InternshipRegistration { get; set; }
|
||||||
public Report Report { get; set; }
|
public Report Report { get; set; }
|
||||||
public List<Document> Approvals { get; set; }
|
|
||||||
public List<Document> Documentation { get; set; }
|
public List<Document> Documentation { get; set; }
|
||||||
|
|
||||||
public Edition Edition { get; set; }
|
public Edition Edition { get; set; }
|
||||||
@ -25,7 +24,6 @@ namespace InternshipSystem.Core.Entity.Internship
|
|||||||
|
|
||||||
internship.InternshipRegistration = InternshipRegistration.Create();
|
internship.InternshipRegistration = InternshipRegistration.Create();
|
||||||
internship.Report = Report.Create();
|
internship.Report = Report.Create();
|
||||||
internship.Approvals = new List<Document>();
|
|
||||||
internship.Documentation = new List<Document>();
|
internship.Documentation = new List<Document>();
|
||||||
|
|
||||||
return internship;
|
return internship;
|
||||||
|
Loading…
Reference in New Issue
Block a user