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