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