diff --git a/Shifty.Api/Generated/AnalogCoreV2/AnalogCoreV2.cs b/Shifty.Api/Generated/AnalogCoreV2/AnalogCoreV2.cs index d1471b1..a2a7048 100644 --- a/Shifty.Api/Generated/AnalogCoreV2/AnalogCoreV2.cs +++ b/Shifty.Api/Generated/AnalogCoreV2/AnalogCoreV2.cs @@ -733,7 +733,7 @@ public virtual async System.Threading.Tasks.Task ApiV2AccountResendVerificationE /// The length of a page /// Users, possible with filter applied /// A server side error occurred. - public virtual System.Threading.Tasks.Task ApiV2AccountSearchAsync(int? pageNum, string filter, int? pageLength) + public virtual System.Threading.Tasks.Task ApiV2AccountSearchAsync(int? pageNum, string filter, int? pageLength) { return ApiV2AccountSearchAsync(pageNum, filter, pageLength, System.Threading.CancellationToken.None); } @@ -747,7 +747,7 @@ public virtual System.Threading.Tasks.Task ApiV2AccountSearc /// The length of a page /// Users, possible with filter applied /// A server side error occurred. - public virtual async System.Threading.Tasks.Task ApiV2AccountSearchAsync(int? pageNum, string filter, int? pageLength, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task ApiV2AccountSearchAsync(int? pageNum, string filter, int? pageLength, System.Threading.CancellationToken cancellationToken) { var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/v2/account/search?"); @@ -807,7 +807,7 @@ public virtual async System.Threading.Tasks.Task ApiV2Accoun else if (status_ == 200) { - var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); if (objectResponse_.Object == null) { throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); @@ -2705,22 +2705,61 @@ public partial class ResendAccountVerificationEmailRequest } + /// + /// Represents a search result + /// + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.18.0.0 (NJsonSchema v10.8.0.0 (Newtonsoft.Json v10.0.0.0))")] + public partial class UserSearchResponse + { + /// + /// The users that match the query + /// + [Newtonsoft.Json.JsonProperty("users", Required = Newtonsoft.Json.Required.Always)] + [System.ComponentModel.DataAnnotations.Required] + public System.Collections.Generic.ICollection Users { get; set; } = new System.Collections.ObjectModel.Collection(); + + /// + /// The number of users that match the query + /// + [Newtonsoft.Json.JsonProperty("totalUsers", Required = Newtonsoft.Json.Required.Always)] + public int TotalUsers { get; set; } + + } + + /// + /// Basic User details + /// [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.18.0.0 (NJsonSchema v10.8.0.0 (Newtonsoft.Json v10.0.0.0))")] public partial class SimpleUserResponse { + /// + /// User Id + /// [Newtonsoft.Json.JsonProperty("id", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] public int Id { get; set; } + /// + /// User's Display Name + /// [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] public string Name { get; set; } + /// + /// User's Email + /// [Newtonsoft.Json.JsonProperty("email", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] public string Email { get; set; } + /// + /// User's User group relationship + /// [Newtonsoft.Json.JsonProperty("userGroup", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] public UserGroup UserGroup { get; set; } + /// + /// User's State + /// [Newtonsoft.Json.JsonProperty("state", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] public UserState State { get; set; } diff --git a/Shifty.App/Components/UserTable.razor b/Shifty.App/Components/UserTable.razor index c07f474..fd6d41a 100644 --- a/Shifty.App/Components/UserTable.razor +++ b/Shifty.App/Components/UserTable.razor @@ -10,8 +10,8 @@ Id Name Email - Role + UserGroup @context.Id @context.Name @context.Email - @context.Role + @context.UserGroup @context.Id @context.Name @context.Email - - - @foreach (var role in Enum.GetValues()) { - @role + + + @foreach (var group in Enum.GetValues()) { + @group } @@ -66,21 +66,21 @@ @code { - private MudTable _table; + private MudTable _table; private string searchString = ""; - UserRole RoleBeforeEdit; + UserGroup UserGroupBeforeEdit; - private async Task> LoadUsers(TableState state) + private async Task> LoadUsers(TableState state) { var result = await _userService.SearchUsers(searchString, state.Page, state.PageSize); return result.Match( - Succ: users => { - return new TableData(){ Items = users.ToList(), TotalItems = 15};; + Succ: res => { + return new TableData(){ Items = res.Users.AsEnumerable(), TotalItems = res.TotalUsers};; }, Fail: error => { Snackbar.Add(error.Message, Severity.Error); - return new TableData(){ Items = new List(), TotalItems = 0}; + return new TableData(){ Items = new List(), TotalItems = 0}; } ); } @@ -93,9 +93,9 @@ private void UpdateUserGroup(object element) { - var user = (UserSearchResponse)element; + var user = (SimpleUserResponse)element; - var result = _userService.UpdateUserGroupAsync(user.Id, UserRoleToUserGroup(user.Role)); + var result = _userService.UpdateUserGroupAsync(user.Id, user.UserGroup); result.Match( Succ: user => { @@ -112,26 +112,14 @@ private void BackupUser(object element) { - RoleBeforeEdit = ((UserSearchResponse)element).Role; + UserGroupBeforeEdit = ((SimpleUserResponse)element).UserGroup; StateHasChanged(); } private void ResetUserOnCancel(object user) { - ((UserSearchResponse)user).Role = RoleBeforeEdit; + ((SimpleUserResponse)user).UserGroup = UserGroupBeforeEdit; StateHasChanged(); Snackbar.Add("Canceled editing", Severity.Warning); } - - public static UserGroup UserRoleToUserGroup(UserRole role) - { - return role switch - { - UserRole.Board => UserGroup.Board, - UserRole.Manager => UserGroup.Manager, - UserRole.Barista => UserGroup.Barista, - UserRole.Customer => UserGroup.Customer, - _ => throw new Exception("Invalid user role") - }; - } } \ No newline at end of file diff --git a/Shifty.App/Repositories/AccountRepository.cs b/Shifty.App/Repositories/AccountRepository.cs index 73bab58..29ffbde 100755 --- a/Shifty.App/Repositories/AccountRepository.cs +++ b/Shifty.App/Repositories/AccountRepository.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Threading.Tasks; using LanguageExt; +using LanguageExt.ClassInstances.Pred; using LanguageExt.Common; using Shifty.Api.Generated.AnalogCoreV1; using Shifty.Api.Generated.AnalogCoreV2; @@ -30,9 +31,9 @@ public async Task> LoginAsync(string username, string pa return await TryAsync(_v1client.ApiV1AccountLoginAsync(loginDto: dto)).ToEither(); } - public async Task>> SearchUserAsync(string query, int page, int pageSize) + public async Task> SearchUserAsync(string query, int page, int pageSize) { - return await TryAsync(_v2client.ApiV2AccountSearchAsync(query, page, pageSize)); + return await TryAsync(_v2client.ApiV2AccountSearchAsync(filter: query, pageNum: page, pageLength: pageSize)); } public async Task> UpdateUserGroupAsync(int userId, UserGroup group) diff --git a/Shifty.App/Repositories/IAccountRepository.cs b/Shifty.App/Repositories/IAccountRepository.cs index a7012ea..7b5ab93 100644 --- a/Shifty.App/Repositories/IAccountRepository.cs +++ b/Shifty.App/Repositories/IAccountRepository.cs @@ -10,7 +10,7 @@ namespace Shifty.App.Repositories public interface IAccountRepository { public Task> LoginAsync(string username, string password); - public Task>> SearchUserAsync(string query, int page, int pageSize); + public Task> SearchUserAsync(string query, int page, int pageSize); public Task> UpdateUserGroupAsync(int userId, UserGroup group); } } \ No newline at end of file diff --git a/Shifty.App/Services/IUserService.cs b/Shifty.App/Services/IUserService.cs index ee99d75..c603def 100644 --- a/Shifty.App/Services/IUserService.cs +++ b/Shifty.App/Services/IUserService.cs @@ -8,7 +8,7 @@ namespace Shifty.App.Services { public interface IUserService { - Task>> SearchUsers(string query, int pageNumber = 0, int pageSize = 10); + Task> SearchUsers(string query, int pageNumber = 0, int pageSize = 10); Task> UpdateUserGroupAsync(int userId, UserGroup group); } } \ No newline at end of file diff --git a/Shifty.App/Services/UserService.cs b/Shifty.App/Services/UserService.cs index f00e147..235ed45 100644 --- a/Shifty.App/Services/UserService.cs +++ b/Shifty.App/Services/UserService.cs @@ -17,7 +17,7 @@ public UserService(IAccountRepository accountRepository) _accountRepository = accountRepository; } - public Task>> SearchUsers(string query, int pageNumber = 0, int pageSize = 10) + public Task> SearchUsers(string query, int pageNumber = 0, int pageSize = 10) { return _accountRepository.SearchUserAsync(query, pageNumber, pageSize); } diff --git a/Shifty.GenerateApi/OpenApiSpecs/AnalogCoreV2.json b/Shifty.GenerateApi/OpenApiSpecs/AnalogCoreV2.json index a6d2643..a3ae47d 100644 --- a/Shifty.GenerateApi/OpenApiSpecs/AnalogCoreV2.json +++ b/Shifty.GenerateApi/OpenApiSpecs/AnalogCoreV2.json @@ -383,7 +383,7 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/SimpleUserResponse" + "$ref": "#/components/schemas/UserSearchResponse" } } } @@ -1451,25 +1451,81 @@ } } }, + "UserSearchResponse": { + "type": "object", + "description": "Represents a search result", + "example": { + "users": [ + { + "id": 12232, + "name": "John Doe", + "email": "johndoe@itu.dk", + "userGroup": "Barista", + "state": "Active" + } + ], + "totalUsers": 1 + }, + "additionalProperties": false, + "required": [ + "users", + "totalUsers" + ], + "properties": { + "users": { + "type": "array", + "description": "The users that match the query", + "example": "[\n {\n \"id\": 12232,\n \"name\": \"John Doe\",\n \"email\": \"johndoe@itu.dk\",\n \"userGroup\": \"Barista\",\n \"state\": \"Active\"\n }\n ],", + "items": { + "$ref": "#/components/schemas/SimpleUserResponse" + } + }, + "totalUsers": { + "type": "integer", + "description": "The number of users that match the query", + "format": "int32", + "example": 1 + } + } + }, "SimpleUserResponse": { "type": "object", + "description": "Basic User details", "additionalProperties": false, "properties": { "id": { "type": "integer", - "format": "int32" + "description": "User Id", + "format": "int32", + "example": 1 }, "name": { - "type": "string" + "type": "string", + "description": "User's Display Name", + "example": "Name" }, "email": { - "type": "string" + "type": "string", + "description": "User's Email", + "example": "john@doe.test" }, "userGroup": { - "$ref": "#/components/schemas/UserGroup" + "description": "User's User group relationship", + "example": "Barista", + "oneOf": [ + { + "$ref": "#/components/schemas/UserGroup" + } + ] }, "state": { - "$ref": "#/components/schemas/UserState" + "description": "User's State", + "example": "Active", + "oneOf": [ + { + "$ref": "#/components/schemas/UserState" + } + ] } } },