using DXPBLL.Kyc; using DXPDAL.Common; 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.Kyc; // Multipart upload — ObjectTypeId is hardcoded to OBJECTDXPPARTYKYCPROFILE server-side (never // client-supplied) so this endpoint can't be used to tag an attachment against an unrelated // entity. ObjectId is typically 0 at this point (profile doesn't exist yet) — RowGuid is what // KycBLL.SubmitAsync later resolves against via UAS's two-phase pattern (see KycBLL.cs). public class UploadKycDocument : DXPBaseEndpoint> { private readonly IKycBLL _bll; private readonly IDXPSystemContext _systemContext; public UploadKycDocument(IKycBLL bll, IDXPSystemContext systemContext) { _bll = bll; _systemContext = systemContext; } public record UploadKycDocumentParameters( [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/Kyc/UploadDocument"); AllowFileUploads(); } protected override async Task> ExecuteAsync( UploadKycDocumentParameters 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.OBJECTDXPPARTYKYCPROFILE, ObjectId = req.ObjectId, RowGuid = req.RowGuid, Remarks = req.Remarks, Tags = req.Tags ?? string.Empty }; var result = await _bll.UploadDocumentAsync( uploadRequest, stream, file.FileName, file.ContentType, _systemContext.GetSystemLogin(caller.DxpUserId), ct); return new ResponseStandardDTO { Status = FrameworkEnumDTO.ResponseStatus.Ok, Body = result }; } }