skantravels/services/AuthorizationService/Application/Users/Commands/DeleteUser.cs

30 lines
907 B
C#
Raw Normal View History

2024-08-15 14:21:17 +01:00
using AuthorizationService.Models;
using AuthorizationService.Persistence.Repositories;
using Microsoft.AspNetCore.Mvc;
2024-08-15 14:21:17 +01:00
namespace AuthorizationService.Application.Users.Commands
{
public class DeleteUser
{
private readonly IUserRepository _repository;
public DeleteUser(IUserRepository repository)
{
_repository = repository;
}
public async Task<IActionResult> Handle(string id)
{
User currentUser = await _repository.QueryUserByIdAsync(id);
if (currentUser == null)
return new ConflictObjectResult(new { message = "User dosent exist." });
bool success = await _repository.DeleteUserAsync(id);
if (success)
return new OkResult();
else
return new StatusCodeResult(StatusCodes.Status500InternalServerError);
}
}
}