Skip to content

Commit

Permalink
fixed comments, logs messages
Browse files Browse the repository at this point in the history
  • Loading branch information
AndriyBorkovich committed May 6, 2024
1 parent fe18898 commit 9d6168e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/BSMS.API/BackgroundJobs/ScheduleTripsJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace BSMS.API.BackgroundJobs;
/// Schedule new trips based on current date
/// </summary>
/// <param name="serviceProvider"></param>
/// <param name="logger"></param>
public class ScheduleTripsJob(
IServiceProvider serviceProvider,
ILogger<ScheduleTripsJob> logger) : IHostedService
Expand Down
11 changes: 6 additions & 5 deletions src/BSMS.API/BackgroundJobs/TripStartOrStopPeriodicJob.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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));
}
}

Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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));
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/BSMS.Infrastructure/Seed/BusStationSeeder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
{
Expand All @@ -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
{
Expand Down

0 comments on commit 9d6168e

Please sign in to comment.