SyncController API

This commit is contained in:
2025-02-06 14:02:18 +01:00
parent 7570908177
commit b5e5158f1e
7 changed files with 135 additions and 0 deletions
@@ -0,0 +1,41 @@
using Microsoft.AspNetCore.Mvc;
using WorkFlowCheck.BL.Services;
using WorkFlowCheck.BL.Services.Interfaces;
using WorkFlowCheck.Common.DTO;
namespace WorkFlowCheck.API.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class SyncController : ControllerBase
{
private ISyncService _syncService;
public SyncController(ISyncService syncService)
{
_syncService = syncService;
}
[HttpGet("GetAllCheckPoints")]
public async Task<ApiResponseDTO<CheckPointListDTO>> GetAllCheckpoint()
{
var retVal = new ApiResponseDTO<CheckPointListDTO>()
{
IsSuccess = true,
};
var checkPointListDTO = await _syncService.GetAllCheckPoint();
if (checkPointListDTO != null)
{
retVal.IsSuccess = true;
retVal.Data = checkPointListDTO;
}
else
{
retVal.IsSuccess = false;
retVal.Errors.Add("No data!");
}
return retVal;
}
}
}
+1
View File
@@ -14,6 +14,7 @@ namespace WorkFlowCheck.BL.Infra
public static void DIInit(IServiceCollection service)
{
service.AddScoped<IUserService, UserService>();
service.AddScoped<ISyncService, SyncService>();
}
}
}
@@ -18,7 +18,9 @@ namespace WorkFlowCheck.BL.Mappings
CreateMap<UserDTO, User>()
.ForMember(dest => dest.PasswordHash, opt => opt.MapFrom<PasswordHashResolver>());
CreateMap<CheckListTemplateHeader, CheckListTemplateHeaderDTO>();
CreateMap<CheckPoint, CheckPointDTO>();
}
}
}
@@ -0,0 +1,10 @@
using WorkFlowCheck.Common.DTO;
namespace WorkFlowCheck.BL.Services.Interfaces
{
public interface ISyncService
{
Task<CheckPointListDTO> GetAllCheckPoint();
}
}
@@ -0,0 +1,62 @@
using AutoMapper;
using Microsoft.EntityFrameworkCore;
using Serilog;
using WorkFlowCheck.BL.Services.Interfaces;
using WorkFlowCheck.Common.DTO;
using WorkFlowCheck.DL;
using WorkFlowCheck.DL.Entities;
namespace WorkFlowCheck.BL.Services
{
public class SyncService : ISyncService
{
private AppDbContext _dbContext;
private IMapper _mapper;
public SyncService(AppDbContext dbContext, IMapper mapper)
{
_dbContext = dbContext;
_mapper = mapper;
}
public async Task<CheckPointListDTO> GetAllCheckPoint()
{
var retVal = new CheckPointListDTO();
try
{
var res = await _dbContext.CheckPoints.ToListAsync();
if (res != null)
{
retVal.CheckPointList = _mapper.Map<List<CheckPointDTO>>(res);
}
}
catch (Exception ex)
{
Log.Error(ex.Message);
}
return retVal;
}
public async Task<CheckPointListDTO> GetAllLocation()
{
var retVal = new CheckPointListDTO();
try
{
var res = await _dbContext.CheckPoints.ToListAsync();
if (res != null)
{
retVal.CheckPointList = _mapper.Map<List<CheckPointDTO>>(res);
}
}
catch (Exception ex)
{
Log.Error(ex.Message);
}
return retVal;
}
}
}
@@ -0,0 +1,10 @@
namespace WorkFlowCheck.Common.DTO
{
public class CheckPointDTO
{
public int Id { get; set; }
public string ShortName { get; set; }
public string Code { get; set; }
}
}
@@ -0,0 +1,9 @@
namespace WorkFlowCheck.Common.DTO
{
public class CheckPointListDTO
{
public List<CheckPointDTO> CheckPointList { get; set; } = new List<CheckPointDTO>();
}
}