using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using MaintenanceBLL.KeyComponent; using static GB5Shared.GB5Constant.Constant; namespace MaintenanceSL.FastEndPoints.KeyComponent { public class GetKeyComponent : BaseEndpoint { private readonly IKeyComponentBLL _KeyComponentBLL; public GetKeyComponent(IKeyComponentBLL KeyComponentBLL) { _KeyComponentBLL = KeyComponentBLL; } public override void Configure() { Get("/KeyComponent/GetKeyComponent"); AllowAnonymous(); } public record GetKeyComponentParameters( [property: QueryParam] int KeyComponentId, [property: FromHeader] string Login ); protected override string? GetCacheKey(GetKeyComponentParameters GetKeyComponentParameters, LoginDTO LoginDTO) { try { return KeyGenerator.KeyGeneration(GetKeyComponentParameters.KeyComponentId!, EntityConstant.OBJECTKEYCOMPONENT, CacheKeyLevel.USER_LEVEL, LoginDTO); } catch (Exception) { throw; } } protected override async Task> ExecuteAsync(GetKeyComponentParameters parameters, LoginDTO loginDTO, CancellationToken ct) { try { var result = await _KeyComponentBLL.GetKeyComponent(parameters.KeyComponentId, 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); } } } }