Add ScheduleUpdateDna endpoint and DTO for updating DNA information in LeaveBeginningController
All checks were successful
Build & Deploy Leave Service / build (push) Successful in 1m35s

This commit is contained in:
Suphonchai Phoonsawat 2026-02-25 15:26:49 +07:00
parent 9a74b690cd
commit 006cea048d
2 changed files with 53 additions and 0 deletions

View file

@ -577,6 +577,44 @@ namespace BMA.EHR.Leave.Service.Controllers
}
}
[HttpPut("schedule/update-dna")]
[AllowAnonymous]
public async Task<ActionResult<ResponseObject>> ScheduleUpdateDnaAsync([FromBody] ScheduleUpdateDnaDto req)
{
try
{
var profile = await _userProfileRepository.GetProfileByProfileIdNoAuthAsync(req.ProfileId, AccessToken);
if(profile == null)
{
return Error("ไม่พบข้อมูลข้าราชการหรือลูกจ้าง", StatusCodes.Status404NotFound);
}
// check duplicate
var oldData = await _context.LeaveBeginnings.Where(x => x.ProfileId == req.ProfileId
&& x.LeaveYear == req.LeaveYear).ToListAsync();
foreach(var item in oldData)
{
item.RootDnaId = profile.RootDnaId;
item.Child1DnaId = profile.Child1DnaId;
item.Child2DnaId = profile.Child2DnaId;
item.Child3DnaId = profile.Child3DnaId;
item.Child4DnaId = profile.Child4DnaId;
item.LastUpdateUserId = "";
item.LastUpdateFullName = "System";
item.LastUpdatedAt = DateTime.Now;
await _leaveBeginningRepository.UpdateAsync(item);
}
return Success();
}
catch (Exception ex)
{
return Error(ex);
}
}
#endregion
}
}

View file

@ -45,4 +45,19 @@ namespace BMA.EHR.Leave.Service.DTOs.LeaveBeginnings
[Required, Comment("จำนวนวันลายกมา")]
public double LeaveDays { get; set; } = 0.0;
}
public class ScheduleUpdateDnaDto
{
[Required]
public Guid ProfileId { get; set; } = Guid.Empty;
[Required, Comment("ปีงบประมาณ")]
public int LeaveYear { get; set; } = 0;
public Guid? RootDnaId { get; set; }
public Guid? Child1DnaId { get; set; }
public Guid? Child2DnaId { get; set; }
public Guid? Child3DnaId { get; set; }
public Guid? Child4DnaId { get; set; }
}
}