create userdto constructor out of user
All checks were successful
Build and Deploy API / build-and-deploy (push) Successful in 8s

This commit is contained in:
2026-04-22 21:19:35 -05:00
parent 68685e6398
commit 1afa30040d
3 changed files with 12 additions and 14 deletions

View File

@@ -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

View File

@@ -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);
}

View File

@@ -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;
}
};