Skip to content

Commit

Permalink
Reimplemented updated version of sample app
Browse files Browse the repository at this point in the history
  • Loading branch information
fancyDevelopment committed Aug 10, 2024
1 parent 517eef1 commit 255b61e
Show file tree
Hide file tree
Showing 331 changed files with 14,593 additions and 16,600 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public FlightsController(
[Route("api/flight-management/flights/summary")]
public async Task<IActionResult> GetFlightsSummary()
{
_logger.LogInformation("Reading flights summary.");
_logger.LogInformation("Reading flights summary by user: " + User.Identity!.Name);
IQueryable<Flight> query = _flightManagementDbContext.Flights;
FlightsSummaryDto result = new FlightsSummaryDto();
result.FlightCount = await _flightManagementDbContext.Flights.CountAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<Compile Remove="Migrations\**" />
<Content Remove="Migrations\**" />
<EmbeddedResource Remove="Migrations\**" />
<None Remove="Migrations\**" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.6" />
Expand All @@ -21,7 +14,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.6" />
<PackageReference Include="Fancy.ResourceLinker.Hateoas" Version="0.0.9" />
<PackageReference Include="Fancy.ResourceLinker.Hateoas" Version="1.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ protected override void LinkResourceInternal(Flight resource, IUrlHelper urlHelp
//Add links
resource.AddLink("self", urlHelper.LinkTo<FlightsController>(c => c.GetFlightById(resource.Id)));

resource.Connection.AddAction("update", "PUT", urlHelper.LinkTo<FlightsController>(c => c.UpdateFlightConnection(resource.Id, null!)));
resource.Times.AddAction("update", "PUT", urlHelper.LinkTo<FlightsController>(c => c.UpdateFlightTimes(resource.Id, null!)));

// Add actions
if (urlHelper.ActionContext.HttpContext.User.Claims.Any(c => c.Type == "caneditoperator" && c.Value == "true"))
if (urlHelper.ActionContext.HttpContext.User.IsInRole("flightmanagement-admin"))
{
resource.Connection.AddAction("update", "PUT", urlHelper.LinkTo<FlightsController>(c => c.UpdateFlightConnection(resource.Id, null!)));
resource.Times.AddAction("update", "PUT", urlHelper.LinkTo<FlightsController>(c => c.UpdateFlightTimes(resource.Id, null!)));
resource.Operator?.AddAction("update", "PUT", urlHelper.LinkTo<FlightsController>(c => c.UpdateFlightOperator(resource.Id, null!)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.IdentityModel.Logging;

IdentityModelEventSource.ShowPII = true;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
Expand All @@ -16,7 +18,6 @@
string? connectionString = builder.Configuration.GetConnectionString("database");
builder.Services.AddDbContext<FlightManagementDbContext>(options => options.UseSqlServer(connectionString));

IdentityModelEventSource.ShowPII = true;
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options =>
{
options.Authority = builder.Configuration.GetValue<string>("Authentication:Authority");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Trace",
"Microsoft.AspNetCore": "Trace"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"AllowedHosts": "*",

"ConnectionStrings": {
"database": "Server=.;Database=FlightManagement_sample;User Id=sa;Password=SA@sqlserver;TrustServerCertificate=True"
"database": "Server=.;Database=Sample_FlightManagement;User Id=sa;Password=SA@sqlserver;TrustServerCertificate=True"
},

"Authentication": {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.6" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
<PackageReference Include="Fancy.ResourceLinker.Hateoas" Version="0.0.9" />
<PackageReference Include="Fancy.ResourceLinker.Hateoas" Version="1.0.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ public class FlightLinkStrategy : LinkStrategyBase<Flight>
protected override void LinkResourceInternal(Flight resource, IUrlHelper urlHelper)
{
resource.AddLink("self", urlHelper.LinkTo<FlightsController>(c => c.GetFlightById(resource.Id)));
resource.Price?.AddAction("update", "PUT", urlHelper.LinkTo<FlightsController>(c => c.UpdatePrice(resource.Id, null!)));
if(urlHelper.ActionContext.HttpContext.User.IsInRole("flightshopping-admin"))
{
resource.Price?.AddAction("update", "PUT", urlHelper.LinkTo<FlightsController>(c => c.UpdatePrice(resource.Id, null!)));
}
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"AllowedHosts": "*",

"ConnectionStrings": {
"database": "Server=.;Database=FlightShopping_sample;User Id=sa;Password=SA@sqlserver;TrustServerCertificate=True"
"database": "Server=.;Database=Sample_FlightShopping;User Id=sa;Password=SA@sqlserver;TrustServerCertificate=True"
},

"Authentication": {
Expand Down
51 changes: 51 additions & 0 deletions Backend/Fancy.ResourceLinker.Sample.Backend.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AppServices", "AppServices", "{5EA7671B-E745-4CCB-B24B-3399D6E91809}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Gateways", "Gateways", "{3DA359CB-8189-4723-8985-A487FCADAEB9}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FlightManagement", "AppServices\FlightManagement\FlightManagement.csproj", "{E790834F-1965-418B-8EBC-C06792824E77}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AdminClientApi", "Gateways\AdminClientApi\AdminClientApi.csproj", "{9659FFE9-1262-4D18-A714-2D9F00DBD604}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FlightShopping", "AppServices\FlightShopping\FlightShopping.csproj", "{FFB90C99-99BD-407C-A10B-42AF5871C49A}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{FFB6B719-5E1B-470F-BC71-85C81F7DA201}"
ProjectSection(SolutionItems) = preProject
global.json = global.json
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E790834F-1965-418B-8EBC-C06792824E77}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E790834F-1965-418B-8EBC-C06792824E77}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E790834F-1965-418B-8EBC-C06792824E77}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E790834F-1965-418B-8EBC-C06792824E77}.Release|Any CPU.Build.0 = Release|Any CPU
{9659FFE9-1262-4D18-A714-2D9F00DBD604}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9659FFE9-1262-4D18-A714-2D9F00DBD604}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9659FFE9-1262-4D18-A714-2D9F00DBD604}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9659FFE9-1262-4D18-A714-2D9F00DBD604}.Release|Any CPU.Build.0 = Release|Any CPU
{FFB90C99-99BD-407C-A10B-42AF5871C49A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FFB90C99-99BD-407C-A10B-42AF5871C49A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FFB90C99-99BD-407C-A10B-42AF5871C49A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FFB90C99-99BD-407C-A10B-42AF5871C49A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{E790834F-1965-418B-8EBC-C06792824E77} = {5EA7671B-E745-4CCB-B24B-3399D6E91809}
{9659FFE9-1262-4D18-A714-2D9F00DBD604} = {3DA359CB-8189-4723-8985-A487FCADAEB9}
{FFB90C99-99BD-407C-A10B-42AF5871C49A} = {5EA7671B-E745-4CCB-B24B-3399D6E91809}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9431CF92-4165-471B-A1BE-CB40F6DC289F}
EndGlobalSection
EndGlobal
15 changes: 15 additions & 0 deletions Backend/Gateways/AdminClientApi/AdminClientApi.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
<PackageReference Include="Fancy.ResourceLinker.Gateway" Version="1.0.0" />
<PackageReference Include="Fancy.ResourceLinker.Hateoas" Version="1.0.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,16 @@ await Task.WhenAll(result.Flights.Select(async (dynamic f) =>
[Route("api/views/flight/{flightId}/edit")]
public async Task<IActionResult> GetEditViewModel(int flightId)
{
var managementFlight = _router.GetFlightManagementFlight<FlightEditViewModel>(flightId);
var managementFlight = _router.GetFlightManagementFlight<DynamicResource>(flightId);
var shoppingFlight = _router.GetFlightShoppingFlight<DynamicResource>(flightId);

try
{
// Merge price value object into the result of the flight object from flight management
dynamic result = await managementFlight;
result.Price = ((dynamic) await shoppingFlight).Price;
dynamic flight = await managementFlight;
flight.Price = ((dynamic) await shoppingFlight).Price;

return Hypermedia(result);
return Hypermedia(new FlightEditViewModel(flight));
}
catch (HttpRequestException e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ public class FlightEditLinkStrategy : LinkStrategyBase<FlightEditViewModel>
{
protected override void LinkResourceInternal(FlightEditViewModel resource, IUrlHelper urlHelper)
{
resource.AddLink("self", urlHelper.LinkTo<FlightsController>(c => c.GetEditViewModel(resource.Id)));
resource.AddLink("self", urlHelper.LinkTo<FlightsController>(c => c.GetEditViewModel(resource.Flight.GetAsInt("Id"))));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Fancy.ResourceLinker.Models;

namespace Gateway.Controllers.Flights;

public class FlightEditViewModel : DynamicResourceBase
{
public FlightEditViewModel(DynamicResource flight)
{
Flight = flight;
}

public DynamicResource Flight { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ protected override void LinkResourceInternal(RootViewModel resource, IUrlHelper
resource.AddLink("flightSearchVm", urlHelper.LinkTo<FlightsController>(c => c.GetSearchViewModel(null, null)));

if(urlHelper.ActionContext.HttpContext.User.Identity?.IsAuthenticated ?? false)
resource.AddLink("userinfo", "/userinfo");
resource.AddLink("userinfo", urlHelper.LinkTo("userinfo"));
}
}
21 changes: 21 additions & 0 deletions Backend/Gateways/AdminClientApi/Controllers/Routes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Fancy.ResourceLinker.Gateway.Routing;

namespace Sample.Gateway.Controllers;

public static class Routes
{
public static Task<T> GetFlightManagementFlightSummary<T>(this GatewayRouter router) where T : class =>
router.GetCachedAsync<T>("FlightManagement", $"/api/flight-management/flights/summary", TimeSpan.FromSeconds(30));

public static Task<T> GetFlightShoppingFlightSummary<T>(this GatewayRouter router) where T : class =>
router.GetCachedAsync<T>("FlightShopping", $"/api/flight-shopping/flights/summary", TimeSpan.FromSeconds(30));

public static Task<List<T>> GetFlightManagementFlights<T>(this GatewayRouter router, string? from, string? to) where T : class =>
router.GetAsync<List<T>>("FlightManagement", $"/api/flight-management/flights?from={from ?? ""}&to={to ?? ""}");

public static Task<T> GetFlightManagementFlight<T>(this GatewayRouter router, int flightId) where T : class =>
router.GetAsync<T>("FlightManagement", $"/api/flight-management/flights/{flightId}");

public static Task<T> GetFlightShoppingFlight<T>(this GatewayRouter router, int flightId) where T : class =>
router.GetAsync<T>("FlightShopping", $"/api/flight-shopping/flights/{flightId}");
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Fancy.ResourceLinker.Gateway;
using Fancy.ResourceLinker.Hateoas;
using Microsoft.IdentityModel.Logging;
using OpenTelemetry.Trace;
using OpenTelemetry.Resources;

IdentityModelEventSource.ShowPII = true;

var builder = WebApplication.CreateBuilder(args);

Expand All @@ -16,25 +16,11 @@
builder.Services.AddGateway()
.LoadConfiguration(builder.Configuration.GetSection("Gateway"))
.AddRouting()
.AddAntiForgery()
.AddAuthentication();

builder.Services.AddOpenTelemetry()
.WithTracing(builder =>
{
builder.AddSource("Sample.Gateway")
.ConfigureResource(resource => resource.AddService("Sample.Gateway"))
.AddAspNetCoreInstrumentation()
.AddHttpClientInstrumentation()
.AddOtlpExporter(opts => opts.Endpoint = new Uri("http://localhost:4317"));
});

IdentityModelEventSource.ShowPII = true;
.AddAuthentication()
.AddAntiForgery();

var app = builder.Build();

app.UseGatewayAuthentication();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
Expand All @@ -43,6 +29,7 @@
app.UseCors(builder => builder.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin());
}

app.UseGatewayAuthentication();
app.UseGatewayAuthenticationEndpoints();
app.UseGatewayAntiForgery();

Expand Down
8 changes: 8 additions & 0 deletions Backend/Gateways/AdminClientApi/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Trace",
"Microsoft.AspNetCore": "Trace"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"Authentication": {
"Authority": "http://localhost:8080/realms/ResourceLinker-Sample",
"ClientId": "gateway",
"AuthorizationCodeScopes": "openid",
"Scopes": "openid",
"SessionTimeoutInMin": 1,
"UniqueIdentifierClaimType": "preferred_username"
},
Expand All @@ -28,14 +28,11 @@
},
"FlightShopping": {
"BaseUrl": "http://localhost:5001",
"PathMatch": "api/flight-shopping/{**path}",
"Authentication": {
"Strategy": "TokenPassThrough"
}
"PathMatch": "api/flight-shopping/{**path}"
},
"LegacyApp": {
"LegacyWebFormsApp": {
"BaseUrl": "http://localhost:4300",
"PathMatch": "Sample.LegacyApp/{**path}",
"PathMatch": "LegacyWebFormsApp/{**path}",
"Authentication": {
"Strategy": "TokenPassThrough"
}
Expand Down
2 changes: 1 addition & 1 deletion src/global.json → Backend/global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "7.0.0",
"version": "8.0.0",
"rollForward": "latestFeature"
}
}
43 changes: 0 additions & 43 deletions Fancy.ResourceLinker-Sample.sln

This file was deleted.

File renamed without changes.
2 changes: 1 addition & 1 deletion src/Sample.Frontend/.gitignore → Frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# See http://help.github.com/ignore-files/ for more about ignoring files.
# See https://docs.github.com/get-started/getting-started-with-git/ignoring-files for more about ignoring files.

# Compiled output
/dist
Expand Down
Loading

0 comments on commit 255b61e

Please sign in to comment.