api holiday
This commit is contained in:
parent
692acf831a
commit
b1b8d96e57
14 changed files with 1217 additions and 65 deletions
310
BMA.EHR.MetaData.Service/Controllers/HolidayController.cs
Normal file
310
BMA.EHR.MetaData.Service/Controllers/HolidayController.cs
Normal file
|
|
@ -0,0 +1,310 @@
|
|||
using BMA.EHR.Domain.Common;
|
||||
using BMA.EHR.Domain.Models.MetaData;
|
||||
using BMA.EHR.MetaData.Service.Request;
|
||||
using BMA.EHR.MetaData.Service.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Swashbuckle.AspNetCore.Annotations;
|
||||
|
||||
namespace BMA.EHR.MetaData.Service.Controllers
|
||||
{
|
||||
[Route("api/v{version:apiVersion}/metadata/holiday")]
|
||||
[ApiVersion("1.0")]
|
||||
[ApiController]
|
||||
[Produces("application/json")]
|
||||
[Authorize]
|
||||
[SwaggerTag("จัดการข้อมูลปฏิทินวันหยุด")]
|
||||
public class HolidayController : BaseController
|
||||
{
|
||||
#region " Fields "
|
||||
|
||||
private readonly HolidayService _holidayService;
|
||||
|
||||
#endregion
|
||||
|
||||
#region " Constructor and Destructor "
|
||||
|
||||
public HolidayController(HolidayService holidayService)
|
||||
{
|
||||
_holidayService = holidayService;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region " Methods "
|
||||
|
||||
/// <summary>
|
||||
/// อ่านข้อมูลจาก Relational Db โดยแสดงเฉพาะข้อมูลที่ Active เท่านั้น ตามปี
|
||||
/// </summary>
|
||||
/// <param name="year">ปี่ที่ต้องการ</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpGet("{year:int}")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
public async Task<ActionResult<ResponseObject>> GetsAsync(int year)
|
||||
{
|
||||
try
|
||||
{
|
||||
var items1 = await _holidayService.GetNormalAsync(year);
|
||||
var items2 = await _holidayService.Get6DayAsync(year);
|
||||
|
||||
return Success(new { Normal = items1, SixDays = items2 });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Error(ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// อ่านข้อมูลจาก Relational Db โดยแสดงเฉพาะข้อมูลที่ Active เท่านั้น ตามเดือน
|
||||
/// </summary>
|
||||
/// <param name="year">ปี่ที่ต้องการ</param>
|
||||
/// <param name="month">เดือนที่ต้องการ</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpGet("{year:int}/{month:int}")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
public async Task<ActionResult<ResponseObject>> GetsAsyncByMonth(int year, int month)
|
||||
{
|
||||
try
|
||||
{
|
||||
var items1 = await _holidayService.GetNormalByMonthAsync(year, month);
|
||||
var items2 = await _holidayService.Get6DayByMonthAsync(year, month);
|
||||
|
||||
return Success(new { Normal = items1, SixDays = items2 });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Error(ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// สร้างรายการวันหยุดใหม่แบบรายการเดียว
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <response code="200">ทำรายการสำเร็จ</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpPost]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
public async Task<ActionResult<ResponseObject>> CreateAsync(Holiday inserted)
|
||||
{
|
||||
try
|
||||
{
|
||||
// create normal
|
||||
await _holidayService.CreateAsync(inserted);
|
||||
|
||||
// create 6days
|
||||
await _holidayService.Create6DayAsync(inserted);
|
||||
|
||||
//save database
|
||||
await _holidayService.SaveDatabase();
|
||||
|
||||
return Success(inserted);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Error(ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// สร้างรายการวันหยุดใหม่แบบหลายรายการ
|
||||
/// </summary>
|
||||
/// <param name="inserted">ช่วงวันที่ที่ต้องการเพิ่ม</param>
|
||||
/// <param name="category">ประเภทวันหยุด ส่งค่ามาเป็น normal / 6day</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200">ทำรายการสำเร็จ</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpPost("range/add/{category}")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
public async Task<ActionResult<ResponseObject>> CreateRangeAsync(List<Holiday> inserted, string category)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _holidayService.CreateRangeAsync(inserted, category);
|
||||
|
||||
return Success(inserted);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Error(ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// แก้ไขรายการวันหยุด
|
||||
/// </summary>
|
||||
/// <param name="id">รหัส</param>
|
||||
/// <param name="updated">ข้อมูลที่ต้องการแก้ไข</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200">ทำรายการสำเร็จ</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpPut("{category}/{id:length(36)}")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
public async Task<ActionResult<ResponseObject>> UpdateAsync(string id, Holiday updated)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _holidayService.UpdateAsync(Guid.Parse(id), updated);
|
||||
|
||||
return Success(updated);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Error(ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// แก้ไขรายการวันหยุด
|
||||
/// </summary>
|
||||
/// <param name="data">Group ข่อมูลที่แก้ไข</param>
|
||||
/// <param name="category">ประเภทวันหยุด ส่งค่ามาเป็น normal / 6day</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200">ทำรายการสำเร็จ</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpPost("range/edit/{category}")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
public async Task<ActionResult<ResponseObject>> UpdateRangeAsync(HolidayUpdateRequest data, string category)
|
||||
{
|
||||
try
|
||||
{
|
||||
var isNormal = category.ToUpper() == "NORMAL";
|
||||
await _holidayService.UpdateRangeAsync(data.history, data.updated, isNormal);
|
||||
|
||||
return Success(data.updated);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Error(ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ลบรายการวันหยุด
|
||||
/// </summary>
|
||||
/// <param name="id">รหัส</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200">ทำรายการสำเร็จ</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpDelete("{id:length(36)}")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
public async Task<ActionResult<ResponseObject>> DeleteAsync(string id)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _holidayService.DeleteAsync(Guid.Parse(id));
|
||||
|
||||
return Success();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Error(ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ลบรายการวันหยุด
|
||||
/// </summary>
|
||||
/// <param name="delete">ช่วงวันที่ที่ต้องการลบ</param>
|
||||
/// <param name="category">ประเภทวันหยุด ส่งค่ามาเป็น normal / 6day</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200">ทำรายการสำเร็จ</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpPost("range/delete/{category}")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
public async Task<ActionResult<ResponseObject>> DeleteRangeAsync(List<Holiday> delete, string category)
|
||||
{
|
||||
try
|
||||
{
|
||||
var isNormal = category.ToUpper() == "NORMAL";
|
||||
await _holidayService.DeleteRangeAsync(delete, isNormal);
|
||||
|
||||
return Success();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Error(ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// คัดลอกข้อมูลวันหยุด โดยระบุปีที่ต้องการคัดลอก และ ปีที่ต้องการบันทึก
|
||||
/// </summary>
|
||||
/// <param name="request">Request Body</param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("copy")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
public async Task<ActionResult<ResponseObject>> CopyAsync([FromBody] HolidayCopyRequest request)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _holidayService.CopyAsync(request.FromYear, request.ToYear);
|
||||
|
||||
return Success();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Error(ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// สรุปวันหยุดในแต่ละปี
|
||||
/// </summary>
|
||||
/// <param name="year">ปี่ที่ต้องการ</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpGet("summary/{year:int}")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
public async Task<ActionResult<ResponseObject>> GetDataGroupMonthAsync(int year)
|
||||
{
|
||||
try
|
||||
{
|
||||
var items = await _holidayService.GetDataGroupMonthAsync(year);
|
||||
|
||||
return Success(items);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Error(ex);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
using BMA.EHR.Application.Repositories;
|
||||
using BMA.EHR.Domain.Common;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace BMA.EHR.MetaData.Service.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class PrefixController : BaseController
|
||||
{
|
||||
private readonly PrefixRepository _repository;
|
||||
|
||||
public PrefixController(PrefixRepository repository)
|
||||
{
|
||||
_repository = repository;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<ResponseObject>> Get()
|
||||
{
|
||||
var data = await _repository.GetAllAsync();
|
||||
|
||||
return Success(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue