mirror of
https://github.com/Shchoholiev/shopping-assistant-api.git
synced 2025-04-04 16:49:36 +00:00
add personal account deletion
This commit is contained in:
parent
e13bb4bbed
commit
a37b40ed28
@ -2,6 +2,7 @@
|
|||||||
using ShoppingAssistantApi.Application.Models.Dtos;
|
using ShoppingAssistantApi.Application.Models.Dtos;
|
||||||
using ShoppingAssistantApi.Application.Models.Operations;
|
using ShoppingAssistantApi.Application.Models.Operations;
|
||||||
using HotChocolate.Authorization;
|
using HotChocolate.Authorization;
|
||||||
|
using ShoppingAssistantApi.Application.IServices;
|
||||||
|
|
||||||
namespace ShoppingAssistantApi.Api.Mutations;
|
namespace ShoppingAssistantApi.Api.Mutations;
|
||||||
|
|
||||||
@ -27,4 +28,12 @@ public class UsersMutation
|
|||||||
public Task<UserDto> RemoveFromRoleAsync(string roleName, string userId, CancellationToken cancellationToken,
|
public Task<UserDto> RemoveFromRoleAsync(string roleName, string userId, CancellationToken cancellationToken,
|
||||||
[Service] IUserManager userManager)
|
[Service] IUserManager userManager)
|
||||||
=> userManager.RemoveFromRoleAsync(roleName, userId, cancellationToken);
|
=> userManager.RemoveFromRoleAsync(roleName, userId, cancellationToken);
|
||||||
|
|
||||||
|
[Authorize]
|
||||||
|
public async Task<bool> DeletePersonalUserAsync(string guestId, CancellationToken cancellationToken,
|
||||||
|
[Service] IUsersService usersService)
|
||||||
|
{
|
||||||
|
await usersService.DeletePersonalUserAsync(guestId, cancellationToken);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
@ -12,4 +12,6 @@ public interface IUsersService
|
|||||||
Task<UserDto> GetUserAsync(string id, CancellationToken cancellationToken);
|
Task<UserDto> GetUserAsync(string id, CancellationToken cancellationToken);
|
||||||
|
|
||||||
Task UpdateUserAsync(UserDto dto, CancellationToken cancellationToken);
|
Task UpdateUserAsync(UserDto dto, CancellationToken cancellationToken);
|
||||||
|
|
||||||
|
Task DeletePersonalUserAsync(string guestId, CancellationToken cancellationToken);
|
||||||
}
|
}
|
@ -59,4 +59,26 @@ public class UsersService : IUsersService
|
|||||||
entity.LastModifiedDateUtc = DateTime.UtcNow;
|
entity.LastModifiedDateUtc = DateTime.UtcNow;
|
||||||
await _repository.UpdateUserAsync(entity, cancellationToken);
|
await _repository.UpdateUserAsync(entity, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task DeletePersonalUserAsync(string guestId, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
if (!Guid.TryParse(guestId, out var guid))
|
||||||
|
{
|
||||||
|
throw new InvalidDataException("Provided id is invalid.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var entity = await _repository.GetUserAsync(u => u.GuestId == guid, cancellationToken);
|
||||||
|
|
||||||
|
if (entity.Id != GlobalUser.Id)
|
||||||
|
{
|
||||||
|
throw new UnAuthorizedException<User>();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entity == null)
|
||||||
|
{
|
||||||
|
throw new EntityNotFoundException<User>();
|
||||||
|
}
|
||||||
|
|
||||||
|
await _repository.DeleteAsync(entity, cancellationToken);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user