Skip to content

Commit

Permalink
Merge pull request #678 from bcgov/2.0.8
Browse files Browse the repository at this point in the history
2.0.8
  • Loading branch information
ionwyn authored May 30, 2024
2 parents 7f097d7 + 5415276 commit c2ee0d4
Show file tree
Hide file tree
Showing 56 changed files with 11,941 additions and 15,353 deletions.
6 changes: 3 additions & 3 deletions .pipeline/lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const phases = {
hangfire_cpu: "300m",
hangfire_memory: "300Mi",
api_cpu: "200m",
api_memory: "200Mi",
api_memory: "512Mi",
client_cpu: "100m",
client_memory: "100Mi",
},
Expand All @@ -58,7 +58,7 @@ const phases = {
hangfire_cpu: "300m",
hangfire_memory: "300Mi",
api_cpu: "200m",
api_memory: "200Mi",
api_memory: "512Mi",
client_cpu: "100m",
client_memory: "100Mi",
},
Expand All @@ -80,7 +80,7 @@ const phases = {
hangfire_cpu: "300m",
hangfire_memory: "300Mi",
api_cpu: "200m",
api_memory: "200Mi",
api_memory: "512Mi",
client_cpu: "100m",
client_memory: "100Mi",
},
Expand Down
146 changes: 146 additions & 0 deletions api/Hmcr.Api/Controllers/SaltReportsController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
using Microsoft.AspNetCore.Mvc;
using Hmcr.Api.Controllers.Base;
using Hmcr.Model.Dtos.SaltReport;
using System;
using System.Threading.Tasks;
using Hmcr.Domain.Services;
using Hmcr.Api.Authorization;
using Hmcr.Model;
using System.Linq;
using System.Text.Json;
using Microsoft.Extensions.Logging;
using System.Data.Common;
using System.Collections.Generic;

namespace Hmcr.Api.Controllers
{
[ApiVersion("1.0")]
[Route("api/saltreports")]
public class SaltReportController : HmcrControllerBase
{
private readonly ISaltReportService _saltReportService;
private HmcrCurrentUser _currentUser;

public SaltReportController(ISaltReportService saltReportService, ISubmissionObjectService submissionService, HmcrCurrentUser currentUser, IEmailService emailService)
{
_saltReportService = saltReportService ?? throw new ArgumentNullException(nameof(saltReportService));
_currentUser = currentUser ?? throw new ArgumentNullException(nameof(currentUser));
}

[HttpPost]
[RequiresPermission(Permissions.FileUploadWrite)]
public async Task<IActionResult> CreateSaltReportAsync([FromBody] SaltReportDto saltReport)
{
if (saltReport == null)
{
return BadRequest("Received salt report data is null");
}

var problem = IsServiceAreaAuthorized(_currentUser, saltReport.ServiceArea);
if (problem != null)
{
return Unauthorized(problem);
}

try
{
var createdReport = await _saltReportService.CreateReportAsync(saltReport);
return CreatedAtRoute(nameof(GetSaltReportAsync), new { id = createdReport.SaltReportId }, saltReport);
}
catch (Exception ex)
{
// Get the inner exception message if it exists
var innerExceptionMessage = ex.InnerException?.Message ?? "Please contact an administrator to resolve this issue.";

Console.Error.WriteLine($"Exception: {ex.Message}");
if (ex.InnerException != null)
{
Console.Error.WriteLine($"Inner Exception: {innerExceptionMessage}");
}

return StatusCode(500, new
{
message = "An internal error occurred. Please try again later.",
error = $"500 Internal Server Error: {innerExceptionMessage}"
});
}

}


[HttpGet("{id}", Name = "GetSaltReportAsync")]
public async Task<ActionResult<SaltReportDto>> GetSaltReportAsync(int id)
{
var saltReportDto = await _saltReportService.GetSaltReportByIdAsync(id);

if (saltReportDto == null)
{
return NotFound();
}

return Ok(saltReportDto);
}

[HttpGet(Name = "GetSaltReportsAsync")]
public async Task<IActionResult> GetSaltReportsAsync([FromQuery] string serviceAreas, [FromQuery] string format, [FromQuery] DateTime fromDate, [FromQuery] DateTime toDate, int pageSize, int pageNumber)
{
try
{
if (string.IsNullOrWhiteSpace(serviceAreas))
{
return BadRequest("Service areas cannot be null or empty.");
}
format = (format ?? "json").ToLower();

// Decide the output format based on the 'format' parameter
switch (format)
{
case "csv":
var saltReportEntities = await _saltReportService.GetSaltReportEntitiesAsync(serviceAreas, fromDate, toDate).ConfigureAwait(false);

if (!saltReportEntities.Any())
{
return NotFound("No reports found matching the specified criteria.");
}
var csvStream = _saltReportService.ConvertToCsvStream(saltReportEntities);
if (csvStream == null || csvStream.Length == 0)
{
return NotFound("CSV data not found or is empty.");
}
// Return the stream as a CSV file
return File(csvStream, "text/csv", "salt_reports.csv");

case "json":
default:
try
{
var reports = await _saltReportService.GetSaltReportDtosAsync(serviceAreas, fromDate, toDate, pageSize, pageNumber);
return Ok(reports);
}
catch (ArgumentException ex)
{
return BadRequest(ex.Message);
}
catch (Exception ex)
{
// Log the exception details here to diagnose issues.
return StatusCode(500, "An internal server error occurred.");
}
}
}
catch (ArgumentException ex)
{
return BadRequest(ex.Message); // Return 400 Bad Request with error message
}
catch (DbException ex)
{
return StatusCode(500, "An error occurred while processing your request.");
}
catch (Exception ex)
{
return StatusCode(500, "An error occurred while processing your request.");
}
}

}
}
9 changes: 8 additions & 1 deletion api/Hmcr.Api/Extensions/IServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Hmcr.Data.Database;
using Hmcr.Data.Database.Entities;
using Hmcr.Data.Mappings;
using Hmcr.Data.Repositories;
using Hmcr.Domain.Services;
using Hmcr.Model;
using Hmcr.Model.JsonConverters;
Expand All @@ -16,6 +17,7 @@
using Microsoft.AspNetCore.Mvc.Authorization;
using Microsoft.AspNetCore.Mvc.Versioning;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Diagnostics.HealthChecks;
Expand Down Expand Up @@ -78,7 +80,8 @@ public static void AddHmcrControllers(this IServiceCollection services)

