From 8793a1c77c7b6be0e7305beaf83b9ce4c915d90d Mon Sep 17 00:00:00 2001 From: ivanszabo Date: Sat, 15 Mar 2025 14:26:59 +0100 Subject: [PATCH] =?UTF-8?q?User=20dolgok=20jav=C3=ADt=C3=A1sa?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/UserController.cs | 27 ++++++++++++-- .../Services/Interfaces/IUserService.cs | 15 +++++++- src/WorkFlowCheck.BL/Services/UserService.cs | 36 +++++++++++++++++-- src/WorkFlowCheck.Common/DTO/UserRoleDTO.cs | 16 +++++++++ 4 files changed, 89 insertions(+), 5 deletions(-) create mode 100644 src/WorkFlowCheck.Common/DTO/UserRoleDTO.cs diff --git a/src/WorkFlowCheck.API/Controllers/UserController.cs b/src/WorkFlowCheck.API/Controllers/UserController.cs index 7d998f7..1d0468a 100644 --- a/src/WorkFlowCheck.API/Controllers/UserController.cs +++ b/src/WorkFlowCheck.API/Controllers/UserController.cs @@ -24,7 +24,7 @@ namespace WorkFlowCheck.API.Controllers { IsSuccess = true, }; - var userDTO = await _userService.GetUser(id); + var userDTO = await _userService.GetUserAsync(id); if (userDTO != null) { @@ -49,7 +49,30 @@ namespace WorkFlowCheck.API.Controllers return retVal; } - [HttpPost("authenticate")] + [HttpGet("GetAllUser")] + public async Task>> GetAllUser() + { + var retVal = new ApiResponseDTO>() + { + IsSuccess = true, + }; + var userDTO = await _userService.GetAllUserAsync(); + + if (userDTO != null) + { + retVal.IsSuccess = true; + retVal.Data = userDTO; + } + else + { + retVal.IsSuccess = false; + retVal.Errors.Add("No data!"); + } + + return retVal; + } + + [HttpPost("Authenticate")] public async Task> Authenticate([FromBody] UserDTO userDTO) { var retVal = new ApiResponseDTO() diff --git a/src/WorkFlowCheck.BL/Services/Interfaces/IUserService.cs b/src/WorkFlowCheck.BL/Services/Interfaces/IUserService.cs index 32132b9..045bb22 100644 --- a/src/WorkFlowCheck.BL/Services/Interfaces/IUserService.cs +++ b/src/WorkFlowCheck.BL/Services/Interfaces/IUserService.cs @@ -9,8 +9,21 @@ namespace WorkFlowCheck.BL.Services.Interfaces { public interface IUserService { - Task GetUser(int Id); + Task GetUserAsync(int Id); + Task> GetAllUserAsync(); + Task UpdateUserAsync(UserDTO userDTO); Task Authenticate(string UserName, string Password); + + Task GetRoleAsync(int Id); + Task> GetAllRoleAsync(); + Task UpdateRoleAsync(RoleDTO roleDTO); + + Task GetUserRoleAsync(int Id); + Task> GetAllUserRoleAsync(); + Task UpdateUserRoleAsync(RoleDTO roleDTO); + + + string GenerateJwtToken(UserDTO userDTO); } } diff --git a/src/WorkFlowCheck.BL/Services/UserService.cs b/src/WorkFlowCheck.BL/Services/UserService.cs index ab60dbf..0a9c286 100644 --- a/src/WorkFlowCheck.BL/Services/UserService.cs +++ b/src/WorkFlowCheck.BL/Services/UserService.cs @@ -30,7 +30,7 @@ namespace WorkFlowCheck.BL.Services _mapper = mapper; _configuration = configuration; } - public async Task GetUser(int Id) + public async Task GetUserAsync(int Id) { var retVal = new UserDTO() { RoleDTO = new List() }; @@ -48,7 +48,31 @@ namespace WorkFlowCheck.BL.Services } return retVal; } - + + public async Task> GetAllUserAsync() + { + var retVal = new List + { + new UserDTO + { + RoleDTO = new List() + } + }; + try + { + var users = await _dbContext.Users.ToListAsync(); + if (users != null) + { + retVal = _mapper.Map>(users); + } + } + catch (Exception ex) + { + Log.Error(ex.Message); + } + return retVal; + } + public async Task Authenticate(string userName, string password) { var retVal = new UserDTO() { RoleDTO = new List() }; @@ -120,5 +144,13 @@ namespace WorkFlowCheck.BL.Services return new JwtSecurityTokenHandler().WriteToken(token); } + + public Task UpdateUserAsync(UserDTO userDTO) => throw new NotImplementedException(); + public Task GetRoleAsync(int Id) => throw new NotImplementedException(); + public Task> GetAllRoleAsync() => throw new NotImplementedException(); + public Task UpdateRoleAsync(RoleDTO roleDTO) => throw new NotImplementedException(); + Task IUserService.GetUserRoleAsync(int Id) => throw new NotImplementedException(); + public Task> GetAllUserRoleAsync() => throw new NotImplementedException(); + public Task UpdateUserRoleAsync(RoleDTO roleDTO) => throw new NotImplementedException(); } } diff --git a/src/WorkFlowCheck.Common/DTO/UserRoleDTO.cs b/src/WorkFlowCheck.Common/DTO/UserRoleDTO.cs new file mode 100644 index 0000000..81ca738 --- /dev/null +++ b/src/WorkFlowCheck.Common/DTO/UserRoleDTO.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WorkFlowCheck.Common.DTO +{ + public class UserRoleDTO + { + public int Id { get; set; } + public int? RoleId { get; set; } = 0; + public int UserId { get; set; } + } +}