mirror of
https://github.com/QuotifyTeam/QuotifyBE.git
synced 2025-12-16 02:30:08 +01:00
feat: return user's role name inside UserInfoDTO
This commit is contained in:
@@ -70,7 +70,7 @@ public class AuthController : ControllerBase
|
||||
{
|
||||
// All set - generate the token and return it
|
||||
var token = guhf.GenerateJwtToken(user);
|
||||
SuccessfulLoginDTO response = user.ToSuccessfulLoginDTO(token);
|
||||
SuccessfulLoginDTO response = user.ToSuccessfulLoginDTO(token, guhf.UserRoleAsStr(user));
|
||||
|
||||
return Ok(response);
|
||||
} else return Unauthorized(new {status = "error", error_msg = "Unknown pair of email and password"});
|
||||
@@ -149,7 +149,7 @@ public class AuthController : ControllerBase
|
||||
return BadRequest(new ErrorDTO { Status = "error", Error_msg = "User not found" });
|
||||
|
||||
// Return user data as a DTO
|
||||
return Ok(u.ToUserInfoDTO());
|
||||
return Ok(u.ToUserInfoDTO(guhf.UserRoleAsStr(u)));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -71,9 +71,9 @@ public class CategoryController : ControllerBase
|
||||
/// [AUTHED] Create a new category
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Allows authorized users to create categories. <br/>
|
||||
/// <b>Important!</b>
|
||||
/// Allows authorized users to create categories.
|
||||
/// <br/><br/>
|
||||
/// <b>Important!</b>
|
||||
/// Category names are case insensitive. <br/>
|
||||
/// Has CORS set.
|
||||
/// </remarks>
|
||||
@@ -110,4 +110,10 @@ public class CategoryController : ControllerBase
|
||||
|
||||
}
|
||||
|
||||
// TODO: Update category
|
||||
// PATCH /api/v1/categories/1
|
||||
|
||||
// TODO: Delete category
|
||||
// DELETE /api/v1/categories/1
|
||||
|
||||
}
|
||||
|
||||
@@ -6,5 +6,6 @@ public record class UserInfoDTO
|
||||
required public string Name { get; set; }
|
||||
required public string Email { get; set; }
|
||||
public int Role { get; set; }
|
||||
public string? RoleName { get; set; }
|
||||
|
||||
};
|
||||
|
||||
@@ -5,18 +5,18 @@ namespace QuotifyBE.Mapping;
|
||||
|
||||
public static class UserMapping
|
||||
{
|
||||
public static SuccessfulLoginDTO ToSuccessfulLoginDTO(this User user, string token)
|
||||
public static SuccessfulLoginDTO ToSuccessfulLoginDTO(this User user, string token, string? roleName)
|
||||
{
|
||||
|
||||
return new SuccessfulLoginDTO
|
||||
{
|
||||
Status = "ok",
|
||||
Token = token,
|
||||
User = user.ToUserInfoDTO()
|
||||
User = user.ToUserInfoDTO(roleName)
|
||||
};
|
||||
}
|
||||
|
||||
public static UserInfoDTO ToUserInfoDTO(this User user)
|
||||
public static UserInfoDTO ToUserInfoDTO(this User user, string? roleName)
|
||||
{
|
||||
|
||||
return new UserInfoDTO
|
||||
@@ -24,7 +24,8 @@ public static class UserMapping
|
||||
Id = user.Id,
|
||||
Name = user.Name,
|
||||
Email = user.Email,
|
||||
Role = user.Role
|
||||
Role = user.Role,
|
||||
RoleName = roleName
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user