cool
This commit is contained in:
parent
63b2f8ceef
commit
0e2529594f
25
src/InternshipSystem.Api/Controllers/AdminController.cs
Normal file
25
src/InternshipSystem.Api/Controllers/AdminController.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
@ -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)
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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()
|
||||
;
|
||||
|
||||
|
29
src/InternshipSystem.Repository/DatabaseFiller.cs
Normal file
29
src/InternshipSystem.Repository/DatabaseFiller.cs
Normal 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
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user