Skip to content

Commit

Permalink
Update to .net 8, update nuget packages, optimize interface
Browse files Browse the repository at this point in the history
  • Loading branch information
tinohager committed Jan 2, 2024
1 parent 0001aca commit 6f63dd0
Show file tree
Hide file tree
Showing 13 changed files with 277 additions and 101 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: Setup .NET Core
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
dotnet-version: 8.0.x
- name: Install dependencies
run: dotnet restore
working-directory: ${{env.working-directory}}
Expand Down

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Nager.AuthenticationService.MssqlRepository.Migrations
{
/// <inheritdoc />
public partial class AddValidationTimestamp : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<DateTime>(
name: "LastSuccessfulValidationTimestamp",
table: "Users",
type: "datetime2",
nullable: false,
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));

migrationBuilder.AddColumn<DateTime>(
name: "LastValidationTimestamp",
table: "Users",
type: "datetime2",
nullable: false,
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));
}

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

migrationBuilder.DropColumn(
name: "LastValidationTimestamp",
table: "Users");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
Expand All @@ -16,7 +17,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.13")
.HasAnnotation("ProductVersion", "8.0.0")
.HasAnnotation("Relational:MaxIdentifierLength", 128);

SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
Expand All @@ -36,6 +37,12 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.HasMaxLength(200)
.HasColumnType("nvarchar(200)");

b.Property<DateTime>("LastSuccessfulValidationTimestamp")
.HasColumnType("datetime2");

b.Property<DateTime>("LastValidationTimestamp")
.HasColumnType("datetime2");

b.Property<string>("Lastname")
.HasMaxLength(200)
.HasColumnType("nvarchar(200)");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public async Task<UserEntity[]> QueryAsync(
Expression<Func<UserEntity, bool>>? predicate = default,
CancellationToken cancellationToken = default)
{
var query = this._databaseContext.Users.AsQueryable();
if (predicate != null )
var query = this._databaseContext.Users.AsNoTracking().AsQueryable();
if (predicate != null)
{
query = query.Where(predicate);
}
Expand All @@ -33,7 +33,7 @@ public async Task<UserEntity[]> QueryAsync(
Expression<Func<UserEntity, bool>> predicate,
CancellationToken cancellationToken = default)
{
var query = this._databaseContext.Users.AsQueryable();
var query = this._databaseContext.Users.AsNoTracking().AsQueryable();
if (predicate != null)
{
query = query.Where(predicate);
Expand Down Expand Up @@ -77,11 +77,33 @@ public async Task<bool> DeleteAsync(
Expression<Func<UserEntity, bool>> predicate,
CancellationToken cancellationToken = default)
{
var items = await this._databaseContext.Users.Where(predicate).ToArrayAsync(cancellationToken);
this._databaseContext.Users.RemoveRange(items);
await this._databaseContext.SaveChangesAsync(cancellationToken);
var totalRowsDeleted = await this._databaseContext.Users
.Where(predicate)
.ExecuteDeleteAsync(cancellationToken);

return true;
return totalRowsDeleted > 0;
}

public async Task<bool> SetLastValidationTimestampAsync(
Expression<Func<UserEntity, bool>> predicate,
CancellationToken cancellationToken = default)
{
var updatedRows = await this._databaseContext.Users
.Where(predicate)
.ExecuteUpdateAsync(s => s.SetProperty(e => e.LastValidationTimestamp, DateTime.UtcNow), cancellationToken);

return updatedRows > 0;
}

public async Task<bool> SetLastSuccessfulValidationTimestampAsync(
Expression<Func<UserEntity, bool>> predicate,
CancellationToken cancellationToken = default)
{
var updatedRows = await this._databaseContext.Users
.Where(predicate)
.ExecuteUpdateAsync(s => s.SetProperty(e => e.LastSuccessfulValidationTimestamp, DateTime.UtcNow), cancellationToken);

return updatedRows > 0;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

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

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.13" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.13">
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.13" />
<PackageReference Include="Nager.Authentication.Abstraction" Version="1.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
<PackageReference Include="Nager.Authentication.Abstraction" Version="1.1.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.13" />
<PackageReference Include="Nager.Authentication.AspNet" Version="1.0.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0" />
<PackageReference Include="Nager.Authentication.AspNet" Version="1.1.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
},
"AllowedHosts": "*",
"ConnectionStrings": {
"Default": "Server=127.0.0.1;Database=WebApp6;User Id=sa;Password=yourStrong(!)Password;MultipleActiveResultSets=true;TrustServerCertificate=true;"
"Default": "Server=127.0.0.1;Database=AuthenticationService;User Id=sa;Password=yourStrong(!)Password;MultipleActiveResultSets=true;TrustServerCertificate=true;"
},
"Authentication": {
"Tokens": {
"Issuer": "Issuer.PLEASE.CHANGE.ME",
"Audience": "Audience.PLEASE.CHANGE.ME",
"SigningKey": "SigningKey.PLEASE.CHANGE.ME"
"SigningKey": "The.SigningKey.ForUserData.PLEASE.CHANGE.ME"
}
}
}
14 changes: 6 additions & 8 deletions src/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
FROM mcr.microsoft.com/dotnet/aspnet:6.0-alpine
FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine

# Listen ports
EXPOSE 80

# Install cultures (same approach as Alpine SDK image)
RUN apk add --no-cache icu-libs

# Disable the invariant mode (set in base image)
# Avoid SQL Globalization Error
RUN apk add icu-libs
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false

# Listen ports
EXPOSE 8080

# Copy files from other build jobs
COPY publish .

Expand Down
Loading

0 comments on commit 6f63dd0

Please sign in to comment.