feat(OrderController): add PostDocument to hand document upload process
This commit is contained in:
parent
6044d0bcb6
commit
ccecf47dca
@ -5,8 +5,9 @@ using MediatR;
|
|||||||
|
|
||||||
namespace Leanetec.EConnect.Client.Order;
|
namespace Leanetec.EConnect.Client.Order;
|
||||||
|
|
||||||
public record PostDocumentRequest(string TenantId, int OrderId, StreamContent Content) : HttpRequest<Response<ProblemDetail>>
|
public record PostDocumentRequest(string TenantId, int OrderId) : HttpRequest<Response<ProblemDetail>>
|
||||||
{
|
{
|
||||||
|
public StreamContent Content { get; set; } = null!;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class PostDocumentRequestHandler : IRequestHandler<PostDocumentRequest, Response<ProblemDetail>>
|
public class PostDocumentRequestHandler : IRequestHandler<PostDocumentRequest, Response<ProblemDetail>>
|
||||||
|
|||||||
@ -6,8 +6,16 @@ public record Response<TError>() where TError : class
|
|||||||
{
|
{
|
||||||
public bool Ok { get; init; }
|
public bool Ok { get; init; }
|
||||||
|
|
||||||
public HttpStatusCode? StatusCode { get; init; }
|
private HttpStatusCode? _statusCode;
|
||||||
|
|
||||||
|
public HttpStatusCode StatusCode
|
||||||
|
{
|
||||||
|
get => _statusCode ?? (Ok ? HttpStatusCode.OK : HttpStatusCode.InternalServerError);
|
||||||
|
init => _statusCode = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int StatusCodeInt => (int)StatusCode;
|
||||||
|
|
||||||
public TError? Error { get; init; }
|
public TError? Error { get; init; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -91,7 +91,6 @@ public class EConnectClient<TError> : IEConnectClient<TError> where TError : cl
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Response<TError>> PostAsync(string? route = null, object? queryParams = null, CancellationToken cancel = default)
|
public async Task<Response<TError>> PostAsync(string? route = null, object? queryParams = null, CancellationToken cancel = default)
|
||||||
where TData : class
|
|
||||||
{
|
{
|
||||||
route = AddQueryString(route, queryParams);
|
route = AddQueryString(route, queryParams);
|
||||||
|
|
||||||
@ -118,7 +117,6 @@ public class EConnectClient<TError> : IEConnectClient<TError> where TError : cl
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Response<TError>> PostAsync(StreamContent content, string? route = null, object? queryParams = null, CancellationToken cancel = default)
|
public async Task<Response<TError>> PostAsync(StreamContent content, string? route = null, object? queryParams = null, CancellationToken cancel = default)
|
||||||
where TData : class
|
|
||||||
{
|
{
|
||||||
route = AddQueryString(route, queryParams);
|
route = AddQueryString(route, queryParams);
|
||||||
|
|
||||||
|
|||||||
@ -28,4 +28,26 @@ public class OrderController : ControllerBase
|
|||||||
return StatusCode(res?.Error?.Status ?? 500, res?.Error);
|
return StatusCode(res?.Error?.Status ?? 500, res?.Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpPost("document")]
|
||||||
|
public async Task<IActionResult> PostDocument(IFormFile file, [FromQuery] PostDocumentRequest request, CancellationToken cancel)
|
||||||
|
{
|
||||||
|
using var content = new MultipartFormDataContent();
|
||||||
|
using var stream = file.OpenReadStream();
|
||||||
|
using var streamContent = new StreamContent(stream);
|
||||||
|
streamContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(file.ContentType);
|
||||||
|
content.Add(streamContent, "file", file.FileName);
|
||||||
|
request.Content = streamContent;
|
||||||
|
|
||||||
|
var res = await _mediator.Send(request, cancel);
|
||||||
|
|
||||||
|
if (res.Ok)
|
||||||
|
{
|
||||||
|
return StatusCode(res.StatusCodeInt);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return StatusCode(res?.Error?.Status ?? 500, res?.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user