This commit is contained in:
MaxchilKH 2020-07-11 13:18:10 +02:00
parent 63b2f8ceef
commit 0e2529594f
5 changed files with 60 additions and 4 deletions

View File

@ -0,0 +1,25 @@
using System.Threading.Tasks;
using Internship.Repository;
using Microsoft.AspNetCore.Mvc;
namespace Internship.Api.Controller
{
[ApiController]
[Route("[controller]")]
class AdminController : ControllerBase
{
public AdminController(DatabaseFiller fillerService)
{
FillerService = fillerService;
}
public DatabaseFiller FillerService { get; }
[HttpPost]
public async Task<IActionResult> FillCompaniesAsync()
{
await FillerService.FillCompany();
return Ok();
}
}
}

View File

@ -30,7 +30,7 @@ namespace InternshipSystem.Api.Controllers
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<IReadOnlyCollection<Company>> SearchByNameAsync([FromQuery]SearchQuery query, CancellationToken cancellationToken) =>
await Context.Companies
.Where(c => c.Name.Contains(query.Query ?? ""))
.Where(c => c.Name.Contains(query.Query))
.OrderBy(o => o.Name)
.Skip(query.Page * query.PerPage)
.Take(query.PerPage)

View File

@ -5,16 +5,16 @@ namespace InternshipSystem.Api.Queries
/// <summary>
/// Value against which collection will be queried
/// </summary>
public string Query { get; set; }
public string Query { get; set; } = "";
/// <summary>
/// Which part of the collections to retrieve
/// </summary>
public int Page { get; set; }
public int Page { get; set; } = 0;
/// <summary>
/// Size of the retrieved part
/// </summary>
public int PerPage { get; set; }
public int PerPage { get; set; } = 30;
}
}

View File

@ -1,6 +1,7 @@
using System;
using System.IO;
using System.Reflection;
using Internship.Repository;
using InternshipSystem.Repository;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
@ -29,6 +30,7 @@ namespace InternshipSystem.Api
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
options.IncludeXmlComments(xmlPath);
})
.AddSingleton<DatabaseFiller>()
.AddControllers()
;

View File

@ -0,0 +1,29 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using InternshipSystem.Core;
using InternshipSystem.Repository;
namespace Internship.Repository
{
public class DatabaseFiller
{
public DatabaseFiller(InternshipDbContext context)
{
Context = context;
}
public InternshipDbContext Context { get; }
public async Task FillCompany()
{
var companies = new List<Company>
{
new Company
{
}
};
}
}
}