using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using MMBLL.MachineType; using static GB5Shared.GB5Constant.Constant; namespace MMSL.EndPoints.MachineType { public class GetMachineType : BaseEndpoint> { private readonly IMachineTypeBLL _MachineTypeBLL; public GetMachineType(IMachineTypeBLL IMachineTypeBLL) { _MachineTypeBLL = IMachineTypeBLL; } public override void Configure() { Get("/MachineType/GetMachineType"); AllowAnonymous(); } public record GetMachineTypeParameters( [property: FromHeader] string Login, [property: QueryParam] int MachineTypeId ); protected override string? GetCacheKey(GetMachineTypeParameters Parameters, LoginDTO LoginDTO) { try { return KeyGenerator.KeyGeneration(Parameters.MachineTypeId!, EntityConstant.OBJECTMACHINETYPE, CacheKeyLevel.USER_LEVEL, LoginDTO); } catch (Exception) { throw; } } protected override async Task> ExecuteAsync(GetMachineTypeParameters req, LoginDTO LoginDTO, CancellationToken ct) { try { var Result = await _MachineTypeBLL.GetMachineType(req.MachineTypeId, LoginDTO!); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse(Result, CacheKeyLevel.USER_LEVEL, LoginDTO); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError(ex, CacheKeyLevel.USER_LEVEL, LoginDTO, ex.Message, 500); } } } }