add api post
This commit is contained in:
parent
11a683bf9b
commit
ab57fee8b4
2 changed files with 112 additions and 25 deletions
|
|
@ -2261,31 +2261,6 @@ namespace BMA.EHR.Recruit.Service.Controllers
|
||||||
|
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
|
|
||||||
//var periods = _context.RecruitImports.AsQueryable()
|
|
||||||
// .Where(x => x.Year == this_year)
|
|
||||||
// .Include(x => x.RecruitImages)
|
|
||||||
// .Select(r => new
|
|
||||||
// {
|
|
||||||
// id = r.Id,
|
|
||||||
// title = $"{r.Name} ครั้งที่ {r.Order}/{r.Year.ToThaiYear()}",
|
|
||||||
// category = "สำนักงาน ก.ก.",
|
|
||||||
// category_id = 1,
|
|
||||||
// announcement_startDate = r.AnnouncementStartDate == null ? "" : r.AnnouncementStartDate.Value.ToString("yyyy-mm-dd"),
|
|
||||||
// announcement_endDate = r.AnnouncementEndDate == null ? "" : r.AnnouncementEndDate.Value.ToString("yyyy-MM-dd"),
|
|
||||||
// announcementExam = true,
|
|
||||||
// register_startDate = r.RegisterStartDate == null ? "" : r.RegisterStartDate.Value.ToString("yyyy-MM-dd"),
|
|
||||||
// register_endDate = r.RegisterEndDate == null ? "" : r.RegisterEndDate.Value.ToString("yyyy-MM-dd"),
|
|
||||||
// payment_startDate = r.PaymentStartDate == null ? "" : r.PaymentStartDate.Value.ToString("yyyy-MM-dd"),
|
|
||||||
// payment_endDate = r.PaymentEndDate == null ? "" : r.PaymentEndDate.Value.ToString("yyyy-MM-dd"),
|
|
||||||
// exam_date = r.ExamDate == null ? "" : r.ExamDate.Value.ToString("yyyy-MM-dd"),
|
|
||||||
// image = r.RecruitImages.OrderBy(o => o.CreatedAt).FirstOrDefault() == null ? "" :
|
|
||||||
// r.RecruitImages.OrderBy(o => o.CreatedAt).FirstOrDefault().Document.Id.ToString("D")
|
|
||||||
// })
|
|
||||||
// .OrderByDescending(x => x.announcement_startDate)
|
|
||||||
// .ToList();
|
|
||||||
|
|
||||||
|
|
||||||
if (limit > 0)
|
if (limit > 0)
|
||||||
periods = periods.Take(limit).ToList();
|
periods = periods.Take(limit).ToList();
|
||||||
|
|
||||||
|
|
@ -2319,6 +2294,95 @@ namespace BMA.EHR.Recruit.Service.Controllers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// ดึงรายการรอบการสอบแข่งขันสำหรับ CMS (POST version)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request">ข้อมูลการกรองตามช่วงวันที่</param>
|
||||||
|
/// <returns>รายการรอบการสอบแข่งขัน</returns>
|
||||||
|
/// <response code="200">เมื่อดึงข้อมูลสำเร็จ</response>
|
||||||
|
/// <response code="400">ข้อมูลที่ส่งมาไม่ถูกต้อง</response>
|
||||||
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||||
|
[HttpPost("competitive")]
|
||||||
|
[AllowAnonymous]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||||
|
public IActionResult GetPeriodForCMSPost([FromBody] CompetitivePeriodRequest request)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (request == null)
|
||||||
|
return BadRequest("Request body is required");
|
||||||
|
|
||||||
|
var query = _context.RecruitImports.AsQueryable();
|
||||||
|
|
||||||
|
// กรองตามช่วงวันที่ (ถ้ามีการส่งมา)
|
||||||
|
if (request.StartDate.HasValue && request.EndDate.HasValue)
|
||||||
|
{
|
||||||
|
var startDate = request.StartDate.Value.Date;
|
||||||
|
var endDate = request.EndDate.Value.Date.AddDays(1).AddTicks(-1); // ถึงสิ้นวัน
|
||||||
|
|
||||||
|
query = query.Where(r =>
|
||||||
|
(r.AnnouncementStartDate != null && r.AnnouncementStartDate.Value >= startDate && r.AnnouncementStartDate.Value <= endDate) ||
|
||||||
|
(r.AnnouncementEndDate != null && r.AnnouncementEndDate.Value >= startDate && r.AnnouncementEndDate.Value <= endDate) ||
|
||||||
|
(r.AnnouncementStartDate != null && r.AnnouncementEndDate != null &&
|
||||||
|
r.AnnouncementStartDate.Value <= endDate && r.AnnouncementEndDate.Value >= startDate)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
var periods = (from r in query.Include(x => x.RecruitImages)
|
||||||
|
orderby r.AnnouncementStartDate descending
|
||||||
|
select new
|
||||||
|
{
|
||||||
|
id = r.Id,
|
||||||
|
title = $"{r.Name} ครั้งที่ {r.Order}/{r.Year.ToThaiYear()}",
|
||||||
|
category = "สำนักงาน ก.ก.",
|
||||||
|
category_id = 1,
|
||||||
|
announcement_startDate = r.AnnouncementStartDate == null ? "" : r.AnnouncementStartDate.Value.ToString("yyyy-MM-dd"),
|
||||||
|
announcement_endDate = r.AnnouncementEndDate == null ? "" : r.AnnouncementEndDate.Value.ToString("yyyy-MM-dd"),
|
||||||
|
announcementExam = true,
|
||||||
|
register_startDate = r.RegisterStartDate == null ? "" : r.RegisterStartDate.Value.ToString("yyyy-MM-dd"),
|
||||||
|
register_endDate = r.RegisterEndDate == null ? "" : r.RegisterEndDate.Value.ToString("yyyy-MM-dd"),
|
||||||
|
payment_startDate = r.PaymentStartDate == null ? "" : r.PaymentStartDate.Value.ToString("yyyy-MM-dd"),
|
||||||
|
payment_endDate = r.PaymentEndDate == null ? "" : r.PaymentEndDate.Value.ToString("yyyy-MM-dd"),
|
||||||
|
exam_date = r.ExamDate == null ? "" : r.ExamDate.Value.ToString("yyyy-MM-dd"),
|
||||||
|
image = r.RecruitImages.OrderBy(o => o.CreatedAt).FirstOrDefault() == null ? "" :
|
||||||
|
r.RecruitImages.OrderBy(o => o.CreatedAt).FirstOrDefault().Document.Id.ToString("D")
|
||||||
|
})
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
if (request.Limit > 0)
|
||||||
|
periods = periods.Take(request.Limit).ToList();
|
||||||
|
|
||||||
|
var result = new List<dynamic>();
|
||||||
|
foreach (var p in periods)
|
||||||
|
{
|
||||||
|
result.Add(new
|
||||||
|
{
|
||||||
|
p.id,
|
||||||
|
p.title,
|
||||||
|
p.category,
|
||||||
|
p.category_id,
|
||||||
|
p.announcementExam,
|
||||||
|
p.announcement_startDate,
|
||||||
|
p.announcement_endDate,
|
||||||
|
p.register_endDate,
|
||||||
|
p.register_startDate,
|
||||||
|
p.payment_startDate,
|
||||||
|
p.payment_endDate,
|
||||||
|
p.exam_date,
|
||||||
|
image = p.image == "" ? "" : _minioService.GetFilePath(Guid.Parse(p.image)).Result,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return StatusCode(500, ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[HttpGet("competitive/{id:length(36)}")]
|
[HttpGet("competitive/{id:length(36)}")]
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
public IActionResult GetPeriodForCMSById(Guid id)
|
public IActionResult GetPeriodForCMSById(Guid id)
|
||||||
|
|
|
||||||
23
Requests/Recruits/CompetitivePeriodRequest.cs
Normal file
23
Requests/Recruits/CompetitivePeriodRequest.cs
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace BMA.EHR.Recruit.Service.Requests.Recruits
|
||||||
|
{
|
||||||
|
public class CompetitivePeriodRequest
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// วันที่เริ่มต้นของช่วงที่ต้องการกรอง
|
||||||
|
/// </summary>
|
||||||
|
public DateTime? StartDate { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// วันที่สิ้นสุดของช่วงที่ต้องการกรอง
|
||||||
|
/// </summary>
|
||||||
|
public DateTime? EndDate { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// จำนวนรายการสูงสุดที่ต้องการ (0 = ไม่จำกัด)
|
||||||
|
/// </summary>
|
||||||
|
[Range(0, int.MaxValue, ErrorMessage = "Limit ต้องมากกว่าหรือเท่ากับ 0")]
|
||||||
|
public int Limit { get; set; } = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue