Skip to content

Commit 2692bef

Browse files
authored
Merge pull request #624 from bcgov/2.0.6
2.0.6
2 parents 02c17c1 + 9ffa20c commit 2692bef

39 files changed

+1557
-871
lines changed

.pipeline/lib/config.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
const options = require("@bcgov/pipeline-cli").Util.parseArguments();
33

44
const changeId = options.pr; //aka pull-request
5-
const version = "2.0.0";
5+
const version = "2.0.6";
66
const name = "sbi"; //project name prefix
77

88
Object.assign(options.git, { owner: "ychung-mot", repository: "schoolbus" });
@@ -30,11 +30,11 @@ const phases = {
3030
host: `sbi-e82e9a-dev.apps.silver.devops.gov.bc.ca`,
3131
dotnet_env: "Development",
3232
dbUser: "userUXN",
33-
dbSize: "5Gi",
33+
dbSize: "10Gi",
3434
transient: true,
3535
backupVolume: "schoolbus",
36-
backupVolumeSize: "5Gi",
37-
verificationVolumeSize: "5Gi",
36+
backupVolumeSize: "10Gi",
37+
verificationVolumeSize: "10Gi",
3838
},
3939
test: {
4040
namespace: "e82e9a-test",
@@ -47,7 +47,7 @@ const phases = {
4747
tag: `test-${version}`,
4848
host: `sbi-e82e9a-test.apps.silver.devops.gov.bc.ca`,
4949
dbUser: "user7KU",
50-
dbSize: "5Gi",
50+
dbSize: "6Gi",
5151
dotnet_env: "Staging",
5252
backupVolume: "schoolbus",
5353
backupVolumeSize: "5Gi",

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ The application is being developed as an open source solution.
2020

2121
## Prerequisites
2222

23-
- .Net Core 3.1 SDK
23+
- .Net 7
2424
- Node.JS v13.7.0 or newer
2525
- PostgreSQL 10
2626

@@ -130,5 +130,4 @@ Please note that this project is released with a [Contributor Code of Conduct](C
130130
## Maintenance
131131

132132
This repository is maintained by [BC Ministry of Transportation](http://www.th.gov.bc.ca/).
133-
Click [here](https://github.com/orgs/bcgov/teams/tran/repositories) for a complete list of our repositories on GitHub.
134-
133+
Click [here](https://github.com/orgs/bcgov/teams/tran/repositories) for a complete list of our repositories on GitHub.

Server/SchoolBusAPI/Authentication/SbJwtBearerEvents.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,10 @@ namespace SchoolBusAPI.Authentication
1313
public class SbJwtBearerEvents : JwtBearerEvents
1414
{
1515
private DbAppContext _dbContext;
16-
private ILogger<SbJwtBearerEvents> _logger;
1716

18-
public SbJwtBearerEvents(DbAppContext dbContext, ILogger<SbJwtBearerEvents> logger) : base()
17+
public SbJwtBearerEvents(DbAppContext dbContext) : base()
1918
{
2019
_dbContext = dbContext;
21-
_logger = logger;
2220
}
2321

2422
public override async Task AuthenticationFailed(AuthenticationFailedContext context)

Server/SchoolBusAPI/Authorization/PermissionHandler.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,10 @@ public static IServiceCollection RegisterPermissionHandler(this IServiceCollecti
2828
/// </remarks>
2929
public class PermissionHandler : AuthorizationHandler<PermissionRequirement>
3030
{
31-
private ILogger _logger;
3231
private IHttpContextAccessor _httpContextAccessor;
3332

34-
public PermissionHandler(ILogger logger, IHttpContextAccessor httpContextAccessor)
33+
public PermissionHandler(IHttpContextAccessor httpContextAccessor)
3534
{
36-
_logger = logger;
3735
_httpContextAccessor = httpContextAccessor;
3836
}
3937

@@ -53,7 +51,7 @@ protected override Task HandleRequirementAsync(AuthorizationHandlerContext conte
5351
}
5452
else
5553
{
56-
_logger.Information("RequiresPermission - {user} - {url}", user.Identity.Name, _httpContextAccessor.HttpContext.Request.Path);
54+
Log.Information("RequiresPermission - {user} - {url}", user.Identity.Name, _httpContextAccessor.HttpContext.Request.Path);
5755
}
5856

5957
return Task.CompletedTask;

Server/SchoolBusAPI/DbAppContext.cs

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,14 @@
1212
using Microsoft.EntityFrameworkCore;
1313
using Microsoft.EntityFrameworkCore.ChangeTracking;
1414
using Microsoft.EntityFrameworkCore.Storage;
15-
using Microsoft.Extensions.Logging;
15+
using Serilog;
1616
using SchoolBusAPI.Extensions;
1717
using SchoolBusAPI.ViewModels;
1818
using SchoolBusCommon;
1919
using System;
2020
using System.Collections.Generic;
2121
using System.Linq;
2222
using System.Security.Claims;
23-
using System.Text;
2423

2524
namespace SchoolBusAPI.Models
2625
{
@@ -33,18 +32,16 @@ public class DbAppContextFactory : IDbAppContextFactory
3332
{
3433
DbContextOptions<DbAppContext> _options;
3534
IHttpContextAccessor _httpContextAccessor;
36-
ILogger<DbAppContext> _logger;
3735

38-
public DbAppContextFactory(IHttpContextAccessor httpContextAccessor, DbContextOptions<DbAppContext> options, ILogger<DbAppContext> logger)
36+
public DbAppContextFactory(IHttpContextAccessor httpContextAccessor, DbContextOptions<DbAppContext> options)
3937
{
4038
_options = options;
4139
_httpContextAccessor = httpContextAccessor;
42-
_logger = logger;
4340
}
4441

4542
public IDbAppContext Create()
4643
{
47-
return new DbAppContext(_httpContextAccessor, _options, _logger);
44+
return new DbAppContext(_httpContextAccessor, _options);
4845
}
4946
}
5047

@@ -91,16 +88,16 @@ public interface IDbAppContext
9188
public class DbAppContext : DbContext, IDbAppContext
9289
{
9390
private readonly IHttpContextAccessor _httpContextAccessor;
94-
private readonly ILogger<DbAppContext> _logger;
9591

9692
/// <summary>
9793
/// Constructor for Class used for Entity Framework access.
9894
/// </summary>
99-
public DbAppContext(IHttpContextAccessor httpContextAccessor, DbContextOptions<DbAppContext> options, ILogger<DbAppContext> logger)
95+
public DbAppContext(IHttpContextAccessor httpContextAccessor, DbContextOptions<DbAppContext> options)
10096
: base(options)
10197
{
10298
_httpContextAccessor = httpContextAccessor;
103-
_logger = logger;
99+
// To fix datetime utc issue after upgraded to .net 7.0
100+
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
104101
}
105102

106103
/// <summary>
@@ -114,6 +111,37 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
114111
modelBuilder.Entity<Contact>()
115112
.HasOne(s => s.SchoolBusOwner)
116113
.WithMany(g => g.Contacts);
114+
115+
/*
116+
// Npgsql 6+ datetime type issue
117+
var dateTimeConverter = new ValueConverter<DateTime, DateTime>(
118+
v => v.ToUniversalTime(),
119+
v => DateTime.SpecifyKind(v, DateTimeKind.Utc));
120+
121+
var nullableDateTimeConverter = new ValueConverter<DateTime?, DateTime?>(
122+
v => v.HasValue ? v.Value.ToUniversalTime() : v,
123+
v => v.HasValue ? DateTime.SpecifyKind(v.Value, DateTimeKind.Utc) : v);
124+
125+
foreach (var entityType in modelBuilder.Model.GetEntityTypes())
126+
{
127+
if (entityType.IsKeyless)
128+
{
129+
continue;
130+
}
131+
132+
foreach (var property in entityType.GetProperties())
133+
{
134+
if (property.ClrType == typeof(DateTime))
135+
{
136+
property.SetValueConverter(dateTimeConverter);
137+
}
138+
else if (property.ClrType == typeof(DateTime?))
139+
{
140+
property.SetValueConverter(nullableDateTimeConverter);
141+
}
142+
}
143+
}
144+
*/
117145
}
118146

119147
public virtual DbSet<Audit> Audits { get; set; }
@@ -252,7 +280,8 @@ public override int SaveChanges()
252280
var modifiedEntries = ChangeTracker.Entries()
253281
.Where(e => e.State == EntityState.Added || e.State == EntityState.Modified || e.State == EntityState.Deleted).ToList();
254282

255-
DateTime currentTime = DateTime.UtcNow;
283+
DateTime utcCurrentTime = DateTime.UtcNow;
284+
DateTime currentTime = DateTime.SpecifyKind(utcCurrentTime, DateTimeKind.Unspecified);
256285

257286
foreach (var entry in modifiedEntries)
258287
{
@@ -341,7 +370,7 @@ public override int SaveChanges()
341370
catch (Exception e)
342371
{
343372
string exceptionMessage = e.ToString();
344-
_logger.LogError($"DbAppContext exception: {exceptionMessage}");
373+
Log.Error($"DbAppContext exception: {exceptionMessage}");
345374
}
346375
}
347376
}

Server/SchoolBusAPI/Extensions/IDbAppContextExtensions.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Microsoft.EntityFrameworkCore;
22
using Newtonsoft.Json;
33
using SchoolBusAPI.Models;
4+
using SchoolBusCommon.Helpers;
45
using System;
56
using System.Collections.Generic;
67
using System.IO;
@@ -251,7 +252,8 @@ private static void AddInitialUser(this IDbAppContext context, User initialUser)
251252
user.UserRoles.Add(
252253
new UserRole
253254
{
254-
EffectiveDate = DateTime.UtcNow.Date,
255+
EffectiveDate = DateUtils.ConvertPacificToUtcTime(
256+
new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0)),
255257
Role = role
256258
});
257259
}

Server/SchoolBusAPI/Hangfire/CcwJobService.cs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using Hangfire;
22
using Microsoft.Extensions.Configuration;
3-
using Microsoft.Extensions.Logging;
3+
using Serilog;
44
using SchoolBusAPI.Models;
55
using SchoolBusAPI.Services;
66
using SchoolBusCcw;
@@ -21,19 +21,15 @@ public class CcwJobService : ICcwJobService
2121
private readonly DbAppContext _context;
2222
private readonly IConfiguration _configuration;
2323
private readonly ICCWDataService _ccwDataService;
24-
private readonly ILogger _logger;
25-
2624
private readonly string _userId;
2725
private readonly string _userGuid;
2826
private readonly string _userDir;
2927

30-
public CcwJobService(DbAppContext context, IConfiguration configuration, ICCWDataService ccwDataService, ILogger<CcwJobService> logger)
28+
public CcwJobService(DbAppContext context, IConfiguration configuration, ICCWDataService ccwDataService)
3129
{
3230
_context = context;
3331
_configuration = configuration;
3432
_ccwDataService = ccwDataService;
35-
_logger = logger;
36-
3733
_userId = _configuration["CCW_USER_ID"];
3834
_userGuid = _configuration["CCW_USER_GUID"];
3935
_userDir = _configuration["CCW_USER_DIR"];
@@ -76,17 +72,17 @@ public async Task PopulateCCWJob()
7672

7773
if (cCWData == null)
7874
{
79-
_logger.LogInformation($"[Hangfire] PopulateCCWJob - No data from CCW for regi: {regi} vin: {vin}, plate: {plate}.");
75+
Log.Information($"[Hangfire] PopulateCCWJob - No data from CCW for regi: {regi} vin: {vin}, plate: {plate}.");
8076
_context.SaveChanges();
81-
_logger.LogInformation($"[Hangfire] PopulateCCWJob - Updated bus record timestamp with the ID {data.Id}.");
77+
Log.Information($"[Hangfire] PopulateCCWJob - Updated bus record timestamp with the ID {data.Id}.");
8278
return;
8379
}
8480

8581
data.CCWData = cCWData;
8682

8783
// ensure that the record is touched in the database
8884
_context.SaveChanges();
89-
_logger.LogInformation($"[Hangfire] PopulateCCWJob - Saved bus record with the ID {data.Id}.");
85+
Log.Information($"[Hangfire] PopulateCCWJob - Saved bus record with the ID {data.Id}.");
9086
}
9187
}
9288

@@ -110,7 +106,7 @@ public async Task UpdateCCWJob()
110106

111107
if (maxUpdateCount > 500)
112108
{
113-
_logger.LogInformation($"[Hangfire] UpdateCCWJob - Today's max update count({maxUpdateCount}) reached.");
109+
Log.Information($"[Hangfire] UpdateCCWJob - Today's max update count({maxUpdateCount}) reached.");
114110
return;
115111
}
116112

@@ -138,9 +134,9 @@ public async Task UpdateCCWJob()
138134
// fetch did not work, but we don't want it to fire again, so update the timestamp.
139135
if (cCWData == null)
140136
{
141-
_logger.LogInformation($"[Hangfire] UpdateCCWJob - No data from CCW for regi: {regi} vin: {vin}, plate: {plate}.");
137+
Log.Information($"[Hangfire] UpdateCCWJob - No data from CCW for regi: {regi} vin: {vin}, plate: {plate}.");
142138
_context.SaveChanges();
143-
_logger.LogInformation($"[Hangfire] UpdateCCWJob - Updated bus record timestamp with the ID {data.Id}.");
139+
Log.Information($"[Hangfire] UpdateCCWJob - Updated bus record timestamp with the ID {data.Id}.");
144140
return;
145141
}
146142

@@ -165,7 +161,7 @@ public async Task UpdateCCWJob()
165161
}
166162

167163
_context.SaveChanges();
168-
_logger.LogInformation($"[Hangfire] UpdateCCWJob - Saved bus record with the ID {data.Id}.");
164+
Log.Information($"[Hangfire] UpdateCCWJob - Saved bus record with the ID {data.Id}.");
169165
}
170166
}
171167

Server/SchoolBusAPI/Middlewares/ExceptionMiddleware.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using Microsoft.AspNetCore.Http;
22
using Microsoft.AspNetCore.Mvc;
3-
using Microsoft.Extensions.Logging;
3+
using Serilog;
44
using SchoolBusAPI.Extensions;
55
using System;
66
using System.Net;
@@ -11,11 +11,9 @@ namespace SchoolBusAPI.Middlewares
1111
public class ExceptionMiddleware
1212
{
1313
private readonly RequestDelegate _next;
14-
private readonly ILogger _logger;
1514

16-
public ExceptionMiddleware(RequestDelegate next, ILogger<ExceptionMiddleware> logger)
15+
public ExceptionMiddleware(RequestDelegate next)
1716
{
18-
_logger = logger;
1917
_next = next;
2018
}
2119

@@ -31,7 +29,7 @@ public async Task InvokeAsync(HttpContext httpContext)
3129
return;
3230

3331
var guid = Guid.NewGuid();
34-
_logger.LogError($"HMCR Exception{guid}: {ex}");
32+
Log.Error($"HMCR Exception{guid}: {ex}");
3533
await HandleExceptionAsync(httpContext, guid);
3634
}
3735
}

0 commit comments

Comments
 (0)