feat: new exceptions

This commit is contained in:
2026-10-07 02:59:23 +04:00
parent 274e60a433
commit e7e7bf4db7
13 changed files with 74 additions and 36 deletions
@@ -20,7 +20,7 @@ public sealed class DeleteCollectionCommandHandler(
var user = await users.GetByTelegramIdAsync(request.RequestingTelegramId, ct);
if (user?.InboxCollectionId == collection.Id)
throw new DomainException("Cannot delete the Inbox collection.");
throw new InboxProtectionException("Cannot delete the Inbox collection.");
collection.Delete(request.RequestingTelegramId);
await collections.RemoveAsync(collection, ct);
@@ -22,7 +22,7 @@ public sealed class SetCollectionInboxCommandHandler(
if (user is null) return false;
if (user.InboxCollectionId == target.Id)
throw new DomainException("Collection is already the Inbox.");
throw new InboxProtectionException("Collection is already the Inbox.");
user.SetInboxCollection(target.Id);
await users.UpdateAsync(user, ct);
@@ -1,13 +1,11 @@
using MediatR;
using MemeVault.Application.Common;
using MemeVault.Domain.Exceptions;
using MemeVault.Domain.Repositories;
namespace MemeVault.Application.Commands.UpdateCollection;
public sealed class UpdateCollectionCommandHandler(
ICollectionRepository collections,
IBotUserRepository users,
IUnitOfWork unitOfWork)
: IRequestHandler<UpdateCollectionCommand, bool>
{
@@ -15,14 +13,10 @@ public sealed class UpdateCollectionCommandHandler(
{
var collection = await collections.GetByIdAsync(request.CollectionId, ct);
// Если коллекции нет или пользователь — не участник, возвращаем 404.
// Если роль ниже Manager — domain.Rename() бросит DomainException.
// Если роль ниже Manager — domain.Rename() бросит InsufficientPermissionException.
if (collection is null || collection.GetRole(request.RequestingTelegramId) is null)
return false;
var user = await users.GetByTelegramIdAsync(request.RequestingTelegramId, ct);
if (user?.InboxCollectionId == collection.Id)
throw new DomainException("Cannot rename the Inbox collection.");
collection.Rename(request.Name, request.RequestingTelegramId);
await unitOfWork.SaveChangesAsync(ct);
return true;