From 9b8d621f425b53e48f9f725d122da8370b3e5866 Mon Sep 17 00:00:00 2001 From: Piotr Kus Date: Thu, 20 Feb 2025 06:39:06 +0100 Subject: [PATCH] * Managed API to handle User maintenance * Managed Users view in application --- .../Controllers/FunctionsController.cs | 52 ++++++ FaKrosnoApi/Controllers/RolesController.cs | 45 +++++ .../Controllers/UserRolesController.cs | 43 +++++ FaKrosnoApi/Controllers/UsersController.cs | 52 ++++++ FaKrosnoApi/Program.cs | 5 + .../Components/Pages/Admin/Users.razor | 151 --------------- .../Components/Pages/Admin/UsersManager.razor | 173 ++++++++++++++++++ OrdersManagement/Program.cs | 3 + OrdersManagement/Services/FunctionService.cs | 36 ++++ OrdersManagement/Services/RoleService.cs | 41 +++++ OrdersManagement/Services/UserService.cs | 36 ++++ .../Services/FunctionService.cs | 12 +- .../Services/IFunctionService.cs | 12 +- .../Services/IRoleService.cs | 10 +- .../Services/IUserRoleService.cs | 10 +- .../Services/IUserService.cs | 12 +- .../Services/RoleService.cs | 10 +- .../Services/UserRoleService.cs | 10 +- .../Services/UserService.cs | 12 +- 19 files changed, 530 insertions(+), 195 deletions(-) create mode 100644 FaKrosnoApi/Controllers/FunctionsController.cs create mode 100644 FaKrosnoApi/Controllers/RolesController.cs create mode 100644 FaKrosnoApi/Controllers/UserRolesController.cs create mode 100644 FaKrosnoApi/Controllers/UsersController.cs delete mode 100644 OrdersManagement/Components/Pages/Admin/Users.razor create mode 100644 OrdersManagement/Components/Pages/Admin/UsersManager.razor create mode 100644 OrdersManagement/Services/FunctionService.cs create mode 100644 OrdersManagement/Services/RoleService.cs create mode 100644 OrdersManagement/Services/UserService.cs diff --git a/FaKrosnoApi/Controllers/FunctionsController.cs b/FaKrosnoApi/Controllers/FunctionsController.cs new file mode 100644 index 0000000..794c5e8 --- /dev/null +++ b/FaKrosnoApi/Controllers/FunctionsController.cs @@ -0,0 +1,52 @@ +using Microsoft.AspNetCore.Mvc; +using OrdersManagementDataModel.Dtos; +using OrdersManagementDataModel.Services; + +namespace FaKrosnoApi.Controllers; + +[ApiController] +[Route("api/[controller]")] +public class FunctionsController(IFunctionService service) : Controller +{ + [HttpGet] + public async Task>> GetAll() + { + IEnumerable functions = await service.GetAll(); + return Ok(functions); + } + + [HttpGet("by-id")] + public async Task> GetById([FromQuery] Guid id) + { + FunctionDto? function = await service.GetById(id); + return function != null ? Ok(function) : NotFound(); + } + + [HttpGet("by-name")] + public async Task> GetByName([FromQuery] string name) + { + FunctionDto? function = await service.GetByName(name); + return function != null ? Ok(function) : NotFound(); + } + + [HttpPost] + public async Task> Add([FromBody] FunctionDto function) + { + await service.Add(function); + return Ok(function); + } + + [HttpPut] + public async Task> Update([FromBody] FunctionDto function) + { + await service.Update(function); + return Ok(function); + } + + [HttpDelete] + public async Task> Delete([FromQuery] Guid id) + { + await service.Delete(id); + return Ok(); + } +} \ No newline at end of file diff --git a/FaKrosnoApi/Controllers/RolesController.cs b/FaKrosnoApi/Controllers/RolesController.cs new file mode 100644 index 0000000..a9807cf --- /dev/null +++ b/FaKrosnoApi/Controllers/RolesController.cs @@ -0,0 +1,45 @@ +using Microsoft.AspNetCore.Mvc; +using OrdersManagementDataModel.Dtos; +using OrdersManagementDataModel.Services; + +namespace FaKrosnoApi.Controllers; + +[ApiController] +[Route("api/[controller]")] +public class RolesController(IRoleService service) : Controller +{ + [HttpGet] + public async Task>> GetAll() + { + IEnumerable roles = await service.GetAll(); + return Ok(roles); + } + + [HttpGet("by-id")] + public async Task> GetById([FromQuery] Guid id) + { + RoleDto? role = await service.GetById(id); + return role != null ? Ok(role) : NotFound(); + } + + [HttpGet("by-name")] + public async Task> GetByName([FromQuery] string name) + { + RoleDto? role = await service.GetByName(name); + return role != null ? Ok(role) : NotFound(); + } + + [HttpPost] + public async Task> Add([FromBody] RoleDto role) + { + await service.Add(role); + return Ok(role); + } + + [HttpDelete] + public async Task> Delete([FromQuery] Guid id) + { + await service.Delete(id); + return Ok(); + } +} \ No newline at end of file diff --git a/FaKrosnoApi/Controllers/UserRolesController.cs b/FaKrosnoApi/Controllers/UserRolesController.cs new file mode 100644 index 0000000..3edf5fc --- /dev/null +++ b/FaKrosnoApi/Controllers/UserRolesController.cs @@ -0,0 +1,43 @@ +using Microsoft.AspNetCore.Mvc; +using OrdersManagementDataModel.Dtos; +using OrdersManagementDataModel.Services; + +namespace FaKrosnoApi.Controllers; + +public class UserRolesController(IUserRoleService service) : Controller +{ + [HttpGet] + public async Task>> GetAll() + { + IEnumerable userRoles = await service.GetAll(); + return Ok(userRoles); + } + + [HttpGet("by-id")] + public async Task> GetById([FromQuery] Guid id) + { + UserRoleDto? userRole = await service.GetById(id); + return userRole != null ? Ok(userRole) : NotFound(); + } + + [HttpPost] + public async Task> Add([FromBody] UserRoleDto userRole) + { + await service.Add(userRole); + return Ok(userRole); + } + + [HttpPut] + public async Task> Update([FromBody] UserRoleDto userRole) + { + await service.Update(userRole); + return Ok(userRole); + } + + [HttpDelete] + public async Task> Delete([FromQuery] Guid id) + { + await service.Delete(id); + return Ok(); + } +} \ No newline at end of file diff --git a/FaKrosnoApi/Controllers/UsersController.cs b/FaKrosnoApi/Controllers/UsersController.cs new file mode 100644 index 0000000..9283ebb --- /dev/null +++ b/FaKrosnoApi/Controllers/UsersController.cs @@ -0,0 +1,52 @@ +using Microsoft.AspNetCore.Mvc; +using OrdersManagementDataModel.Dtos; +using OrdersManagementDataModel.Services; + +namespace FaKrosnoApi.Controllers; + +[ApiController] +[Route("api/[controller]")] +public class UsersController(IUserService service) : Controller +{ + [HttpGet] + public async Task>> GetAll() + { + IEnumerable users = await service.GetAll(); + return Ok(users); + } + + [HttpGet("by-id")] + public async Task> GetById([FromQuery] Guid id) + { + UserDto? user = await service.GetById(id); + return user != null ? Ok(user) : NotFound(); + } + + [HttpGet("by-username")] + public async Task> GetByUsername([FromQuery] string username) + { + UserDto? user = await service.GetByUsername(username); + return user != null ? Ok(user) : NotFound(); + } + + [HttpPost] + public async Task> Add([FromBody] UserDto user) + { + await service.Add(user); + return Ok(user); + } + + [HttpPut] + public async Task> Update([FromBody] UserDto user) + { + await service.Update(user); + return Ok(user); + } + + [HttpDelete] + public async Task> Delete([FromQuery] Guid id) + { + await service.Delete(id); + return Ok(); + } +} \ No newline at end of file diff --git a/FaKrosnoApi/Program.cs b/FaKrosnoApi/Program.cs index 891a885..685fba2 100644 --- a/FaKrosnoApi/Program.cs +++ b/FaKrosnoApi/Program.cs @@ -83,6 +83,11 @@ builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); + //builder.Services.AddHostedService(); var app = builder.Build(); diff --git a/OrdersManagement/Components/Pages/Admin/Users.razor b/OrdersManagement/Components/Pages/Admin/Users.razor deleted file mode 100644 index f21f982..0000000 --- a/OrdersManagement/Components/Pages/Admin/Users.razor +++ /dev/null @@ -1,151 +0,0 @@ -@page "/admin/UsersManager" -@using OrdersManagementDataModel.Dtos -@using Syncfusion.Blazor.Grids -@using Action = Syncfusion.Blazor.Grids.Action -@* @inject UserService UserService *@ -@* @inject RoleService RoleService *@ -@* @inject FunctionService FunctionService *@ - -

