From 9d6168e60791514d8d47ee11185f928e654035aa Mon Sep 17 00:00:00 2001 From: Andriy Borkovich Date: Mon, 6 May 2024 16:54:01 +0300 Subject: [PATCH] fixed comments, logs messages --- src/BSMS.API/BackgroundJobs/ScheduleTripsJob.cs | 1 + .../BackgroundJobs/TripStartOrStopPeriodicJob.cs | 11 ++++++----- src/BSMS.Infrastructure/Seed/BusStationSeeder.cs | 10 +++++----- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/BSMS.API/BackgroundJobs/ScheduleTripsJob.cs b/src/BSMS.API/BackgroundJobs/ScheduleTripsJob.cs index c421395..cfabf1a 100644 --- a/src/BSMS.API/BackgroundJobs/ScheduleTripsJob.cs +++ b/src/BSMS.API/BackgroundJobs/ScheduleTripsJob.cs @@ -8,6 +8,7 @@ namespace BSMS.API.BackgroundJobs; /// Schedule new trips based on current date /// /// +/// public class ScheduleTripsJob( IServiceProvider serviceProvider, ILogger logger) : IHostedService diff --git a/src/BSMS.API/BackgroundJobs/TripStartOrStopPeriodicJob.cs b/src/BSMS.API/BackgroundJobs/TripStartOrStopPeriodicJob.cs index 062b4aa..c82d2f6 100644 --- a/src/BSMS.API/BackgroundJobs/TripStartOrStopPeriodicJob.cs +++ b/src/BSMS.API/BackgroundJobs/TripStartOrStopPeriodicJob.cs @@ -1,6 +1,4 @@ -using System.Collections.Concurrent; -using Bogus; -using BSMS.Core.Entities; +using BSMS.Core.Entities; using BSMS.Core.Enums; using BSMS.Infrastructure.Persistence; using Microsoft.EntityFrameworkCore; @@ -90,7 +88,8 @@ private async Task HandleDepartingAsync( if (tripsToSetInTransit.Count is not 0) { await dbContext.BulkUpdateAsync(tripsToSetInTransit, opt => opt.IncludeGraph = true, stoppingToken); - logger.LogInformation("{0} trips has started", tripsToSetInTransit.Count); + logger.LogInformation("{0} trips have started", tripsToSetInTransit.Count(t => t.Status == TripStatus.InTransit)); + logger.LogInformation("{0} trips have been delayed", tripsToSetInTransit.Count(t => t.Status == TripStatus.Delayed)); } } @@ -115,7 +114,7 @@ private async Task HandleArrivingAsync( if (updatedRows > 0) { - logger.LogInformation("{0} trips has completed", updatedRows); + logger.LogInformation("{0} trips have completed", updatedRows); } } @@ -157,6 +156,8 @@ private async Task TryRestartAsync(BusStationContext dbContext, DateTime current if (tripsToRestart.Count is not 0) { await dbContext.BulkUpdateAsync(tripsToRestart, opt => opt.IncludeGraph = true, stoppingToken); + logger.LogInformation("{0} trips have been restarted", tripsToRestart.Count(t => t.Status == TripStatus.InTransit)); + logger.LogInformation("{0} trips are still delaying", tripsToRestart.Count(t => t.Status == TripStatus.Delayed)); } } diff --git a/src/BSMS.Infrastructure/Seed/BusStationSeeder.cs b/src/BSMS.Infrastructure/Seed/BusStationSeeder.cs index 9fe1223..c0f453b 100644 --- a/src/BSMS.Infrastructure/Seed/BusStationSeeder.cs +++ b/src/BSMS.Infrastructure/Seed/BusStationSeeder.cs @@ -128,7 +128,7 @@ public async Task GenerateTicketsAndPaymentsForTrip(int tripId) var tripScheduleEntries = dbContext.BusScheduleEntries.Where(be => be.Trips.Any(t => t.TripId == tripId)); var seatIds = await tripScheduleEntries - .Select(be => be.Bus) + .Select(e => e.Bus) .SelectMany(b => b.Seats) .Where(s => s.IsFree) .Select(s => s.SeatId) @@ -164,9 +164,9 @@ public async Task GenerateTicketsAndPaymentsForTrip(int tripId) var endStopId = f.PickRandom(orderedStopsIds); - // Pick a random seat that hasn't been chosen yet and remove the chosen seat from available seats - var chosenSeatId = f.PickRandom(availableSeatIds.ToList()); - availableSeatIds.Remove(chosenSeatId); + // Pick a random seat that hasn't been choosen yet and remove the choosen seat from available seats + var choosenSeatId = f.PickRandom(availableSeatIds.ToList()); + availableSeatIds.Remove(choosenSeatId); var newTicket = new Ticket { @@ -191,7 +191,7 @@ public async Task GenerateTicketsAndPaymentsForTrip(int tripId) await dbContext.BulkInsertOptimizedAsync(tickets, opt => opt.IncludeGraph = true); - logger.LogInformation("Passengers bought {0} tickets", ticketsToGenerate); + logger.LogInformation("Passengers have bought {0} tickets", ticketsToGenerate); } else {