diff --git a/server/AyaNova/Controllers/NotifySubscriptionController.cs b/server/AyaNova/Controllers/NotifySubscriptionController.cs index 4f39f2c6..18f1870b 100644 --- a/server/AyaNova/Controllers/NotifySubscriptionController.cs +++ b/server/AyaNova/Controllers/NotifySubscriptionController.cs @@ -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 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 ret = new List(); + 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 tags, string info); + //Provide extra info about subscription + private static async Task 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; + } + } //------------