fix upload attatchment

This commit is contained in:
Suphonchai Phoonsawat 2023-08-08 12:37:02 +07:00
parent aff4dcd38d
commit 68c9ed1ad9
3 changed files with 68 additions and 18 deletions

View file

@ -1,7 +1,6 @@
using BMA.EHR.Application.Common.Interfaces; using BMA.EHR.Application.Common.Interfaces;
using BMA.EHR.Application.Requests.Commands; using BMA.EHR.Application.Requests.Commands;
using BMA.EHR.Application.Responses; using BMA.EHR.Application.Responses;
using BMA.EHR.Domain.Extensions;
using BMA.EHR.Domain.Models.Commands.Core; using BMA.EHR.Domain.Models.Commands.Core;
using BMA.EHR.Domain.Models.MetaData; using BMA.EHR.Domain.Models.MetaData;
using BMA.EHR.Domain.Models.Organizations; using BMA.EHR.Domain.Models.Organizations;
@ -48,7 +47,7 @@ namespace BMA.EHR.Application.Repositories.Commands
case "C-PM-01": case "C-PM-01":
case "C-PM-02": case "C-PM-02":
case "C-PM-03": case "C-PM-03":
result = await GetReceiver01(command); result = await GetReceiver01Async(command);
break; break;
default: throw new Exception(GlobalMessages.MethodForCommandTypeNotImplement); default: throw new Exception(GlobalMessages.MethodForCommandTypeNotImplement);
} }
@ -61,7 +60,7 @@ namespace BMA.EHR.Application.Repositories.Commands
/// </summary> /// </summary>
/// <param name="command"></param> /// <param name="command"></param>
/// <returns></returns> /// <returns></returns>
private async Task<List<CommandReceiver>> GetReceiver01(Command command) private async Task<List<CommandReceiver>> GetReceiver01Async(Command command)
{ {
try try
{ {
@ -120,6 +119,32 @@ namespace BMA.EHR.Application.Repositories.Commands
#region " Execute and Deploy " #region " Execute and Deploy "
private async Task ExecuteCommandByTypeAsync(Command command)
{
switch (command.CommandType.CommandCode.Trim().ToUpper())
{
case "C-PM-01":
case "C-PM-02":
case "C-PM-03":
await ExecuteCommand01Async(command);
break;
default: throw new Exception(GlobalMessages.MethodForCommandTypeNotImplement);
}
}
private async Task ExecuteCommand01Async(Command command)
{
try
{
}
catch
{
throw;
}
}
#endregion #endregion
@ -579,17 +604,21 @@ namespace BMA.EHR.Application.Repositories.Commands
{ {
try try
{ {
var command = await _dbContext.Set<Command>().Include(x => x.Documents).FirstOrDefaultAsync(c => c.Id == id); var command = await _dbContext.Set<Command>()
.Include(x => x.Documents)
//.ThenInclude(x =>x.Document)
.FirstOrDefaultAsync(c => c.Id == id);
if (command == null) if (command == null)
throw new Exception(GlobalMessages.CommandNotFound); throw new Exception(GlobalMessages.CommandNotFound);
// insert new record to comand Document // insert new record to comand Document
var exist = command.Documents.Where(x => x.Category == category).ToList(); //var exist = command.Documents.Where(x => x.Category == category).ToList();
if (exist.Any()) //if (exist.Any())
{ //{
_dbContext.Set<CommandDocument>().RemoveRange(exist); // _dbContext.Set<CommandDocument>().RemoveRange(exist);
await _dbContext.SaveChangesAsync(); // await _dbContext.SaveChangesAsync();
} //}
// insert new Record // insert new Record
command.Documents.Add(document); command.Documents.Add(document);

View file

@ -601,7 +601,7 @@ namespace BMA.EHR.Command.Service.Controllers
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)] [ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<ResponseObject>> SaveCommandSelectReceiverAsync(Guid orderId,[FromBody] List<Guid> selected) public async Task<ActionResult<ResponseObject>> SaveCommandSelectReceiverAsync(Guid orderId, [FromBody] List<Guid> selected)
{ {
try try
{ {
@ -853,8 +853,8 @@ namespace BMA.EHR.Command.Service.Controllers
orderNo = command.CommandNo, orderNo = command.CommandNo,
orderYear = command.CommandYear, orderYear = command.CommandYear,
signDate = command.CommandExcecuteDate, signDate = command.CommandExcecuteDate,
orderFileUrl = cover == null ? null : _documentService.ImagesPath(cover.Document.ObjectRefId), orderFileUrl = cover == null ? null : await _documentService.ImagesPath(cover.Document.Id),
attachmentFileUrl = attach == null ? null : _documentService.ImagesPath(attach.Document.ObjectRefId), attachmentFileUrl = attach == null ? null : await _documentService.ImagesPath(attach.Document.Id),
}; };
return Success(result); return Success(result);
@ -875,6 +875,16 @@ namespace BMA.EHR.Command.Service.Controllers
/// <response code="401">ไม่ได้ Login เข้าระบบ</response> /// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response> /// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpPost("attachment/order-file/{orderId}"), DisableRequestSizeLimit] [HttpPost("attachment/order-file/{orderId}"), DisableRequestSizeLimit]
[Consumes("multipart/form-data")]
[SwaggerOperation(
Summary = "Upload a file",
Description = "Upload a file using multipart/form-data",
OperationId = "UploadCommandCoverAsync"
//Tags = new[] { "File" }
)]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<ResponseObject>> UploadCommandCoverAsync(Guid orderId) public async Task<ActionResult<ResponseObject>> UploadCommandCoverAsync(Guid orderId)
{ {
try try
@ -893,7 +903,7 @@ namespace BMA.EHR.Command.Service.Controllers
// delete exist document from s3 // delete exist document from s3
foreach (var doc in docs) foreach (var doc in docs)
{ {
await _documentService.DeleteFileAsync(doc.Document.ObjectRefId); await _documentService.DeleteFileAsync(doc.Document.Id);
} }
// upload new document to s3 // upload new document to s3
@ -926,6 +936,16 @@ namespace BMA.EHR.Command.Service.Controllers
/// <response code="401">ไม่ได้ Login เข้าระบบ</response> /// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response> /// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpPost("attachment/file/{orderId}"), DisableRequestSizeLimit] [HttpPost("attachment/file/{orderId}"), DisableRequestSizeLimit]
[Consumes("multipart/form-data")]
[SwaggerOperation(
Summary = "Upload a file",
Description = "Upload a file using multipart/form-data",
OperationId = "UploadCommandAttachmentAsync"
//Tags = new[] { "File" }
)]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<ResponseObject>> UploadCommandAttachmentAsync(Guid orderId) public async Task<ActionResult<ResponseObject>> UploadCommandAttachmentAsync(Guid orderId)
{ {
try try
@ -942,9 +962,10 @@ namespace BMA.EHR.Command.Service.Controllers
var docs = await _repository.GetExistDocument(orderId, GlobalConstants.TYPE_ATTACHMENT); var docs = await _repository.GetExistDocument(orderId, GlobalConstants.TYPE_ATTACHMENT);
// delete exist document from s3 // delete exist document from s3
foreach (var doc in docs) foreach (var doc in docs)
{ {
await _documentService.DeleteFileAsync(doc.Document.ObjectRefId); await _documentService.DeleteFileAsync(doc.Document.Id);
} }
// upload new document to s3 // upload new document to s3

View file

@ -26,10 +26,10 @@
} }
}, },
"MinIO": { "MinIO": {
"Endpoint": "https://s3.frappet.com/", "Endpoint": "https://s3cluster.frappet.com/",
"AccessKey": "frappet", "AccessKey": "frappet",
"SecretKey": "P@ssw0rd", "SecretKey": "FPTadmin2357",
"BucketName": "bma-recruit" "BucketName": "bma-ehr-fpt"
}, },
"Protocol": "HTTPS" "Protocol": "HTTPS"
} }