Add cancellation token support and extend timeout to 30 minutes for external API calls
All checks were successful
Build & Deploy Leave Service / build (push) Successful in 1m19s
All checks were successful
Build & Deploy Leave Service / build (push) Successful in 1m19s
This commit is contained in:
parent
0a170fd259
commit
659e06a08d
7 changed files with 76 additions and 76 deletions
|
|
@ -428,18 +428,26 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
public async Task<ActionResult<ResponseObject>> CheckTimeAsync()
|
||||
public async Task<ActionResult<ResponseObject>> CheckTimeAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
var userId = UserId == null ? Guid.Empty : Guid.Parse(UserId);
|
||||
var data = await _userTimeStampRepository.GetLastRecord(userId);
|
||||
|
||||
// Get user's last check-in record and profile in parallel
|
||||
var dataTask = _userTimeStampRepository.GetLastRecord(userId);
|
||||
var profileTask = _userProfileRepository.GetProfileByKeycloakIdNewAsync(userId, AccessToken);
|
||||
var defaultRoundTask = _dutyTimeRepository.GetDefaultAsync();
|
||||
|
||||
await Task.WhenAll(dataTask, profileTask, defaultRoundTask);
|
||||
|
||||
var data = await dataTask;
|
||||
var profile = await profileTask;
|
||||
var getDefaultRound = await defaultRoundTask;
|
||||
|
||||
var profile = await _userProfileRepository.GetProfileByKeycloakIdNewAsync(userId, AccessToken);
|
||||
if (profile == null)
|
||||
{
|
||||
throw new Exception(GlobalMessages.DataNotFound);
|
||||
}
|
||||
|
||||
var getDefaultRound = await _dutyTimeRepository.GetDefaultAsync();
|
||||
if (getDefaultRound == null)
|
||||
{
|
||||
return Error("ไม่พบรอบลงเวลา Default", StatusCodes.Status404NotFound);
|
||||
|
|
@ -451,65 +459,43 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
|
||||
var duty = userRound ?? getDefaultRound;
|
||||
|
||||
// TODO : รอดุึงรอบที่ผูกกับ user
|
||||
//var duty = await _dutyTimeRepository.GetDefaultAsync();
|
||||
CheckInResultDto ret;
|
||||
|
||||
if (data == null)
|
||||
{
|
||||
ret = new CheckInResultDto
|
||||
{
|
||||
StartTimeMorning = duty == null ? "00:00" : duty.StartTimeMorning,
|
||||
EndTimeMorning = duty == null ? "00:00" : duty.EndTimeMorning,
|
||||
StartTimeAfternoon = duty == null ? "00:00" : duty.StartTimeAfternoon,
|
||||
EndTimeAfternoon = duty == null ? "00:00" : duty.EndTimeAfternoon,
|
||||
Description = duty == null ? "-" : duty.Description,
|
||||
CheckInTime = null,
|
||||
CheckInId = null,
|
||||
};
|
||||
}
|
||||
else
|
||||
// Determine check-in status and data
|
||||
DateTime? checkInTime = null;
|
||||
Guid? checkInId = null;
|
||||
|
||||
if (data != null)
|
||||
{
|
||||
if (data.CheckOut != null)
|
||||
{
|
||||
// fix issue SIT ระบบบันทึกเวลาปฏิบัติงาน>>ลงเวลาเข้า-ออกงาน (กรณีลงเวลาออกอีกวัน) #921
|
||||
var cur_date = DateTime.Now.Date;
|
||||
// ถ้า check-in + check-out ไปแล้ว
|
||||
if (data.CheckIn.Date == cur_date && data.CheckOut.Value.Date == cur_date)
|
||||
var currentDate = DateTime.Now.Date;
|
||||
// ถ้า check-in + check-out ไปแล้วในวันเดียวกัน
|
||||
if (data.CheckIn.Date == currentDate && data.CheckOut.Value.Date == currentDate)
|
||||
{
|
||||
return Error("คุณได้ทำการลงเวลาเข้าและออกเรียบร้อยแล้ว คุณจะสามารถลงเวลาได้อีกครั้งในวันถัดไป");
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = new CheckInResultDto
|
||||
{
|
||||
StartTimeMorning = duty == null ? "00:00" : duty.StartTimeMorning,
|
||||
EndTimeMorning = duty == null ? "00:00" : duty.EndTimeMorning,
|
||||
StartTimeAfternoon = duty == null ? "00:00" : duty.StartTimeAfternoon,
|
||||
EndTimeAfternoon = duty == null ? "00:00" : duty.EndTimeAfternoon,
|
||||
Description = duty == null ? "-" : duty.Description,
|
||||
CheckInTime = null,
|
||||
CheckInId = null,
|
||||
};
|
||||
}
|
||||
// ถ้า check-out คนละวัน ให้แสดงว่ายังไม่ได้ check-in วันนี้
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = new CheckInResultDto
|
||||
{
|
||||
StartTimeMorning = duty == null ? "00:00" : duty.StartTimeMorning,
|
||||
EndTimeMorning = duty == null ? "00:00" : duty.EndTimeMorning,
|
||||
StartTimeAfternoon = duty == null ? "00:00" : duty.StartTimeAfternoon,
|
||||
EndTimeAfternoon = duty == null ? "00:00" : duty.EndTimeAfternoon,
|
||||
Description = duty == null ? "-" : duty.Description,
|
||||
CheckInTime = data.CheckIn,
|
||||
CheckInId = data.Id,
|
||||
};
|
||||
// มี check-in แต่ยังไม่ check-out
|
||||
checkInTime = data.CheckIn;
|
||||
checkInId = data.Id;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Create response DTO (duty is never null here due to fallback logic)
|
||||
var ret = new CheckInResultDto
|
||||
{
|
||||
StartTimeMorning = duty.StartTimeMorning,
|
||||
EndTimeMorning = duty.EndTimeMorning,
|
||||
StartTimeAfternoon = duty.StartTimeAfternoon,
|
||||
EndTimeAfternoon = duty.EndTimeAfternoon,
|
||||
Description = duty.Description,
|
||||
CheckInTime = checkInTime,
|
||||
CheckInId = checkInId,
|
||||
};
|
||||
|
||||
return Success(ret);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue