using FastEndpoints; using FrameworkBLL.DataAlert; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using static GB5Shared.GB5Constant.Constant; namespace FrameworkSL.Endpoints.DataAlert { public class GetDataAlert : BaseEndpoint { private readonly IDataAlertBLL _dataAlertBLL; public GetDataAlert(IDataAlertBLL dataAlertBLL) { _dataAlertBLL = dataAlertBLL; } public override void Configure() { Get("/DataAlert/GetDataAlert"); AllowAnonymous(); } public record GetDataAlertParameters( [property: QueryParam] int DataAlertId, [property: FromHeader] string Login ); protected override string? GetCacheKey(GetDataAlertParameters GetDataAlertParameters, LoginDTO LoginDTO) { try { return KeyGenerator.KeyGeneration(GetDataAlertParameters.DataAlertId!, EntityConstant.DATAALERT, CacheKeyLevel.USER_LEVEL, LoginDTO); } catch (Exception) { throw; } } protected override async Task> ExecuteAsync(GetDataAlertParameters parameters, LoginDTO loginDTO, CancellationToken ct) { try { var result = await _dataAlertBLL.GetDataAlert(parameters.DataAlertId, 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); } } } }