File tree Expand file tree Collapse file tree 8 files changed +91
-302
lines changed
Expand file tree Collapse file tree 8 files changed +91
-302
lines changed Original file line number Diff line number Diff line change @@ -106,6 +106,7 @@ await client.Child($"/seasons/{state.CurrentSeason}/events/{id}").PatchAsync(Jso
106106 } ) ) ;
107107
108108 var notifyTasks = new List < Task > ( ) ;
109+ // TODO: Listen to supabase to notify carts of changes
109110 if ( oldCartId is not null && oldCartId != cartId )
110111 notifyTasks . Add ( assistantService . SendEventsToCart ( oldCartId . Value ) ) ;
111112 if ( cartId is not null ) notifyTasks . Add ( assistantService . SendEventsToCart ( cartId . Value ) ) ;
Original file line number Diff line number Diff line change @@ -19,7 +19,10 @@ public FimDbContext(DbContextOptions options) : base(options)
1919 public DbSet < AlertCart > AlertCarts { get ; set ; } = null ! ;
2020
2121 public DbSet < EquipmentLog > EquipmentLogs { get ; set ; } = null ! ;
22-
22+ public DbSet < Event > Events { get ; set ; } = null ! ;
23+ public DbSet < Season > Seasons { get ; set ; } = null ! ;
24+ public DbSet < Level > Levels { get ; set ; } = null ! ;
25+
2326 protected override void ConfigureConventions ( ModelConfigurationBuilder configurationBuilder )
2427 {
2528 configurationBuilder . Properties ( typeof ( Enum ) ) . HaveConversion < string > ( ) ;
Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ public class BaseEquipment
1919 public required string Name { get ; set ; }
2020 [ MaxLength ( 16 ) ]
2121 public string ? TeamviewerId { get ; set ; }
22-
22+ public int ? TruckRouteId { get ; set ; }
2323}
2424
2525public abstract class BaseEquipmentEntityTypeConfiguration < T > : IEntityTypeConfiguration < T > where T : BaseEquipment
Original file line number Diff line number Diff line change 1+ // ReSharper disable InconsistentNaming Intentional to match casing of DB model
2+
3+ using System . ComponentModel ;
4+ using Microsoft . EntityFrameworkCore ;
5+ using Microsoft . EntityFrameworkCore . Metadata . Builders ;
6+
7+ namespace fim_queueing_admin . Models ;
8+
9+ [ EntityTypeConfiguration ( typeof ( EventEntityTypeConfiguration ) ) ]
10+ public class Event
11+ {
12+ public Guid Id { get ; set ; }
13+ public required int SeasonId { get ; set ; }
14+ public required string Key { get ; set ; }
15+ public string ? Code { get ; set ; }
16+ public required string Name { get ; set ; }
17+ public required bool IsOfficial { get ; set ; }
18+ public int ? TruckRouteId { get ; set ; }
19+ public required DateTime StartTime { get ; set ; }
20+ public required DateTime EndTime { get ; set ; }
21+ public required string TimeZone { get ; set ; }
22+ public DateTimeOffset ? SyncAsOf { get ; set ; }
23+ public required EventStatus Status { get ; set ; } = EventStatus . NotStarted ;
24+
25+ // Relations
26+ [ Description ( "Note: This object may not be populated in some endpoints." ) ]
27+ public Season ? Season { get ; set ; }
28+ }
29+
30+ public enum EventStatus
31+ {
32+ NotStarted ,
33+ AwaitingQuals ,
34+ QualsInProgress ,
35+ AwaitingAlliances ,
36+ AwaitingPlayoffs ,
37+ PlayoffsInProgress ,
38+ WinnerDetermined ,
39+ Completed
40+ }
41+
42+ public class EventEntityTypeConfiguration : IEntityTypeConfiguration < Event >
43+ {
44+ public void Configure ( EntityTypeBuilder < Event > builder )
45+ {
46+
47+ }
48+ }
Original file line number Diff line number Diff line change 1+ using System . ComponentModel . DataAnnotations ;
2+ using System . ComponentModel . DataAnnotations . Schema ;
3+
4+ namespace fim_queueing_admin . Models ;
5+
6+ [ Table ( "levels" ) ]
7+ public class Level
8+ {
9+ [ Key ]
10+ public int Id { get ; set ; }
11+ public required string Name { get ; set ; }
12+ }
Original file line number Diff line number Diff line change 1+ using System . ComponentModel . DataAnnotations ;
2+ using System . ComponentModel . DataAnnotations . Schema ;
3+
4+ namespace fim_queueing_admin . Models ;
5+
6+ [ Table ( "seasons" ) ]
7+ public class Season
8+ {
9+ [ Key ]
10+ public int Id { get ; set ; }
11+ public required int LevelId { get ; set ; }
12+ public Level ? Level { get ; set ; }
13+ public required string Name { get ; set ; }
14+ public required DateTime StartTime { get ; set ; }
15+ public required DateTime EndTime { get ; set ; }
16+ }
Original file line number Diff line number Diff line change @@ -28,21 +28,16 @@ public async Task SendPendingAlertsToEveryone()
2828
2929 public async Task SendEventsToCart ( Guid cartId )
3030 {
31- var season = serviceProvider . GetRequiredService < GlobalState > ( ) . CurrentSeason ;
32- var rtdb = serviceProvider . GetRequiredService < FirebaseClient > ( ) ;
31+ var dbContext = serviceProvider . GetRequiredService < FimDbContext > ( ) ;
3332
34- var events = await rtdb . Child ( $ "/seasons/{ season } /events") . OrderBy ( "cartId" ) . EqualTo ( cartId . ToString ( ) )
35- . OnceAsync < DbEvent > ( ) ;
33+ var route = ( await dbContext . Carts . FindAsync ( cartId ) ) ? . TruckRouteId ;
34+ var events = route is not null
35+ ? await dbContext . Events . Where ( e =>
36+ e . TruckRouteId == route && e . Season ! . StartTime <= DateTime . UtcNow &&
37+ e . Season ! . EndTime >= DateTime . UtcNow ) . OrderBy ( e => e . StartTime ) . ToListAsync ( )
38+ : [ ] ;
3639
37- await hubContext . Clients . User ( cartId . ToString ( ) ) . SendAsync ( "Events" , events . Select ( e => new
38- {
39- eventKey = e . Key ,
40- e . Object . eventCode ,
41- e . Object . name ,
42- e . Object . start ,
43- e . Object . end ,
44- state = e . Object . state ? . ToString ( )
45- } ) ) ;
40+ await hubContext . Clients . User ( cartId . ToString ( ) ) . SendAsync ( "Events" , events ) ;
4641 }
4742
4843 public async Task StartStreamForCart ( Guid cartId , int ? streamNumber )
You can’t perform that action at this time.
0 commit comments