create userdto constructor out of user
All checks were successful
Build and Deploy API / build-and-deploy (push) Successful in 8s
All checks were successful
Build and Deploy API / build-and-deploy (push) Successful in 8s
This commit is contained in:
@@ -27,7 +27,7 @@ public class AuthController : ControllerBase {
|
||||
|
||||
[HttpPost("register")]
|
||||
public async Task<ActionResult> Register(RegisterDto dto) {
|
||||
var user = new User {
|
||||
User user = new User {
|
||||
UserName = dto.UserName,
|
||||
Email = dto.Email,
|
||||
CreatedAt = DateTime.UtcNow // yeah why not utc
|
||||
|
||||
@@ -32,12 +32,7 @@ public class UsersController : ControllerBase {
|
||||
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
|
||||
};
|
||||
UserDto newDto = new UserDto(user);
|
||||
dtoArray.Add(newDto);
|
||||
}
|
||||
|
||||
@@ -52,12 +47,7 @@ public class UsersController : ControllerBase {
|
||||
|
||||
if (user == null) return NotFound();
|
||||
|
||||
UserDto newDto = new UserDto{
|
||||
CreatedAt = user.CreatedAt,
|
||||
Email = user.Email,
|
||||
Id = user.Id,
|
||||
UserName = user.UserName
|
||||
};
|
||||
UserDto newDto = new UserDto(user);
|
||||
|
||||
return Ok(newDto);
|
||||
}
|
||||
|
||||
@@ -55,9 +55,17 @@ public class LoginDto {
|
||||
public class UserDto {
|
||||
|
||||
public DateTime CreatedAt { get; set; } = DateTime.UtcNow; // gets compressed to a string'
|
||||
public List<string> permissions { get; set; } = [];
|
||||
public List<string>? Permissions { get; set; } = [];
|
||||
public string? Email { get; set; } = "";
|
||||
public string Id { get; set; } = "";
|
||||
public string? UserName { get; set; } = "";
|
||||
|
||||
public UserDto(User user) {
|
||||
CreatedAt = user.CreatedAt;
|
||||
Email = user.Email;
|
||||
Id = user.Id;
|
||||
UserName = user.UserName;
|
||||
Permissions = user.Permissions;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user