Adding users endpoint to return all users to authorized users
This commit is contained in:
@@ -108,6 +108,15 @@ public class AuthController : ControllerBase
|
|||||||
|
|
||||||
return Ok($"{request.Username}'s role updated to {request.NewRole}");
|
return Ok($"{request.Username}'s role updated to {request.NewRole}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpGet("users")]
|
||||||
|
[Authorize(Roles = "SUPER")]
|
||||||
|
public async Task<IActionResult> GetAllUsers()
|
||||||
|
{
|
||||||
|
var users = await _userService.GetAllAsync();
|
||||||
|
return Ok(users);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private string GenerateJwtToken(User user)
|
private string GenerateJwtToken(User user)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using GameAuthApi.Models;
|
using GameAuthApi.Models;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
@@ -19,6 +20,9 @@ public class UserService
|
|||||||
public async Task<User> GetByUsernameAsync(string username) =>
|
public async Task<User> GetByUsernameAsync(string username) =>
|
||||||
await _users.Find(u => u.Username == username).FirstOrDefaultAsync();
|
await _users.Find(u => u.Username == username).FirstOrDefaultAsync();
|
||||||
|
|
||||||
|
public async Task<List<User>> GetAllAsync() =>
|
||||||
|
await _users.Find(_ => true).ToListAsync();
|
||||||
|
|
||||||
public async Task CreateAsync(User user) =>
|
public async Task CreateAsync(User user) =>
|
||||||
await _users.InsertOneAsync(user);
|
await _users.InsertOneAsync(user);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user