/
d.alekseev
/
SmartMenuBot
Обзор
Документация
Войти
/
d.alekseev
/
SmartMenuBot
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
ConsoleBot/Core/Services/Domain/ToDoListService.cs
47 строк
2 KB
d.alekseev
feat: списки задач, callback-сценарии и рефактор маршрутизации UpdateHandler
13 фев 2026, 17:30
13 фев 2026, 17:30
a225948
Код
Авторство
О чём код?
using SmartMenuBot.Core.DataAccess; using SmartMenuBot.Core.Entities; using SmartMenuBot.Core.Services.Interfaces; namespace SmartMenuBot.Core.Services.Domain { public class ToDoListService(IToDoListRepository toDoListRepository) : IToDoListService { private const int MaxListNameLength = 10; public async Task<ToDoList> AddAsync(ToDoUser user, string name, CancellationToken ct) { ArgumentNullException.ThrowIfNull(user); if (string.IsNullOrWhiteSpace(name)) throw new ArgumentException("Название списка не может быть пустым", nameof(name)); var trimmedName = name.Trim(); if (trimmedName.Length > MaxListNameLength) throw new ArgumentException( $"Название списка не может быть длиннее {MaxListNameLength} символов", nameof(name)); if (await toDoListRepository.ExistsByNameAsync(user.UserId, trimmedName, ct)) throw new InvalidOperationException($"Список с названием '{trimmedName}' уже существует."); var list = new ToDoList(user, trimmedName); await toDoListRepository.AddAsync(list, ct); return list; } public async Task<ToDoList?> GetAsync(Guid id, CancellationToken ct) { return await toDoListRepository.GetAsync(id, ct); } public async Task DeleteAsync(Guid id, CancellationToken ct) { await toDoListRepository.DeleteAsync(id, ct); } public async Task<IReadOnlyList<ToDoList>> GetUserListsAsync(Guid userId, CancellationToken ct) { return await toDoListRepository.GetByUserIdAsync(userId, ct); } } }