using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using MarketingBLL.Advertisement; using static GB5Shared.GB5Constant.Constant; namespace MarketingSL.EndPoints.Advertisement; public class GetAdvertisement : BaseEndpoint> { private readonly IAdvertisementBLL _AdvertisementBLL; public GetAdvertisement(IAdvertisementBLL advertisementBLL) => _AdvertisementBLL = advertisementBLL; public override void Configure() { Get("/Advertisement/GetAdvertisement"); AllowAnonymous(); } public record GetAdvertisementParameters( [property: QueryParam] int AdId, [property: FromHeader] string Login ); protected override string? GetCacheKey(GetAdvertisementParameters req, LoginDTO login) => KeyGenerator.KeyGeneration(req.AdId, EntityConstant.OBJECTMARKETINGADVERTISEMENT, CacheKeyLevel.CLIENT_LEVEL, login); protected override async Task> ExecuteAsync(GetAdvertisementParameters req, LoginDTO login, CancellationToken ct) { try { var result = await _AdvertisementBLL.GetAdvertisement(req.AdId, login!, ct); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse(result, CacheKeyLevel.CLIENT_LEVEL, login); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError(ex, CacheKeyLevel.CLIENT_LEVEL, login, ex.Message, 500); } } }