Controller javítása userId-vel

This commit is contained in:
2025-03-22 14:19:00 +01:00
parent 3a4db4dd14
commit d55dee91e9
4 changed files with 78 additions and 17 deletions
@@ -3,6 +3,7 @@ using Serilog;
using WorkFlowCheck.BL.Services; using WorkFlowCheck.BL.Services;
using WorkFlowCheck.BL.Services.Interfaces; using WorkFlowCheck.BL.Services.Interfaces;
using WorkFlowCheck.Common.DTO; using WorkFlowCheck.Common.DTO;
using WorkFlowCheck.DL.Entities;
namespace WorkFlowCheck.API.Controllers namespace WorkFlowCheck.API.Controllers
{ {
@@ -225,14 +226,37 @@ namespace WorkFlowCheck.API.Controllers
} }
[HttpGet("GetAllCheckListTemplateHeader")] [HttpGet("GetAllCheckListTemplateHeader/{userId}")]
public async Task<ApiResponseDTO<List<CheckListTemplateHeaderDTO>>> GetAllCheckListTemplateHeaderAsync() public async Task<ApiResponseDTO<List<CheckListTemplateHeaderDTO>>> GetAllCheckListTemplateHeaderAsync(int userId)
{ {
var retVal = new ApiResponseDTO<List<CheckListTemplateHeaderDTO>>() var retVal = new ApiResponseDTO<List<CheckListTemplateHeaderDTO>>()
{ {
IsSuccess = true, IsSuccess = true,
}; };
var response = await _syncService.GetAllCheckListTemplateAsync(); var response = await _syncService.GetAllCheckListTemplateAsync(userId);
if (response != null)
{
retVal.IsSuccess = true;
retVal.Data = response;
}
else
{
retVal.IsSuccess = false;
retVal.Errors.Add("No data!");
}
return retVal;
}
[HttpGet("GetAllCheckListHeader/{userId}")]
public async Task<ApiResponseDTO<List<CheckListHeaderDTO>>> GetAllCheckListHeaderAsync(int userId)
{
var retVal = new ApiResponseDTO<List<CheckListHeaderDTO>>()
{
IsSuccess = true,
};
var response = await _syncService.GetAllCheckListAsync(userId);
if (response != null) if (response != null)
{ {
@@ -249,10 +273,10 @@ namespace WorkFlowCheck.API.Controllers
return retVal; return retVal;
} }
} }
} }
@@ -20,6 +20,7 @@ namespace WorkFlowCheck.BL.Services.Interfaces
Task<EquipmentDTO> UpdateEquipmentAsync(EquipmentDTO EquipmentDTO); Task<EquipmentDTO> UpdateEquipmentAsync(EquipmentDTO EquipmentDTO);
Task<List<CheckListTemplateHeaderDTO>> GetAllCheckListTemplateAsync(); Task<List<CheckListTemplateHeaderDTO>> GetAllCheckListTemplateAsync(int userId);
Task<List<CheckListHeaderDTO>> GetAllCheckListAsync(int userId);
} }
} }
+44 -8
View File
@@ -101,9 +101,9 @@ namespace WorkFlowCheck.BL.Services
return retVal; return retVal;
} }
public async Task<List<LocationDTO>> GetAllLocationAsync() public async Task<List<LocationDTO>> GetAllLocationAsync()
{ {
var retVal = new List<LocationDTO>(); var retVal = new List<LocationDTO>();
@@ -164,7 +164,7 @@ namespace WorkFlowCheck.BL.Services
var res = await _dbContext.Locations.Where(w => w.Id == LocationDTO.Id).FirstOrDefaultAsync(); var res = await _dbContext.Locations.Where(w => w.Id == LocationDTO.Id).FirstOrDefaultAsync();
if (res != null) if (res != null)
{ {
res=_mapper.Map<Location>(LocationDTO); res = _mapper.Map<Location>(LocationDTO);
await _dbContext.SaveChangesAsync(); await _dbContext.SaveChangesAsync();
@@ -260,18 +260,54 @@ namespace WorkFlowCheck.BL.Services
return retVal; return retVal;
} }
public async Task<List<CheckListTemplateHeaderDTO>> GetAllCheckListTemplateAsync() public async Task<List<CheckListTemplateHeaderDTO>> GetAllCheckListTemplateAsync(int userId)
{ {
var retVal = new List<CheckListTemplateHeaderDTO>(); var retVal = new List<CheckListTemplateHeaderDTO>();
try try
{ {
var res = await _dbContext.CheckListTemplateHeaders.Include(i => i.CheckListTemplateRows).AsNoTracking().ToListAsync(); var user = _dbContext.Users.Where(w => w.Id == userId).FirstOrDefault();
if (user != null)
{
var res = await (from ur in _dbContext.UserRoles
join rth in _dbContext.RoleCheckListTemplateHeaders on ur.RoleId equals rth.RoleId
join header in _dbContext.CheckListTemplateHeaders on rth.CheckListTemplateHeaderId equals header.Id
where ur.UserId == userId
select header)
.Include(h => h.CheckListTemplateRows)
.Distinct()
.AsNoTracking()
.ToListAsync();
if (res != null)
{
retVal = _mapper.Map<List<CheckListTemplateHeaderDTO>>(res);
}
}
}
catch (Exception ex)
{
Log.Error(ex.Message);
}
return retVal;
}
public async Task<List<CheckListHeaderDTO>> GetAllCheckListAsync(int userId)
{
var retVal = new List<CheckListHeaderDTO>();
try
{
var res = await _dbContext.CheckListHeaders
.Where(w => w.IsEditable && w.UserId == userId)
.Include(i => i.CheckListRows)
.AsNoTracking()
.ToListAsync();
if (res != null) if (res != null)
{ {
retVal = _mapper.Map<List<CheckListTemplateHeaderDTO>>(res); retVal = _mapper.Map<List<CheckListHeaderDTO>>(res);
} }
} }
catch (Exception ex) catch (Exception ex)
+1 -1
View File
@@ -45,7 +45,7 @@ namespace WorkFlowCheck.DL
public DbSet<Entities.User> Users { get; set; } = null!; public DbSet<Entities.User> Users { get; set; } = null!;
public DbSet<Entities.UserRole> UserRoles { get; set; } = null!; public DbSet<Entities.UserRole> UserRoles { get; set; } = null!;
public DbSet<Entities.RoleCheckListTemplateHeader> UsersCheckListTemplateHeaders { get; set; } = null!; public DbSet<Entities.RoleCheckListTemplateHeader> RoleCheckListTemplateHeaders { get; set; } = null!;
#endregion #endregion