change insigniaTypeId เป็น optional
Some checks failed
release-dev / release-dev (push) Failing after 11s

This commit is contained in:
Suphonchai Phoonsawat 2025-05-07 14:05:08 +07:00
parent 8ce58201e9
commit 0b407f3c68
4 changed files with 116 additions and 78 deletions

View file

@ -4,8 +4,10 @@ using BMA.EHR.Application.Requests;
using BMA.EHR.Application.Responses.Profiles; using BMA.EHR.Application.Responses.Profiles;
using BMA.EHR.Domain.Common; using BMA.EHR.Domain.Common;
using BMA.EHR.Domain.Models.Insignias; using BMA.EHR.Domain.Models.Insignias;
using BMA.EHR.Domain.Models.MetaData;
using BMA.EHR.Domain.Shared; using BMA.EHR.Domain.Shared;
using BMA.EHR.Infrastructure.Persistence; using BMA.EHR.Infrastructure.Persistence;
using BMA.EHR.Insignia.Service.Requests;
using Elasticsearch.Net; using Elasticsearch.Net;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@ -583,8 +585,8 @@ namespace BMA.EHR.Insignia.Service.Controllers
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response> /// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response> /// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response> /// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpGet("reclaim/{year}/{insigniaTypeId:length(36)}")] [HttpPost("reclaim-list")]
public async Task<ActionResult<ResponseObject>> ListReclaimInsignia(int year, Guid insigniaTypeId) public async Task<ActionResult<ResponseObject>> ListReclaimInsignia([FromBody] GetReclaimListRequest req)
{ {
var getPermission = await _permission.GetPermissionAPIAsync("LIST", "SYS_INSIGNIA_RECLAIM"); var getPermission = await _permission.GetPermissionAPIAsync("LIST", "SYS_INSIGNIA_RECLAIM");
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission); var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
@ -592,10 +594,16 @@ namespace BMA.EHR.Insignia.Service.Controllers
{ {
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden); return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
} }
var insigniaType = await _context.InsigniaTypes
.FirstOrDefaultAsync(x => x.Id == insigniaTypeId); InsigniaType? insigniaType = null;
if (req.InsigniaTypeId != null)
{
insigniaType = await _context.InsigniaTypes
.FirstOrDefaultAsync(x => x.Id == req.InsigniaTypeId);
if (insigniaType == null) if (insigniaType == null)
return Error(GlobalMessages.InsigniaTypeNotFound); return Error(GlobalMessages.InsigniaTypeNotFound);
}
string role = jsonData["result"]; string role = jsonData["result"];
var nodeId = string.Empty; var nodeId = string.Empty;
@ -623,8 +631,11 @@ namespace BMA.EHR.Insignia.Service.Controllers
var node = profileAdmin?.Node; var node = profileAdmin?.Node;
var rawData = await _context.InsigniaReclaimProfiles.AsQueryable() var rawData = await _context.InsigniaReclaimProfiles.AsQueryable()
.Where(x => x.InsigniaNoteProfile.RequestInsignia.InsigniaType == insigniaType) .Include(x => x.InsigniaNoteProfile)
.Where(x => year == 0 ? x.Id != null : x.ReclaimDate!.Value.Year == year) .ThenInclude(x => x.RequestInsignia)
.ThenInclude(x => x.InsigniaType)
//.Where(x => x.InsigniaNoteProfile.RequestInsignia.InsigniaType == insigniaType)
.Where(x => req.Year == 0 ? x.Id != null : x.ReclaimDate!.Value.Year == req.Year)
.OrderByDescending(x => x.CreatedAt) .OrderByDescending(x => x.CreatedAt)
.Select(p => new .Select(p => new
{ {
@ -668,9 +679,15 @@ namespace BMA.EHR.Insignia.Service.Controllers
Child3DnaId = p.InsigniaNoteProfile.Child3DnaId, Child3DnaId = p.InsigniaNoteProfile.Child3DnaId,
Child4DnaId = p.InsigniaNoteProfile.Child4DnaId, Child4DnaId = p.InsigniaNoteProfile.Child4DnaId,
InsigniaTypeId = p.InsigniaNoteProfile.RequestInsignia.InsigniaType.Id
}).ToListAsync(); }).ToListAsync();
if (req.InsigniaTypeId != null)
{
rawData = rawData.Where(x => x.InsigniaTypeId == req.InsigniaTypeId).ToList();
}
if (role == "OWNER") if (role == "OWNER")
{ {

View file

@ -7,6 +7,7 @@ using BMA.EHR.Application.Responses.Organizations;
using BMA.EHR.Domain.Common; using BMA.EHR.Domain.Common;
using BMA.EHR.Domain.Extensions; using BMA.EHR.Domain.Extensions;
using BMA.EHR.Domain.Models.Insignias; using BMA.EHR.Domain.Models.Insignias;
using BMA.EHR.Domain.Models.MetaData;
using BMA.EHR.Domain.Shared; using BMA.EHR.Domain.Shared;
using BMA.EHR.Infrastructure.Persistence; using BMA.EHR.Infrastructure.Persistence;
using BMA.EHR.Insignia.Service.Requests; using BMA.EHR.Insignia.Service.Requests;
@ -1417,17 +1418,23 @@ namespace BMA.EHR.Insignia.Service.Controllers
.FirstOrDefaultAsync(x => x.Id == req.InsigniaNoteId); .FirstOrDefaultAsync(x => x.Id == req.InsigniaNoteId);
if (insigniaNote == null) if (insigniaNote == null)
return Error(GlobalMessages.InsigniaRequestNotFound); return Error(GlobalMessages.InsigniaRequestNotFound);
var insigniaType = await _context.InsigniaTypes
InsigniaType? insigniaType = null;
if (req.InsigniaTypeId != null)
{
insigniaType = await _context.InsigniaTypes
.FirstOrDefaultAsync(x => x.Id == req.InsigniaTypeId); .FirstOrDefaultAsync(x => x.Id == req.InsigniaTypeId);
if (insigniaType == null) if (insigniaType == null)
return Error(GlobalMessages.InsigniaTypeNotFound); return Error(GlobalMessages.InsigniaTypeNotFound);
}
var rawNoteProfiles = await _context.InsigniaNoteProfiles var rawNoteProfiles = await _context.InsigniaNoteProfiles
.Where(x => x.InsigniaNote == insigniaNote) .Where(x => x.InsigniaNote == insigniaNote)
.Where(x => x.RequestInsignia.InsigniaType == insigniaType) //.Where(x => x.RequestInsignia.InsigniaType == insigniaType)
.Where(x => req.InsigniaId == null ? x.RequestInsignia != null : (x.RequestInsignia.Id == req.InsigniaId)) .Where(x => req.InsigniaId == null ? x.RequestInsignia != null : (x.RequestInsignia.Id == req.InsigniaId))
.Select(x => new .Select(x => new
{ {
InsigniaTypeId = x.RequestInsignia.InsigniaType.Id,
Id = x.Id, Id = x.Id,
x.CitizenId, x.CitizenId,
x.Prefix, x.Prefix,
@ -1465,6 +1472,11 @@ namespace BMA.EHR.Insignia.Service.Controllers
}) })
.ToListAsync(); .ToListAsync();
if (req.InsigniaTypeId != null)
{
rawNoteProfiles = rawNoteProfiles.Where(x => x.InsigniaTypeId == req.InsigniaTypeId).ToList();
}
var insigniaNoteProfiles = rawNoteProfiles var insigniaNoteProfiles = rawNoteProfiles
.Select(x => new .Select(x => new
{ {

View file

@ -0,0 +1,9 @@
namespace BMA.EHR.Insignia.Service.Requests
{
public class GetReclaimListRequest
{
public int Year { get; set; } = 0;
public Guid? InsigniaTypeId { get; set; }
}
}

View file

@ -5,7 +5,7 @@ namespace BMA.EHR.Insignia.Service.Requests
{ {
public class InsigniaNoteSearchRequest public class InsigniaNoteSearchRequest
{ {
public Guid InsigniaTypeId { get; set; } public Guid? InsigniaTypeId { get; set; }
public Guid InsigniaNoteId { get; set; } public Guid InsigniaNoteId { get; set; }
public Guid? InsigniaId { get; set; } public Guid? InsigniaId { get; set; }
} }