public static void AddHmcrDbContext(this IServiceCollection services, string connectionString, bool enableSensitiveDataLogging)
{
services.AddDbContext<AppDbContext>(options => {
services.AddDbContext<AppDbContext>(options =>
{
options.UseSqlServer(connectionString, x => x.UseNetTopologySuite().CommandTimeout(1800));
options.EnableSensitiveDataLogging(enableSensitiveDataLogging);
});
Expand Down Expand Up @@ -183,6 +186,10 @@ public static void AddHmcrTypes(this IServiceCollection services)
//Jwt Bearer Handler
services.AddScoped<HmcrJwtBearerEvents>();

//Salt Report
services.AddScoped<ISaltReportService, SaltReportService>();
services.AddScoped<ISaltReportRepository, SaltReportRepository>();

services.AddSingleton<EmailBody>();
}

Expand Down
14 changes: 7 additions & 7 deletions api/Hmcr.Api/Hmcr.Api.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
<TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
<IsPackable>false</IsPackable>
Expand Down Expand Up @@ -36,17 +36,17 @@
<PackageReference Include="Hangfire.AspNetCore" Version="1.7.9" />
<PackageReference Include="HangFire.Core" Version="1.7.9" />
<PackageReference Include="HangFire.SqlServer" Version="1.7.9" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.18" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.9" />
<PackageReference Include="Microsoft.AspNetCore.Http.Extensions" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.2" />
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="3.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="7.0.9" />
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="7.0.9" />
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="2.2.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.2">
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.9">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="3.1.2" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="7.0.9" />
<PackageReference Include="NetCore.AutoRegisterDi" Version="1.1.0" />
<PackageReference Include="Serilog.AspNetCore" Version="4.1.0" />
<PackageReference Include="Serilog.Enrichers.Environment" Version="2.1.3" />
Expand Down
2 changes: 1 addition & 1 deletion api/Hmcr.Api/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"AllowedHosts": "*",
"Constants": {
"Version": "2.0.6.0",
"Version": "2.0.8.0",
"SwaggerApiUrl": "/swagger/v1/swagger.json"
},
"Serilog": {
Expand Down
10 changes: 5 additions & 5 deletions api/Hmcr.Bceid/Hmcr.Bceid.csproj
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<None Remove="BceidServiceCollectionExtensions.cs~RF711bcd2e.TMP" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="3.1.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="3.1.2" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.1.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.4" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
<PackageReference Include="System.ServiceModel.Duplex" Version="4.7.0" />
<PackageReference Include="System.ServiceModel.Http" Version="4.7.0" />
<PackageReference Include="System.ServiceModel.NetTcp" Version="4.7.0" />
Expand Down
28 changes: 14 additions & 14 deletions api/Hmcr.Chris/ChrisServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,44 +12,44 @@ public static void AddChrisHttpClient(this IServiceCollection services, IConfigu
{
services.AddHttpClient<IMapsApi, MapsApi>(client =>
{
client.BaseAddress = new Uri(config.GetValue<string>("CHRIS:MapUrl"));
client.Timeout = new TimeSpan(0, 0, config.GetValue<int>("Timeouts:MapsAPI"));
client.BaseAddress = new Uri(config["CHRIS:MapUrl"]);
client.Timeout = new TimeSpan(0, 0, int.Parse(config["Timeouts:MapsAPI"]));
client.DefaultRequestHeaders.Clear();
});

services.AddHttpClient<IOasApi, OasApi>(client =>
{
client.BaseAddress = new Uri(config.GetValue<string>("CHRIS:OASUrl"));
client.Timeout = new TimeSpan(0, 0, config.GetValue<int>("Timeouts:OasAPI"));
client.BaseAddress = new Uri(config["CHRIS:OASUrl"]);
client.Timeout = new TimeSpan(0, 0, int.Parse(config["Timeouts:OasAPI"]));
client.DefaultRequestHeaders.Clear();

var userId = config.GetValue<string>("ServiceAccount:User");
var password = config.GetValue<string>("ServiceAccount:Password");
var userId = config["ServiceAccount:User"];
var password = config["ServiceAccount:Password"];
var basicAuth = Convert.ToBase64String(Encoding.GetEncoding("ISO-8859-1").GetBytes($"{userId}:{password}"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", basicAuth);
});

services.AddHttpClient<IExportApi, ExportApi>(client =>
{
client.BaseAddress = new Uri(config.GetValue<string>("CHRIS:ExportUrl"));
client.Timeout = new TimeSpan(0, 0, config.GetValue<int>("Timeouts:ExportAPI"));
client.BaseAddress = new Uri(config["CHRIS:ExportUrl"]);
client.Timeout = new TimeSpan(0, 0, int.Parse(config["Timeouts:ExportAPI"]));
client.DefaultRequestHeaders.Clear();

var userId = config.GetValue<string>("ServiceAccount:User");
var password = config.GetValue<string>("ServiceAccount:Password");
var userId = config["ServiceAccount:User"];
var password = config["ServiceAccount:Password"];
var basicAuth = Convert.ToBase64String(Encoding.GetEncoding("ISO-8859-1").GetBytes($"{userId}:{password}"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", basicAuth);
});

services.AddHttpClient<IInventoryApi, InventoryApi>(client =>
{
client.BaseAddress = new Uri(config.GetValue<string>("CHRIS:OASUrl"));
client.BaseAddress = new Uri(config["CHRIS:OASUrl"]);
//TODO: need to set the timeouts to be configurable with the ConfigMap of OCP
client.Timeout = new TimeSpan(0, 0, config.GetValue<int>("Timeouts:InventoryAPI"));
client.Timeout = new TimeSpan(0, 0, int.Parse(config["Timeouts:InventoryAPI"]));
client.DefaultRequestHeaders.Clear();

var userId = config.GetValue<string>("ServiceAccount:User");
var password = config.GetValue<string>("ServiceAccount:Password");
var userId = config["ServiceAccount:User"];
var password = config["ServiceAccount:Password"];
var basicAuth = Convert.ToBase64String(Encoding.GetEncoding("ISO-8859-1").GetBytes($"{userId}:{password}"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", basicAuth);
});
Expand Down
2 changes: 1 addition & 1 deletion api/Hmcr.Chris/ExportApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public ExportApi(HttpClient client, IApi api, IConfiguration config, ILogger<IEx

public async Task<HttpResponseMessage> ExportReport(string query, string exportEndpointConfig)
{
string path = _config.GetValue<string>($"CHRIS:{exportEndpointConfig}");
string path = _config[$"CHRIS:{exportEndpointConfig}"];

//_client.BaseAddress.ToString() + path + "&" + query
_logger.LogInformation($"ExportReport - Calling Export URL { _client.BaseAddress.ToString() + path + "&" + query}");
Expand Down
10 changes: 5 additions & 5 deletions api/Hmcr.Chris/Hmcr.Chris.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand All @@ -24,9 +24,9 @@

<ItemGroup>
<PackageReference Include="GeoJSON.Net" Version="1.2.19" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="3.1.2" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.1.2" />
<PackageReference Include="Microsoft.Extensions.Http" Version="3.1.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
<PackageReference Include="NetTopologySuite" Version="2.2.0" />
<PackageReference Include="NetTopologySuite.IO.GeoJSON" Version="2.0.4" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion api/Hmcr.Chris/InventoryApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public InventoryApi(HttpClient client, IApi api, IConfiguration config, ILogger<
_client = client;
_queries = new InventoryQueries();
_api = api;
_path = config.GetValue<string>("CHRIS:OASPath");
_path = config["CHRIS:OASPath"];
_logger = logger;
}

Expand Down
2 changes: 1 addition & 1 deletion api/Hmcr.Chris/MapsApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public MapsApi(HttpClient client, IApi api, IConfiguration config)
_client = client;
_queries = new MapsQueries();
_api = api;
_path = config.GetValue<string>("CHRIS:MapPath");
_path = config["CHRIS:MapPath"];
}

public async Task<bool> IsPointWithinServiceAreaQuery(decimal longitude, decimal latitude, string serviceAreaNumber)
Expand Down
2 changes: 1 addition & 1 deletion api/Hmcr.Chris/OasApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public OasApi(HttpClient client, IApi api, IConfiguration config, ILogger<OasApi
_client = client;
_api = api;
_queries = new OasQueries();
_path = config.GetValue<string>("CHRIS:OASPath");
_path = config["CHRIS:OASPath"];
_logger = logger;
}

Expand Down
Loading

0 comments on commit c2ee0d4

Please sign in to comment.