Skip to content

Commit

Permalink
Fix code review issues
Browse files Browse the repository at this point in the history
The main fix is that `GetTenorStorageDirectory` will create the directory
if it does not exist.
  • Loading branch information
ivarne committed Oct 13, 2023
1 parent 26eef87 commit a5bb228
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 104 deletions.
75 changes: 33 additions & 42 deletions src/Controllers/DebugUsersController.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
#nullable enable
using System.Text.Json;

using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;

using Altinn.Platform.Storage.Repository;

using LocalTest.Configuration;
using LocalTest.Models;
using LocalTest.Services.LocalApp.Interface;

using LocalTest.Services.TestData;
using Microsoft.AspNetCore.Authorization;
Expand All @@ -18,57 +14,52 @@ namespace LocalTest.Controllers;
[Route("Home/[controller]/[action]")]
public class DebugUsersController : Controller
{
private readonly TenorDataRepository _tenorDataRepository;
private readonly LocalPlatformSettings _localPlatformSettings;
private readonly ILocalApp _localApp;
private readonly TenorDataRepository _tenorDataRepository;

public DebugUsersController(
TenorDataRepository tenorDataRepository,
IOptions<LocalPlatformSettings> localPlatformSettings,
ILocalApp localApp)
TenorDataRepository tenorDataRepository)
{
_tenorDataRepository = tenorDataRepository;
_localPlatformSettings = localPlatformSettings.Value;
_localApp = localApp;
_tenorDataRepository = tenorDataRepository;
}

// Debugging endpoint
[AllowAnonymous]
public async Task<IActionResult> LocalTestUsersRaw()
{
var localData = await TestDataDiskReader.ReadFromDisk(_localPlatformSettings.LocalTestingStaticTestDataPath);

return Json(localData);
}

//Debugging endpoint
[AllowAnonymous]
public async Task<IActionResult> LocalTestUsers()
{
var localData = await TestDataDiskReader.ReadFromDisk(_localPlatformSettings.LocalTestingStaticTestDataPath);
var constructedAppData = AppTestDataModel.FromTestDataModel(localData);
// Debugging endpoint
[AllowAnonymous]
public async Task<IActionResult> LocalTestUsersRaw()
{
var localData = await TestDataDiskReader.ReadFromDisk(_localPlatformSettings.LocalTestingStaticTestDataPath);

return Json(constructedAppData);
}
return Json(localData);
}

// Debugging endpoint
[AllowAnonymous]
public async Task<IActionResult> LocalTestUsersRoundTrip()
{
var localData = await TestDataDiskReader.ReadFromDisk(_localPlatformSettings.LocalTestingStaticTestDataPath);
var constructedAppData = AppTestDataModel.FromTestDataModel(localData);
//Debugging endpoint
[AllowAnonymous]
public async Task<IActionResult> LocalTestUsers()
{
var localData = await TestDataDiskReader.ReadFromDisk(_localPlatformSettings.LocalTestingStaticTestDataPath);
var constructedAppData = AppTestDataModel.FromTestDataModel(localData);

return Json(constructedAppData.GetTestDataModel());
}
return Json(constructedAppData);
}

// Debugging endpoint
[AllowAnonymous]
public async Task<IActionResult> ShowTenorUsers([FromServices] TenorDataRepository tenorDataRepository)
{
var localData = await tenorDataRepository.GetAppTestDataModel();
// Debugging endpoint
[AllowAnonymous]
public async Task<IActionResult> LocalTestUsersRoundTrip()
{
var localData = await TestDataDiskReader.ReadFromDisk(_localPlatformSettings.LocalTestingStaticTestDataPath);
var constructedAppData = AppTestDataModel.FromTestDataModel(localData);

return Json(localData);
}
return Json(constructedAppData.GetTestDataModel());
}

// Debugging endpoint
[AllowAnonymous]
public async Task<IActionResult> ShowTenorUsers()
{
var localData = await _tenorDataRepository.GetAppTestDataModel();

return Json(localData);
}
}
16 changes: 0 additions & 16 deletions src/Controllers/FrontendVersionController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;

using Altinn.Platform.Storage.Repository;

using LocalTest.Configuration;
using LocalTest.Models;
using LocalTest.Services.LocalApp.Interface;

using LocalTest.Services.TestData;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Mvc.Rendering;

