From c9f68b045b279aafd157bf47f4aa1c243aebe462 Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Thu, 9 Nov 2023 15:07:19 +0700 Subject: [PATCH] =?UTF-8?q?add=20api=20LV1=5F012=20-=20=E0=B8=82=E0=B9=89?= =?UTF-8?q?=E0=B8=AD=E0=B8=A1=E0=B8=B9=E0=B8=A5=E0=B8=97=E0=B8=B1=E0=B9=89?= =?UTF-8?q?=E0=B8=87=E0=B8=AB=E0=B8=A1=E0=B8=94=E0=B8=82=E0=B8=AD=E0=B8=87?= =?UTF-8?q?=E0=B8=A3=E0=B8=AD=E0=B8=9A=E0=B8=81=E0=B8=B2=E0=B8=A3=E0=B8=9B?= =?UTF-8?q?=E0=B8=8F=E0=B8=B4=E0=B8=9A=E0=B8=B1=E0=B8=95=E0=B8=B4=E0=B8=87?= =?UTF-8?q?=E0=B8=B2=E0=B8=99=E0=B8=97=E0=B8=B5=E0=B9=88=20active=20(ADMIN?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Repositories/Leaves/DutyTimeRepository.cs | 10 ++ .../Controllers/RoundController.cs | 94 +++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 BMA.EHR.Leave.Service/Controllers/RoundController.cs diff --git a/BMA.EHR.Application/Repositories/Leaves/DutyTimeRepository.cs b/BMA.EHR.Application/Repositories/Leaves/DutyTimeRepository.cs index ac55fa2a..57e5880f 100644 --- a/BMA.EHR.Application/Repositories/Leaves/DutyTimeRepository.cs +++ b/BMA.EHR.Application/Repositories/Leaves/DutyTimeRepository.cs @@ -2,6 +2,7 @@ using BMA.EHR.Application.Messaging; using BMA.EHR.Domain.Models.Leave; using Microsoft.AspNetCore.Http; +using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; namespace BMA.EHR.Application.Repositories.Leaves @@ -52,5 +53,14 @@ namespace BMA.EHR.Application.Repositories.Leaves } #endregion + + #region " Methods " + + public async Task> GetAllActiveAsync() + { + return await _dbContext.Set().Where(x => x.IsActive).ToListAsync(); + } + + #endregion } } diff --git a/BMA.EHR.Leave.Service/Controllers/RoundController.cs b/BMA.EHR.Leave.Service/Controllers/RoundController.cs new file mode 100644 index 00000000..ccaf315f --- /dev/null +++ b/BMA.EHR.Leave.Service/Controllers/RoundController.cs @@ -0,0 +1,94 @@ +using BMA.EHR.Application.Repositories; +using BMA.EHR.Application.Repositories.Leaves; +using BMA.EHR.Domain.Common; +using BMA.EHR.Infrastructure.Persistence; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Swashbuckle.AspNetCore.Annotations; +using System.Security.Claims; + +namespace BMA.EHR.Command.Service.Controllers +{ + [Route("api/v{version:apiVersion}/leave/round")] + [ApiVersion("1.0")] + [ApiController] + [Produces("application/json")] + [Authorize] + [SwaggerTag("API ระบบจัดการรอบการลงเวลาทำงาน")] + public class RoundController : BaseController + { + #region " Fields " + + private readonly DutyTimeRepository _repository; + private readonly LeaveDbContext _context; + private readonly IHttpContextAccessor _httpContextAccessor; + private readonly IWebHostEnvironment _hostingEnvironment; + private readonly IConfiguration _configuration; + private readonly UserProfileRepository _userProfileRepository; + + #endregion + + #region " Constuctor and Destructor " + + public RoundController(DutyTimeRepository repository, + LeaveDbContext context, + IHttpContextAccessor httpContextAccessor, + IWebHostEnvironment hostingEnvironment, + IConfiguration configuration, + UserProfileRepository userProfileRepository) + { + _repository = repository; + _context = context; + _httpContextAccessor = httpContextAccessor; + _hostingEnvironment = hostingEnvironment; + _configuration = configuration; + _userProfileRepository = userProfileRepository; + } + + #endregion + + #region " Properties " + + private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value; + + private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value; + + private bool? PlacementAdmin => _httpContextAccessor?.HttpContext?.User?.IsInRole("placement1"); + + private Guid OcId + { + get + { + if (UserId != null || UserId != "") + return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!)); + else + return Guid.Empty; + } + } + + #endregion + + #region " Methods " + + /// + /// LV1_012 - ข้อมูลทั้งหมดของรอบการปฏิบัติงานที่ active (ADMIN) + /// + /// + /// + /// เมื่อทำรายการสำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpGet] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> GetAllActiveAsync() + { + var data = await _repository.GetAllActiveAsync(); + + return Success(data); + } + + #endregion + } +}