Skip to content

Commit

Permalink
removed trip and ticket status entities
Browse files Browse the repository at this point in the history
  • Loading branch information
AndriyBorkovich committed May 1, 2024
1 parent 7adfd48 commit 2e91655
Show file tree
Hide file tree
Showing 14 changed files with 968 additions and 169 deletions.

This file was deleted.

This file was deleted.

7 changes: 4 additions & 3 deletions src/BSMS.Application/MappingProfiles/TicketProfile.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using BSMS.Application.Features.Ticket.Commands.Create;
using BSMS.Core.Entities;
using BSMS.Core.Enums;
using Mapster;

namespace BSMS.Application.MappingProfiles;
Expand All @@ -9,9 +10,9 @@ public class TicketProfile : IRegister
public void Register(TypeAdapterConfig config)
{
config.NewConfig<CreateTicketCommand, Ticket>()
.AfterMapping((_, dest) =>
.AfterMapping((_, dest) =>
{
dest.IsSold = false;
dest.Status = TicketStatus.Active;
});
}
}
}
3 changes: 2 additions & 1 deletion src/BSMS.Core/Entities/Ticket.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.ComponentModel.DataAnnotations.Schema;
using BSMS.Core.Enums;

namespace BSMS.Core.Entities;

Expand All @@ -12,10 +13,10 @@ public class Ticket
[Column(TypeName = "decimal(18,2)")]
public decimal Price { get; set; }
public bool IsSold { get; set; }
public TicketStatus Status {get; set; }

public Stop StartStop { get; set; } = null!;
public Stop EndStop { get; set; } = null!;
public Seat Seat { get; set; } = null!;
public TicketPayment Payment { get; set; } = null!;
public List<TicketStatus> Statuses { get; set; }
}
14 changes: 0 additions & 14 deletions src/BSMS.Core/Entities/TicketStatus.cs

This file was deleted.

12 changes: 9 additions & 3 deletions src/BSMS.Core/Entities/Trip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@ public class Trip
public int TripId { get; set; }
public int BusScheduleEntryId { get; set; }

public DateTime DepartureTime { get; set; }
public DateTime ArrivalTime { get; set; }
/// <summary>
/// actual time when trip has started
/// </summary>
public DateTime? DepartureTime { get; set; }
/// <summary>
/// actual time when trip has ended
/// </summary>
public DateTime? ArrivalTime { get; set; }
public TripStatus Status {get; set; }

public BusScheduleEntry BusScheduleEntry { get; set; }

Check warning on line 22 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.
public List<TicketPayment> BoughtTickets { get; set; }

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

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'BoughtTickets' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
public List<TripStatus> Statuses { get; set; }
}
14 changes: 0 additions & 14 deletions src/BSMS.Core/Entities/TripStatus.cs

This file was deleted.

4 changes: 1 addition & 3 deletions src/BSMS.Core/Enums/TripStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ public enum TripStatus
{
Scheduled = 100,
InTransit = 200,
Delayed = 300,
Canceled = 400,
Disrupted = 500,
Completed = 600
Completed = 500
}
17 changes: 2 additions & 15 deletions src/BSMS.Infrastructure/Persistence/BusStationContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ public BusStationContext(DbContextOptions<BusStationContext> options)
public DbSet<Ticket> Tickets { get; set; }
public DbSet<TicketPayment> TicketPayments { get; set; }
public DbSet<Trip> Trips { get; set; }
public DbSet<TicketStatus> TicketStatuses { get; set; }
public DbSet<TripStatus> TripStatuses { get; set; }
public DbSet<User> Users { get; set; }
public DbSet<BusDetailsView> BusesDetailsView { get; set; }

Expand All @@ -42,8 +40,6 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
.ToTable(tb => tb.UseSqlOutputClause(false));
modelBuilder.Entity<Ticket>()
.ToTable(tb => tb.UseSqlOutputClause(false));
modelBuilder.Entity<TicketStatus>()
.ToTable(tb => tb.UseSqlOutputClause(false));
modelBuilder.Entity<Route>()
.ToTable(tb => tb.UseSqlOutputClause(false));
modelBuilder.Entity<Stop>()
Expand Down Expand Up @@ -80,12 +76,12 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
.HasConversion<string>()
.HasMaxLength(20);

modelBuilder.Entity<TicketStatus>()
modelBuilder.Entity<Ticket>()
.Property(ts => ts.Status)
.HasConversion<string>()
.HasMaxLength(20);

modelBuilder.Entity<TripStatus>()
modelBuilder.Entity<Trip>()
.Property(ts => ts.Status)
.HasConversion<string>()
.HasMaxLength(20);
Expand All @@ -95,15 +91,6 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
.WithOne(p => p.Ticket)
.OnDelete(DeleteBehavior.ClientCascade);

modelBuilder.Entity<Ticket>()
.HasMany(t => t.Statuses)
.WithOne(s => s.Ticket)
.OnDelete(DeleteBehavior.ClientCascade);

modelBuilder.Entity<Trip>()
.HasMany(t => t.Statuses)
.WithOne(s => s.Trip)
.OnDelete(DeleteBehavior.ClientCascade);

modelBuilder.HasDbFunction(
typeof(BusStationContext).GetMethod(nameof(StopsBelongToSameRoute),
Expand Down
Loading

0 comments on commit 2e91655

Please sign in to comment.