เพิ่มเงื่อนไข api

This commit is contained in:
Suphonchai Phoonsawat 2023-11-15 14:02:21 +07:00
parent 247071b246
commit 4d5170d9f6
2 changed files with 25 additions and 6 deletions

View file

@ -57,6 +57,16 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants
#region " Methods " #region " Methods "
public async Task<UserTimeStamp?> GetTimestampByDateAsync(Guid keycloakId,DateTime date)
{
var data = await _dbContext.Set<UserTimeStamp>()
.Where(u => u.KeycloakUserId == keycloakId)
.Where(u => u.CheckIn.Date == date.Date)
.FirstOrDefaultAsync();
return data;
}
public async Task<UserTimeStamp?> GetLastRecord(Guid keycloakId) public async Task<UserTimeStamp?> GetLastRecord(Guid keycloakId)
{ {
var data = await _dbContext.Set<UserTimeStamp>() var data = await _dbContext.Set<UserTimeStamp>()

View file

@ -9,6 +9,7 @@ using BMA.EHR.Infrastructure.Persistence;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Swashbuckle.AspNetCore.Annotations; using Swashbuckle.AspNetCore.Annotations;
using System.ComponentModel.DataAnnotations;
using System.Security.Claims; using System.Security.Claims;
namespace BMA.EHR.Command.Service.Controllers namespace BMA.EHR.Command.Service.Controllers
@ -377,6 +378,14 @@ namespace BMA.EHR.Command.Service.Controllers
// create check in object // create check in object
if (data.CheckInId == null) if (data.CheckInId == null)
{ {
// validate duplicate check in
var currentCheckIn = await _userTimeStampRepository.GetTimestampByDateAsync(Guid.Parse(UserId), currentDate);
if (currentCheckIn != null)
{
throw new Exception("ไม่สามารถลงเวลาได้ เนืองจากมีการลงเวลาในวันนี้แล้ว!");
}
var checkin = new UserTimeStamp var checkin = new UserTimeStamp
{ {
KeycloakUserId = UserId != null ? Guid.Parse(UserId) : Guid.Empty, KeycloakUserId = UserId != null ? Guid.Parse(UserId) : Guid.Empty,
@ -436,7 +445,7 @@ namespace BMA.EHR.Command.Service.Controllers
// TODO : รอดุึงรอบที่ผูกกับ user // TODO : รอดุึงรอบที่ผูกกับ user
var duty = await _dutyTimeRepository.GetDefaultAsync(); var duty = await _dutyTimeRepository.GetDefaultAsync();
if(duty == null) if (duty == null)
{ {
throw new Exception(GlobalMessages.DataNotFound); throw new Exception(GlobalMessages.DataNotFound);
} }
@ -482,7 +491,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>> LogRecordAsync(DateTime startDate, DateTime endDate, int page = 1, int pageSize = 10, string keyword = "") public async Task<ActionResult<ResponseObject>> LogRecordAsync([Required] DateTime startDate, [Required] DateTime endDate, int page = 1, int pageSize = 10, string keyword = "")
{ {
var imgUrl = $"{_configuration["MinIO:Endpoint"]}{_configuration["MinIO:BucketName"]}"; var imgUrl = $"{_configuration["MinIO:Endpoint"]}{_configuration["MinIO:BucketName"]}";
var data = (await _userTimeStampRepository.GetTimeStampHistoryForAdminAsync(startDate, endDate, page, pageSize, keyword)) var data = (await _userTimeStampRepository.GetTimeStampHistoryForAdminAsync(startDate, endDate, page, pageSize, keyword))