Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Review apis consistency #253

Merged
merged 3 commits into from
Feb 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@ public class ConcentratorsControllerTests
private Mock<IRouterConfigManager> mockRouterManager;
private Mock<IConcentratorTwinMapper> mockConcentratorTwinMapper;
private Mock<IDeviceService> mockDeviceService;
private Mock<ILogger<ConcentratorsController>> mockLogger;
private Mock<ILogger<LoRaWANConcentratorsController>> mockLogger;

[SetUp]
public void SetUp()
{
this.mockRepository = new MockRepository(MockBehavior.Strict);

this.mockLogger = this.mockRepository.Create<ILogger<ConcentratorsController>>();
this.mockLogger = this.mockRepository.Create<ILogger<LoRaWANConcentratorsController>>();
this.mockRouterManager = this.mockRepository.Create<IRouterConfigManager>();
this.mockConcentratorTwinMapper = this.mockRepository.Create<IConcentratorTwinMapper>();
this.mockDeviceService = this.mockRepository.Create<IDeviceService>();
}

private ConcentratorsController CreateController()
private LoRaWANConcentratorsController CreateController()
{
return new ConcentratorsController(
return new LoRaWANConcentratorsController(
this.mockLogger.Object,
this.mockDeviceService.Object,
this.mockRouterManager.Object,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class GatewaysControllerTests
private MockRepository mockRepository;

private Mock<IConfiguration> mockConfiguration;
private Mock<ILogger<GatewaysController>> mockLogger;
private Mock<ILogger<EdgeDevicesController>> mockLogger;
private Mock<RegistryManager> mockRegistryManager;
private Mock<IConnectionStringManager> mockConnectionStringManager;
private Mock<IDeviceService> mockDeviceService;
Expand All @@ -32,15 +32,15 @@ public void SetUp()
this.mockRepository = new MockRepository(MockBehavior.Strict);

this.mockConfiguration = this.mockRepository.Create<IConfiguration>();
this.mockLogger = this.mockRepository.Create<ILogger<GatewaysController>>();
this.mockLogger = this.mockRepository.Create<ILogger<EdgeDevicesController>>();
this.mockRegistryManager = this.mockRepository.Create<RegistryManager>();
this.mockConnectionStringManager = this.mockRepository.Create<IConnectionStringManager>();
this.mockDeviceService = this.mockRepository.Create<IDeviceService>();
}

private GatewaysController CreateGatewaysController()
private EdgeDevicesController CreateGatewaysController()
{
return new GatewaysController(
return new EdgeDevicesController(
this.mockConfiguration.Object,
this.mockLogger.Object,
this.mockRegistryManager.Object,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@page "/configdetail/{ConfigurationID}"
@page "/edge/configurations/{ConfigurationID}"
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
@using AzureIoTHub.Portal.Shared.Models
Expand Down Expand Up @@ -132,7 +132,7 @@
try
{
// Sends a GET request to the ConfigController, to retrieve a specific deployment from Azure IoT Hub
Config = await Http.GetFromJsonAsync<ConfigListItem>($"api/Configs/{ConfigurationID}");
Config = await Http.GetFromJsonAsync<ConfigListItem>($"api/edge/configurations/{ConfigurationID}");
ConditionOwner = RetrieveCondition("owner");
ConditionEnv = RetrieveCondition("env");
ConditionType = RetrieveCondition("type");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@page "/configurations"
@page "/edge/configurations"
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
@using AzureIoTHub.Portal.Shared.Models
Expand Down Expand Up @@ -45,7 +45,7 @@
</HeaderContent>
<RowTemplate>
<MudTd DataLabel="ID" Style="word-break: break-all;">
<a href="configdetail/@context.ConfigurationID">@context.ConfigurationID</a>
<a href="/edge/configurations/@context.ConfigurationID">@context.ConfigurationID</a>
</MudTd>
<MudTd DataLabel="Conditions" Style="word-break: break-all; ">
<a href="#">@context.Conditions</a>
Expand All @@ -61,7 +61,7 @@
<MudTd DataLabel="Priority" Style="text-align: center">@context.Priority</MudTd>
<MudTd DataLabel="Creation date" Style="text-align: center;">@context.CreationDate</MudTd>
<MudTd DataLabel="Details" Style="text-align: center">
<a href="configdetail/@context.ConfigurationID"><MudIconButton Icon="@Icons.Filled.Visibility" Color="Color.Default" /></a>
<a href="/edge/configurations/@context.ConfigurationID"><MudIconButton Icon="@Icons.Filled.Visibility" Color="Color.Default" /></a>
</MudTd>
<MudTd DataLabel="Delete" Style="text-align: center">
<MudIconButton Color="Color.Default" Icon="@Icons.Material.Filled.Delete" Size="Size.Medium" OnClick="@(e => DeleteConfiguration(context))"></MudIconButton>
Expand Down Expand Up @@ -93,7 +93,7 @@
{
try
{
result = await Http.GetFromJsonAsync<ConfigListItem[]>("api/Configs");
result = await Http.GetFromJsonAsync<ConfigListItem[]>("api/edge/configurations");
}
catch (AccessTokenNotAvailableException exception)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,11 @@

private async Task Save()
{
var result = await httpClient.PostAsJsonAsync("api/DeviceModels", DeviceModel);
var result = await httpClient.PostAsJsonAsync("api/models", DeviceModel);

if (content is not null)
{
var response = await httpClient.PostAsync($"api/DeviceModels/{DeviceModel.ModelId}/avatar", content);
var response = await httpClient.PostAsync($"api/models/{DeviceModel.ModelId}/avatar", content);
}

if (result.IsSuccessStatusCode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
private async Task DeleteDevice()
{
// var response = await Http.PostAsJsonAsync<DeviceListItem>($"Devices/delete", device);
var response = await Http.DeleteAsync($"api/DeviceModels/{deviceModelID}");
var response = await Http.DeleteAsync($"api/models/{deviceModelID}");
var errorMsg = await response.Content.ReadAsStringAsync();

// Prompts a snack bar to inform if the action was successful
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,13 @@

protected override async Task OnInitializedAsync()
{
DeviceModel = await httpClient.GetFromJsonAsync<DeviceModel>($"api/DeviceModels/{ModelID}");
imageDataUrl = await httpClient.GetStringAsync($"api/DeviceModels/{ModelID}/avatar");
DeviceModel = await httpClient.GetFromJsonAsync<DeviceModel>($"api/models/{ModelID}");
imageDataUrl = await httpClient.GetStringAsync($"api/models/{ModelID}/avatar");
}

async Task DeleteAvatar()
{
await httpClient.DeleteAsync($"api/DeviceModels/{ModelID}/avatar");
await httpClient.DeleteAsync($"api/models/{ModelID}/avatar");
imageDataUrl = null;
}

Expand All @@ -150,14 +150,14 @@
name: "\"file\"",
fileName: e.File.Name);

var response = await httpClient.PostAsync($"api/DeviceModels/{ModelID}/avatar", content);
var response = await httpClient.PostAsync($"api/models/{ModelID}/avatar", content);

imageDataUrl = await response.Content.ReadAsStringAsync();
}

private async Task Save()
{
var result = await httpClient.PutAsJsonAsync("api/DeviceModels", DeviceModel);
var result = await httpClient.PutAsJsonAsync("api/models", DeviceModel);

if (result.IsSuccessStatusCode)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
{
try
{
result = await httpClient.GetFromJsonAsync<DeviceModel[]>("api/DeviceModels");
result = await httpClient.GetFromJsonAsync<DeviceModel[]>("api/models");
}
catch (AccessTokenNotAvailableException exception)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
Device.IsEnabled = true;

// Gets a list of device model previously registered to Azure to allow autocomplete field in the form
DeviceModelList = await Http.GetFromJsonAsync<DeviceModel[]>("api/DeviceModels");
DeviceModelList = await Http.GetFromJsonAsync<DeviceModel[]>("api/models");
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
// Gets the DeviceModel Name from the DeviceModel ID
if (!string.IsNullOrEmpty(Device.ModelId))
{
DeviceModel model = await Http.GetFromJsonAsync<DeviceModel>($"api/DeviceModels/{Device.ModelId}");
DeviceModel model = await Http.GetFromJsonAsync<DeviceModel>($"api/models/{Device.ModelId}");
Device.ModelName = model?.Name;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@page "/edge-devices/add"
@page "/edge/devices/add"
@using Microsoft.AspNetCore.Authorization
@using AzureIoTHub.Portal.Shared.Models;

Expand Down Expand Up @@ -61,7 +61,7 @@

private async Task OnValidation()
{
var result = await Http.PostAsJsonAsync("api/Gateways", gateway);
var result = await Http.PostAsJsonAsync("api/edge/device", gateway);

if (result.IsSuccessStatusCode)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

private async Task DeleteDevice()
{
var result = await Http.DeleteAsync($"api/Gateways/{DeviceId}");
var result = await Http.DeleteAsync($"api/edge/device/{DeviceId}");

if (!result.IsSuccessStatusCode)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@page "/edge-device/detail/{deviceId}"
@page "/edge/devices/{deviceId}"
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
@using AzureIoTHub.Portal.Shared.Models
Expand Down Expand Up @@ -191,7 +191,7 @@

public async Task LoadDevice()
{
Gateway = await Http.GetFromJsonAsync<Gateway>($"api/Gateways/{deviceId}");
Gateway = await Http.GetFromJsonAsync<Gateway>($"api/edge/device/{deviceId}");

if (Gateway.ConnectionState == "Disconnected")
{
Expand All @@ -203,7 +203,7 @@
public async Task UpdateDevice()
{
processingUpdate = true;
var result = await Http.PutAsJsonAsync($"api/Gateways/{Gateway.DeviceId}", Gateway);
var result = await Http.PutAsJsonAsync($"api/edge/device/{Gateway.DeviceId}", Gateway);

if (result.IsSuccessStatusCode)
{
Expand All @@ -215,7 +215,7 @@

public async Task OnMethod(GatewayModule module, string methodName)
{
var result = await Http.PostAsJsonAsync($"api/Gateways/{Gateway.DeviceId}/{module.ModuleName}/{methodName}", module);
var result = await Http.PostAsJsonAsync($"api/edge/device/{Gateway.DeviceId}/{module.ModuleName}/{methodName}", module);

var c2dResult = result.Content.ReadFromJsonAsync<C2Dresult>().Result;

Expand Down Expand Up @@ -246,11 +246,11 @@
{
if (Gateway.Type is null)
{
Gateway.SymmetricKey = await this.Http.GetStringAsync($"api/Gateways/{Gateway.DeviceId}/unknown/ConnectionString");
Gateway.SymmetricKey = await this.Http.GetStringAsync($"api/edge/device/{Gateway.DeviceId}/unknown/ConnectionString");
}
else
{
Gateway.SymmetricKey = await this.Http.GetStringAsync($"api/Gateways/{Gateway.DeviceId}/{Gateway.Type}/ConnectionString");
Gateway.SymmetricKey = await this.Http.GetStringAsync($"api/edge/device/{Gateway.DeviceId}/{Gateway.Type}/ConnectionString");
}

var parameter = new DialogParameters();
Expand Down Expand Up @@ -290,7 +290,7 @@
return;
}

NavigationManager.NavigateTo("/edge-devices");
NavigationManager.NavigateTo("/edge/devices");
}

public class CustomStringToBoolConverter : BoolConverter<string>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@page "/edge-devices"
@page "/edge/devices"
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
@using AzureIoTHub.Portal.Shared.Models
Expand Down Expand Up @@ -87,7 +87,7 @@
</HeaderContent>
<RowTemplate>
<MudTd DataLabel="Device" Style="word-break: break-all;">
<a href="/edge-device/detail/@context.DeviceId">@context.DeviceId</a>
<a href="/edge/devices/@context.DeviceId">@context.DeviceId</a>
</MudTd>
<MudTd DataLabel="Status" Style="text-align: center">
@if (context.Status == "Enabled")
Expand All @@ -103,7 +103,7 @@
<MudTd DataLabel="Type" Style="text-align: center">@context.Type</MudTd>
<MudTd DataLabel="NbDevices" Style="text-align: center">@context.NbDevices</MudTd>
<MudTd DataLabel="Details" Style="text-align: center">
<a href="/edge-device/detail/@context.DeviceId"><MudIconButton Icon="@Icons.Filled.Visibility" Color="Color.Default" /></a>
<a href="/edge/devices/@context.DeviceId"><MudIconButton Icon="@Icons.Filled.Visibility" Color="Color.Default" /></a>
</MudTd>
<MudTd DataLabel="Delete" Style="text-align: center">
<MudIconButton Color="Color.Default" Icon="@Icons.Material.Filled.Delete" Size="Size.Medium" OnClick="@(e => ShowDeleteDialog(context))"></MudIconButton>
Expand Down Expand Up @@ -138,7 +138,7 @@
{
try
{
result = await Http.GetFromJsonAsync<List<GatewayListItem>>("api/Gateways");
result = await Http.GetFromJsonAsync<List<GatewayListItem>>("api/edge/device");
}
catch (AccessTokenNotAvailableException exception)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@page "/edge-devices/logs"
@page "/edge/devices/logs"
@using AzureIoTHub.Portal.Shared.Models
@using Newtonsoft.Json;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
try
{
// Sends a GET request to the DevicesController, to retrieve the specific device from Azure IoT Hub
concentrator = await Http.GetFromJsonAsync<Concentrator>($"api/concentrators/{DeviceID}");
concentrator = await Http.GetFromJsonAsync<Concentrator>($"api/lorawan/concentrators/{DeviceID}");
}
catch (AccessTokenNotAvailableException exception)
{
Expand All @@ -127,7 +127,7 @@
/// </summary>
public async void SaveDevice()
{
var result = await Http.PutAsJsonAsync<Concentrator>($"api/concentrators", concentrator);
var result = await Http.PutAsJsonAsync<Concentrator>($"api/lorawan/concentrators", concentrator);

if (result.IsSuccessStatusCode)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
{
try
{
concentrators = await Http.GetFromJsonAsync<Concentrator[]>("api/Concentrators");
concentrators = await Http.GetFromJsonAsync<Concentrator[]>("api/lorawan/concentrators");
}
catch (AccessTokenNotAvailableException exception)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
{
concentrator.DeviceType = "LoRa Concentrator";
// Sends the device to be added to the controller
var response = await Http.PostAsJsonAsync<Concentrator>($"api/Concentrators", concentrator);
var response = await Http.PostAsJsonAsync<Concentrator>($"api/lorawan/concentrators", concentrator);

if (response.IsSuccessStatusCode)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
/// <returns></returns>
private async Task DeleteDevice()
{
var response = await Http.DeleteAsync($"api/Concentrators/{deviceId}");
var response = await Http.DeleteAsync($"api/lorawan/concentrators/{deviceId}");

// Prompts a snack bar to inform if the action was successful
// TODO : Deal more effectively with error/success messages
Expand Down
2 changes: 1 addition & 1 deletion src/AzureIoTHub.Portal/Client/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private static async Task ConfigureOidc(WebAssemblyHostBuilder builder)
{
using (var httpClient = new HttpClient() { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) })
{
var settings = await httpClient.GetFromJsonAsync<OIDCSettings>("OIDCSettings");
var settings = await httpClient.GetFromJsonAsync<OIDCSettings>("api/settings/oidc");

builder.Services.AddOidcAuthentication(options =>
{
Expand Down
4 changes: 2 additions & 2 deletions src/AzureIoTHub.Portal/Client/Shared/NavMenu.razor
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

<MudText Typo="Typo.subtitle2" Color="Color.Inherit" Class="ml-4 my-3">IoT Edge</MudText>

<MudNavLink Href="/edge-devices">Devices</MudNavLink>
<MudNavLink Href="/configurations">Configuration</MudNavLink>
<MudNavLink Href="/edge/devices">Devices</MudNavLink>
<MudNavLink Href="/edge/configurations">Configuration</MudNavLink>

<MudText Typo="Typo.subtitle2" Color="Color.Inherit" Class="ml-4 my-3">LoRaWAN Management</MudText>
<MudNavLink Href="/lorawan/concentrators">Concentrators</MudNavLink>
Expand Down
Loading