Skip to content

Commit

Permalink
Added Role to UserResponse in Get AccountV2 (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
TTA777 authored Apr 11, 2023
1 parent 7d8b270 commit e4c12f0
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ namespace CoffeeCard.Models.DataTransferObjects.v2.User
/// "programme": 1,
/// "rankAllTime": 15,
/// "rankSemester": 4,
/// "rankMonth": 5
/// "rankMonth": 5,
/// "role": "Barista"
/// }
/// </example>
public class UserResponse
Expand Down Expand Up @@ -52,6 +53,14 @@ public class UserResponse
[Required]
public bool PrivacyActivated { get; set; }

/// <summary>
/// User's role
/// </summary>
/// <value>Role</value>
/// <example>Barista</example>
[Required]
public UserRole Role { get; set; } = UserRole.Customer;

/// <summary>
/// Study Programme Id of user
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace CoffeeCard.Models.DataTransferObjects.v2.User
{
/// Corresponds to UserRole in the Entities, only serves to not expose the datamodel directly
public enum UserRole
{
/// Normal user for customers
Customer,
/// Active Barista in Analog
Barista,
/// Active Manager in Analog
Manager,
/// Active board member in Analog
Board
}


}
16 changes: 15 additions & 1 deletion coffeecard/CoffeeCard.Models/Entities/UserGroup.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace CoffeeCard.Models.Entities
using CoffeeCard.Models.DataTransferObjects.v2.User;

namespace CoffeeCard.Models.Entities
{
public enum UserGroup
{
Expand All @@ -12,4 +14,16 @@ public enum UserGroup
/// Active board member in Analog
Board
}

public static class UserGroupExtention {
public static UserRole toUserRole(this UserGroup userGroup){
return userGroup switch {
UserGroup.Customer => UserRole.Customer,
UserGroup.Barista => UserRole.Barista,
UserGroup.Board => UserRole.Board,
UserGroup.Manager => UserRole.Manager,
_ => UserRole.Customer,
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,13 @@ private async Task<UserResponse> UserWithRanking(User user){

return new UserResponse
{
Id = user.Id,
Email = user.Email,
RankAllTime = leaderBoardPlacement.Total,
RankMonth = leaderBoardPlacement.Month,
RankSemester = leaderBoardPlacement.Semester,
Name = user.Name,
Role = user.UserGroup.toUserRole(),
Programme = new ProgrammeResponse()
{
Id = user.Programme.Id,
Expand Down

0 comments on commit e4c12f0

Please sign in to comment.