mirror of
https://github.com/QuotifyTeam/QuotifyBE.git
synced 2025-12-16 19:00:07 +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
|
// All set - generate the token and return it
|
||||||
var token = guhf.GenerateJwtToken(user);
|
var token = guhf.GenerateJwtToken(user);
|
||||||
SuccessfulLoginDTO response = user.ToSuccessfulLoginDTO(token);
|
SuccessfulLoginDTO response = user.ToSuccessfulLoginDTO(token, guhf.UserRoleAsStr(user));
|
||||||
|
|
||||||
return Ok(response);
|
return Ok(response);
|
||||||
} else return Unauthorized(new {status = "error", error_msg = "Unknown pair of email and password"});
|
} 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 BadRequest(new ErrorDTO { Status = "error", Error_msg = "User not found" });
|
||||||
|
|
||||||
// Return user data as a DTO
|
// 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
|
/// [AUTHED] Create a new category
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// Allows authorized users to create categories. <br/>
|
/// Allows authorized users to create categories.
|
||||||
/// <b>Important!</b>
|
|
||||||
/// <br/><br/>
|
/// <br/><br/>
|
||||||
|
/// <b>Important!</b>
|
||||||
/// Category names are case insensitive. <br/>
|
/// Category names are case insensitive. <br/>
|
||||||
/// Has CORS set.
|
/// Has CORS set.
|
||||||
/// </remarks>
|
/// </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 Name { get; set; }
|
||||||
required public string Email { get; set; }
|
required public string Email { get; set; }
|
||||||
public int Role { 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 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
|
return new SuccessfulLoginDTO
|
||||||
{
|
{
|
||||||
Status = "ok",
|
Status = "ok",
|
||||||
Token = token,
|
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
|
return new UserInfoDTO
|
||||||
@@ -24,7 +24,8 @@ public static class UserMapping
|
|||||||
Id = user.Id,
|
Id = user.Id,
|
||||||
Name = user.Name,
|
Name = user.Name,
|
||||||
Email = user.Email,
|
Email = user.Email,
|
||||||
Role = user.Role
|
Role = user.Role,
|
||||||
|
RoleName = roleName
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user