using FastEndpoints; using FrameworkBLL.EventRule; using FrameworkDAL.DTO.EventRule; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using System; using System.Threading; using System.Threading.Tasks; using static FrameworkDAL.Constant.Constant; namespace FrameworkSL.Endpoints.EventRule { public class UpdateEventRule : BaseEndpoint> { private readonly IEventRuleBLL _bll; public UpdateEventRule(IEventRuleBLL bll) => _bll = bll; public override void Configure() { Put("/EventRule/UpdateEventRule"); AllowAnonymous(); } public record Params( [property: FromHeader] string Login, [property: FromBody] EventRuleDTO EventRule ); protected override string? GetCacheKey(Params req, LoginDTO login) => null; protected override async Task> ExecuteAsync( Params req, LoginDTO login, CancellationToken ct) { try { var result = await _bll.UpdateEventRuleAsync(req.EventRule, login, ct); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse(result, CacheKeyLevel.UserLevel, login); } catch (ArgumentException aex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError(aex, CacheKeyLevel.UserLevel, login, aex.Message, 400); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError(ex, CacheKeyLevel.UserLevel, login, ex.Message, 500); } } } }