feat(employees): Добавил возможность поиска сотрудников по имени с учетом пустого значения и включил сортировку по фио
Some checks failed
Create and publish a Docker image / Publish image (push) Has been cancelled
Some checks failed
Create and publish a Docker image / Publish image (push) Has been cancelled
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Text;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
@@ -46,7 +45,7 @@ public class ScheduleController(ModeusService modeusService, ModeusEmployeeServi
|
||||
/// <response code="503">Сервис сотрудников не инициализирован</response>
|
||||
[HttpGet]
|
||||
[Route("searchemployee")]
|
||||
public async Task<IActionResult> SearchEmployees([Required][MinLength(1)] string fullname)
|
||||
public async Task<IActionResult> SearchEmployees(string fullname = "")
|
||||
{
|
||||
if (!modeusEmployeeService.IsInitialized())
|
||||
return StatusCode(503, "Сервис сотрудников не инициализирован, попробуйте позже.");
|
||||
|
||||
@@ -6,15 +6,22 @@ namespace SfeduSchedule.Services;
|
||||
public class ModeusEmployeeService(ISchedulerFactory schedulerFactory)
|
||||
: IHostedService
|
||||
{
|
||||
private Dictionary<string, (string, List<string>)> _employees = [];
|
||||
private Dictionary<string, (string, List<string>)> _employees = []; //
|
||||
private Task? _backgroundTask;
|
||||
private CancellationTokenSource? _cts;
|
||||
private readonly string _employeesFilePath = Path.Combine(Path.Combine(AppContext.BaseDirectory, AppConsts.DataFolderName), AppConsts.EmployeesFileName);
|
||||
|
||||
public async Task<Dictionary<string, (string, List<string>)>> GetEmployees(string fullname, int size = 10)
|
||||
{
|
||||
if (string.IsNullOrEmpty(fullname))
|
||||
return _employees
|
||||
.OrderBy(e => e.Key)
|
||||
.Take(size)
|
||||
.ToDictionary(e => e.Key, e => e.Value);
|
||||
|
||||
return _employees
|
||||
.Where(e => e.Key.Contains(fullname, StringComparison.OrdinalIgnoreCase))
|
||||
.OrderBy(e => e.Key)
|
||||
.Take(size)
|
||||
.ToDictionary(e => e.Key, e => e.Value);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user