Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions FlightPlanner/FlightPlanner/Controllers/AdminApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ public class AdminApiController : ControllerBase
private static readonly object DeleteLock = new();
private readonly FlightStorage _storage;

public AdminApiController()
public AdminApiController(FlightStorage storage)
{
_storage = new FlightStorage();
_storage = storage;
}

[HttpPut]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ public class CleanupApiController : ControllerBase
{
private readonly FlightStorage _storage;

public CleanupApiController()
public CleanupApiController(FlightStorage storage)
{
_storage = new FlightStorage();
_storage = storage;
}

[Route("clear")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ public class CustomerApiController : ControllerBase
{
private readonly FlightStorage _storage;

public CustomerApiController()
public CustomerApiController(FlightStorage storage)
{
_storage = new FlightStorage();
_storage = storage;
}

[Route("airports")]
Expand Down
15 changes: 15 additions & 0 deletions FlightPlanner/FlightPlanner/FlightPlanner.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,22 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.22" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.22">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.22" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.22" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.22">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>

<ItemGroup>
<Folder Include="Migrations\" />
</ItemGroup>

</Project>
13 changes: 13 additions & 0 deletions FlightPlanner/FlightPlanner/FlightPlannerDbContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using FlightPlanner.Models;
using Microsoft.EntityFrameworkCore;

namespace FlightPlanner
{
public class FlightPlannerDbContext : DbContext
{
public FlightPlannerDbContext(DbContextOptions<FlightPlannerDbContext> options) :
base(options) { }
public DbSet<Flight> Flights { get; set; }
public DbSet<Airport> Airports { get; set; }
}
}
107 changes: 107 additions & 0 deletions FlightPlanner/FlightPlanner/Migrations/20231009102911_Init.Designer.cs

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

75 changes: 75 additions & 0 deletions FlightPlanner/FlightPlanner/Migrations/20231009102911_Init.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace FlightPlanner.Migrations
{
public partial class Init : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Airports",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Country = table.Column<string>(type: "nvarchar(max)", nullable: false),
City = table.Column<string>(type: "nvarchar(max)", nullable: false),
AirportCode = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Airports", x => x.Id);
});

migrationBuilder.CreateTable(
name: "Flights",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
FromId = table.Column<int>(type: "int", nullable: false),
ToId = table.Column<int>(type: "int", nullable: false),
Carrier = table.Column<string>(type: "nvarchar(max)", nullable: false),
DepartureTime = table.Column<string>(type: "nvarchar(max)", nullable: false),
ArrivalTime = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Flights", x => x.Id);
table.ForeignKey(
name: "FK_Flights_Airports_FromId",
column: x => x.FromId,
principalTable: "Airports",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Flights_Airports_ToId",
column: x => x.ToId,
principalTable: "Airports",
principalColumn: "Id",
onDelete: ReferentialAction.NoAction);
});

migrationBuilder.CreateIndex(
name: "IX_Flights_FromId",
table: "Flights",
column: "FromId");

migrationBuilder.CreateIndex(
name: "IX_Flights_ToId",
table: "Flights",
column: "ToId");
}

protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Flights");

migrationBuilder.DropTable(
name: "Airports");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
// <auto-generated />
using FlightPlanner;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;

#nullable disable

namespace FlightPlanner.Migrations
{
[DbContext(typeof(FlightPlannerDbContext))]
partial class FlightPlannerDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "6.0.22")
.HasAnnotation("Relational:MaxIdentifierLength", 128);

SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1);

modelBuilder.Entity("FlightPlanner.Models.Airport", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");

SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1);

b.Property<string>("AirportCode")
.IsRequired()
.HasColumnType("nvarchar(max)");

b.Property<string>("City")
.IsRequired()
.HasColumnType("nvarchar(max)");

b.Property<string>("Country")
.IsRequired()
.HasColumnType("nvarchar(max)");

b.HasKey("Id");

b.ToTable("Airports");
});

modelBuilder.Entity("FlightPlanner.Models.Flight", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");

SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1);

b.Property<string>("ArrivalTime")
.IsRequired()
.HasColumnType("nvarchar(max)");

b.Property<string>("Carrier")
.IsRequired()
.HasColumnType("nvarchar(max)");

b.Property<string>("DepartureTime")
.IsRequired()
.HasColumnType("nvarchar(max)");

b.Property<int>("FromId")
.HasColumnType("int");

b.Property<int>("ToId")
.HasColumnType("int");

b.HasKey("Id");

b.HasIndex("FromId");

b.HasIndex("ToId");

b.ToTable("Flights");
});

modelBuilder.Entity("FlightPlanner.Models.Flight", b =>
{
b.HasOne("FlightPlanner.Models.Airport", "From")
.WithMany()
.HasForeignKey("FromId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();

b.HasOne("FlightPlanner.Models.Airport", "To")
.WithMany()
.HasForeignKey("ToId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();

b.Navigation("From");

b.Navigation("To");
});
#pragma warning restore 612, 618
}
}
}
2 changes: 2 additions & 0 deletions FlightPlanner/FlightPlanner/Models/Airport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ namespace FlightPlanner.Models;

public class Airport
{
[JsonIgnore]
public int Id { get; set; }
public string Country { get; set; }
public string City { get; set; }

Expand Down
7 changes: 5 additions & 2 deletions FlightPlanner/FlightPlanner/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using FlightPlanner.Handlers;
using FlightPlanner.Handlers;
using FlightPlanner.Storage;
using Microsoft.AspNetCore.Authentication;
using Microsoft.EntityFrameworkCore;

namespace FlightPlanner
{
Expand All @@ -11,13 +12,15 @@ public static void Main(string[] args)
var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddScoped<FlightStorage>();
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddDbContext<FlightPlannerDbContext>(options => options.UseSqlServer(builder.Configuration.GetConnectionString("flight-planner")));
builder.Services.AddSwaggerGen();
builder.Services.AddAuthentication("BasicAuthentication")
.AddScheme<AuthenticationSchemeOptions, BasicAuthenticationHandler>("BasicAuthentication", null);

var app = builder.Build();

// Configure the HTTP request pipeline.
Expand Down
Loading