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