added userDtos
This commit is contained in:
@@ -23,7 +23,23 @@ public class UsersController : ControllerBase {
|
||||
[Authorize(Policy = "RequireAdmin")]
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<List<User>>> getUsers() {
|
||||
return Ok(await service_.GetAll());
|
||||
List<User> rawArray = await service_.GetAll();
|
||||
|
||||
List<UserDto> dtoArray = new List<UserDto>();
|
||||
|
||||
foreach(User user in rawArray) {
|
||||
// TODO: can you operator overload a cast? if so cast<UserDto>(UserDto) would go hard
|
||||
// if not then just a new custom cast function that returns a dto type will do
|
||||
UserDto newDto = new UserDto{
|
||||
CreatedAt = user.CreatedAt,
|
||||
Email = user.Email,
|
||||
Id = user.Id,
|
||||
UserName = user.UserName
|
||||
};
|
||||
dtoArray.Add(newDto);
|
||||
}
|
||||
|
||||
return Ok(dtoArray);
|
||||
}
|
||||
|
||||
[Authorize(Policy = "RequireAdmin")]
|
||||
@@ -34,7 +50,14 @@ public class UsersController : ControllerBase {
|
||||
|
||||
if (user == null) return NotFound();
|
||||
|
||||
return Ok(user);
|
||||
UserDto newDto = new UserDto{
|
||||
CreatedAt = user.CreatedAt,
|
||||
Email = user.Email,
|
||||
Id = user.Id,
|
||||
UserName = user.UserName
|
||||
};
|
||||
|
||||
return Ok(newDto);
|
||||
}
|
||||
|
||||
[Authorize(Policy = "RequireSuperuser")]
|
||||
|
||||
Reference in New Issue
Block a user