Skip to content

Commit

Permalink
optimize last validation timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
tinohager committed Jan 2, 2024
1 parent da1a999 commit 95d1912
Show file tree
Hide file tree
Showing 10 changed files with 180 additions and 41 deletions.

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,60 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Nager.AuthenticationService.MssqlRepository.Migrations
{
/// <inheritdoc />
public partial class OptimizeValidationTimestamp : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "LastValidationTimestamp",
table: "Users");

migrationBuilder.AlterColumn<DateTime>(
name: "LastSuccessfulValidationTimestamp",
table: "Users",
type: "datetime2",
nullable: true,
oldClrType: typeof(DateTime),
oldType: "datetime2");

migrationBuilder.AddColumn<DateTime>(
name: "LastFailedValidationTimestamp",
table: "Users",
type: "datetime2",
nullable: true);

migrationBuilder.Sql("UPDATE Users SET LastSuccessfulValidationTimestamp = NULL");
}

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

migrationBuilder.AlterColumn<DateTime>(
name: "LastSuccessfulValidationTimestamp",
table: "Users",
type: "datetime2",
nullable: false,
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
oldClrType: typeof(DateTime),
oldType: "datetime2",
oldNullable: true);

migrationBuilder.AddColumn<DateTime>(
name: "LastValidationTimestamp",
table: "Users",
type: "datetime2",
nullable: false,
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.HasMaxLength(200)
.HasColumnType("nvarchar(200)");

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

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

b.Property<string>("Lastname")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public async Task<bool> SetLastValidationTimestampAsync(
{
var updatedRows = await this._databaseContext.Users
.Where(predicate)
.ExecuteUpdateAsync(s => s.SetProperty(e => e.LastValidationTimestamp, DateTime.UtcNow), cancellationToken);
.ExecuteUpdateAsync(s => s.SetProperty(e => e.LastFailedValidationTimestamp, DateTime.UtcNow), cancellationToken);

return updatedRows > 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
<PackageReference Include="Nager.Authentication.Abstraction" Version="1.1.0" />
<PackageReference Include="Nager.Authentication.Abstraction" Version="1.2.0" />
</ItemGroup>

</Project>
12 changes: 12 additions & 0 deletions src/Backend/Nager.AuthenticationService.WebApi/MigrationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,19 @@

namespace Nager.AuthenticationService.WebApi
{
/// <summary>
/// MigrationHelper
/// </summary>
public class MigrationHelper
{
private readonly ILogger<MigrationHelper> _logger;
private readonly IServiceScopeFactory _serviceScopeFactory;

/// <summary>
/// MigrationHelper
/// </summary>
/// <param name="logger"></param>
/// <param name="serviceScopeFactory"></param>
public MigrationHelper(
ILogger<MigrationHelper> logger,
IServiceScopeFactory serviceScopeFactory)
Expand All @@ -16,6 +24,10 @@ public MigrationHelper(
this._serviceScopeFactory = serviceScopeFactory;
}

/// <summary>
/// Update the database structure
/// </summary>
/// <returns></returns>
public async Task<bool> UpdateDatabaseAsync()
{
var retryCount = 60;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0" />
<PackageReference Include="Nager.Authentication.AspNet" Version="1.1.1" />
<PackageReference Include="Nager.Authentication.AspNet" Version="1.2.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>

Expand Down
9 changes: 3 additions & 6 deletions src/Backend/Nager.AuthenticationService.WebApi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
{
var issuer = builder.Configuration["Authentication:Tokens:Issuer"];
var audience = builder.Configuration["Authentication:Tokens:Audience"];
var signingKey = builder.Configuration["Authentication:Tokens:SigningKey"];
var signingKey = builder.Configuration["Authentication:Tokens:SigningKey"] ?? throw new NullReferenceException("Missing configuration for SigningKey");

//configuration.RequireHttpsMetadata = false;
configuration.SaveToken = true;
Expand Down Expand Up @@ -169,10 +169,7 @@
app.UseAuthentication();
app.UseAuthorization();

app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapFallbackToFile("index.html");
});
app.MapFallbackToFile("index.html");
app.MapControllers();

app.Run();
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
{
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Nager.AuthenticationService..WebApi": {
"Nager.AuthenticationService.WebApi": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
Expand All @@ -18,13 +10,5 @@
"applicationUrl": "http://localhost:5234"
}
},
"$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:60638",
"sslPort": 0
}
}
"$schema": "https://json.schemastore.org/launchsettings.json"
}
35 changes: 23 additions & 12 deletions src/Frontend/src/components/UserManagementList.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { QTableProps, useQuasar } from 'quasar'
import { QTableProps, useQuasar, date } from 'quasar'
import { User } from 'src/models/User'
Expand All @@ -26,31 +26,42 @@ const columns : QTableProps['columns'] = [
label: 'Email Address',
align: 'left',
field: row => row.emailAddress,
format: val => `${val}`
format: val => `${val}`,
style: 'width: 300px'
},
{
name: 'name',
required: true,
label: 'Name',
align: 'left',
field: row => row,
format: row => `${row.lastname} ${row.firstname}`,
style: 'width: 300px'
},
{
name: 'roles',
required: true,
label: 'Roles',
align: 'left',
field: row => row.roles,
format: val => `${val}`
field: row => row.roles
},
{
name: 'firstname',
name: 'lastFailedValidationTimestamp',
required: true,
label: 'Firstname',
label: 'Last Failed Validation',
align: 'left',
field: row => row.firstname,
format: val => `${val}`
field: row => row.lastValidationTimestamp,
format: val => date.formatDate(val, 'YYYY-MM-DD HH:mm'),
style: 'width: 180px'
},
{
name: 'lastname',
name: 'roles2',
required: true,
label: 'Lastname',
label: 'Last Successful Validation',
align: 'left',
field: row => row.lastname,
format: val => `${val}`
field: row => row.lastSuccessfulValidationTimestamp,
format: val => date.formatDate(val, 'YYYY-MM-DD HH:mm'),
style: 'width: 180px'
},
{
name: 'actions',
Expand Down

0 comments on commit 95d1912

Please sign in to comment.