using System.Threading; using DocumentFormat.OpenXml.Bibliography; using FastEndpoints; using FrameworkBLL.CommonReport; using FrameworkBLL.DocumentSet; using FrameworkSL.Endpoints.DocumentSet; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.DTO.Report; using GB5Shared.FastEndPoint; using Google.Protobuf; using static GB5Shared.GB5Constant.Constant; namespace FrameworkSL.Endpoints.CommonReport { public class Report : BaseEndpoint { private readonly ICommonReportBLL _ICommonReportBLL; public Report(ICommonReportBLL ICommonReportBLL) { _ICommonReportBLL = ICommonReportBLL; } public override void Configure() { Post("/CommonReport/Report"); AllowAnonymous(); } public record ReportStandardAsyncReq( [property: FromBody] ReportCallingDTO ReportCallingDTO, [property: FromHeader] string Login ); protected override async Task> ExecuteAsync( ReportStandardAsyncReq ReportReq, LoginDTO LoginDTO, CancellationToken CancellationToken) { try { object? result; switch (ReportReq.ReportCallingDTO.IsExcelImport) { case FILEFORMAT.EXCEL: result = await _ICommonReportBLL.ExcelExport(ReportReq.ReportCallingDTO, LoginDTO, CancellationToken); break; case FILEFORMAT.CSV: result = await _ICommonReportBLL.CSVExport(ReportReq.ReportCallingDTO, LoginDTO, CancellationToken); break; case FILEFORMAT.PDF: result = await _ICommonReportBLL.PdfExport(ReportReq.ReportCallingDTO, LoginDTO, CancellationToken); break; case FILEFORMAT.PDFNATIVE: result = await _ICommonReportBLL.PdfNativeExport(ReportReq.ReportCallingDTO, LoginDTO, CancellationToken); break; case FILEFORMAT.JSON: result = await _ICommonReportBLL.JsonReport(ReportReq.ReportCallingDTO, LoginDTO, CancellationToken); break; default: throw new NotSupportedException($"File format {ReportReq.ReportCallingDTO.IsExcelImport} is not supported."); } return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse( result!, CacheKeyLevel.NOT_REQUIRED, LoginDTO ); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError(ex, CacheKeyLevel.USER_LEVEL, LoginDTO, ex.Message, 500); } } } }