User dolgok javítása

This commit is contained in:
2025-03-15 14:27:08 +01:00
parent 2d13b0909e
commit 8793a1c77c
4 changed files with 89 additions and 5 deletions
@@ -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<ApiResponseDTO<List<UserDTO>>> GetAllUser()
{
var retVal = new ApiResponseDTO<List<UserDTO>>()
{
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<ApiResponseDTO<UserDTO>> Authenticate([FromBody] UserDTO userDTO)
{
var retVal = new ApiResponseDTO<UserDTO>()
@@ -9,8 +9,21 @@ namespace WorkFlowCheck.BL.Services.Interfaces
{
public interface IUserService
{
Task<UserDTO> GetUser(int Id);
Task<UserDTO> GetUserAsync(int Id);
Task<List<UserDTO>> GetAllUserAsync();
Task<UserDTO> UpdateUserAsync(UserDTO userDTO);
Task<UserDTO> Authenticate(string UserName, string Password);
Task<RoleDTO> GetRoleAsync(int Id);
Task<List<RoleDTO>> GetAllRoleAsync();
Task<RoleDTO> UpdateRoleAsync(RoleDTO roleDTO);
Task<UserRoleDTO> GetUserRoleAsync(int Id);
Task<List<UserRoleDTO>> GetAllUserRoleAsync();
Task<UserRoleDTO> UpdateUserRoleAsync(RoleDTO roleDTO);
string GenerateJwtToken(UserDTO userDTO);
}
}
+33 -1
View File
@@ -30,7 +30,7 @@ namespace WorkFlowCheck.BL.Services
_mapper = mapper;
_configuration = configuration;
}
public async Task<UserDTO> GetUser(int Id)
public async Task<UserDTO> GetUserAsync(int Id)
{
var retVal = new UserDTO() { RoleDTO = new List<RoleDTO>() };
@@ -49,6 +49,30 @@ namespace WorkFlowCheck.BL.Services
return retVal;
}
public async Task<List<UserDTO>> GetAllUserAsync()
{
var retVal = new List<UserDTO>
{
new UserDTO
{
RoleDTO = new List<RoleDTO>()
}
};
try
{
var users = await _dbContext.Users.ToListAsync();
if (users != null)
{
retVal = _mapper.Map<List<UserDTO>>(users);
}
}
catch (Exception ex)
{
Log.Error(ex.Message);
}
return retVal;
}
public async Task<UserDTO> Authenticate(string userName, string password)
{
var retVal = new UserDTO() { RoleDTO = new List<RoleDTO>() };
@@ -120,5 +144,13 @@ namespace WorkFlowCheck.BL.Services
return new JwtSecurityTokenHandler().WriteToken(token);
}
public Task<UserDTO> UpdateUserAsync(UserDTO userDTO) => throw new NotImplementedException();
public Task<RoleDTO> GetRoleAsync(int Id) => throw new NotImplementedException();
public Task<List<RoleDTO>> GetAllRoleAsync() => throw new NotImplementedException();
public Task<RoleDTO> UpdateRoleAsync(RoleDTO roleDTO) => throw new NotImplementedException();
Task<UserRoleDTO> IUserService.GetUserRoleAsync(int Id) => throw new NotImplementedException();
public Task<List<UserRoleDTO>> GetAllUserRoleAsync() => throw new NotImplementedException();
public Task<UserRoleDTO> UpdateUserRoleAsync(RoleDTO roleDTO) => throw new NotImplementedException();
}
}
@@ -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; }
}
}