This commit is contained in:
2021-06-18 18:19:07 +00:00
parent 8e72717fa7
commit 5fd4362143

View File

@@ -8,6 +8,7 @@ using AyaNova.Api.ControllerHelpers;
using AyaNova.Biz;
using System.Linq;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
namespace AyaNova.Api.Controllers
{
@@ -155,26 +156,38 @@ namespace AyaNova.Api.Controllers
[HttpGet("list")]
public async Task<IActionResult> GetQueue()
{
if (!serverState.IsOpen)
if (!serverState.IsOpen)
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
//NOTE: in future if getting list for another user should just duplicate this method but add the parameter for user id
//and checking of rights
long UserId = UserIdFromContext.Id(HttpContext.Items);
var ret = await ct.NotifySubscription.Where(z => z.UserId == UserId).Select(z => new
var subs = await ct.NotifySubscription.AsNoTracking().Where(z => z.UserId == UserId).ToListAsync();
List<NotifySubscriptionRecord> ret = new List<NotifySubscriptionRecord>();
foreach (var s in subs)
{
z.Id,
z.UserId,
z.EventType,
z.AyaType,
z.DeliveryMethod,
z.DeliveryAddress,
z.Tags
}).ToListAsync();
ret.Add(new NotifySubscriptionRecord(s.Id, s.UserId, s.EventType, s.AyaType, s.DeliveryMethod, s.DeliveryAddress, s.Tags, await GetInfo(s, ct)));
}
return Ok(ApiOkResponse.Response(ret));
}
private record NotifySubscriptionRecord(long id, long userid, NotifyEventType eventType, AyaType AyaType, NotifyDeliveryMethod deliveryMethod, string deliveryAddress, List<string> tags, string info);
//Provide extra info about subscription
private static async Task<string> GetInfo(NotifySubscription s, AyContext ct)
{
switch (s.EventType)
{
case NotifyEventType.WorkorderStatusAge:
case NotifyEventType.WorkorderStatusChange:
//add status text to info
return await ct.WorkOrderStatus.AsNoTracking().Where(x => x.Id == s.IdValue).Select(x => x.Name).FirstOrDefaultAsync();
default:
return string.Empty;
}
}
//------------