Skip to content

Commit 2754919

Browse files
committed
Re-enable support for alerts in new DB
1 parent 99d8a14 commit 2754919

File tree

8 files changed

+19
-22
lines changed

8 files changed

+19
-22
lines changed

Data/FimDbContext.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using fim_queueing_admin.Models;
22
using Microsoft.EntityFrameworkCore;
3-
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
43

54
namespace fim_queueing_admin.Data;
65

Hubs/AssistantHub.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,8 @@ public async Task GetStreamInfo()
8787

8888
private async Task SendPendingAlertsToCaller()
8989
{
90-
// var pendingAlerts = await dbContext.AlertCarts.Where(ac => ac.CartId == CartId && ac.ReadTime == null)
91-
// .Select(ac => ac.Alert).ToListAsync();
92-
var pendingAlerts = new List<Alert>();
90+
var pendingAlerts = await dbContext.AlertCarts.Where(ac => ac.CartId == CartId && ac.ReadTime == null)
91+
.Select(ac => ac.Alert).ToListAsync();
9392

9493
await Clients.Caller.SendAsync("PendingAlerts", pendingAlerts);
9594
}

Models/Alert.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class AlertEntityTypeConfiguration : IEntityTypeConfiguration<Alert>
2020
public void Configure(EntityTypeBuilder<Alert> builder)
2121
{
2222
builder
23+
.ToTable("alerts", "temp")
2324
.HasMany(a => a.AlertCarts)
2425
.WithOne(ac => ac.Alert);
2526
}

Models/AlertCart.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ public class AlertCartEntityTypeConfiguration : IEntityTypeConfiguration<AlertCa
1919
{
2020
public void Configure(EntityTypeBuilder<AlertCart> builder)
2121
{
22-
builder.HasKey(nameof(AlertCart.AlertId), nameof(AlertCart.CartId));
22+
builder
23+
.ToTable("alert_carts", "temp")
24+
.HasKey(nameof(AlertCart.AlertId), nameof(AlertCart.CartId));
2325
}
2426
}

Models/Cart.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ public class Cart : BaseEquipment
99
{
1010
public AvCartConfiguration? Configuration { get; set; } = new();
1111

12-
// TODO: This is not yet implemented in Postgres
13-
// public ICollection<AlertCart>? AlertCarts { get; set; }
12+
public ICollection<AlertCart>? AlertCarts { get; set; }
1413

1514
public class AvCartConfiguration
1615
{
@@ -25,9 +24,9 @@ public class CartEntityTypeConfiguration : BaseEquipmentEntityTypeConfiguration<
2524
{
2625
protected override void ConfigureEntity(EntityTypeBuilder<Cart> builder)
2726
{
28-
// builder
29-
// .HasMany(a => a.AlertCarts)
30-
// .WithOne(ac => ac.Cart);
27+
builder
28+
.HasMany(a => a.AlertCarts)
29+
.WithOne(ac => ac.Cart);
3130
builder.HasQueryFilter(c => c.EquipmentType == EquipmentType.AvCart);
3231
builder.OwnsOne(c => c.Configuration, d =>
3332
{

Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ async Task<string> GetAccessToken()
171171
});
172172
}
173173

174-
builder.Services.AddHostedService<DatabaseKeepAliveService>();
174+
// builder.Services.AddHostedService<DatabaseKeepAliveService>();
175175

176176
builder.Services.AddCors(opt =>
177177
{

Services/AssistantService.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ public async Task SendPendingAlertsToEveryone()
1818
var hubContext = serviceProvider.GetRequiredService<IHubContext<AssistantHub>>();
1919
var dbContext = serviceProvider.GetRequiredService<FimDbContext>();
2020

21-
// var pendingAlerts = await dbContext.AlertCarts.Where(ac => ac.ReadTime == null)
22-
// .GroupBy(k => k.CartId, v => v.Alert).ToListAsync();
23-
var pendingAlerts = new List<IGrouping<Guid, Alert>>();
21+
var pendingAlerts = await dbContext.AlertCarts.Where(ac => ac.ReadTime == null)
22+
.GroupBy(k => k.CartId, v => v.Alert).ToListAsync();
2423

2524
foreach (var group in pendingAlerts)
2625
{

Views/Alert/Index.cshtml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@
1212
</div>
1313
<div><a asp-action="Manage">Create Alert</a></div>
1414
@{
15-
var alerts = new List<Alert>();
16-
// TODO: Implement alerts in postgres
17-
// var alerts = await DbContext.Alerts.OrderByDescending(c => c.CreatedAt).Select(a => new
18-
// {
19-
// a.Id,
20-
// Content = a.Content.Substring(0, 50),
21-
// a.CreatedAt
22-
// }).ToListAsync();
15+
var alerts = await DbContext.Alerts.OrderByDescending(c => c.CreatedAt).Select(a => new
16+
{
17+
a.Id,
18+
Content = a.Content.Substring(0, 50),
19+
a.CreatedAt
20+
}).ToListAsync();
2321
}
2422
@if (!alerts.Any())
2523
{

0 commit comments

Comments
 (0)