Zarządzanie Użytkownikami i Rolami

-
- - -

Użytkownicy

- - - - - - - - - - - - - -
- - -

Role

- - - - - - - - -
- - -

Funkcje

- - - - - - - - - - -@code { - private List UserList { get; set; } = new(); - private List Roles { get; set; } = new(); - private List Functions { get; set; } = new(); - - protected override async Task OnInitializedAsync() - { - await LoadUsers(); - await LoadRoles(); - await LoadFunctions(); - } - - // Użytkownicy - private async Task UserActionBegin(ActionEventArgs args) - { - // if (args.RequestType.Equals(Action.Delete)) - // { - // await UserService.DeleteUserAsync(args.Data.Id); - // } - // else if (args.RequestType.Equals(Action.Add)) - // { - // args.Data.RowPointer = Guid.NewGuid(); - // } - } - - private async Task UserActionComplete(ActionEventArgs args) - { - switch (args.RequestType) - { - case Action.Delete: - case Action.Save: - await LoadUsers(); - break; - } - } - - private async Task LoadUsers() - { - //Users = (await UserService.GetUsersAsync() ?? Array.Empty()).ToList(); - } - - // Role - private async Task RoleActionBegin(ActionEventArgs args) - { - // if (args.RequestType.Equals(Action.Delete)) - // { - // await RoleService.DeleteRoleAsync(args.Data.Id); - // } - // else if (args.RequestType.Equals(Action.Add)) - // { - // args.Data.RowPointer = Guid.NewGuid(); - // } - } - - private async Task RoleActionComplete(ActionEventArgs args) - { - switch (args.RequestType) - { - case Action.Delete: - case Action.Save: - await LoadRoles(); - break; - } - } - - private async Task LoadRoles() - { - //Roles = (await RoleService.GetRolesAsync() ?? Array.Empty()).ToList(); - } - - // Funkcje - private async Task FunctionActionBegin(ActionEventArgs args) - { - if (args.RequestType.Equals(Action.Delete)) - { - //await FunctionService.DeleteFunctionAsync(args.Data.Id); - } - else if (args.RequestType.Equals(Action.Add)) - { - args.Data.RowPointer = Guid.NewGuid(); - } - } - - private async Task FunctionActionComplete(ActionEventArgs args) - { - switch (args.RequestType) - { - case Action.Delete: - case Action.Save: - await LoadFunctions(); - break; - } - } - - private async Task LoadFunctions() - { - //Functions = (await FunctionService.GetFunctionsAsync() ?? Array.Empty()).ToList(); - } -} diff --git a/OrdersManagement/Components/Pages/Admin/UsersManager.razor b/OrdersManagement/Components/Pages/Admin/UsersManager.razor new file mode 100644 index 0000000..8e4c520 --- /dev/null +++ b/OrdersManagement/Components/Pages/Admin/UsersManager.razor @@ -0,0 +1,173 @@ +@page "/admin/UsersManager" + +@using OrdersManagementDataModel.Dtos +@using Syncfusion.Blazor.Grids +@using Action = Syncfusion.Blazor.Grids.Action +@using UserService = OrdersManagement.Services.UserService +@inject UserService UserService +@inject RoleService RoleService +@inject FunctionService FunctionService + +
+
Użytkownicy
+ + + + + + + + + + + + + § +
+
Role
+ + + + + + + + +
+
Funkcje
+ + + + + + + + + +
+ +@code { + private List UserList { get; set; } = new(); + private List Roles { get; set; } = new(); + private List Functions { get; set; } = new(); + + protected override async Task OnInitializedAsync() + { + await LoadUsers(); + await LoadRoles(); + await LoadFunctions(); + } + + private async Task LoadUsers() + { + UserList = (await UserService.GetUsersAsync() ?? Array.Empty()).ToList(); + } + + private async Task LoadRoles() + { + Roles = (await RoleService.GetRolesAsync() ?? Array.Empty()).ToList(); + } + + private async Task LoadFunctions() + { + Functions = (await FunctionService.GetFunctionsAsync() ?? Array.Empty()).ToList(); + } + + private async Task UserActionBegin(ActionEventArgs args) + { + if (args.RequestType.Equals(Action.Delete)) + { + await UserService.DeleteUserAsync(args.Data.RowPointer); + } + else if (args.RequestType.Equals(Action.Add)) + { + args.Data.RowPointer = Guid.NewGuid(); + } + } + + private async Task UserActionComplete(ActionEventArgs args) + { + switch (args.RequestType) + { + case Action.Delete: + await LoadUsers(); + break; + case Action.Add: + await UserService.AddUserAsync(args.Data); + await LoadUsers(); + break; + case Action.Save: + await UserService.UpdateUserAsync(args.Data); + await LoadUsers(); + break; + } + } + + private async Task RoleActionBegin(ActionEventArgs args) + { + if (args.RequestType.Equals(Action.Delete)) + { + await RoleService.DeleteRoleAsync(args.Data.RowPointer); + } + else if (args.RequestType.Equals(Action.Add)) + { + args.Data.RowPointer = Guid.NewGuid(); + } + } + + private async Task RoleActionComplete(ActionEventArgs args) + { + switch (args.RequestType) + { + case Action.Delete: + await LoadRoles(); + break; + case Action.Add: + await RoleService.AddRoleAsync(args.Data); + await LoadRoles(); + break; + case Action.Save: + await RoleService.UpdateRoleAsync(args.Data); + await LoadRoles(); + break; + } + } + + private async Task FunctionActionBegin(ActionEventArgs args) + { + if (args.RequestType.Equals(Action.Delete)) + { + await FunctionService.DeleteFunctionAsync(args.Data.RowPointer); + } + else if (args.RequestType.Equals(Action.Add)) + { + args.Data.RowPointer = Guid.NewGuid(); + } + } + + private async Task FunctionActionComplete(ActionEventArgs args) + { + switch (args.RequestType) + { + case Action.Delete: + await LoadFunctions(); + break; + case Action.Add: + await FunctionService.AddFunctionAsync(args.Data); + await LoadFunctions(); + break; + case Action.Save: + await FunctionService.UpdateFunctionAsync(args.Data); + await LoadFunctions(); + break; + } + } + +} \ No newline at end of file diff --git a/OrdersManagement/Program.cs b/OrdersManagement/Program.cs index 53be7fd..3427f39 100644 --- a/OrdersManagement/Program.cs +++ b/OrdersManagement/Program.cs @@ -20,6 +20,9 @@ builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); var app = builder.Build(); diff --git a/OrdersManagement/Services/FunctionService.cs b/OrdersManagement/Services/FunctionService.cs new file mode 100644 index 0000000..ea60e1b --- /dev/null +++ b/OrdersManagement/Services/FunctionService.cs @@ -0,0 +1,36 @@ +using OrdersManagementDataModel.Dtos; + +namespace OrdersManagement.Services; + +public class FunctionService(HttpClient httpClient) +{ + public async Task?> GetFunctionsAsync() + { + return await httpClient.GetFromJsonAsync>("api/Functions"); + } + + public async Task GetFunctionAsync(Guid functionId) + { + return await httpClient.GetFromJsonAsync($"api/Functions/by-id/?id={functionId}"); + } + + public async Task GetFunctionByNameAsync(string functionName) + { + return await httpClient.GetFromJsonAsync($"api/Functions/by-name/?name={functionName}"); + } + + public async Task AddFunctionAsync(FunctionDto function) + { + await httpClient.PostAsJsonAsync("api/Functions", function); + } + + public async Task UpdateFunctionAsync(FunctionDto function) + { + await httpClient.PutAsJsonAsync("api/Functions", function); + } + + public async Task DeleteFunctionAsync(Guid functionId) + { + await httpClient.DeleteAsync($"api/Functions/?id={functionId}"); + } +} \ No newline at end of file diff --git a/OrdersManagement/Services/RoleService.cs b/OrdersManagement/Services/RoleService.cs new file mode 100644 index 0000000..3c6f11a --- /dev/null +++ b/OrdersManagement/Services/RoleService.cs @@ -0,0 +1,41 @@ +using OrdersManagementDataModel.Dtos; + +namespace OrdersManagement.Services; + +public class RoleService(HttpClient httpClient) +{ + public async Task?> GetRolesAsync() + { + return await httpClient.GetFromJsonAsync>("api/Roles"); + } + + public async Task GetRoleAsync(Guid roleId) + { + return await httpClient.GetFromJsonAsync($"api/Roles/by-id/?id={roleId}"); + } + + public async Task GetRoleByNameAsync(string roleName) + { + return await httpClient.GetFromJsonAsync($"api/Roles/by-name/?name={roleName}"); + } + + public async Task AddRoleAsync(RoleDto role) + { + await httpClient.PostAsJsonAsync("api/Roles", role); + } + + public async Task UpdateRoleAsync(RoleDto role) + { + await httpClient.PutAsJsonAsync("api/Roles", role); + } + + public async Task DeleteRoleAsync(Guid roleId) + { + await httpClient.DeleteAsync($"api/Roles/?id={roleId}"); + } + + // public async Task?> GetUsersInRoleAsync(Guid roleId) + // { + // return await httpClient.GetFromJsonAsync>($"api/Roles/{roleId}/Users"); + // } +} \ No newline at end of file diff --git a/OrdersManagement/Services/UserService.cs b/OrdersManagement/Services/UserService.cs new file mode 100644 index 0000000..b54412c --- /dev/null +++ b/OrdersManagement/Services/UserService.cs @@ -0,0 +1,36 @@ +using OrdersManagementDataModel.Dtos; + +namespace OrdersManagement.Services; + +public class UserService(HttpClient httpClient) +{ + public async Task?> GetUsersAsync() + { + return await httpClient.GetFromJsonAsync>("api/Users"); + } + + public async Task GetUserAsync(Guid userId) + { + return await httpClient.GetFromJsonAsync($"api/Users/by-id/?id={userId}"); + } + + public async Task GetUserByUsernameAsync(string username) + { + return await httpClient.GetFromJsonAsync($"api/Users/by-username/?username={username}"); + } + + public async Task AddUserAsync(UserDto user) + { + await httpClient.PostAsJsonAsync("api/Users", user); + } + + public async Task UpdateUserAsync(UserDto user) + { + await httpClient.PutAsJsonAsync("api/Users", user); + } + + public async Task DeleteUserAsync(Guid userId) + { + await httpClient.DeleteAsync($"api/Users/?id={userId}"); + } +} \ No newline at end of file diff --git a/OrdersManagementDataModel/Services/FunctionService.cs b/OrdersManagementDataModel/Services/FunctionService.cs index 840f73a..fc0975c 100644 --- a/OrdersManagementDataModel/Services/FunctionService.cs +++ b/OrdersManagementDataModel/Services/FunctionService.cs @@ -7,14 +7,14 @@ namespace OrdersManagementDataModel.Services; public class FunctionService(OrdersManagementDbContext context, IMapper mapper) : IFunctionService { - public async Task> GetFunctions() + public async Task> GetAll() { IList functions = await context.Functions.Select(x => mapper.Map(x)).ToListAsync(); return functions; } - public async Task GetFunctionById(Guid id) + public async Task GetById(Guid id) { FunctionDto? function = await context.Functions.Where(x => x.RowPointer == id) .Select(x => mapper.Map(x)).FirstOrDefaultAsync(); @@ -22,7 +22,7 @@ public class FunctionService(OrdersManagementDbContext context, IMapper mapper) return function; } - public async Task GetFunctionByName(string name) + public async Task GetByName(string name) { FunctionDto? function = await context.Functions.Where(x => x.Name == name) .Select(x => mapper.Map(x)).FirstOrDefaultAsync(); @@ -30,7 +30,7 @@ public class FunctionService(OrdersManagementDbContext context, IMapper mapper) return function; } - public async Task AddFunction(FunctionDto functionDto) + public async Task Add(FunctionDto functionDto) { Function function = new Function { @@ -42,7 +42,7 @@ public class FunctionService(OrdersManagementDbContext context, IMapper mapper) return await context.SaveChangesAsync(); } - public async Task DeleteFunction(Guid id) + public async Task Delete(Guid id) { Function? function = await context.Functions.Where(x => x.RowPointer == id).FirstOrDefaultAsync() ?? null; @@ -52,7 +52,7 @@ public class FunctionService(OrdersManagementDbContext context, IMapper mapper) return await context.SaveChangesAsync(); } - public async Task UpdateFunction(FunctionDto functionDto) + public async Task Update(FunctionDto functionDto) { Function function = mapper.Map(functionDto); context.Functions.Update(function); diff --git a/OrdersManagementDataModel/Services/IFunctionService.cs b/OrdersManagementDataModel/Services/IFunctionService.cs index baafe17..1f0b7c0 100644 --- a/OrdersManagementDataModel/Services/IFunctionService.cs +++ b/OrdersManagementDataModel/Services/IFunctionService.cs @@ -4,12 +4,12 @@ namespace OrdersManagementDataModel.Services; public interface IFunctionService { - Task> GetFunctions(); - Task GetFunctionById(Guid id); - Task GetFunctionByName(string name); - Task AddFunction(FunctionDto functionDto); - Task DeleteFunction(Guid id); - Task UpdateFunction(FunctionDto functionDto); + Task> GetAll(); + Task GetById(Guid id); + Task GetByName(string name); + Task Add(FunctionDto functionDto); + Task Delete(Guid id); + Task Update(FunctionDto functionDto); Task> GetFunctionsByRoleId(Guid roleId); Task AddFunctionToRole(Guid roleId, Guid functionId); Task RemoveFunctionFromRole(Guid roleId, Guid functionId); diff --git a/OrdersManagementDataModel/Services/IRoleService.cs b/OrdersManagementDataModel/Services/IRoleService.cs index 418ec32..e7dbe50 100644 --- a/OrdersManagementDataModel/Services/IRoleService.cs +++ b/OrdersManagementDataModel/Services/IRoleService.cs @@ -4,9 +4,9 @@ namespace OrdersManagementDataModel.Services; public interface IRoleService { - Task> GetRoles(); - Task GetRoleById(Guid id); - Task GetRoleByName(string name); - Task AddRole(RoleDto roleDto); - Task DeleteRole(Guid id); + Task> GetAll(); + Task GetById(Guid id); + Task GetByName(string name); + Task Add(RoleDto roleDto); + Task Delete(Guid id); } \ No newline at end of file diff --git a/OrdersManagementDataModel/Services/IUserRoleService.cs b/OrdersManagementDataModel/Services/IUserRoleService.cs index cf3f132..5709aa1 100644 --- a/OrdersManagementDataModel/Services/IUserRoleService.cs +++ b/OrdersManagementDataModel/Services/IUserRoleService.cs @@ -4,11 +4,11 @@ namespace OrdersManagementDataModel.Services; public interface IUserRoleService { - Task> GetUserRoles(); - Task GetUserRoleById(Guid id); - Task AddUserRole(UserRoleDto userRoleDto); - Task DeleteUserRole(Guid id); - Task UpdateUserRole(UserRoleDto userRoleDto); + Task> GetAll(); + Task GetById(Guid id); + Task Add(UserRoleDto userRoleDto); + Task Delete(Guid id); + Task Update(UserRoleDto userRoleDto); Task> GetUserRolesByUserId(Guid userId); Task> GetUserRolesByRoleId(Guid roleId); Task AddRoleToUser(Guid userId, Guid roleId); diff --git a/OrdersManagementDataModel/Services/IUserService.cs b/OrdersManagementDataModel/Services/IUserService.cs index f227bdb..7a0bf7d 100644 --- a/OrdersManagementDataModel/Services/IUserService.cs +++ b/OrdersManagementDataModel/Services/IUserService.cs @@ -4,12 +4,12 @@ namespace OrdersManagementDataModel.Services; public interface IUserService { - Task> GetUsers(); - Task GetUserById(Guid id); - Task GetUserByUsername(string username); - Task AddUser(UserDto userDto); - Task UpdateUser(UserDto userDto); - Task DeleteUser(Guid id); + Task> GetAll(); + Task GetById(Guid id); + Task GetByUsername(string username); + Task Add(UserDto userDto); + Task Update(UserDto userDto); + Task Delete(Guid id); Task> GetUserRoles(Guid userId); Task GetUserByLoginAndPassword(string login, string password); } \ No newline at end of file diff --git a/OrdersManagementDataModel/Services/RoleService.cs b/OrdersManagementDataModel/Services/RoleService.cs index 602ed40..c78d8e2 100644 --- a/OrdersManagementDataModel/Services/RoleService.cs +++ b/OrdersManagementDataModel/Services/RoleService.cs @@ -7,14 +7,14 @@ namespace OrdersManagementDataModel.Services; public class RoleService(OrdersManagementDbContext context, IMapper mapper) : IRoleService { - public async Task> GetRoles() + public async Task> GetAll() { IList roles = await context.Roles.Select(x => mapper.Map(x)).ToListAsync(); return roles; } - public async Task GetRoleById(Guid id) + public async Task GetById(Guid id) { RoleDto? role = await context.Roles.Where(x => x.RowPointer == id) .Select(x => mapper.Map(x)).FirstOrDefaultAsync(); @@ -22,7 +22,7 @@ public class RoleService(OrdersManagementDbContext context, IMapper mapper) : IR return role; } - public async Task GetRoleByName(string name) + public async Task GetByName(string name) { RoleDto? role = await context.Roles.Where(x => x.Name == name) .Select(x => mapper.Map(x)).FirstOrDefaultAsync(); @@ -30,7 +30,7 @@ public class RoleService(OrdersManagementDbContext context, IMapper mapper) : IR return role; } - public async Task AddRole(RoleDto roleDto) + public async Task Add(RoleDto roleDto) { Role role = new Role { @@ -42,7 +42,7 @@ public class RoleService(OrdersManagementDbContext context, IMapper mapper) : IR return await context.SaveChangesAsync(); } - public async Task DeleteRole(Guid id) + public async Task Delete(Guid id) { Role? role = await context.Roles.Where(x => x.RowPointer == id).FirstOrDefaultAsync() ?? null; diff --git a/OrdersManagementDataModel/Services/UserRoleService.cs b/OrdersManagementDataModel/Services/UserRoleService.cs index 29c82ed..217f731 100644 --- a/OrdersManagementDataModel/Services/UserRoleService.cs +++ b/OrdersManagementDataModel/Services/UserRoleService.cs @@ -7,14 +7,14 @@ namespace OrdersManagementDataModel.Services; public class UserRoleService(OrdersManagementDbContext context, IMapper mapper) : IUserRoleService { - public async Task> GetUserRoles() + public async Task> GetAll() { IList userRoles = await context.UserRoles.Select(x => mapper.Map(x)).ToListAsync(); return userRoles; } - public async Task GetUserRoleById(Guid id) + public async Task GetById(Guid id) { UserRoleDto? userRole = await context.UserRoles.Where(x => x.RowPointer == id) .Select(x => mapper.Map(x)).FirstOrDefaultAsync(); @@ -22,14 +22,14 @@ public class UserRoleService(OrdersManagementDbContext context, IMapper mapper) return userRole; } - public Task AddUserRole(UserRoleDto userRoleDto) + public Task Add(UserRoleDto userRoleDto) { UserRole userRole = mapper.Map(userRoleDto); context.UserRoles.Add(userRole); return context.SaveChangesAsync(); } - public async Task DeleteUserRole(Guid id) + public async Task Delete(Guid id) { UserRole? userRole = await context.UserRoles.Where(x => x.RowPointer == id).FirstOrDefaultAsync() ?? null; @@ -39,7 +39,7 @@ public class UserRoleService(OrdersManagementDbContext context, IMapper mapper) return await context.SaveChangesAsync(); } - public async Task UpdateUserRole(UserRoleDto userRoleDto) + public async Task Update(UserRoleDto userRoleDto) { UserRole userRole = mapper.Map(userRoleDto); context.UserRoles.Update(userRole); diff --git a/OrdersManagementDataModel/Services/UserService.cs b/OrdersManagementDataModel/Services/UserService.cs index ed535d7..131216c 100644 --- a/OrdersManagementDataModel/Services/UserService.cs +++ b/OrdersManagementDataModel/Services/UserService.cs @@ -7,14 +7,14 @@ namespace OrdersManagementDataModel.Services; public class UserService(OrdersManagementDbContext context, IMapper mapper) : IUserService { - public async Task> GetUsers() + public async Task> GetAll() { IList users = await context.Users.Select(x => mapper.Map(x)).ToListAsync(); return users; } - public async Task GetUserById(Guid id) + public async Task GetById(Guid id) { UserDto? user = await context.Users.Where(x => x.RowPointer == id) .Select(x => mapper.Map(x)).FirstOrDefaultAsync(); @@ -22,7 +22,7 @@ public class UserService(OrdersManagementDbContext context, IMapper mapper) : IU return user; } - public async Task GetUserByUsername(string username) + public async Task GetByUsername(string username) { UserDto? user = await context.Users.Where(x => x.Login == username) .Select(x => mapper.Map(x)).FirstOrDefaultAsync(); @@ -30,7 +30,7 @@ public class UserService(OrdersManagementDbContext context, IMapper mapper) : IU return user; } - public async Task AddUser(UserDto userDto) + public async Task Add(UserDto userDto) { User user = new User { @@ -50,14 +50,14 @@ public class UserService(OrdersManagementDbContext context, IMapper mapper) : IU return await context.SaveChangesAsync(); } - public async Task UpdateUser(UserDto userDto) + public async Task Update(UserDto userDto) { User user = mapper.Map(userDto); context.Users.Update(user); return await context.SaveChangesAsync(); } - public async Task DeleteUser(Guid id) + public async Task Delete(Guid id) { User? user = await context.Users.Where(x => x.RowPointer == id).FirstOrDefaultAsync() ?? null;