Added Policy for getUsers and moved some APIs.

This commit is contained in:
Joseph Milazzo 2020-12-24 10:13:22 -06:00
parent fbe2daac6a
commit a40bc9e9f7
4 changed files with 444 additions and 22 deletions

View file

@ -1,4 +1,6 @@
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Threading.Tasks;
using API.DTOs;
using API.Entities;
using API.Interfaces;
using Microsoft.AspNetCore.Authorization;
@ -25,20 +27,7 @@ namespace API.Controllers
return users.Count > 0;
}
[Authorize(Policy = "RequireAdminRole")]
[HttpDelete("delete-user")]
public async Task<ActionResult> DeleteUser(string username)
{
var user = await _userRepository.GetUserByUsernameAsync(username);
_userRepository.Delete(user);
if (await _userRepository.SaveAllAsync())
{
return Ok();
}
return BadRequest("Could not delete the user.");
}
}