Expand All @@ -20,19 +17,6 @@ namespace LocalTest.Controllers;
[Route("Home/[controller]/[action]")]
public class FrontendVersionController : Controller
{
private readonly TenorDataRepository _tenorDataRepository;
private readonly LocalPlatformSettings _localPlatformSettings;
private readonly ILocalApp _localApp;

public FrontendVersionController(
TenorDataRepository tenorDataRepository,
IOptions<LocalPlatformSettings> localPlatformSettings,
ILocalApp localApp)
{
_tenorDataRepository = tenorDataRepository;
_localPlatformSettings = localPlatformSettings.Value;
_localApp = localApp;
}
/// <summary>
/// See src\development\loadbalancer\nginx.conf
/// </summary>
Expand Down
1 change: 0 additions & 1 deletion src/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Diagnostics;
using System.Text.Json;
using System.Xml;

using Microsoft.AspNetCore.Authentication;
Expand Down
25 changes: 0 additions & 25 deletions src/Controllers/StorageExplorerController.cs
Original file line number Diff line number Diff line change
@@ -1,37 +1,12 @@
#nullable enable
using System.Text.Json;

using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;

using Altinn.Platform.Storage.Repository;

using LocalTest.Configuration;
using LocalTest.Models;
using LocalTest.Services.LocalApp.Interface;

using LocalTest.Services.TestData;
using Microsoft.AspNetCore.Authorization;

namespace LocalTest.Controllers;

[Route("Home/[controller]/[action]")]
public class StorageExplorerController : Controller
{
private readonly TenorDataRepository _tenorDataRepository;
private readonly LocalPlatformSettings _localPlatformSettings;
private readonly ILocalApp _localApp;

public StorageExplorerController(
TenorDataRepository tenorDataRepository,
IOptions<LocalPlatformSettings> localPlatformSettings,
ILocalApp localApp)
{
_tenorDataRepository = tenorDataRepository;
_localPlatformSettings = localPlatformSettings.Value;
_localApp = localApp;
}

public IActionResult Index()
{
return View();
Expand Down
15 changes: 1 addition & 14 deletions src/Controllers/TenorUsersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
using System.Text.Json;

using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;

using Altinn.Platform.Storage.Repository;

using LocalTest.Configuration;
using LocalTest.Models;
using LocalTest.Services.LocalApp.Interface;

Expand All @@ -18,27 +13,19 @@ namespace LocalTest.Controllers;
public class TenorUsersController : Controller
{
private readonly TenorDataRepository _tenorDataRepository;
private readonly ILocalApp _localApp;

public TenorUsersController(
TenorDataRepository tenorDataRepository,
ILocalApp localApp)
public TenorUsersController(TenorDataRepository tenorDataRepository)
{
_tenorDataRepository = tenorDataRepository;
_localApp = localApp;
}



public async Task<IActionResult> Index()
{
var appUsers = await _localApp.GetTestData();

return View(new TenorViewModel()
{
AppUsers = appUsers,
FileItems = await _tenorDataRepository.GetFileItems(),

});
}

Expand Down
1 change: 0 additions & 1 deletion src/Models/TenorViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ namespace LocalTest.Models;
public class TenorViewModel
{
public List<TenorFileItem> FileItems { get; set; } = default!;
public AppTestDataModel? AppUsers { get; set; }
}

public class TenorFileItem
Expand Down
11 changes: 6 additions & 5 deletions src/Services/Tenor/TenorDataReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ public TenorDataRepository(IOptions<LocalPlatformSettings> settings)

public DirectoryInfo GetTenorStorageDirectory()
{
return new DirectoryInfo(Path.Join(_settings.LocalTestingStorageBasePath, _settings.TenorDataFolder));
var dir = new DirectoryInfo(Path.Join(_settings.LocalTestingStorageBasePath, _settings.TenorDataFolder));
if (!dir.Exists)
{
dir.Create();
}
return dir;
}


Expand All @@ -32,10 +37,6 @@ public DirectoryInfo GetTenorStorageDirectory()
var freg = new List<Freg>();
var brregErFr = new List<BrregErFr>();
var tenorFolder = GetTenorStorageDirectory();
if (!tenorFolder.Exists)
{
return (brregErFr, freg);
}

foreach (var fregFile in tenorFolder.GetFiles("freg.*.kildedata.json").Where(f => files?.Contains(f.Name) ?? true))
{
Expand Down

0 comments on commit a5bb228

Please sign in to comment.