Merge branch 'develop' into working

This commit is contained in:
Suphonchai Phoonsawat 2024-01-19 08:48:16 +07:00
commit 2dd5aa1e33
2 changed files with 74 additions and 15 deletions

View file

@ -54,32 +54,39 @@ namespace BMA.EHR.Application.Repositories.MessageQueue
.Where(x => x.ReceiverUserId == profile.Id) .Where(x => x.ReceiverUserId == profile.Id)
.Where(x => x.DeleteDate == null) .Where(x => x.DeleteDate == null)
.OrderByDescending(x => x.ReceiveDate) .OrderByDescending(x => x.ReceiveDate)
.Select(x => new NotificationResponse
{
Id = x.Id,
Body = x.Body,
ReceiverUserId = x.ReceiverUserId,
IsOpen = x.IsOpen,
Type = x.Type,
ReceiveDate = x.ReceiveDate,
OpenDate = x.OpenDate,
Payload = x.Payload == "" ? null : JsonConvert.DeserializeObject<CommandPayload>(Regex.Unescape(x.Payload))
})
.ToListAsync(); .ToListAsync();
var totalNoti = data_search.Where(x => x.IsOpen == false).Count();
var data = data_search var data = data_search
.Skip((page - 1) * pageSize) .Skip((page - 1) * pageSize)
.Take(pageSize) .Take(pageSize)
.ToList(); .Select(x => new NotificationResponse
{
Id = x.Id,
Body = x.Body,
ReceiverUserId = x.ReceiverUserId,
IsOpen = x.IsOpen,
Type = x.Type,
ReceiveDate = x.ReceiveDate,
OpenDate = x.OpenDate,
Payload = x.Payload == "" ? null : JsonConvert.DeserializeObject<CommandPayload>(Regex.Unescape(x.Payload))
}).ToList();
var data_opens = data.Where(x => x.IsOpen == false).ToList(); var data_opens = await _dbContext.Set<Notification>()
.Where(x => x.ReceiverUserId == profile.Id)
.Where(x => x.DeleteDate == null)
.OrderByDescending(x => x.ReceiveDate)
.Skip((page - 1) * pageSize)
.Take(pageSize)
.Where(x => x.IsOpen == false)
.ToListAsync();
foreach (var data_open in data_opens) foreach (var data_open in data_opens)
{ {
data_open.IsOpen = true; data_open.IsOpen = true;
data_open.OpenDate = DateTime.Now;
} }
await _dbContext.SaveChangesAsync(); await _dbContext.SaveChangesAsync();
var _data = new { data, total = data_search.Count(), totalNoti = data_search.Where(x => x.IsOpen == false).Count() }; var _data = new { data, total = data_search.Count(), totalNoti = totalNoti };
return _data; return _data;
} }
catch catch
@ -88,6 +95,33 @@ namespace BMA.EHR.Application.Repositories.MessageQueue
} }
} }
public async Task<dynamic> GetMyNotificationAsyncNoread()
{
try
{
var profile = await _dbContext.Set<Profile>()
.FirstOrDefaultAsync(p => p.KeycloakId == Guid.Parse(UserId!));
if (profile == null)
{
return 0;
}
var data_search = await _dbContext.Set<Notification>()
.Where(x => x.ReceiverUserId == profile.Id)
.Where(x => x.DeleteDate == null)
.Where(x => x.IsOpen == false)
.OrderByDescending(x => x.ReceiveDate)
.ToListAsync();
return data_search.Count();
}
catch
{
throw;
}
}
public async Task DeleteMyNotificationAsync(Guid id) public async Task DeleteMyNotificationAsync(Guid id)
{ {
try try

View file

@ -134,6 +134,31 @@ namespace BMA.EHR.Command.Service.Controllers
} }
} }
/// <summary>
/// แสดงข้อมูล Notification ของ user ที่ Login ที่ยังไม่ได้อ่าน
/// </summary>
/// <returns></returns>
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpGet("my-notifications/noread")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<ResponseObject>> GetMyNotificationAsyncNoread()
{
try
{
var noti = await _notificationRepository.GetMyNotificationAsyncNoread();
return Success(noti);
}
catch
{
throw;
}
}
/// <summary> /// <summary>
/// ลบข้อมูล Notification ของ user ที่ Login /// ลบข้อมูล Notification ของ user ที่ Login
/// </summary> /// </summary>