Skip to content

Commit

Permalink
Refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
mrica-equinor committed Dec 3, 2024
1 parent ea7ce29 commit 95b9b4c
Show file tree
Hide file tree
Showing 14 changed files with 366 additions and 354 deletions.
9 changes: 7 additions & 2 deletions backend/api/Controllers/InspectionController.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Api.Controllers.Models;
using System.Globalization;
using Api.Controllers.Models;
using Api.Database.Models;
using Api.Services;
using Api.Services.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

Expand Down Expand Up @@ -50,6 +50,11 @@ public async Task<ActionResult<Inspection>> GetInspectionImageById([FromRoute] s

if (inspectionData == null) return NotFound($"Could not find inspection data for inspection with Id {inspection.Id}.");

if (!inspectionData.BlobContainer.ToLower(CultureInfo.CurrentCulture).Equals(installationCode.ToLower(CultureInfo.CurrentCulture), StringComparison.Ordinal))
{
return NotFound($"Could not find inspection data for inspection with Id {inspection.Id} because blob name {inspectionData.BlobName} does not match installation {installationCode}.");
}

try
{
byte[] inspectionStream = await inspectionService.FetchInpectionImage(inspectionData.BlobName, inspectionData.BlobContainer, inspectionData.StorageAccount);
Expand Down
7 changes: 0 additions & 7 deletions backend/api/Options/IDAOptions.cs

This file was deleted.

3 changes: 1 addition & 2 deletions backend/api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@

builder.Services.Configure<AzureAdOptions>(builder.Configuration.GetSection("AzureAd"));
builder.Services.Configure<MapBlobOptions>(builder.Configuration.GetSection("Maps"));
builder.Services.Configure<IDAOptions>(builder.Configuration.GetSection("IDA"));


builder.Services
Expand All @@ -144,7 +143,7 @@
.AddInMemoryTokenCaches()
.AddDownstreamApi(EchoService.ServiceName, builder.Configuration.GetSection("Echo"))
.AddDownstreamApi(StidService.ServiceName, builder.Configuration.GetSection("Stid"))
.AddDownstreamApi(InspectionService.ServiceName, builder.Configuration.GetSection("IDAApi"))
.AddDownstreamApi(InspectionService.ServiceName, builder.Configuration.GetSection("IDA"))
.AddDownstreamApi(IsarService.ServiceName, builder.Configuration.GetSection("Isar"));

builder.Services.AddAuthorizationBuilder().AddFallbackPolicy(
Expand Down
8 changes: 3 additions & 5 deletions backend/api/Services/InspectionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
using Api.Controllers.Models;
using Api.Database.Context;
using Api.Database.Models;
using Api.Options;
using Api.Services.Models;
using Api.Utilities;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
using Microsoft.Identity.Abstractions;
namespace Api.Services
{
Expand All @@ -31,7 +29,7 @@ public interface IInspectionService
public class InspectionService(FlotillaDbContext context, ILogger<InspectionService> logger, IDownstreamApi idaApi, IAccessRoleService accessRoleService,
IBlobService blobService) : IInspectionService
{
public const string ServiceName = "IDAApi";
public const string ServiceName = "IDA";

public async Task<byte[]> FetchInpectionImage(string inpectionName, string installationCode, string storageAccount)
{
Expand Down Expand Up @@ -114,8 +112,8 @@ private IQueryable<Inspection> GetInspections(bool readOnly = true)

public async Task<IDAInspectionDataResponse?> GetInspectionStorageInfo(string inspectionId)
{
var inspectionID = "finaltest";
string relativePath = $"InspectionData/{inspectionID}/inspection-data-storage-location";
inspectionId = "finaltest";
string relativePath = $"InspectionData/{inspectionId}/inspection-data-storage-location";

var response = await idaApi.CallApiForUserAsync(
ServiceName,
Expand Down
2 changes: 1 addition & 1 deletion backend/api/appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"Isar": {
"Scopes": ["fd384acd-5c1b-4c44-a1ac-d41d720ed0fe/.default"]
},
"IDAApi": {
"IDA": {
"BaseUrl": "http://ida.robotics-analytics-dev.svc.cluster.local:8100/",
"Scopes": ["bd4b0a3e-af88-4b7c-aab2-ad4956f2f789/.default"]
},
Expand Down
2 changes: 1 addition & 1 deletion backend/api/appsettings.Local.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"Maps": {
"StorageAccount": "flotillamaps"
},
"IDAApi": {
"IDA": {
"BaseUrl": "https://localhost:8100/",
"Scopes": ["bd4b0a3e-af88-4b7c-aab2-ad4956f2f789/.default"]
},
Expand Down
4 changes: 4 additions & 0 deletions backend/api/appsettings.Production.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
"Isar": {
"Scopes": ["e08edece-ba2d-4fe1-8cd1-ee7b05ba7155/.default"]
},
"IDA": {
"BaseUrl": "http://ida.robotics-analytics-prod.svc.cluster.local:8100/",
"Scopes": ["16df0336-e42b-45c6-a380-8f6fe66e1fa3/.default"]
},
"Maps": {
"StorageAccount": "flotillamaps"
},
Expand Down
4 changes: 4 additions & 0 deletions backend/api/appsettings.Staging.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
"Isar": {
"Scopes": ["9cd787ea-8ce2-4d18-8bc8-279e7a8e6289/.default"]
},
"IDA": {
"BaseUrl": "http://ida.robotics-analytics-staging.svc.cluster.local:8100/",
"Scopes": ["6f40ba9b-2029-400e-85e9-f1922cbf12c1/.default"]
},
"Maps": {
"StorageAccount": "flotillamaps"
},
Expand Down
Loading

0 comments on commit 95b9b4c

Please sign in to comment.