Skip to content

Commit

Permalink
feat: single passenger per booking
Browse files Browse the repository at this point in the history
  • Loading branch information
kirinnee committed Dec 17, 2023
1 parent f3e5ae7 commit 2ddf421
Show file tree
Hide file tree
Showing 13 changed files with 325 additions and 60 deletions.
213 changes: 213 additions & 0 deletions App/Migrations/20231217101855_SinglePassenger.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

73 changes: 73 additions & 0 deletions App/Migrations/20231217101855_SinglePassenger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace App.Migrations
{
/// <inheritdoc />
public partial class SinglePassenger : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Passengers",
table: "Bookings");

migrationBuilder.AddColumn<string>(
name: "Passenger_FullName",
table: "Bookings",
type: "text",
nullable: false,
defaultValue: "");

migrationBuilder.AddColumn<byte>(
name: "Passenger_Gender",
table: "Bookings",
type: "smallint",
nullable: false,
defaultValue: (byte)0);

migrationBuilder.AddColumn<DateOnly>(
name: "Passenger_PassportExpiry",
table: "Bookings",
type: "date",
nullable: false,
defaultValue: new DateOnly(1, 1, 1));

migrationBuilder.AddColumn<string>(
name: "Passenger_PassportNumber",
table: "Bookings",
type: "text",
nullable: false,
defaultValue: "");
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Passenger_FullName",
table: "Bookings");

migrationBuilder.DropColumn(
name: "Passenger_Gender",
table: "Bookings");

migrationBuilder.DropColumn(
name: "Passenger_PassportExpiry",
table: "Bookings");

migrationBuilder.DropColumn(
name: "Passenger_PassportNumber",
table: "Bookings");

migrationBuilder.AddColumn<string>(
name: "Passengers",
table: "Bookings",
type: "jsonb",
nullable: true);
}
}
}
55 changes: 20 additions & 35 deletions App/Migrations/MainDbContextModelSnapshot.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// <auto-generated />
using System;
using System.Collections.Generic;
using App.StartUp.Database;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
Expand Down Expand Up @@ -57,6 +58,25 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.IsRequired()
.HasColumnType("text");

b.ComplexProperty<Dictionary<string, object>>("Passenger", "App.Modules.Bookings.Data.BookingData.Passenger#BookingPassengerData", b1 =>
{
b1.IsRequired();

b1.Property<string>("FullName")
.IsRequired()
.HasColumnType("text");

b1.Property<byte>("Gender")
.HasColumnType("smallint");

b1.Property<DateOnly>("PassportExpiry")
.HasColumnType("date");

b1.Property<string>("PassportNumber")
.IsRequired()
.HasColumnType("text");
});

b.HasKey("Id");

b.HasIndex("UserId");
Expand Down Expand Up @@ -171,41 +191,6 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();

b.OwnsMany("App.Modules.Bookings.Data.BookingPassengerData", "Passengers", b1 =>
{
b1.Property<Guid>("BookingDataId")
.HasColumnType("uuid");

b1.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");

b1.Property<string>("FullName")
.IsRequired()
.HasColumnType("text");

b1.Property<byte>("Gender")
.HasColumnType("smallint");

b1.Property<DateOnly>("PassportExpiry")
.HasColumnType("date");

b1.Property<string>("PassportNumber")
.IsRequired()
.HasColumnType("text");

b1.HasKey("BookingDataId", "Id");

b1.ToTable("Bookings");

b1.ToJson("Passengers");

b1.WithOwner()
.HasForeignKey("BookingDataId");
});

b.Navigation("Passengers");

b.Navigation("User");
});

Expand Down
6 changes: 3 additions & 3 deletions App/Modules/Bookings/API/V1/BookingController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ public async Task<ActionResult<IEnumerable<BookingCountRes>>> CountStatus()
return this.ReturnResult(x);
}

[Authorize(Policy = AuthPolicies.AdminOrTin), HttpPost("reserve/{id:guid}")]
public async Task<ActionResult<BookingPrincipalRes>> Reserve(Guid id)
[Authorize(Policy = AuthPolicies.AdminOrTin), HttpPost("buying/{id:guid}")]
public async Task<ActionResult<BookingPrincipalRes>> Buying(Guid id)
{
var x = await service.Reserve(id)
var x = await service.Buying(id)
.Then(x => x?.ToRes(), Errors.MapAll)
.ThenAwait(x => Utils.ToNullableTaskResultOr(x, r => enrich.Enrich(r)));
return this.ReturnNullableResult(x, new EntityNotFound("Booking not found", typeof(Booking), id.ToString()));
Expand Down
Loading

0 comments on commit 2ddf421

Please sign in to comment.