Skip to content

Commit

Permalink
Add support for Device model in AWS through AWS thing types (#2050)
Browse files Browse the repository at this point in the history
* getThingType created in Service

* getThingType created in Service

* listing thing types (Backend)

* fix test problems

* Listing Thing Type With pagination (Code + Tests=

* Get Thing Type And Deprecate Thing Type (Backend OK)

* Deprecate Thing Type Back & Front (Not tested yet)

* DONE. Some other tests to DO

* some tests added for the coverage

* some tests added for the coverage

* some new tests added for the coverage
  • Loading branch information
ssgueye2 authored and kbeaugrand committed Jun 18, 2023
1 parent efb5d5c commit a027dbc
Show file tree
Hide file tree
Showing 31 changed files with 1,741 additions and 228 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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));
Expand Down
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
Expand Up @@ -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);
Expand Down
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">
Expand Down
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>
Expand All @@ -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();

Expand All @@ -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)
Expand Down
Loading

0 comments on commit a027dbc

Please sign in to comment.