Compare commits
2 Commits
680458b0f3
...
ba5766f9d5
Author | SHA1 | Date | |
---|---|---|---|
ba5766f9d5 | |||
25876813e5 |
@ -1,6 +1,6 @@
|
|||||||
# syntax=docker/dockerfile:1.7-labs
|
# syntax=docker/dockerfile:1.7-labs
|
||||||
|
|
||||||
FROM mcr.microsoft.com/dotnet/sdk:9.0-alpine AS build1
|
FROM mcr.microsoft.com/dotnet/sdk:10.0-preview-alpine AS build1
|
||||||
|
|
||||||
WORKDIR /src
|
WORKDIR /src
|
||||||
COPY ./.config ./
|
COPY ./.config ./
|
||||||
@ -10,7 +10,7 @@ WORKDIR Groceries
|
|||||||
COPY ./Groceries/libman.json ./
|
COPY ./Groceries/libman.json ./
|
||||||
RUN dotnet libman restore
|
RUN dotnet libman restore
|
||||||
|
|
||||||
FROM mcr.microsoft.com/dotnet/sdk:9.0-alpine AS build2
|
FROM mcr.microsoft.com/dotnet/sdk:10.0-preview-alpine AS build2
|
||||||
|
|
||||||
WORKDIR /src
|
WORKDIR /src
|
||||||
COPY ./Groceries.sln ./
|
COPY ./Groceries.sln ./
|
||||||
@ -23,7 +23,7 @@ COPY . ./
|
|||||||
COPY --from=build1 /src ./
|
COPY --from=build1 /src ./
|
||||||
RUN dotnet publish --no-restore --output /out
|
RUN dotnet publish --no-restore --output /out
|
||||||
|
|
||||||
FROM mcr.microsoft.com/dotnet/aspnet:9.0-alpine-composite AS base
|
FROM mcr.microsoft.com/dotnet/aspnet:10.0-preview-alpine-composite AS base
|
||||||
WORKDIR /groceries
|
WORKDIR /groceries
|
||||||
|
|
||||||
COPY --from=build2 /out .
|
COPY --from=build2 /out .
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net9.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<WarningsAsErrors>nullable</WarningsAsErrors>
|
<WarningsAsErrors>nullable</WarningsAsErrors>
|
||||||
@ -9,10 +9,10 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="DbUp-PostgreSQL" Version="5.0.40" />
|
<PackageReference Include="DbUp-PostgreSQL" Version="6.0.3" />
|
||||||
<PackageReference Include="EFCore.NamingConventions" Version="9.0.0" />
|
<PackageReference Include="EFCore.NamingConventions" Version="9.0.0" />
|
||||||
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
|
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
|
||||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.2" />
|
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="10.0.0-preview.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net9.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<WarningsAsErrors>nullable</WarningsAsErrors>
|
<WarningsAsErrors>nullable</WarningsAsErrors>
|
||||||
|
@ -32,10 +32,10 @@ public static class HttpRequestExtensions
|
|||||||
return origin.IsBaseOf(uri);
|
return origin.IsBaseOf(uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Uri? GetRefererIfSameOrigin(this HttpRequest request)
|
public static Uri? GetReferrerIfSameOrigin(this HttpRequest request)
|
||||||
{
|
{
|
||||||
var referer = request.GetTypedHeaders().Referer;
|
var referrer = request.GetTypedHeaders().Referer;
|
||||||
return referer != null && request.IsSameOrigin(referer) ? referer : null;
|
return referrer != null && request.IsSameOrigin(referrer) ? referrer : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsTurboFrameRequest(this HttpRequest request, string frameId)
|
public static bool IsTurboFrameRequest(this HttpRequest request, string frameId)
|
||||||
|
@ -65,19 +65,16 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
items = itemsQuery
|
items = itemsQuery
|
||||||
.GroupJoin(
|
.LeftJoin(
|
||||||
dbContext.ItemPurchases.Where(purchase => purchase.IsLastPurchase),
|
dbContext.ItemPurchases.Where(purchase => purchase.IsLastPurchase),
|
||||||
item => item.Id,
|
item => item.Id,
|
||||||
purchase => purchase.ItemId,
|
purchase => purchase.ItemId,
|
||||||
(item, purchases) => new { item, purchases })
|
(item, lastPurchase) => new ItemModel
|
||||||
.SelectMany(
|
|
||||||
group => group.purchases.DefaultIfEmpty(),
|
|
||||||
(group, lastPurchase) => new ItemModel
|
|
||||||
{
|
{
|
||||||
Id = group.item.Id,
|
Id = item.Id,
|
||||||
Brand = group.item.Brand,
|
Brand = item.Brand,
|
||||||
Name = group.item.Name,
|
Name = item.Name,
|
||||||
HasBarcode = group.item.Barcodes.Count != 0,
|
HasBarcode = item.Barcodes.Count > 0,
|
||||||
LastPurchasedAt = lastPurchase != null ? lastPurchase.CreatedAt : null,
|
LastPurchasedAt = lastPurchase != null ? lastPurchase.CreatedAt : null,
|
||||||
})
|
})
|
||||||
.OrderBy(item => item.Brand)
|
.OrderBy(item => item.Brand)
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using DbUp;
|
using DbUp;
|
||||||
|
using DbUp.Engine.Output;
|
||||||
using Groceries.Data;
|
using Groceries.Data;
|
||||||
using Microsoft.AspNetCore.DataProtection;
|
using Microsoft.AspNetCore.DataProtection;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
@ -13,20 +14,6 @@ builder.Configuration
|
|||||||
.AddIniFile(Path.Combine(dataDir, $"config_{env.EnvironmentName}.ini"), optional: true, reloadOnChange: true);
|
.AddIniFile(Path.Combine(dataDir, $"config_{env.EnvironmentName}.ini"), optional: true, reloadOnChange: true);
|
||||||
|
|
||||||
var dbConn = builder.Configuration["Database"]!;
|
var dbConn = builder.Configuration["Database"]!;
|
||||||
EnsureDatabase.For.PostgresqlDatabase(dbConn);
|
|
||||||
|
|
||||||
var dbUpgradeResult = DeployChanges.To
|
|
||||||
.PostgresqlDatabase(dbConn)
|
|
||||||
.JournalToPostgresqlTable("public", "__dbup_migrations")
|
|
||||||
.WithScriptsEmbeddedInAssembly(typeof(AppDbContext).Assembly)
|
|
||||||
.WithTransactionPerScript()
|
|
||||||
.Build()
|
|
||||||
.PerformUpgrade();
|
|
||||||
|
|
||||||
if (!dbUpgradeResult.Successful)
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
var dataProtection = builder.Services.AddDataProtection();
|
var dataProtection = builder.Services.AddDataProtection();
|
||||||
if (env.IsProduction())
|
if (env.IsProduction())
|
||||||
@ -58,6 +45,22 @@ app.MapStaticAssets();
|
|||||||
app.MapControllers()
|
app.MapControllers()
|
||||||
.WithStaticAssets();
|
.WithStaticAssets();
|
||||||
|
|
||||||
await app.RunAsync();
|
var dbUpgradeLogger = new MicrosoftUpgradeLog(app.Logger);
|
||||||
|
EnsureDatabase.For.PostgresqlDatabase(dbConn, dbUpgradeLogger);
|
||||||
|
|
||||||
return 0;
|
var dbUpgradeResult = DeployChanges.To
|
||||||
|
.PostgresqlDatabase(dbConn)
|
||||||
|
.JournalToPostgresqlTable("public", "__dbup_migrations")
|
||||||
|
.WithScriptsEmbeddedInAssembly(typeof(AppDbContext).Assembly)
|
||||||
|
.WithTransactionPerScript()
|
||||||
|
.LogTo(dbUpgradeLogger)
|
||||||
|
.Build()
|
||||||
|
.PerformUpgrade();
|
||||||
|
|
||||||
|
if (!dbUpgradeResult.Successful)
|
||||||
|
{
|
||||||
|
Environment.Exit(-1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
app.Run();
|
||||||
|
@ -24,9 +24,9 @@
|
|||||||
protected override void OnInitialized()
|
protected override void OnInitialized()
|
||||||
{
|
{
|
||||||
var request = HttpContextAccessor.HttpContext!.Request;
|
var request = HttpContextAccessor.HttpContext!.Request;
|
||||||
if (request.GetRefererIfSameOrigin() is Uri referer && referer != request.GetUri())
|
if (request.GetReferrerIfSameOrigin() is Uri referrer && referrer != request.GetUri())
|
||||||
{
|
{
|
||||||
returnUrl = referer.PathAndQuery;
|
returnUrl = referrer.PathAndQuery;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,9 +19,9 @@
|
|||||||
protected override void OnInitialized()
|
protected override void OnInitialized()
|
||||||
{
|
{
|
||||||
var request = HttpContextAccessor.HttpContext!.Request;
|
var request = HttpContextAccessor.HttpContext!.Request;
|
||||||
if (request.GetRefererIfSameOrigin() is Uri referer && referer != request.GetUri())
|
if (request.GetReferrerIfSameOrigin() is Uri referrer && referrer != request.GetUri())
|
||||||
{
|
{
|
||||||
returnUrl = referer.PathAndQuery;
|
returnUrl = referrer.PathAndQuery;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -97,17 +97,14 @@
|
|||||||
items = await dbContext.Items
|
items = await dbContext.Items
|
||||||
.OrderBy(item => item.Brand)
|
.OrderBy(item => item.Brand)
|
||||||
.ThenBy(item => item.Name)
|
.ThenBy(item => item.Name)
|
||||||
.GroupJoin(
|
.LeftJoin(
|
||||||
dbContext.ItemPurchases.Where(purchase => purchase.IsLastPurchase),
|
dbContext.ItemPurchases.Where(purchase => purchase.IsLastPurchase),
|
||||||
item => item.Id,
|
item => item.Id,
|
||||||
lastPurchase => lastPurchase.ItemId,
|
lastPurchase => lastPurchase.ItemId,
|
||||||
(item, purchases) => new { item, purchases })
|
(item, lastPurchase) => new ItemModel(
|
||||||
.SelectMany(
|
item.Id,
|
||||||
group => group.purchases.DefaultIfEmpty(),
|
item.Brand,
|
||||||
(group, lastPurchase) => new ItemModel(
|
item.Name,
|
||||||
group.item.Id,
|
|
||||||
group.item.Brand,
|
|
||||||
group.item.Name,
|
|
||||||
lastPurchase != null ? lastPurchase.Price : null,
|
lastPurchase != null ? lastPurchase.Price : null,
|
||||||
lastPurchase != null ? lastPurchase.Quantity : null))
|
lastPurchase != null ? lastPurchase.Quantity : null))
|
||||||
.ToArrayAsync();
|
.ToArrayAsync();
|
||||||
|
@ -3,11 +3,11 @@
|
|||||||
"defaultProvider": "unpkg",
|
"defaultProvider": "unpkg",
|
||||||
"libraries": [
|
"libraries": [
|
||||||
{
|
{
|
||||||
"library": "@fontsource-variable/inter@5.1.1",
|
"library": "@fontsource-variable/inter@5.2.5",
|
||||||
"destination": "wwwroot/lib/inter/"
|
"destination": "wwwroot/lib/inter/"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"library": "@hotwired/turbo@8.0.12",
|
"library": "@hotwired/turbo@8.0.13",
|
||||||
"destination": "wwwroot/lib/hotwired/turbo/"
|
"destination": "wwwroot/lib/hotwired/turbo/"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user