Adding User Controller and Delete endpoint
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
using GameAuthApi.Models;
|
||||
using GameAuthApi.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace GameAuthApi.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class UserController : ControllerBase
|
||||
{
|
||||
private readonly UserService _userService;
|
||||
|
||||
public UserController(UserService userService)
|
||||
{
|
||||
_userService = userService;
|
||||
}
|
||||
|
||||
// GET: /api/User
|
||||
[HttpGet]
|
||||
[Authorize(Roles = "SUPER")]
|
||||
public async Task<IActionResult> GetAllUsers()
|
||||
{
|
||||
var users = await _userService.GetAllAsync();
|
||||
return Ok(users);
|
||||
}
|
||||
|
||||
// DELETE: /api/User?username=foo
|
||||
[HttpDelete]
|
||||
[Authorize(Roles = "SUPER")]
|
||||
public async Task<IActionResult> DeleteUser([FromQuery] string username)
|
||||
{
|
||||
var deleted = await _userService.DeleteAsync(username);
|
||||
if (!deleted)
|
||||
return NotFound($"User '{username}' not found.");
|
||||
|
||||
return Ok($"User '{username}' deleted successfully.");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user