feat(employees): Добавил возможность поиска сотрудников по имени с учетом пустого значения и включил сортировку по фио
Some checks failed
Create and publish a Docker image / Publish image (push) Has been cancelled

This commit is contained in:
2026-03-26 02:50:04 +03:00
parent b85fdc777a
commit f7bc7af9e3
2 changed files with 9 additions and 3 deletions

View File

@@ -1,4 +1,3 @@
using System.ComponentModel.DataAnnotations;
using System.Text; using System.Text;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@@ -46,7 +45,7 @@ public class ScheduleController(ModeusService modeusService, ModeusEmployeeServi
/// <response code="503">Сервис сотрудников не инициализирован</response> /// <response code="503">Сервис сотрудников не инициализирован</response>
[HttpGet] [HttpGet]
[Route("searchemployee")] [Route("searchemployee")]
public async Task<IActionResult> SearchEmployees([Required][MinLength(1)] string fullname) public async Task<IActionResult> SearchEmployees(string fullname = "")
{ {
if (!modeusEmployeeService.IsInitialized()) if (!modeusEmployeeService.IsInitialized())
return StatusCode(503, "Сервис сотрудников не инициализирован, попробуйте позже."); return StatusCode(503, "Сервис сотрудников не инициализирован, попробуйте позже.");

View File

@@ -6,15 +6,22 @@ namespace SfeduSchedule.Services;
public class ModeusEmployeeService(ISchedulerFactory schedulerFactory) public class ModeusEmployeeService(ISchedulerFactory schedulerFactory)
: IHostedService : IHostedService
{ {
private Dictionary<string, (string, List<string>)> _employees = []; private Dictionary<string, (string, List<string>)> _employees = []; //
private Task? _backgroundTask; private Task? _backgroundTask;
private CancellationTokenSource? _cts; private CancellationTokenSource? _cts;
private readonly string _employeesFilePath = Path.Combine(Path.Combine(AppContext.BaseDirectory, AppConsts.DataFolderName), AppConsts.EmployeesFileName); 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) 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 return _employees
.Where(e => e.Key.Contains(fullname, StringComparison.OrdinalIgnoreCase)) .Where(e => e.Key.Contains(fullname, StringComparison.OrdinalIgnoreCase))
.OrderBy(e => e.Key)
.Take(size) .Take(size)
.ToDictionary(e => e.Key, e => e.Value); .ToDictionary(e => e.Key, e => e.Value);
} }