Skip to content

Commit

Permalink
added bus schedule entity
Browse files Browse the repository at this point in the history
  • Loading branch information
AndriyBorkovich committed Apr 1, 2024
1 parent 512d4df commit d83f97e
Show file tree
Hide file tree
Showing 15 changed files with 875 additions and 52 deletions.
6 changes: 5 additions & 1 deletion src/BSMS.Core/Entities/Bus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
public class Bus
{
public int BusId { get; set; }

public int Capacity { get; set; }
public string Brand { get; set; } = null!;
public string Number { get; set; } = null!;

/// <summary>
/// helps to get bus schedule, trip statistic
/// </summary>
public List<BusScheduleEntry> BusScheduleEntries { get; set; }
public List<BusReview> BusReviews { get; set; }
public List<Driver> Drivers { get; set; }
public List<Passenger> Passengers { get; set; }
public List<Seat> Seats { get; set; }
public List<Trip> Trips { get; set; }
}
1 change: 1 addition & 0 deletions src/BSMS.Core/Entities/BusReview.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public class BusReview
public int BusReviewId { get; set; }
public int BusId { get; set; }
public int PassengerId { get; set; }

public int? ComfortRating { get; set; }
public int? PunctualityRating { get; set; }
public int? PriceQualityRatioRating { get; set; }
Expand Down
21 changes: 21 additions & 0 deletions src/BSMS.Core/Entities/BusScheduleEntry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.ComponentModel.DataAnnotations;
using BSMS.Core.Enums;

namespace BSMS.Core.Entities;

public class BusScheduleEntry
{
[Key]
public int BusScheduleEntryId { get; set; }
public int BusId { get; set; }
public int RouteId { get; set; }

public DateTime DepartureTime { get; set; }
public DateTime ArrivalTime { get; set; }
public Direction MoveDirection { get; set; }
public DayOfWeek Day { get; set; }

public Bus Bus { get; set; }
public Route Route { get; set; }
public Trip? Trip { get; set; }
}
1 change: 1 addition & 0 deletions src/BSMS.Core/Entities/Company.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
public class Company
{
public int CompanyId { get; set; }

public string Name { get; set; } = null!;
public string Address { get; set; } = null!;
public string? ContactPhone { get; set; }
Expand Down
5 changes: 3 additions & 2 deletions src/BSMS.Core/Entities/Driver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
public class Driver
{
public int DriverId { get; set; }
public int? CompanyId { get; set; }
public int? BusId { get; set; }

public string FirstName { get; set; } = null!;
public string LastName { get; set; } = null!;
public string? DriverLicense { get; set; }
public int? CompanyId { get; set; }
public int? BusId { get; set; }

public Bus? Bus { get; set; }
public Company? Company { get; set; }
Expand Down
3 changes: 2 additions & 1 deletion src/BSMS.Core/Entities/Passenger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
public class Passenger
{
public int PassengerId { get; set; }
public int? BusId { get; set; }

public string FirstName { get; set; } = null!;
public string LastName { get; set; } = null!;
public string? PhoneNumber { get; set; }
public string? Email { get; set; }
public int? BusId { get; set; }

public Bus? Bus { get; set; }
public List<BusReview> BusReviews { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion src/BSMS.Core/Entities/Route.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ public class Route
public string Destination { get; set; } = null!;

public List<Stop> Stops { get; set; }

Check warning on line 9 in src/BSMS.Core/Entities/Route.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Stops' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
public List<Trip> Trips { get; set; }
public List<BusScheduleEntry> BusScheduleEntries { get; set; }

Check warning on line 10 in src/BSMS.Core/Entities/Route.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'BusScheduleEntries' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
}
4 changes: 2 additions & 2 deletions src/BSMS.Core/Entities/Ticket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ public class Ticket
public bool IsSold { get; set; }
public int StartStopId { get; set; }
public int EndStopId { get; set; }

public Stop EndStop { get; set; } = null!;

public Stop StartStop { get; set; } = null!;
public Stop EndStop { get; set; } = null!;
public Seat Seat { get; set; } = null!;
public TicketPayment Payment { get; set; } = null!;
}
9 changes: 5 additions & 4 deletions src/BSMS.Core/Entities/Trip.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
using BSMS.Core.Enums;

namespace BSMS.Core.Entities;

/// <summary>
/// represent trip history (live) for specific bus on specific route
/// </summary>
public class Trip
{
public int TripId { get; set; }
public TripStatus Status { get; set; }
public int RouteId { get; set; }
public int BusScheduleEntryId { get; set; }
public DateTime DepartureTime { get; set; }
public DateTime ArrivalTime { get; set; }

public Route Route { get; set; }
public List<Bus> Buses { get; set; }
public BusScheduleEntry BusScheduleEntry { get; set; }

Check warning on line 15 in src/BSMS.Core/Entities/Trip.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'BusScheduleEntry' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
}
7 changes: 7 additions & 0 deletions src/BSMS.Core/Enums/Direction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace BSMS.Core.Enums;

public enum Direction
{
ToDestination = 100,
FromDestination = 200
}
3 changes: 2 additions & 1 deletion src/BSMS.Core/Enums/TripStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ public enum TripStatus
InTransit = 200,
Delayed = 300,
Canceled = 400,
Disrupted = 500
Disrupted = 500,
Completed = 600
}
11 changes: 11 additions & 0 deletions src/BSMS.Infrastructure/Persistence/BusStationContext.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using BSMS.Core.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;

namespace BSMS.Infrastructure.Persistence;

Expand Down Expand Up @@ -36,5 +37,15 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
.HasMany(s => s.TicketEndStops)
.WithOne(t => t.EndStop)
.OnDelete(DeleteBehavior.ClientSetNull);

// modelBuilder
// .Entity<BusScheduleEntry>()
// .Property(bs => bs.Day)
// .HasConversion<string>();
//
// modelBuilder
// .Entity<BusScheduleEntry>()
// .Property(bs => bs.MoveDirection)
// .HasConversion<string>();
}
}
Loading

0 comments on commit d83f97e

Please sign in to comment.