Wip clean code and pass by postgres !

This commit is contained in:
Thomas Fransolet 2025-03-06 17:39:08 +01:00
parent d968c419b3
commit 8c18825c5d
71 changed files with 1396 additions and 379 deletions

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net8.0</TargetFramework>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
@ -9,4 +9,10 @@
<PackageReference Include="Scrypt.NET" Version="1.3.0" /> <PackageReference Include="Scrypt.NET" Version="1.3.0" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="Business\" />
<Folder Include="Helpers\Passwords\" />
<Folder Include="Models\" />
</ItemGroup>
</Project> </Project>

View File

@ -1,13 +0,0 @@
using Manager.Interfaces.Models;
using System;
using System.Collections.Generic;
using System.Text;
namespace Manager.Interfaces.DTO
{
public class TranslationDTO
{
public string language { get; set; }
public string value { get; set; }
}
}

View File

@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MongoDB.Bson" Version="2.12.1" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.3" />
</ItemGroup>
<ItemGroup>
<Folder Include="DTO\" />
<Folder Include="Models\" />
</ItemGroup>
</Project>

View File

@ -1,11 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MongoDB.Bson" Version="2.12.1" />
</ItemGroup>
</Project>

View File

@ -1,14 +1,10 @@
 
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16 # Visual Studio Version 17
VisualStudioVersion = 16.0.30907.101 VisualStudioVersion = 17.12.35527.113 d17.12
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ManagerService", "ManagerService\ManagerService.csproj", "{042E0BC4-8DCF-4EEC-8420-C71AA85D4D99}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ManagerService", "ManagerService\ManagerService.csproj", "{042E0BC4-8DCF-4EEC-8420-C71AA85D4D99}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Manager.Framework", "Manager.Framework\Manager.Framework.csproj", "{B9548312-650F-4538-85B8-8447F8BB2BD3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Manager.Interfaces", "Manager.Interfaces\Manager.Interfaces.csproj", "{0B2EDCA0-C813-4EAA-9215-E219AE884F7D}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -19,14 +15,6 @@ Global
{042E0BC4-8DCF-4EEC-8420-C71AA85D4D99}.Debug|Any CPU.Build.0 = Debug|Any CPU {042E0BC4-8DCF-4EEC-8420-C71AA85D4D99}.Debug|Any CPU.Build.0 = Debug|Any CPU
{042E0BC4-8DCF-4EEC-8420-C71AA85D4D99}.Release|Any CPU.ActiveCfg = Release|Any CPU {042E0BC4-8DCF-4EEC-8420-C71AA85D4D99}.Release|Any CPU.ActiveCfg = Release|Any CPU
{042E0BC4-8DCF-4EEC-8420-C71AA85D4D99}.Release|Any CPU.Build.0 = Release|Any CPU {042E0BC4-8DCF-4EEC-8420-C71AA85D4D99}.Release|Any CPU.Build.0 = Release|Any CPU
{B9548312-650F-4538-85B8-8447F8BB2BD3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B9548312-650F-4538-85B8-8447F8BB2BD3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B9548312-650F-4538-85B8-8447F8BB2BD3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B9548312-650F-4538-85B8-8447F8BB2BD3}.Release|Any CPU.Build.0 = Release|Any CPU
{0B2EDCA0-C813-4EAA-9215-E219AE884F7D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0B2EDCA0-C813-4EAA-9215-E219AE884F7D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0B2EDCA0-C813-4EAA-9215-E219AE884F7D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0B2EDCA0-C813-4EAA-9215-E219AE884F7D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@ -1,18 +1,16 @@
using Manager.Interfaces.DTO; using Manager.Services;
using Manager.Services; using ManagerService.Data;
using ManagerService.DTOs;
using ManagerService.Service.Services; using ManagerService.Service.Services;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Net.Http.Headers;
using Mqtt.Client.AspNetCore.Services; using Mqtt.Client.AspNetCore.Services;
using NSwag.Annotations; using NSwag.Annotations;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Net; using System.Net;
using System.Threading.Tasks; using System.Linq;
namespace ManagerService.Service.Controllers namespace ManagerService.Service.Controllers
{ {
@ -26,17 +24,20 @@ namespace ManagerService.Service.Controllers
{ {
private readonly ILogger<AuthenticationController> _logger; private readonly ILogger<AuthenticationController> _logger;
private readonly TokensService _tokensService; private readonly TokensService _tokensService;
private readonly UserDatabaseService _UserDatabaseService; /*private readonly UserDatabaseService _UserDatabaseService;
private readonly DeviceDatabaseService _DeviceDatabaseService; private readonly DeviceDatabaseService _DeviceDatabaseService;
private readonly ConfigurationDatabaseService _ConfigurationDatabaseService; private readonly ConfigurationDatabaseService _ConfigurationDatabaseService;*/
private readonly MyInfoMateDbContext _myInfoMateDbContext;
public AuthenticationController(ILogger<AuthenticationController> logger, TokensService tokensService, UserDatabaseService UserDatabaseService, DeviceDatabaseService DeviceDatabaseService, ConfigurationDatabaseService ConfigurationDatabaseService)
public AuthenticationController(ILogger<AuthenticationController> logger, TokensService tokensService, MyInfoMateDbContext myInfoMateDbContext/*UserDatabaseService UserDatabaseService, DeviceDatabaseService DeviceDatabaseService, ConfigurationDatabaseService ConfigurationDatabaseService*/)
{ {
_logger = logger; _logger = logger;
_tokensService = tokensService; _tokensService = tokensService;
_UserDatabaseService = UserDatabaseService; _myInfoMateDbContext = myInfoMateDbContext;
_DeviceDatabaseService = DeviceDatabaseService; //_UserDatabaseService = UserDatabaseService;
_ConfigurationDatabaseService = ConfigurationDatabaseService; //_DeviceDatabaseService = DeviceDatabaseService;
//_ConfigurationDatabaseService = ConfigurationDatabaseService;
} }
/// <summary> /// <summary>
@ -54,14 +55,15 @@ namespace ManagerService.Service.Controllers
password = "kljqsdkljqsd"; // password = "kljqsdkljqsd"; // W/7aj4NB60i3YFKJq50pbw== password = "kljqsdkljqsd"; // password = "kljqsdkljqsd"; // W/7aj4NB60i3YFKJq50pbw==
#endif #endif
// Set user token ? // Set user token ?
var user = _UserDatabaseService.GetByEmail(email.ToLower()); var user = _myInfoMateDbContext.Users.FirstOrDefault(u => u.Email.ToLower() == email.ToLower());
//var user = _UserDatabaseService.GetByEmail(email.ToLower());
if (user == null) if (user == null)
throw new KeyNotFoundException("User not found"); throw new KeyNotFoundException("User not found");
var token = _tokensService.Authenticate(user, password); var token = _tokensService.Authenticate(user, password);
MqttClientService.SetServices(_DeviceDatabaseService, _ConfigurationDatabaseService); MqttClientService.SetServices(_myInfoMateDbContext);//_DeviceDatabaseService, _ConfigurationDatabaseService);
return new OkObjectResult(token); return new OkObjectResult(token);
} }

View File

@ -4,13 +4,13 @@ using System.Linq;
using System.Net.Http; using System.Net.Http;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Manager.DTOs;
using Manager.Helpers; using Manager.Helpers;
using Manager.Interfaces.DTO;
using Manager.Interfaces.Models; using Manager.Interfaces.Models;
using Manager.Services; using Manager.Services;
using ManagerService.Service.Services; using ManagerService.Data;
using ManagerService.DTOs;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.DataProtection.KeyManagement;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
@ -25,23 +25,21 @@ namespace ManagerService.Controllers
[OpenApiTag("Configuration", Description = "Configuration management")] [OpenApiTag("Configuration", Description = "Configuration management")]
public class ConfigurationController : ControllerBase public class ConfigurationController : ControllerBase
{ {
private ConfigurationDatabaseService _configurationService; private readonly MyInfoMateDbContext _myInfoMateDbContext;
/*private ConfigurationDatabaseService _configurationService;
private InstanceDatabaseService _instanceService; private InstanceDatabaseService _instanceService;
private SectionDatabaseService _sectionService; private SectionDatabaseService _sectionService;
private ResourceDatabaseService _resourceService; private ResourceDatabaseService _resourceService;
private DeviceDatabaseService _deviceService; private DeviceDatabaseService _deviceService;*/
private readonly ILogger<ConfigurationController> _logger; private readonly ILogger<ConfigurationController> _logger;
private readonly IConfiguration _configuration; private readonly IConfiguration _configuration;
public ConfigurationController(IConfiguration configuration, ILogger<ConfigurationController> logger, ConfigurationDatabaseService configurationService, InstanceDatabaseService instanceService, SectionDatabaseService sectionService, ResourceDatabaseService resourceService, DeviceDatabaseService deviceService) public ConfigurationController(IConfiguration configuration, ILogger<ConfigurationController> logger, MyInfoMateDbContext myInfoMateDbContext)
{ {
_logger = logger; _logger = logger;
_configuration = configuration; _configuration = configuration;
_configurationService = configurationService; _myInfoMateDbContext = myInfoMateDbContext;
_instanceService = instanceService;
_sectionService = sectionService;
_resourceService = resourceService;
_deviceService = deviceService;
} }
/// <summary> /// <summary>
@ -56,13 +54,13 @@ namespace ManagerService.Controllers
{ {
try try
{ {
List<Configuration> configurations = _configurationService.GetAll(instanceId); List<Configuration> configurations = _myInfoMateDbContext.Configurations.Where(c => c.InstanceId == instanceId).ToList();
List<ConfigurationDTO> configurationDTOs = new List<ConfigurationDTO>(); List<ConfigurationDTO> configurationDTOs = new List<ConfigurationDTO>();
foreach(var configuration in configurations) foreach(var configuration in configurations)
{ {
List<string> sectionIds = _sectionService.GetAllIdsFromConfiguration(configuration.Id); List<string> sectionIds = _myInfoMateDbContext.Sections.Where(c => c.ConfigurationId == configuration.Id).Select(c => c.Id).ToList();
ConfigurationDTO configurationDTO = configuration.ToDTO(sectionIds); ConfigurationDTO configurationDTO = configuration.ToDTO(sectionIds);
configurationDTOs.Add(configurationDTO); configurationDTOs.Add(configurationDTO);
} }
@ -225,7 +223,7 @@ namespace ManagerService.Controllers
Configuration configuration = new Configuration(); Configuration configuration = new Configuration();
configuration.InstanceId = newConfiguration.instanceId; configuration.InstanceId = newConfiguration.instanceId;
configuration.Label = newConfiguration.label; configuration.Label = newConfiguration.label;
configuration.Title = new List<TranslationDTO>(); configuration.Title = new List<Translation>();
configuration.ImageId = newConfiguration.imageId; configuration.ImageId = newConfiguration.imageId;
configuration.ImageSource = newConfiguration.imageSource; configuration.ImageSource = newConfiguration.imageSource;
configuration.PrimaryColor = newConfiguration.primaryColor; configuration.PrimaryColor = newConfiguration.primaryColor;
@ -294,7 +292,7 @@ namespace ManagerService.Controllers
// Todo add some verification ? // Todo add some verification ?
configuration.InstanceId = updatedConfiguration.instanceId; configuration.InstanceId = updatedConfiguration.instanceId;
configuration.Label = updatedConfiguration.label; configuration.Label = updatedConfiguration.label;
configuration.Title = updatedConfiguration.title; configuration.Title = updatedConfiguration.title.Select(t => new Translation().FromDTO(t)).ToList(); // TO CHEECK !
configuration.ImageId = updatedConfiguration.imageId; configuration.ImageId = updatedConfiguration.imageId;
configuration.ImageSource = updatedConfiguration.imageSource; configuration.ImageSource = updatedConfiguration.imageSource;
configuration.PrimaryColor = updatedConfiguration.primaryColor; configuration.PrimaryColor = updatedConfiguration.primaryColor;
@ -644,7 +642,7 @@ namespace ManagerService.Controllers
configuration.Id = exportConfiguration.id; configuration.Id = exportConfiguration.id;
configuration.InstanceId = exportConfiguration.instanceId; configuration.InstanceId = exportConfiguration.instanceId;
configuration.Label = exportConfiguration.label; configuration.Label = exportConfiguration.label;
configuration.Title = exportConfiguration.title; configuration.Title = exportConfiguration.title.Select(t => new Translation().FromDTO(t)).ToList(); // TO CHEECK !
configuration.ImageId = exportConfiguration.imageId; configuration.ImageId = exportConfiguration.imageId;
configuration.ImageSource = exportConfiguration.imageSource; configuration.ImageSource = exportConfiguration.imageSource;
@ -683,8 +681,8 @@ namespace ManagerService.Controllers
newSection.Id = section.id; newSection.Id = section.id;
newSection.InstanceId = section.instanceId; newSection.InstanceId = section.instanceId;
newSection.Label = section.label; newSection.Label = section.label;
newSection.Title = section.title; newSection.Title = section.title.Select(t => new Translation().FromDTO(t)).ToList(); // TODO TEST
newSection.Description = section.description; newSection.Description = section.description.Select(t => new Translation().FromDTO(t)).ToList(); // TODO TEST
newSection.Order = section.order.GetValueOrDefault(); // if one day we can use same section in multiple configuration, need to change that newSection.Order = section.order.GetValueOrDefault(); // if one day we can use same section in multiple configuration, need to change that
newSection.Type = section.type; newSection.Type = section.type;
newSection.ImageId = section.imageId; newSection.ImageId = section.imageId;

View File

@ -1,14 +1,9 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq; using System.Linq;
using System.Threading.Tasks;
using Manager.Interfaces.DTO;
using Manager.Interfaces.Models;
using Manager.Services; using Manager.Services;
using ManagerService.Service.Services; using ManagerService.Data;
using ManagerService.DTOs;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;

View File

@ -1,12 +1,10 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks;
using Manager.Framework.Business;
using Manager.Interfaces.DTO;
using Manager.Interfaces.Models;
using Manager.Services; using Manager.Services;
using ManagerService.Service.Services; using ManagerService.Data;
using ManagerService.DTOs;
using ManagerService.Helpers;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;

View File

@ -1,25 +1,17 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Net.Http.Headers; using Manager.DTOs;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Manager.Interfaces.DTO;
using Manager.Interfaces.Models;
using Manager.Services; using Manager.Services;
using ManagerService.Data;
using ManagerService.DTOs;
using ManagerService.Helpers; using ManagerService.Helpers;
using ManagerService.Service.Services;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Server.IIS.Core;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Newtonsoft.Json; using Newtonsoft.Json;
using NSwag.Annotations; using NSwag.Annotations;
using static System.Net.Mime.MediaTypeNames;
namespace ManagerService.Controllers namespace ManagerService.Controllers
{ {

View File

@ -1,7 +1,8 @@
using Manager.Helpers; using Manager.DTOs;
using Manager.Interfaces.DTO; using Manager.Helpers;
using Manager.Interfaces.Models;
using Manager.Services; using Manager.Services;
using ManagerService.Data;
using ManagerService.DTOs;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
@ -292,8 +293,8 @@ namespace ManagerService.Controllers
section.IsSubSection = newSection.isSubSection; section.IsSubSection = newSection.isSubSection;
section.ParentId = newSection.parentId; section.ParentId = newSection.parentId;
section.Type = newSection.type; section.Type = newSection.type;
section.Title = new List<TranslationDTO>(); section.Title = new List<Translation>();
section.Description = new List<TranslationDTO>(); section.Description = new List<Translation>();
section.Order = _sectionService.GetAllFromConfiguration(newSection.configurationId).Count; section.Order = _sectionService.GetAllFromConfiguration(newSection.configurationId).Count;
section.IsBeacon = newSection.isBeacon; section.IsBeacon = newSection.isBeacon;
section.BeaconId = newSection.beaconId; section.BeaconId = newSection.beaconId;
@ -304,7 +305,7 @@ namespace ManagerService.Controllers
// Preparation // Preparation
List<string> languages = _configuration.GetSection("SupportedLanguages").Get<List<string>>(); List<string> languages = _configuration.GetSection("SupportedLanguages").Get<List<string>>();
var contentArticle = new List<TranslationDTO>(); var contentArticle = new List<Translation>();
var mapDTO = new MapDTO(); // For menu dto var mapDTO = new MapDTO(); // For menu dto
var sliderDTO = new SliderDTO(); // For menu dto var sliderDTO = new SliderDTO(); // For menu dto
@ -349,8 +350,8 @@ namespace ManagerService.Controllers
contentArticle.Add(content); contentArticle.Add(content);
}*/ }*/
section.Title = section.Title.OrderBy(t => t.language).ToList(); section.Title = section.Title.OrderBy(t => t.Language).ToList();
section.Description = section.Description.OrderBy(d => d.language).ToList(); section.Description = section.Description.OrderBy(d => d.Language).ToList();
switch (newSection.type) { switch (newSection.type) {
case SectionType.Map: case SectionType.Map:
@ -418,8 +419,8 @@ namespace ManagerService.Controllers
case SectionType.Article: case SectionType.Article:
ArticleDTO articleDTO = new ArticleDTO(); ArticleDTO articleDTO = new ArticleDTO();
articleDTO.contents = new List<ContentDTO>(); articleDTO.contents = new List<ContentDTO>();
articleDTO.content = contentArticle; articleDTO.content = contentArticle.Select(c => c.ToDTO()).ToList(); // TODO check
articleDTO.audioIds = LanguageInit.Init("Audio", languages, true); articleDTO.audioIds = LanguageInit.Init("Audio", languages, true).Select(c => c.ToDTO()).ToList(); // TODO check
section.Data = JsonConvert.SerializeObject(articleDTO); // Include all info from specific section as JSON section.Data = JsonConvert.SerializeObject(articleDTO); // Include all info from specific section as JSON
break; break;
@ -535,8 +536,8 @@ namespace ManagerService.Controllers
// Todo add some verification ? // Todo add some verification ?
section.InstanceId = updatedSection.instanceId; section.InstanceId = updatedSection.instanceId;
section.Label = updatedSection.label; section.Label = updatedSection.label;
section.Title = updatedSection.title; section.Title = updatedSection.title.Select(t => new Translation().FromDTO(t)).ToList(); // TODO CHECK
section.Description = updatedSection.description; section.Description = updatedSection.description.Select(t => new Translation().FromDTO(t)).ToList();// TODO CHECK
section.Type = updatedSection.type; section.Type = updatedSection.type;
section.ImageId = updatedSection.imageId; section.ImageId = updatedSection.imageId;
section.ImageSource = updatedSection.imageSource; section.ImageSource = updatedSection.imageSource;

View File

@ -1,11 +1,10 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks;
using Manager.Framework.Business;
using Manager.Interfaces.DTO;
using Manager.Interfaces.Models;
using Manager.Services; using Manager.Services;
using ManagerService.Data;
using ManagerService.DTOs;
using ManagerService.Helpers;
using ManagerService.Service.Services; using ManagerService.Service.Services;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;

View File

@ -1,9 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text;
using System.Xml.Linq;
namespace Manager.Interfaces.DTO namespace ManagerService.DTOs
{ {
public class ConfigurationDTO public class ConfigurationDTO
{ {

View File

@ -1,8 +1,6 @@
using System; using System;
using System.Collections.Generic;
using System.Text;
namespace Manager.Interfaces.DTO namespace ManagerService.DTOs
{ {
public class DeviceDTO public class DeviceDTO
{ {

View File

@ -1,7 +1,6 @@
using System; using System.Collections.Generic;
using System.Collections.Generic;
namespace Manager.Interfaces.DTO namespace ManagerService.DTOs
{ {
public class ExportConfigurationDTO : ConfigurationDTO public class ExportConfigurationDTO : ConfigurationDTO
{ {

View File

@ -1,8 +1,6 @@
using System; using System;
using System.Collections.Generic;
using System.Text;
namespace Manager.Interfaces.DTO namespace ManagerService.DTOs
{ {
public class InstanceDTO public class InstanceDTO
{ {

View File

@ -1,4 +1,4 @@
namespace Manager.Interfaces.DTO namespace ManagerService.DTOs
{ {
public class LoginDTO public class LoginDTO
{ {

View File

@ -1,8 +1,4 @@
using System; namespace ManagerService.DTOs
using System.Collections.Generic;
using System.Text;
namespace Manager.Interfaces.Models
{ {
public class PlayerMessageDTO public class PlayerMessageDTO
{ {

View File

@ -1,9 +1,7 @@
using Manager.Interfaces.Models; using ManagerService.Data;
using System; using System;
using System.Collections.Generic;
using System.Text;
namespace Manager.Interfaces.DTO namespace ManagerService.DTOs
{ {
public class ResourceDTO public class ResourceDTO
{ {

View File

@ -1,9 +1,8 @@
using Manager.Interfaces.Models; using ManagerService.Data;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text;
namespace Manager.Interfaces.DTO namespace ManagerService.DTOs
{ {
public class SectionDTO public class SectionDTO
{ {

View File

@ -1,8 +1,7 @@
using System; using ManagerService.DTOs;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text;
namespace Manager.Interfaces.DTO namespace Manager.DTOs
{ {
public class AgendaDTO public class AgendaDTO
{ {

View File

@ -1,9 +1,7 @@
using Manager.Interfaces.Models; using ManagerService.DTOs;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text;
namespace Manager.Interfaces.DTO namespace Manager.DTOs
{ {
public class ArticleDTO public class ArticleDTO
{ {

View File

@ -1,9 +1,9 @@
using Manager.Interfaces.Models; using Manager.Interfaces.Models;
using System; using ManagerService.Data;
using ManagerService.DTOs;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text;
namespace Manager.Interfaces.DTO namespace Manager.DTOs
{ {
public class MapDTO public class MapDTO
{ {

View File

@ -1,8 +1,7 @@
using System; using ManagerService.DTOs;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text;
namespace Manager.Interfaces.DTO namespace Manager.DTOs
{ {
public class MenuDTO public class MenuDTO
{ {

View File

@ -1,8 +1,7 @@
using System; using ManagerService.DTOs;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text;
namespace Manager.Interfaces.DTO namespace Manager.DTOs
{ {
public class PdfDTO public class PdfDTO
{ {

View File

@ -1,9 +1,7 @@
using Manager.Interfaces.Models; using ManagerService.DTOs;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text;
namespace Manager.Interfaces.DTO namespace Manager.DTOs
{ {
public class PuzzleDTO public class PuzzleDTO
{ {

View File

@ -1,9 +1,8 @@
using System; using ManagerService.DTOs;
using System.Collections.Generic; using System.Collections.Generic;
using System.Security.AccessControl; using System.Security.AccessControl;
using System.Text;
namespace Manager.Interfaces.DTO namespace Manager.DTOs
{ {
public class QuizzDTO public class QuizzDTO
{ {

View File

@ -1,9 +1,8 @@
using Manager.Interfaces.Models; using ManagerService.Data;
using System; using ManagerService.DTOs;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text;
namespace Manager.Interfaces.DTO namespace Manager.DTOs
{ {
public class SliderDTO public class SliderDTO
{ {

View File

@ -1,8 +1,4 @@
using System; namespace Manager.DTOs
using System.Collections.Generic;
using System.Text;
namespace Manager.Interfaces.DTO
{ {
public class VideoDTO public class VideoDTO
{ {

View File

@ -1,8 +1,6 @@
using System; using System;
using System.Collections.Generic;
using System.Text;
namespace Manager.Interfaces.DTO namespace Manager.DTOs
{ {
public class WeatherDTO public class WeatherDTO
{ {

View File

@ -1,8 +1,4 @@
using System; namespace Manager.DTOs
using System.Collections.Generic;
using System.Text;
namespace Manager.Interfaces.DTO
{ {
public class WebDTO public class WebDTO
{ {

View File

@ -1,4 +1,4 @@
namespace Manager.Interfaces.DTO namespace ManagerService.DTOs
{ {
/// <summary> /// <summary>
/// Swagger test client authentication data /// Swagger test client authentication data

View File

@ -1,6 +1,6 @@
using System; using System;
namespace Manager.Interfaces.DTO namespace ManagerService.DTOs
{ {
public class TokenDTO public class TokenDTO
{ {

View File

@ -1,9 +1,7 @@
using Manager.Interfaces.Models; 
using System; using ManagerService.Data;
using System.Collections.Generic;
using System.Text;
namespace Manager.Interfaces.DTO namespace ManagerService.DTOs
{ {
public class TranslationAndResourceDTO public class TranslationAndResourceDTO
{ {

View File

@ -0,0 +1,8 @@
namespace ManagerService.DTOs
{
public class TranslationDTO
{
public string language { get; set; }
public string value { get; set; }
}
}

View File

@ -1,8 +1,4 @@
using System; namespace ManagerService.DTOs
using System.Collections.Generic;
using System.Text;
namespace Manager.Interfaces.DTO
{ {
public class UserDetailDTO public class UserDetailDTO
{ {

View File

@ -1,88 +1,96 @@
using Manager.Interfaces.DTO; using ManagerService.DTOs;
using MongoDB.Bson.Serialization.Attributes; using MongoDB.Bson.Serialization.Attributes;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
namespace Manager.Interfaces.Models namespace ManagerService.Data
{ {
/// <summary> /// <summary>
/// Configuration Information /// Configuration Information
/// </summary> /// </summary>
public class Configuration public class Configuration
{ {
[BsonId] [Key]
[BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)] [Required]
/*[BsonId]
[BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)]*/
public string Id { get; set; } public string Id { get; set; }
[BsonElement("Label")] /*[BsonElement("Label")]
[BsonRequired] [BsonRequired]*/
[Required]
public string Label { get; set; } public string Label { get; set; }
[BsonElement("Title")] /*[BsonElement("Title")]
[BsonRequired] [BsonRequired]*/
public List<TranslationDTO> Title { get; set; } [Required]
[Column(TypeName = "jsonb")]
public List<Translation> Title { get; set; }
[BsonElement("ImageId")] /*[BsonElement("ImageId")]*/
public string ImageId { get; set; } public string ImageId { get; set; }
[BsonElement("ImageSource")] /*[BsonElement("ImageSource")]*/
public string ImageSource { get; set; } public string ImageSource { get; set; }
[BsonElement("PrimaryColor")] /*[BsonElement("PrimaryColor")]*/
public string PrimaryColor { get; set; } public string PrimaryColor { get; set; }
[BsonElement("SecondaryColor")] /*[BsonElement("SecondaryColor")]*/
public string SecondaryColor { get; set; } public string SecondaryColor { get; set; }
[BsonElement("Languages")] /*[BsonElement("Languages")]*/
public List<string> Languages { get; set; } // fr, en, de, nl => Sélection dans une liste déjà établie dans l'application ! public List<string> Languages { get; set; } // fr, en, de, nl => Sélection dans une liste déjà établie dans l'application !
[BsonElement("DateCreation")] /*[BsonElement("DateCreation")]*/
public DateTime DateCreation { get; set; } public DateTime DateCreation { get; set; }
[BsonElement("IsMobile")] /*[BsonElement("IsMobile")]*/
public bool IsMobile { get; set; } public bool IsMobile { get; set; }
[BsonElement("IsTablet")] /*[BsonElement("IsTablet")]*/
public bool IsTablet { get; set; } public bool IsTablet { get; set; }
[BsonElement("IsOffline")] /*[BsonElement("IsOffline")]*/
public bool IsOffline { get; set; } public bool IsOffline { get; set; }
[BsonElement("InstanceId")] /*[BsonElement("InstanceId")]
[BsonRequired] [BsonRequired]*/
[Required]
public string InstanceId { get; set; } public string InstanceId { get; set; }
[BsonElement("LoaderImageId")] /*[BsonElement("LoaderImageId")]*/
public string LoaderImageId { get; set; } public string LoaderImageId { get; set; }
[BsonElement("LoaderImageUrl")] /*[BsonElement("LoaderImageUrl")]*/
public string LoaderImageUrl { get; set; } public string LoaderImageUrl { get; set; }
[BsonElement("WeatherCity")] /*[BsonElement("WeatherCity")]*/
public string WeatherCity { get; set; } public string WeatherCity { get; set; }
[BsonElement("WeatherUpdatedDate")] /*[BsonElement("WeatherUpdatedDate")]*/
public DateTimeOffset? WeatherUpdatedDate { get; set; } public DateTimeOffset? WeatherUpdatedDate { get; set; }
[BsonElement("WeatherResult")] /*[BsonElement("WeatherResult")]*/
public string WeatherResult { get; set; } public string WeatherResult { get; set; }
[BsonElement("IsDate")] /*[BsonElement("IsDate")]*/
public bool IsDate { get; set; } public bool IsDate { get; set; }
[BsonElement("IsHour")] /*[BsonElement("IsHour")]*/
public bool IsHour { get; set; } public bool IsHour { get; set; }
[BsonElement("IsSectionImageBackground")] /*[BsonElement("IsSectionImageBackground")]*/
public bool IsSectionImageBackground { get; set; } public bool IsSectionImageBackground { get; set; }
[BsonElement("RoundedValue")] /*[BsonElement("RoundedValue")]*/
public int? RoundedValue { get; set; } public int? RoundedValue { get; set; }
[BsonElement("ScreenPercentageSectionsMainPage")] /*[BsonElement("ScreenPercentageSectionsMainPage")]*/
public int? ScreenPercentageSectionsMainPage { get; set; } public int? ScreenPercentageSectionsMainPage { get; set; }
public ConfigurationDTO ToDTO(List<string> sectionIds) public ConfigurationDTO ToDTO(List<string> sectionIds)
@ -91,7 +99,7 @@ namespace Manager.Interfaces.Models
{ {
id = Id, id = Id,
label = Label, label = Label,
title = Title, title = Title.Select(c => c.ToDTO()).ToList(),
imageId = ImageId, imageId = ImageId,
imageSource = ImageSource, imageSource = ImageSource,
loaderImageId = LoaderImageId, loaderImageId = LoaderImageId,
@ -121,7 +129,7 @@ namespace Manager.Interfaces.Models
{ {
id = Id, id = Id,
label = Label, label = Label,
title= Title, title= Title.Select(c => c.ToDTO()).ToList(),
imageId = ImageId, imageId = ImageId,
imageSource = ImageSource, imageSource = ImageSource,
loaderImageId = LoaderImageId, loaderImageId = LoaderImageId,

View File

@ -1,67 +1,72 @@
using Manager.Interfaces.DTO; using ManagerService.DTOs;
using MongoDB.Bson.Serialization.Attributes;
using System; using System;
using System.Collections.Generic; using System.ComponentModel.DataAnnotations;
using System.Text;
namespace Manager.Interfaces.Models namespace ManagerService.Data
{ {
/// <summary> /// <summary>
/// Device Information (Tablet) /// Device Information (Tablet)
/// </summary> /// </summary>
public class Device public class Device
{ {
[BsonId] [Key]
[BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)] [Required]
/*[BsonId]
[BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)]*/
public string Id { get; set; } public string Id { get; set; }
[BsonElement("Identifier")] //[BsonElement("Identifier")]
public string Identifier { get; set; } public string Identifier { get; set; }
[BsonElement("Name")] //[BsonElement("Name")]
public string Name { get; set; } public string Name { get; set; }
[BsonElement("IpAddressWLAN")] /*[BsonElement("IpAddressWLAN")]
[BsonRequired] [BsonRequired]*/
[Required]
public string IpAddressWLAN { get; set; } public string IpAddressWLAN { get; set; }
[BsonElement("IpAddressETH")] //[BsonElement("IpAddressETH")]
[BsonRequired] //[BsonRequired]
[Required]
public string IpAddressETH { get; set; } public string IpAddressETH { get; set; }
[BsonElement("Configuration")] //[BsonElement("Configuration")]
public string Configuration { get; set; } public string Configuration { get; set; }
[BsonElement("ConfigurationId")] //[BsonElement("ConfigurationId")]
[BsonRequired] //[BsonRequired]
[Required]
public string ConfigurationId { get; set; } public string ConfigurationId { get; set; }
[BsonElement("Connected")] //[BsonElement("Connected")]
[BsonRequired] //[BsonRequired]
[Required]
public bool Connected { get; set; } public bool Connected { get; set; }
[BsonElement("DateCreation")] //[BsonElement("DateCreation")]
public DateTime DateCreation { get; set; } public DateTime DateCreation { get; set; }
[BsonElement("DateUpdate")] //[BsonElement("DateUpdate")]
public DateTime DateUpdate { get; set; } public DateTime DateUpdate { get; set; }
// BatteryLevel in case of powered devices // BatteryLevel in case of powered devices
[BsonElement("BatteryLevel")] //[BsonElement("BatteryLevel")]
public string BatteryLevel { get; set; } public string BatteryLevel { get; set; }
[BsonElement("LastBatteryLevel")] //[BsonElement("LastBatteryLevel")]
public DateTime LastBatteryLevel { get; set; } public DateTime LastBatteryLevel { get; set; }
// ConnectionLevel wifi strength level // ConnectionLevel wifi strength level
[BsonElement("ConnectionLevel")] //[BsonElement("ConnectionLevel")]
public string ConnectionLevel { get; set; } public string ConnectionLevel { get; set; }
[BsonElement("LastConnectionLevel")] //[BsonElement("LastConnectionLevel")]
public DateTime LastConnectionLevel { get; set; } public DateTime LastConnectionLevel { get; set; }
[BsonElement("InstanceId")] /*[BsonElement("InstanceId")]
[BsonRequired] [BsonRequired]*/
[Required]
public string InstanceId { get; set; } public string InstanceId { get; set; }
public DeviceDTO ToDTO() public DeviceDTO ToDTO()

View File

@ -1,28 +1,29 @@
using Manager.Interfaces.DTO; using ManagerService.DTOs;
using MongoDB.Bson.Serialization.Attributes;
using System; using System;
using System.Collections.Generic; using System.ComponentModel.DataAnnotations;
using System.Text;
namespace Manager.Interfaces.Models namespace ManagerService.Data
{ {
/// <summary> /// <summary>
/// Instance Information /// Instance Information
/// </summary> /// </summary>
public class Instance public class Instance
{ {
[BsonId] [Key]
[BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)] [Required]
/*[BsonId]
[BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)]*/
public string Id { get; set; } public string Id { get; set; }
[BsonElement("Name")] /*[BsonElement("Name")]
[BsonRequired] [BsonRequired]*/
[Required]
public string Name { get; set; } // UNIQUE !.. public string Name { get; set; } // UNIQUE !..
[BsonElement("DateCreation")] /*[BsonElement("DateCreation")]*/
public DateTime DateCreation { get; set; } public DateTime DateCreation { get; set; }
[BsonElement("PinCode")] /*[BsonElement("PinCode")]*/
public int? PinCode { get; set; } public int? PinCode { get; set; }
public InstanceDTO ToDTO() public InstanceDTO ToDTO()

View File

@ -0,0 +1,33 @@
using Microsoft.EntityFrameworkCore;
namespace ManagerService.Data
{
public class MyInfoMateDbContext : DbContext
{
public MyInfoMateDbContext(DbContextOptions<MyInfoMateDbContext> options) : base(options) { }
public DbSet<Instance> Instances { get; set; }
public DbSet<Configuration> Configurations { get; set; }
public DbSet<Section> Sections { get; set; }
public DbSet<Device> Devices { get; set; }
public DbSet<Resource> Resources { get; set; }
public DbSet<User> Users { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Configuration>()
.Property(s => s.Title)
.HasColumnType("jsonb");
modelBuilder.Entity<Section>()
.Property(s => s.Title)
.HasColumnType("jsonb");
modelBuilder.Entity<Section>()
.Property(s => s.Description)
.HasColumnType("jsonb");
}
}
}

View File

@ -1,37 +1,39 @@
using Manager.Interfaces.DTO; using ManagerService.DTOs;
using MongoDB.Bson.Serialization.Attributes;
using System; using System;
using System.Collections.Generic; using System.ComponentModel.DataAnnotations;
using System.Text;
namespace ManagerService.Data
namespace Manager.Interfaces.Models
{ {
/// <summary> /// <summary>
/// Resource Information /// Resource Information
/// </summary> /// </summary>
public class Resource public class Resource
{ {
[BsonId] [Key]
[BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)] [Required]
/*[BsonId]
[BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)]*/
public string Id { get; set; } public string Id { get; set; }
[BsonElement("Type")] /*[BsonElement("Type")]
[BsonRequired] [BsonRequired]*/
[Required]
public ResourceType Type { get; set; } public ResourceType Type { get; set; }
[BsonElement("Label")] /*[BsonElement("Label")]
[BsonRequired] [BsonRequired]*/
[Required]
public string Label { get; set; } public string Label { get; set; }
[BsonElement("DateCreation")] /*[BsonElement("DateCreation")]*/
public DateTime DateCreation { get; set; } public DateTime DateCreation { get; set; }
[BsonElement("InstanceId")] /*[BsonElement("InstanceId")]
[BsonRequired] [BsonRequired]*/
[Required]
public string InstanceId { get; set; } public string InstanceId { get; set; }
[BsonElement("URL")] /*[BsonElement("URL")]*/
public string Url { get; set; } // Firebase url public string Url { get; set; } // Firebase url
public ResourceDTO ToDTO() public ResourceDTO ToDTO()

View File

@ -1,83 +1,96 @@
using Manager.Interfaces.DTO; using ManagerService.DTOs;
using MongoDB.Bson.Serialization.Attributes;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq; using System.Linq;
using System.Text;
namespace Manager.Interfaces.Models namespace ManagerService.Data
{ {
/// <summary> /// <summary>
/// Section Information /// Section Information
/// </summary> /// </summary>
public class Section public class Section
{ {
[BsonId] [Key]
[BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)] [Required]
/*[BsonId]
[BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)]*/
public string Id { get; set; } public string Id { get; set; }
[BsonElement("Label")] //[BsonElement("Label")]
[BsonRequired] //[BsonRequired]
[Required]
public string Label { get; set; } // Use in manager public string Label { get; set; } // Use in manager
[BsonElement("Title")] //[BsonElement("Title")]
[BsonRequired] //[BsonRequired]
public List<TranslationDTO> Title { get; set; } [Required]
[Column(TypeName = "jsonb")]
public List<Translation> Title { get; set; }
[BsonElement("Description")] //[BsonElement("Description")]
public List<TranslationDTO> Description { get; set; } [Column(TypeName = "jsonb")]
public List<Translation> Description { get; set; }
[BsonElement("Order")] //[BsonElement("Order")]
public int Order { get; set; } public int Order { get; set; }
[BsonElement("ConfigurationId")] //[BsonElement("ConfigurationId")]
[BsonRequired] //[BsonRequired]
[Required]
public string ConfigurationId { get; set; } // Parent id public string ConfigurationId { get; set; } // Parent id
[BsonElement("ImageId")] //[BsonElement("ImageId")]
[BsonRequired] //[BsonRequired]
[Required]
public string ImageId { get; set; } public string ImageId { get; set; }
[BsonElement("ImageSource")] //[BsonElement("ImageSource")]
[BsonRequired] //[BsonRequired]
[Required]
public string ImageSource { get; set; } public string ImageSource { get; set; }
[BsonElement("Type")] //[BsonElement("Type")]
[BsonRequired] //[BsonRequired]
[Required]
public SectionType Type { get; set; } public SectionType Type { get; set; }
[BsonElement("IsSubSection")] //[BsonElement("IsSubSection")]
[BsonRequired] //[BsonRequired]
[Required]
public bool IsSubSection { get; set; } public bool IsSubSection { get; set; }
[BsonElement("ParentId")] //[BsonElement("ParentId")]
public string ParentId { get; set; } // only if it's an subsection public string ParentId { get; set; } // only if it's an subsection
[BsonElement("DateCreation")] //[BsonElement("DateCreation")]
public DateTime DateCreation { get; set; } public DateTime DateCreation { get; set; }
[BsonElement("Data")] //[BsonElement("Data")]
[BsonRequired] //[BsonRequired]
[Required]
public string Data { get; set; } // Json encapsulated section info public string Data { get; set; } // Json encapsulated section info
[BsonElement("InstanceId")] //[BsonElement("InstanceId")]
[BsonRequired] //[BsonRequired]
[Required]
public string InstanceId { get; set; } public string InstanceId { get; set; }
[BsonElement("IsBeacon")] //[BsonElement("IsBeacon")]
public bool IsBeacon { get; set; } public bool IsBeacon { get; set; }
[BsonElement("BeaconId")] //[BsonElement("BeaconId")]
public int? BeaconId { get; set; } public int? BeaconId { get; set; }
[BsonElement("Latitude")] //[BsonElement("Latitude")]
public string Latitude { get; set; } public string Latitude { get; set; }
[BsonElement("Longitude")] //[BsonElement("Longitude")]
public string Longitude { get; set; } public string Longitude { get; set; }
[BsonElement("MeterZoneGPS")] //[BsonElement("MeterZoneGPS")]
public int? MeterZoneGPS { get; set; } public int? MeterZoneGPS { get; set; }
public SectionDTO ToDTO() public SectionDTO ToDTO()
@ -86,8 +99,8 @@ namespace Manager.Interfaces.Models
{ {
id = Id, id = Id,
label = Label, label = Label,
title = Title.OrderBy(t => t.language).ToList(), title = Title.OrderBy(t => t.Language).Select(l => l.ToDTO()).ToList(),
description = Description.OrderBy(d => d.language).ToList(), description = Description.OrderBy(d => d.Language).Select(l => l.ToDTO()).ToList(),
order = Order, order = Order,
type = Type, type = Type,
imageId = ImageId, imageId = ImageId,

View File

@ -0,0 +1,46 @@
using ManagerService.DTOs;
using System;
using System.ComponentModel.DataAnnotations;
namespace ManagerService.Data
{
/// <summary>
/// Translation
/// </summary>
public class Translation
{
[Key]
[Required]
public int Id { get; set; }
[Required]
public string Language { get; set; }
public string Value { get; set; }
public TranslationDTO ToDTO()
{
return new TranslationDTO()
{
language = Language,
value = Value
};
}
public Translation FromDTO(TranslationDTO translationDTO)
{
return new Translation()
{
Language = translationDTO.language,
Value = translationDTO.value
};
}
public enum TranslationType
{
Title,
Description
}
}
}

View File

@ -1,45 +1,50 @@
using Manager.Interfaces.DTO; using ManagerService.DTOs;
using MongoDB.Bson.Serialization.Attributes;
using System; using System;
using System.Collections.Generic; using System.ComponentModel.DataAnnotations;
using System.Text;
namespace Manager.Interfaces.Models namespace ManagerService.Data
{ {
/// <summary> /// <summary>
/// User Information /// User Information
/// </summary> /// </summary>
public class User public class User
{ {
[BsonId] [Key]
[BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)] [Required]
/*[BsonId]
[BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)]*/
public string Id { get; set; } public string Id { get; set; }
[BsonElement("Email")] //[BsonElement("Email")]
[BsonRequired] //[BsonRequired]
[Required]
public string Email { get; set; } // UNIQUE !.. public string Email { get; set; } // UNIQUE !..
[BsonElement("Password")] //[BsonElement("Password")]
[BsonRequired] //[BsonRequired]
[Required]
public string Password { get; set; } public string Password { get; set; }
[BsonElement("FirstName")] //[BsonElement("FirstName")]
[BsonRequired] //[BsonRequired]
public string FirstName { get; set; } public string FirstName { get; set; }
[BsonElement("LastName")] //[BsonElement("LastName")]
[BsonRequired] //[BsonRequired]
[Required]
public string LastName { get; set; } public string LastName { get; set; }
[BsonElement("Token")] //[BsonElement("Token")]
[BsonRequired] //[BsonRequired]
[Required]
public string Token { get; set; } public string Token { get; set; }
[BsonElement("DateCreation")] //[BsonElement("DateCreation")]
public DateTime DateCreation { get; set; } public DateTime DateCreation { get; set; }
[BsonElement("InstanceId")] /*[BsonElement("InstanceId")]
[BsonRequired] [BsonRequired]*/
[Required]
public string InstanceId { get; set; } public string InstanceId { get; set; }
public UserDetailDTO ToDTO() public UserDetailDTO ToDTO()

View File

@ -0,0 +1,25 @@
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md

View File

@ -0,0 +1,12 @@
##
# Copy and rename this file to ".env"
##
# PostgreSQL
POSTGRES_USER=mym
POSTGRES_PASSWORD=mym
POSTGRES_DATABASE=my_info_mate
# pgAdmin
PGADMIN_EMAIL=local@mym.be
PGADMIN_PASSWORD=mym

View File

@ -0,0 +1,12 @@
##
# Copy and rename this file to ".env"
##
# PostgreSQL
POSTGRES_USER=mym
POSTGRES_PASSWORD=mym
POSTGRES_DATABASE=my_info_mate
# pgAdmin
PGADMIN_EMAIL=local@mym.be
PGADMIN_PASSWORD=mym

View File

@ -0,0 +1,60 @@
---
version: '3.9'
services:
postgres:
image: postgres:16
container_name: myim_postgres
environment:
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DATABASE}
ports:
- "5432:5432"
volumes:
- postgres-data:/var/lib/postgresql/data
networks:
- myim-network
# Admin Dashboard for PostgresSQL Database
pgadmin:
image: dpage/pgadmin4
container_name: pgadmin
restart: unless-stopped
environment:
PGADMIN_DEFAULT_EMAIL: ${PGADMIN_EMAIL}
PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_PASSWORD}
ports:
- "5050:80"
volumes:
- pgadmin-data:/var/lib/pgadmin
networks:
- myim-network
depends_on:
- postgres
# myim-api:
# image: myim/myim-api
# container_name: myim_api
# build:
# context: ../.
# dockerfile: ./Dockerfile
# args:
# - mode=dev
# restart: unless-stopped
# ports:
# - "5093:80"
# networks:
# - myim-network
# depends_on:
# - postgres
volumes:
postgres-data:
pgadmin-data:
networks:
myim-network:
driver: bridge
name: myim-network

View File

@ -1,5 +1,6 @@
using Manager.Interfaces.Models; using Manager.Interfaces.Models;
using Manager.Services; using Manager.Services;
using ManagerService.Data;
using MQTTnet; using MQTTnet;
using MQTTnet.Client; using MQTTnet.Client;
using MQTTnet.Client.Connecting; using MQTTnet.Client.Connecting;
@ -19,8 +20,9 @@ namespace Mqtt.Client.AspNetCore.Services
{ {
private static IMqttClient mqttClient; private static IMqttClient mqttClient;
private IMqttClientOptions options; private IMqttClientOptions options;
static DeviceDatabaseService _deviceDatabaseService; /*static DeviceDatabaseService _deviceDatabaseService;
static ConfigurationDatabaseService _configurationDatabaseService; static ConfigurationDatabaseService _configurationDatabaseService;*/
static MyInfoMateDbContext _myInfoMateDbContext;
public static string lastTopic; public static string lastTopic;
public static long lastTimeTopic; public static long lastTimeTopic;
@ -74,13 +76,19 @@ namespace Mqtt.Client.AspNetCore.Services
var deviceId = (string)deserialized["deviceId"]; var deviceId = (string)deserialized["deviceId"];
var connectedStatus = (bool)deserialized["connected"]; var connectedStatus = (bool)deserialized["connected"];
Device device = _deviceDatabaseService.GetById(deviceId); // TODO
Device device = _myInfoMateDbContext.Devices.Find(deviceId); //_deviceDatabaseService.GetById(deviceId);
if (device != null) if (device != null)
{ {
device.Connected = connectedStatus; device.Connected = connectedStatus;
_deviceDatabaseService.Update(device.Id, device); _myInfoMateDbContext.SaveChanges();
//_deviceDatabaseService.Update(device.Id, device);
} }
} }
break; break;
@ -145,10 +153,10 @@ namespace Mqtt.Client.AspNetCore.Services
await mqttClient.PublishAsync(mqttMessage); await mqttClient.PublishAsync(mqttMessage);
} }
public static void SetServices(DeviceDatabaseService _DeviceDatabaseService, ConfigurationDatabaseService _ConfigurationDatabaseService) public static void SetServices(MyInfoMateDbContext myInfoMateDbContext/*DeviceDatabaseService _DeviceDatabaseService, ConfigurationDatabaseService _ConfigurationDatabaseService*/)
{ {
_deviceDatabaseService = _DeviceDatabaseService; _myInfoMateDbContext = myInfoMateDbContext;
_configurationDatabaseService = _ConfigurationDatabaseService; //_configurationDatabaseService = _ConfigurationDatabaseService;
} }
} }
} }

View File

@ -1,24 +1,18 @@
using System; using System.Collections.Generic;
using System.Collections.Generic; using ManagerService.Data;
using System.Linq;
using System.Threading.Tasks;
using Manager.Interfaces.DTO;
using Manager.Interfaces.Models;
using Microsoft.Extensions.Configuration;
using MongoDB.Driver;
namespace Manager.Helpers namespace Manager.Helpers
{ {
public class LanguageInit public class LanguageInit
{ {
public static List<TranslationDTO> Init(string label, List<string> languages, bool toNull = false) public static List<Translation> Init(string label, List<string> languages, bool toNull = false)
{ {
List<TranslationDTO> translations = new List<TranslationDTO>(); List<Translation> translations = new List<Translation>();
foreach (var language in languages) foreach (var language in languages)
{ {
var value = toNull ? null : $"{language} - {label}"; var value = toNull ? null : $"{language} - {label}";
translations.Add(new TranslationDTO() { language = language.ToUpper(), value = value }); translations.Add(new Translation() { Language = language.ToUpper(), Value = value });
} }
return translations; return translations;
} }

View File

@ -6,7 +6,7 @@ using System.Security.Cryptography;
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
namespace Manager.Framework.Helpers namespace ManagerService.Helpers
{ {
/// <summary> /// <summary>
/// Password utils /// Password utils

View File

@ -1,11 +1,7 @@
using Manager.Framework.Helpers; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging;
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Manager.Framework.Business namespace ManagerService.Helpers
{ {
public class ProfileLogic public class ProfileLogic
{ {

View File

@ -1,26 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net8.0</TargetFramework>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS> <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<UserSecretsId>d2e1a747-e204-4b43-bf93-abbd19c46417</UserSecretsId> <UserSecretsId>d2e1a747-e204-4b43-bf93-abbd19c46417</UserSecretsId>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="2.1.30" /> <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="2.1.30" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="7.2.0" /> <PackageReference Include="Microsoft.IdentityModel.Tokens" Version="7.2.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.14.0" /> <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.14.0" />
<PackageReference Include="MongoDB.Driver" Version="2.19.0" /> <PackageReference Include="MongoDB.Driver" Version="2.19.0" />
<PackageReference Include="MQTTnet.AspNetCore" Version="3.0.13" /> <PackageReference Include="MQTTnet.AspNetCore" Version="3.0.13" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.3" />
<PackageReference Include="NSwag.AspNetCore" Version="13.10.8" /> <PackageReference Include="NSwag.AspNetCore" Version="13.10.8" />
<PackageReference Include="Scrypt.NET" Version="1.3.0" />
<PackageReference Include="System.Drawing.Common" Version="6.0.0" /> <PackageReference Include="System.Drawing.Common" Version="6.0.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.2.0" /> <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.2.0" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Manager.Framework\Manager.Framework.csproj" />
<ProjectReference Include="..\Manager.Interfaces\Manager.Interfaces.csproj" />
</ItemGroup>
</Project> </Project>

View File

@ -0,0 +1,320 @@
// <auto-generated />
using System;
using System.Collections.Generic;
using ManagerService.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace ManagerService.Migrations
{
[DbContext(typeof(MyInfoMateDbContext))]
[Migration("20250305163047_InitialCreate")]
partial class InitialCreate
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "9.0.2")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("ManagerService.Data.Configuration", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<DateTime>("DateCreation")
.HasColumnType("timestamp with time zone");
b.Property<string>("ImageId")
.HasColumnType("text");
b.Property<string>("ImageSource")
.HasColumnType("text");
b.Property<string>("InstanceId")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("IsDate")
.HasColumnType("boolean");
b.Property<bool>("IsHour")
.HasColumnType("boolean");
b.Property<bool>("IsMobile")
.HasColumnType("boolean");
b.Property<bool>("IsOffline")
.HasColumnType("boolean");
b.Property<bool>("IsSectionImageBackground")
.HasColumnType("boolean");
b.Property<bool>("IsTablet")
.HasColumnType("boolean");
b.Property<string>("Label")
.IsRequired()
.HasColumnType("text");
b.PrimitiveCollection<List<string>>("Languages")
.HasColumnType("text[]");
b.Property<string>("LoaderImageId")
.HasColumnType("text");
b.Property<string>("LoaderImageUrl")
.HasColumnType("text");
b.Property<string>("PrimaryColor")
.HasColumnType("text");
b.Property<int?>("RoundedValue")
.HasColumnType("integer");
b.Property<int?>("ScreenPercentageSectionsMainPage")
.HasColumnType("integer");
b.Property<string>("SecondaryColor")
.HasColumnType("text");
b.Property<List<Translation>>("Title")
.IsRequired()
.HasColumnType("jsonb");
b.Property<string>("WeatherCity")
.HasColumnType("text");
b.Property<string>("WeatherResult")
.HasColumnType("text");
b.Property<DateTimeOffset?>("WeatherUpdatedDate")
.HasColumnType("timestamp with time zone");
b.HasKey("Id");
b.ToTable("Configurations");
});
modelBuilder.Entity("ManagerService.Data.Device", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("BatteryLevel")
.HasColumnType("text");
b.Property<string>("Configuration")
.HasColumnType("text");
b.Property<string>("ConfigurationId")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("Connected")
.HasColumnType("boolean");
b.Property<string>("ConnectionLevel")
.HasColumnType("text");
b.Property<DateTime>("DateCreation")
.HasColumnType("timestamp with time zone");
b.Property<DateTime>("DateUpdate")
.HasColumnType("timestamp with time zone");
b.Property<string>("Identifier")
.HasColumnType("text");
b.Property<string>("InstanceId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("IpAddressETH")
.IsRequired()
.HasColumnType("text");
b.Property<string>("IpAddressWLAN")
.IsRequired()
.HasColumnType("text");
b.Property<DateTime>("LastBatteryLevel")
.HasColumnType("timestamp with time zone");
b.Property<DateTime>("LastConnectionLevel")
.HasColumnType("timestamp with time zone");
b.Property<string>("Name")
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Devices");
});
modelBuilder.Entity("ManagerService.Data.Instance", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<DateTime>("DateCreation")
.HasColumnType("timestamp with time zone");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<int?>("PinCode")
.HasColumnType("integer");
b.HasKey("Id");
b.ToTable("Instances");
});
modelBuilder.Entity("ManagerService.Data.Resource", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<DateTime>("DateCreation")
.HasColumnType("timestamp with time zone");
b.Property<string>("InstanceId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Label")
.IsRequired()
.HasColumnType("text");
b.Property<int>("Type")
.HasColumnType("integer");
b.Property<string>("Url")
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Resources");
});
modelBuilder.Entity("ManagerService.Data.Section", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<int?>("BeaconId")
.HasColumnType("integer");
b.Property<string>("ConfigurationId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Data")
.IsRequired()
.HasColumnType("text");
b.Property<DateTime>("DateCreation")
.HasColumnType("timestamp with time zone");
b.Property<List<Translation>>("Description")
.HasColumnType("jsonb");
b.Property<string>("ImageId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("ImageSource")
.IsRequired()
.HasColumnType("text");
b.Property<string>("InstanceId")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("IsBeacon")
.HasColumnType("boolean");
b.Property<bool>("IsSubSection")
.HasColumnType("boolean");
b.Property<string>("Label")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Latitude")
.HasColumnType("text");
b.Property<string>("Longitude")
.HasColumnType("text");
b.Property<int?>("MeterZoneGPS")
.HasColumnType("integer");
b.Property<int>("Order")
.HasColumnType("integer");
b.Property<string>("ParentId")
.HasColumnType("text");
b.Property<List<Translation>>("Title")
.IsRequired()
.HasColumnType("jsonb");
b.Property<int>("Type")
.HasColumnType("integer");
b.HasKey("Id");
b.ToTable("Sections");
});
modelBuilder.Entity("ManagerService.Data.User", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<DateTime>("DateCreation")
.HasColumnType("timestamp with time zone");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("text");
b.Property<string>("FirstName")
.HasColumnType("text");
b.Property<string>("InstanceId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("LastName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Token")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Users");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,174 @@
using System;
using System.Collections.Generic;
using ManagerService.Data;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace ManagerService.Migrations
{
/// <inheritdoc />
public partial class InitialCreate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Configurations",
columns: table => new
{
Id = table.Column<string>(type: "text", nullable: false),
Label = table.Column<string>(type: "text", nullable: false),
Title = table.Column<List<Translation>>(type: "jsonb", nullable: false),
ImageId = table.Column<string>(type: "text", nullable: true),
ImageSource = table.Column<string>(type: "text", nullable: true),
PrimaryColor = table.Column<string>(type: "text", nullable: true),
SecondaryColor = table.Column<string>(type: "text", nullable: true),
Languages = table.Column<List<string>>(type: "text[]", nullable: true),
DateCreation = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
IsMobile = table.Column<bool>(type: "boolean", nullable: false),
IsTablet = table.Column<bool>(type: "boolean", nullable: false),
IsOffline = table.Column<bool>(type: "boolean", nullable: false),
InstanceId = table.Column<string>(type: "text", nullable: false),
LoaderImageId = table.Column<string>(type: "text", nullable: true),
LoaderImageUrl = table.Column<string>(type: "text", nullable: true),
WeatherCity = table.Column<string>(type: "text", nullable: true),
WeatherUpdatedDate = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
WeatherResult = table.Column<string>(type: "text", nullable: true),
IsDate = table.Column<bool>(type: "boolean", nullable: false),
IsHour = table.Column<bool>(type: "boolean", nullable: false),
IsSectionImageBackground = table.Column<bool>(type: "boolean", nullable: false),
RoundedValue = table.Column<int>(type: "integer", nullable: true),
ScreenPercentageSectionsMainPage = table.Column<int>(type: "integer", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Configurations", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Devices",
columns: table => new
{
Id = table.Column<string>(type: "text", nullable: false),
Identifier = table.Column<string>(type: "text", nullable: true),
Name = table.Column<string>(type: "text", nullable: true),
IpAddressWLAN = table.Column<string>(type: "text", nullable: false),
IpAddressETH = table.Column<string>(type: "text", nullable: false),
Configuration = table.Column<string>(type: "text", nullable: true),
ConfigurationId = table.Column<string>(type: "text", nullable: false),
Connected = table.Column<bool>(type: "boolean", nullable: false),
DateCreation = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
DateUpdate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
BatteryLevel = table.Column<string>(type: "text", nullable: true),
LastBatteryLevel = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
ConnectionLevel = table.Column<string>(type: "text", nullable: true),
LastConnectionLevel = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
InstanceId = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Devices", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Instances",
columns: table => new
{
Id = table.Column<string>(type: "text", nullable: false),
Name = table.Column<string>(type: "text", nullable: false),
DateCreation = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
PinCode = table.Column<int>(type: "integer", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Instances", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Resources",
columns: table => new
{
Id = table.Column<string>(type: "text", nullable: false),
Type = table.Column<int>(type: "integer", nullable: false),
Label = table.Column<string>(type: "text", nullable: false),
DateCreation = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
InstanceId = table.Column<string>(type: "text", nullable: false),
Url = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Resources", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Sections",
columns: table => new
{
Id = table.Column<string>(type: "text", nullable: false),
Label = table.Column<string>(type: "text", nullable: false),
Title = table.Column<List<Translation>>(type: "jsonb", nullable: false),
Description = table.Column<List<Translation>>(type: "jsonb", nullable: true),
Order = table.Column<int>(type: "integer", nullable: false),
ConfigurationId = table.Column<string>(type: "text", nullable: false),
ImageId = table.Column<string>(type: "text", nullable: false),
ImageSource = table.Column<string>(type: "text", nullable: false),
Type = table.Column<int>(type: "integer", nullable: false),
IsSubSection = table.Column<bool>(type: "boolean", nullable: false),
ParentId = table.Column<string>(type: "text", nullable: true),
DateCreation = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
Data = table.Column<string>(type: "text", nullable: false),
InstanceId = table.Column<string>(type: "text", nullable: false),
IsBeacon = table.Column<bool>(type: "boolean", nullable: false),
BeaconId = table.Column<int>(type: "integer", nullable: true),
Latitude = table.Column<string>(type: "text", nullable: true),
Longitude = table.Column<string>(type: "text", nullable: true),
MeterZoneGPS = table.Column<int>(type: "integer", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Sections", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Users",
columns: table => new
{
Id = table.Column<string>(type: "text", nullable: false),
Email = table.Column<string>(type: "text", nullable: false),
Password = table.Column<string>(type: "text", nullable: false),
FirstName = table.Column<string>(type: "text", nullable: true),
LastName = table.Column<string>(type: "text", nullable: false),
Token = table.Column<string>(type: "text", nullable: false),
DateCreation = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
InstanceId = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Users", x => x.Id);
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Configurations");
migrationBuilder.DropTable(
name: "Devices");
migrationBuilder.DropTable(
name: "Instances");
migrationBuilder.DropTable(
name: "Resources");
migrationBuilder.DropTable(
name: "Sections");
migrationBuilder.DropTable(
name: "Users");
}
}
}

View File

@ -0,0 +1,317 @@
// <auto-generated />
using System;
using System.Collections.Generic;
using ManagerService.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace ManagerService.Migrations
{
[DbContext(typeof(MyInfoMateDbContext))]
partial class MyInfoMateDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "9.0.2")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("ManagerService.Data.Configuration", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<DateTime>("DateCreation")
.HasColumnType("timestamp with time zone");
b.Property<string>("ImageId")
.HasColumnType("text");
b.Property<string>("ImageSource")
.HasColumnType("text");
b.Property<string>("InstanceId")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("IsDate")
.HasColumnType("boolean");
b.Property<bool>("IsHour")
.HasColumnType("boolean");
b.Property<bool>("IsMobile")
.HasColumnType("boolean");
b.Property<bool>("IsOffline")
.HasColumnType("boolean");
b.Property<bool>("IsSectionImageBackground")
.HasColumnType("boolean");
b.Property<bool>("IsTablet")
.HasColumnType("boolean");
b.Property<string>("Label")
.IsRequired()
.HasColumnType("text");
b.PrimitiveCollection<List<string>>("Languages")
.HasColumnType("text[]");
b.Property<string>("LoaderImageId")
.HasColumnType("text");
b.Property<string>("LoaderImageUrl")
.HasColumnType("text");
b.Property<string>("PrimaryColor")
.HasColumnType("text");
b.Property<int?>("RoundedValue")
.HasColumnType("integer");
b.Property<int?>("ScreenPercentageSectionsMainPage")
.HasColumnType("integer");
b.Property<string>("SecondaryColor")
.HasColumnType("text");
b.Property<List<Translation>>("Title")
.IsRequired()
.HasColumnType("jsonb");
b.Property<string>("WeatherCity")
.HasColumnType("text");
b.Property<string>("WeatherResult")
.HasColumnType("text");
b.Property<DateTimeOffset?>("WeatherUpdatedDate")
.HasColumnType("timestamp with time zone");
b.HasKey("Id");
b.ToTable("Configurations");
});
modelBuilder.Entity("ManagerService.Data.Device", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("BatteryLevel")
.HasColumnType("text");
b.Property<string>("Configuration")
.HasColumnType("text");
b.Property<string>("ConfigurationId")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("Connected")
.HasColumnType("boolean");
b.Property<string>("ConnectionLevel")
.HasColumnType("text");
b.Property<DateTime>("DateCreation")
.HasColumnType("timestamp with time zone");
b.Property<DateTime>("DateUpdate")
.HasColumnType("timestamp with time zone");
b.Property<string>("Identifier")
.HasColumnType("text");
b.Property<string>("InstanceId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("IpAddressETH")
.IsRequired()
.HasColumnType("text");
b.Property<string>("IpAddressWLAN")
.IsRequired()
.HasColumnType("text");
b.Property<DateTime>("LastBatteryLevel")
.HasColumnType("timestamp with time zone");
b.Property<DateTime>("LastConnectionLevel")
.HasColumnType("timestamp with time zone");
b.Property<string>("Name")
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Devices");
});
modelBuilder.Entity("ManagerService.Data.Instance", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<DateTime>("DateCreation")
.HasColumnType("timestamp with time zone");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<int?>("PinCode")
.HasColumnType("integer");
b.HasKey("Id");
b.ToTable("Instances");
});
modelBuilder.Entity("ManagerService.Data.Resource", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<DateTime>("DateCreation")
.HasColumnType("timestamp with time zone");
b.Property<string>("InstanceId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Label")
.IsRequired()
.HasColumnType("text");
b.Property<int>("Type")
.HasColumnType("integer");
b.Property<string>("Url")
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Resources");
});
modelBuilder.Entity("ManagerService.Data.Section", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<int?>("BeaconId")
.HasColumnType("integer");
b.Property<string>("ConfigurationId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Data")
.IsRequired()
.HasColumnType("text");
b.Property<DateTime>("DateCreation")
.HasColumnType("timestamp with time zone");
b.Property<List<Translation>>("Description")
.HasColumnType("jsonb");
b.Property<string>("ImageId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("ImageSource")
.IsRequired()
.HasColumnType("text");
b.Property<string>("InstanceId")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("IsBeacon")
.HasColumnType("boolean");
b.Property<bool>("IsSubSection")
.HasColumnType("boolean");
b.Property<string>("Label")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Latitude")
.HasColumnType("text");
b.Property<string>("Longitude")
.HasColumnType("text");
b.Property<int?>("MeterZoneGPS")
.HasColumnType("integer");
b.Property<int>("Order")
.HasColumnType("integer");
b.Property<string>("ParentId")
.HasColumnType("text");
b.Property<List<Translation>>("Title")
.IsRequired()
.HasColumnType("jsonb");
b.Property<int>("Type")
.HasColumnType("integer");
b.HasKey("Id");
b.ToTable("Sections");
});
modelBuilder.Entity("ManagerService.Data.User", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<DateTime>("DateCreation")
.HasColumnType("timestamp with time zone");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("text");
b.Property<string>("FirstName")
.HasColumnType("text");
b.Property<string>("InstanceId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("LastName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Token")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Users");
});
#pragma warning restore 612, 618
}
}
}

19
ManagerService/Readme.md Normal file
View File

@ -0,0 +1,19 @@
# Migrations
## Invite de commande
Ouvrir un invite de commande dans le répertoire de la solution
## Supprimer la dernière migration
A faire uniquement si elle n'a pas encore été appliquée à la base de données
>dotnet ef migrations remove
# Ajouter une migration
>dotnet ef migrations add <Migration name>
# Mise à jour de la base de données
>dotnet ef database update

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Manager.Interfaces.Models; using Manager.Interfaces.Models;
using ManagerService.Data;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using MongoDB.Driver; using MongoDB.Driver;

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Manager.Interfaces.Models; using Manager.Interfaces.Models;
using ManagerService.Data;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using MongoDB.Driver; using MongoDB.Driver;

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Manager.Interfaces.Models; using Manager.Interfaces.Models;
using ManagerService.Data;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using MongoDB.Driver; using MongoDB.Driver;

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Manager.Interfaces.Models; using Manager.Interfaces.Models;
using ManagerService.Data;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using MongoDB.Driver; using MongoDB.Driver;

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Manager.Interfaces.Models; using Manager.Interfaces.Models;
using ManagerService.Data;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using MongoDB.Driver; using MongoDB.Driver;

View File

@ -1,19 +1,17 @@
using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Security.Claims; using System.Security.Claims;
using System.Text; using System.Text;
using System.Threading.Tasks;
using System.Security.Cryptography; using System.Security.Cryptography;
using Manager.Interfaces.Models; using Manager.Interfaces.Models;
using Microsoft.IdentityModel.Tokens; using Microsoft.IdentityModel.Tokens;
using Manager.Framework.Business;
using Manager.Interfaces.DTO;
using System.IdentityModel.Tokens.Jwt; using System.IdentityModel.Tokens.Jwt;
using Manager.Services; using Manager.Services;
using ManagerService.Helpers;
using ManagerService.DTOs;
using ManagerService.Data;
namespace ManagerService.Service.Services namespace ManagerService.Service.Services
{ {
@ -25,7 +23,8 @@ namespace ManagerService.Service.Services
private readonly ILogger<TokensService> _logger; private readonly ILogger<TokensService> _logger;
private readonly TokensSettings _tokenSettings; private readonly TokensSettings _tokenSettings;
private readonly ProfileLogic _profileLogic; private readonly ProfileLogic _profileLogic;
private InstanceDatabaseService _instanceService; /*private InstanceDatabaseService _instanceService;*/
private readonly MyInfoMateDbContext _myInfoMateDbContext;
private readonly SigningCredentials _signingCredentials; private readonly SigningCredentials _signingCredentials;
@ -37,12 +36,12 @@ namespace ManagerService.Service.Services
/// <param name="context">Database context</param> /// <param name="context">Database context</param>
/// <param name="profileLogic">Profile logic</param> /// <param name="profileLogic">Profile logic</param>
/// <param name="emailClient">Email client</param> /// <param name="emailClient">Email client</param>
public TokensService(ILogger<TokensService> logger, IOptions<TokensSettings> tokenSettings, ProfileLogic profileLogic, InstanceDatabaseService instanceService) public TokensService(ILogger<TokensService> logger, IOptions<TokensSettings> tokenSettings, ProfileLogic profileLogic, MyInfoMateDbContext myInfoMateDbContext)
{ {
_logger = logger; _logger = logger;
_tokenSettings = tokenSettings.Value; _tokenSettings = tokenSettings.Value;
_profileLogic = profileLogic; _profileLogic = profileLogic;
_instanceService = instanceService; _myInfoMateDbContext = myInfoMateDbContext;
var key = Encoding.UTF8.GetBytes(_tokenSettings.Secret); var key = Encoding.UTF8.GetBytes(_tokenSettings.Secret);
_signingCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature); _signingCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature);
@ -76,7 +75,9 @@ namespace ManagerService.Service.Services
}; };
var token = tokenHandler.CreateToken(tokenDescriptor); var token = tokenHandler.CreateToken(tokenDescriptor);
var instance = _instanceService.GetById(user.InstanceId); //var instance = _instanceService.GetById(user.InstanceId);
var instance = _myInfoMateDbContext.Instances.Find(user.InstanceId);
return new TokenDTO() return new TokenDTO()
{ {

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Manager.Interfaces.Models; using Manager.Interfaces.Models;
using ManagerService.Data;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using MongoDB.Driver; using MongoDB.Driver;

View File

@ -1,9 +1,11 @@
using Manager.Framework.Business;
using Manager.Framework.Models; using Manager.Framework.Models;
using Manager.Helpers; using Manager.Helpers;
using Manager.Interfaces;
using Manager.Interfaces.Models; using Manager.Interfaces.Models;
using Manager.Services; using Manager.Services;
using ManagerService.Data;
using ManagerService.Extensions; using ManagerService.Extensions;
using ManagerService.Helpers;
using ManagerService.Service; using ManagerService.Service;
using ManagerService.Service.Services; using ManagerService.Service.Services;
using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Authentication.JwtBearer;
@ -14,6 +16,7 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.HttpsPolicy; using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders; using Microsoft.Extensions.FileProviders;
@ -138,13 +141,18 @@ namespace ManagerService
#endif #endif
services.AddScoped(typeof(ProfileLogic)); services.AddScoped(typeof(ProfileLogic));
services.AddScoped<TokensService>(); services.AddScoped<TokensService>();
services.AddScoped<UserDatabaseService>(); /*services.AddScoped<UserDatabaseService>();
services.AddScoped<SectionDatabaseService>(); services.AddScoped<SectionDatabaseService>();
services.AddScoped<ConfigurationDatabaseService>(); services.AddScoped<ConfigurationDatabaseService>();
services.AddScoped<ResourceDatabaseService>(); services.AddScoped<ResourceDatabaseService>();*/
services.AddScoped<LanguageInit>(); services.AddScoped<LanguageInit>();
services.AddScoped<DeviceDatabaseService>(); /*services.AddScoped<DeviceDatabaseService>();
services.AddScoped<InstanceDatabaseService>(); services.AddScoped<InstanceDatabaseService>();*/
var connectionString = Configuration.GetConnectionString("PostgresConnection");
services.AddDbContext<MyInfoMateDbContext>(options =>
options.UseNpgsql(connectionString));
} }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.

View File

@ -1,4 +1,13 @@
{ {
"ConnectionStrings": {
//"TabletDb": "mongodb://admin:MioTech4ever!@localhost:27017" //DEV
//"TabletDb": "mongodb://admin:MioTech4ever!@localhost:27017", //PROD - Thomas
//"TabletDb": "mongodb://admin:MioTech4ever!@192.168.31.140:27017" //PROD - Thomas
//"TabletDb": "mongodb://admin:mdlf2021!@localhost:27017" //PROD MDLF
"TabletDb": "mongodb://admin:MyMuseum2022!@51.77.222.154:27017", //PROD MyMuseum
//"TabletDb": "mongodb://admin:MyInfoMate2023!@135.125.232.116:27017" //PROD MyInfoMate
"PostgresConnection": "Host=localhost;Database=my_info_mate;Username=mym;Password=mym"
},
"Logging": { "Logging": {
"LogLevel": { "LogLevel": {
"Default": "Information", "Default": "Information",

View File

@ -1,12 +1,13 @@
{ {
"ConnectionStrings": { /*"ConnectionStrings": {
//"TabletDb": "mongodb://admin:MioTech4ever!@localhost:27017" //DEV //"TabletDb": "mongodb://admin:MioTech4ever!@localhost:27017" //DEV
//"TabletDb": "mongodb://admin:MioTech4ever!@localhost:27017", //PROD - Thomas //"TabletDb": "mongodb://admin:MioTech4ever!@localhost:27017", //PROD - Thomas
//"TabletDb": "mongodb://admin:MioTech4ever!@192.168.31.140:27017" //PROD - Thomas //"TabletDb": "mongodb://admin:MioTech4ever!@192.168.31.140:27017" //PROD - Thomas
//"TabletDb": "mongodb://admin:mdlf2021!@localhost:27017" //PROD MDLF //"TabletDb": "mongodb://admin:mdlf2021!@localhost:27017" //PROD MDLF
//"TabletDb": "mongodb://admin:MyMuseum2022!@51.77.222.154:27017", //PROD MyMuseum "TabletDb": "mongodb://admin:MyMuseum2022!@51.77.222.154:27017", //PROD MyMuseum
"TabletDb": "mongodb://admin:MyInfoMate2023!@135.125.232.116:27017" //PROD MyInfoMate //"TabletDb": "mongodb://admin:MyInfoMate2023!@135.125.232.116:27017" //PROD MyInfoMate
}, "PostgresConnection": "Host=localhost;Database=my_info_mate;Username=mym;Password=mym"
},*/
"Logging": { "Logging": {
"LogLevel": { "LogLevel": {
"Default": "Information", "Default": "Information",