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

As a user, I want to manage IoT device models in AWS #2050

Merged
merged 12 commits into from
May 11, 2023
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@ public ThingTypeProfile()
.ForMember(dest => dest.Id, opts => opts.MapFrom(src => src.ThingTypeID))
.ForMember(dest => dest.Name, opts => opts.MapFrom(src => src.ThingTypeName))
.ForMember(dest => dest.Description, opts => opts.MapFrom(src => src.ThingTypeDescription))
.ForMember(dest => dest.Deprecated, opts => opts.MapFrom(src => src.Deprecated))
.ForMember(dest => dest.ThingTypeSearchableAttributes, opts => opts.MapFrom(src => src.ThingTypeSearchableAttDtos.Select(pair => new ThingTypeSearchableAtt
{
Name = pair.Name
@@ -29,6 +30,7 @@ public ThingTypeProfile()
.ForMember(dest => dest.ThingTypeID, opts => opts.MapFrom(src => src.Id))
.ForMember(dest => dest.ThingTypeName, opts => opts.MapFrom(src => src.Name))
.ForMember(dest => dest.ThingTypeDescription, opts => opts.MapFrom(src => src.Description))
.ForMember(dest => dest.Deprecated, opts => opts.MapFrom(src => src.Deprecated))
.ForMember(dest => dest.Tags, opts => opts.MapFrom(src => src.Tags != null ? src.Tags.ToList() : null))
.ForMember(dest => dest.ThingTypeSearchableAttDtos, opts => opts.MapFrom(
src => src.ThingTypeSearchableAttributes != null ? src.ThingTypeSearchableAttributes.ToList() : null));
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) CGI France. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace AzureIoTHub.Portal.Application.Mappers.AWS
{
using AutoMapper;
using AzureIoTHub.Portal.Domain.Entities.AWS;
using AzureIoTHub.Portal.Models.v10.AWS;

public class ThingTypeTagProfile : Profile
{
public ThingTypeTagProfile()
{
_ = CreateMap<ThingTypeTag, ThingTypeTagDto>()
.ForMember(dest => dest.Key, opts => opts.MapFrom(src => src.Key))
.ForMember(dest => dest.Value, opts => opts.MapFrom(src => src.Value))
.ReverseMap();

}
}
}
Original file line number Diff line number Diff line change
@@ -4,13 +4,23 @@
namespace AzureIoTHub.Portal.Application.Services.AWS
{
using AzureIoTHub.Portal.Models.v10.AWS;
using AzureIoTHub.Portal.Shared.Models.v1._0;
using AzureIoTHub.Portal.Shared.Models.v10.Filters;
using Microsoft.AspNetCore.Http;

public interface IThingTypeService
{
//Get All Thing Types
Task<PaginatedResult<ThingTypeDto>> GetThingTypes(DeviceModelFilter deviceModelFilter);

//Get a thing type
Task<ThingTypeDto> GetThingType(string thingTypeId);
//Create a thing type
Task<string> CreateThingType(ThingTypeDto thingType);

//Deprecate a thing type
Task<ThingTypeDto> DeprecateThingType(string thingTypeId);
//Delete a thing type
Task DeleteThingType(string thingTypeId);
Task<string> GetThingTypeAvatar(string thingTypeId);

Task<string> UpdateThingTypeAvatar(string thingTypeId, IFormFile file);
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
<MudExpansionPanels>
@using AzureIoTHub.Portal.Models.v10;

@inject PortalSettings Portal;

<MudExpansionPanels>
<MudExpansionPanel Text="Search panel">
<MudGrid>
<MudItem xs="12" md="6">
<MudTextField @bind-Value="searchText" Placeholder="Device Model Name / Device Model Description" id="searchText"></MudTextField>
@if (Portal.CloudProvider.Equals("Azure"))
{
<MudTextField @bind-Value="searchText" Placeholder="Device Model Name / Device Model Description" id="searchText"></MudTextField>

}
else
{
<MudTextField @bind-Value="searchText" Placeholder="Thing Type Name / Description / Tags / Searchable Attributes" id="searchText"></MudTextField>

}
</MudItem>

<MudItem xs="12">
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
@inject ISnackbar Snackbar
@using AzureIoTHub.Portal.Models.v10
@using AzureIoTHub.Portal.Client.Services.AWS

@inject ISnackbar Snackbar
@inject IDeviceModelsClientService DeviceModelsClientService
@inject PortalSettings Portal
@inject IThingTypeClientService ThingTypeClientService

<MudDialog>
<DialogContent>
<p>Delete @deviceModelName ?</p>
@if (Portal.CloudProvider.Equals("AWS"))
{
<p>Delete @thingTypeName ?</p>

}
else
{
<p>Delete @deviceModelName ?</p>

}
<br />
<p><i>Warning : this cannot be undone.</i></p>
</DialogContent>
@@ -21,6 +35,9 @@
[Parameter] public string deviceModelID { get; set; } = default!;
[Parameter] public string deviceModelName { get; set; } = default!;

[Parameter] public string thingTypeID { get; set; } = default!;
[Parameter] public string thingTypeName { get; set; } = default!;

void Submit() => MudDialog.Close(DialogResult.Ok(true));
void Cancel() => MudDialog.Cancel();

@@ -32,8 +49,17 @@
{
try
{
await DeviceModelsClientService.DeleteDeviceModel(deviceModelID);
Snackbar.Add($"Device model {deviceModelName} has been successfully deleted!", Severity.Success);
if (Portal.CloudProvider.Equals("AWS"))
{
await ThingTypeClientService.DeleteThingType(thingTypeID);
Snackbar.Add($"Thing Type {thingTypeName} has been successfully deleted!", Severity.Success);
}
else
{
await DeviceModelsClientService.DeleteDeviceModel(deviceModelID);
Snackbar.Add($"Device model {deviceModelName} has been successfully deleted!", Severity.Success);
}

MudDialog.Close(DialogResult.Ok(true));
}
catch (ProblemDetailsException exception)
Loading