using DXPBLL.Asn; using DXPSL.Common; using FastEndpoints; using GB5Shared.DTO.ECM; using GB5Shared.DTO.Framework.Enum; using GB5Shared.DTO.Framework.ResponseStandard; using static GB5Shared.GB5Constant.Constant; namespace DXPSL.Endpoints.Asn; // Multipart upload — ObjectTypeId hardcoded to OBJECTDXPASN server-side (never client-supplied), // same pattern as UploadKycDocument.cs. ObjectId is typically 0 (the ASN's TMMHEAD row doesn't // exist yet) — RowGuid is what AsnBLL.CreateAsnAsync later resolves via UAS's two-phase pattern. // Uses the TENANT database (not DXPDb) since that's where the ASN's TMMHEAD row will live. public class UploadDeliveryChallan : DXPBaseEndpoint> { private readonly IAsnBLL _bll; public UploadDeliveryChallan(IAsnBLL bll) { _bll = bll; } public record UploadDeliveryChallanParameters( [property: QueryParam] int DocumentSetDetailId, [property: QueryParam] int ObjectId, [property: QueryParam] Guid RowGuid, [property: QueryParam] string? Remarks, [property: QueryParam] string? Tags ); public override void Configure() { Post("/DXP/Asn/UploadDeliveryChallan"); AllowFileUploads(); } protected override async Task> ExecuteAsync( UploadDeliveryChallanParameters req, DXPCallerContext caller, CancellationToken ct) { var file = HttpContext.Request.Form.Files.FirstOrDefault(); if (file is null || file.Length == 0) throw new ArgumentException("No file provided or file is empty."); await using var stream = file.OpenReadStream(); var uploadRequest = new AttachmentUploadRequest { DocumentSetDetailId = req.DocumentSetDetailId, ObjectTypeId = EntityConstant.OBJECTDXPASN, ObjectId = req.ObjectId, RowGuid = req.RowGuid, Remarks = req.Remarks, Tags = req.Tags ?? string.Empty }; var result = await _bll.UploadDeliveryChallanAsync( uploadRequest, stream, file.FileName, file.ContentType, caller.TenantId, caller.DatabaseName, caller.DatabaseType, caller.LocalPartyId, caller.DxpUserId, ct); return new ResponseStandardDTO { Status = FrameworkEnumDTO.ResponseStatus.Ok, Body = result }; } }