diff --git a/Manager.Framework/Manager.Framework.csproj b/Manager.Framework/Manager.Framework.csproj index 423dca0..f28511c 100644 --- a/Manager.Framework/Manager.Framework.csproj +++ b/Manager.Framework/Manager.Framework.csproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 @@ -9,4 +9,10 @@ + + + + + + diff --git a/Manager.Interfaces/DTO/TranslationDTO.cs b/Manager.Interfaces/DTO/TranslationDTO.cs deleted file mode 100644 index e30cef7..0000000 --- a/Manager.Interfaces/DTO/TranslationDTO.cs +++ /dev/null @@ -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; } - } -} diff --git a/Manager.Interfaces/Manager.Data.csproj b/Manager.Interfaces/Manager.Data.csproj new file mode 100644 index 0000000..bef0c91 --- /dev/null +++ b/Manager.Interfaces/Manager.Data.csproj @@ -0,0 +1,17 @@ + + + + net8.0 + + + + + + + + + + + + + diff --git a/Manager.Interfaces/Manager.Interfaces.csproj b/Manager.Interfaces/Manager.Interfaces.csproj deleted file mode 100644 index f53c8b1..0000000 --- a/Manager.Interfaces/Manager.Interfaces.csproj +++ /dev/null @@ -1,11 +0,0 @@ - - - - net6.0 - - - - - - - diff --git a/ManagerService.sln b/ManagerService.sln index 421c103..d65c6f7 100644 --- a/ManagerService.sln +++ b/ManagerService.sln @@ -1,14 +1,10 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.30907.101 +# Visual Studio Version 17 +VisualStudioVersion = 17.12.35527.113 d17.12 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ManagerService", "ManagerService\ManagerService.csproj", "{042E0BC4-8DCF-4EEC-8420-C71AA85D4D99}" 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 GlobalSection(SolutionConfigurationPlatforms) = preSolution 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}.Release|Any CPU.ActiveCfg = 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 GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/ManagerService/Controllers/AuthenticationController.cs b/ManagerService/Controllers/AuthenticationController.cs index 775601d..302ea69 100644 --- a/ManagerService/Controllers/AuthenticationController.cs +++ b/ManagerService/Controllers/AuthenticationController.cs @@ -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 Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; -using Microsoft.Net.Http.Headers; using Mqtt.Client.AspNetCore.Services; using NSwag.Annotations; using System; using System.Collections.Generic; -using System.Linq; using System.Net; -using System.Threading.Tasks; +using System.Linq; namespace ManagerService.Service.Controllers { @@ -26,17 +24,20 @@ namespace ManagerService.Service.Controllers { private readonly ILogger _logger; private readonly TokensService _tokensService; - private readonly UserDatabaseService _UserDatabaseService; + /*private readonly UserDatabaseService _UserDatabaseService; private readonly DeviceDatabaseService _DeviceDatabaseService; - private readonly ConfigurationDatabaseService _ConfigurationDatabaseService; + private readonly ConfigurationDatabaseService _ConfigurationDatabaseService;*/ + private readonly MyInfoMateDbContext _myInfoMateDbContext; - public AuthenticationController(ILogger logger, TokensService tokensService, UserDatabaseService UserDatabaseService, DeviceDatabaseService DeviceDatabaseService, ConfigurationDatabaseService ConfigurationDatabaseService) + + public AuthenticationController(ILogger logger, TokensService tokensService, MyInfoMateDbContext myInfoMateDbContext/*UserDatabaseService UserDatabaseService, DeviceDatabaseService DeviceDatabaseService, ConfigurationDatabaseService ConfigurationDatabaseService*/) { _logger = logger; _tokensService = tokensService; - _UserDatabaseService = UserDatabaseService; - _DeviceDatabaseService = DeviceDatabaseService; - _ConfigurationDatabaseService = ConfigurationDatabaseService; + _myInfoMateDbContext = myInfoMateDbContext; + //_UserDatabaseService = UserDatabaseService; + //_DeviceDatabaseService = DeviceDatabaseService; + //_ConfigurationDatabaseService = ConfigurationDatabaseService; } /// @@ -54,14 +55,15 @@ namespace ManagerService.Service.Controllers password = "kljqsdkljqsd"; // password = "kljqsdkljqsd"; // W/7aj4NB60i3YFKJq50pbw== #endif // 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) throw new KeyNotFoundException("User not found"); var token = _tokensService.Authenticate(user, password); - MqttClientService.SetServices(_DeviceDatabaseService, _ConfigurationDatabaseService); + MqttClientService.SetServices(_myInfoMateDbContext);//_DeviceDatabaseService, _ConfigurationDatabaseService); return new OkObjectResult(token); } diff --git a/ManagerService/Controllers/ConfigurationController.cs b/ManagerService/Controllers/ConfigurationController.cs index 1fdb205..46b6621 100644 --- a/ManagerService/Controllers/ConfigurationController.cs +++ b/ManagerService/Controllers/ConfigurationController.cs @@ -4,13 +4,13 @@ using System.Linq; using System.Net.Http; using System.Text; using System.Threading.Tasks; +using Manager.DTOs; using Manager.Helpers; -using Manager.Interfaces.DTO; using Manager.Interfaces.Models; using Manager.Services; -using ManagerService.Service.Services; +using ManagerService.Data; +using ManagerService.DTOs; using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.DataProtection.KeyManagement; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; @@ -25,23 +25,21 @@ namespace ManagerService.Controllers [OpenApiTag("Configuration", Description = "Configuration management")] public class ConfigurationController : ControllerBase { - private ConfigurationDatabaseService _configurationService; + private readonly MyInfoMateDbContext _myInfoMateDbContext; + + /*private ConfigurationDatabaseService _configurationService; private InstanceDatabaseService _instanceService; private SectionDatabaseService _sectionService; private ResourceDatabaseService _resourceService; - private DeviceDatabaseService _deviceService; + private DeviceDatabaseService _deviceService;*/ private readonly ILogger _logger; private readonly IConfiguration _configuration; - public ConfigurationController(IConfiguration configuration, ILogger logger, ConfigurationDatabaseService configurationService, InstanceDatabaseService instanceService, SectionDatabaseService sectionService, ResourceDatabaseService resourceService, DeviceDatabaseService deviceService) + public ConfigurationController(IConfiguration configuration, ILogger logger, MyInfoMateDbContext myInfoMateDbContext) { _logger = logger; _configuration = configuration; - _configurationService = configurationService; - _instanceService = instanceService; - _sectionService = sectionService; - _resourceService = resourceService; - _deviceService = deviceService; + _myInfoMateDbContext = myInfoMateDbContext; } /// @@ -56,13 +54,13 @@ namespace ManagerService.Controllers { try { - List configurations = _configurationService.GetAll(instanceId); + List configurations = _myInfoMateDbContext.Configurations.Where(c => c.InstanceId == instanceId).ToList(); List configurationDTOs = new List(); foreach(var configuration in configurations) { - List sectionIds = _sectionService.GetAllIdsFromConfiguration(configuration.Id); + List sectionIds = _myInfoMateDbContext.Sections.Where(c => c.ConfigurationId == configuration.Id).Select(c => c.Id).ToList(); ConfigurationDTO configurationDTO = configuration.ToDTO(sectionIds); configurationDTOs.Add(configurationDTO); } @@ -225,7 +223,7 @@ namespace ManagerService.Controllers Configuration configuration = new Configuration(); configuration.InstanceId = newConfiguration.instanceId; configuration.Label = newConfiguration.label; - configuration.Title = new List(); + configuration.Title = new List(); configuration.ImageId = newConfiguration.imageId; configuration.ImageSource = newConfiguration.imageSource; configuration.PrimaryColor = newConfiguration.primaryColor; @@ -294,7 +292,7 @@ namespace ManagerService.Controllers // Todo add some verification ? configuration.InstanceId = updatedConfiguration.instanceId; 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.ImageSource = updatedConfiguration.imageSource; configuration.PrimaryColor = updatedConfiguration.primaryColor; @@ -644,7 +642,7 @@ namespace ManagerService.Controllers configuration.Id = exportConfiguration.id; configuration.InstanceId = exportConfiguration.instanceId; 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.ImageSource = exportConfiguration.imageSource; @@ -683,8 +681,8 @@ namespace ManagerService.Controllers newSection.Id = section.id; newSection.InstanceId = section.instanceId; newSection.Label = section.label; - newSection.Title = section.title; - newSection.Description = section.description; + newSection.Title = section.title.Select(t => new Translation().FromDTO(t)).ToList(); // TODO TEST + 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.Type = section.type; newSection.ImageId = section.imageId; diff --git a/ManagerService/Controllers/DeviceController.cs b/ManagerService/Controllers/DeviceController.cs index 4598aa2..1755a62 100644 --- a/ManagerService/Controllers/DeviceController.cs +++ b/ManagerService/Controllers/DeviceController.cs @@ -1,14 +1,9 @@ using System; using System.Collections.Generic; -using System.Drawing; -using System.Drawing.Imaging; -using System.IO; using System.Linq; -using System.Threading.Tasks; -using Manager.Interfaces.DTO; -using Manager.Interfaces.Models; using Manager.Services; -using ManagerService.Service.Services; +using ManagerService.Data; +using ManagerService.DTOs; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; diff --git a/ManagerService/Controllers/InstanceController.cs b/ManagerService/Controllers/InstanceController.cs index 6b0573e..4a3859c 100644 --- a/ManagerService/Controllers/InstanceController.cs +++ b/ManagerService/Controllers/InstanceController.cs @@ -1,12 +1,10 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Threading.Tasks; -using Manager.Framework.Business; -using Manager.Interfaces.DTO; -using Manager.Interfaces.Models; using Manager.Services; -using ManagerService.Service.Services; +using ManagerService.Data; +using ManagerService.DTOs; +using ManagerService.Helpers; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; diff --git a/ManagerService/Controllers/ResourceController.cs b/ManagerService/Controllers/ResourceController.cs index d0f386f..0d2ed46 100644 --- a/ManagerService/Controllers/ResourceController.cs +++ b/ManagerService/Controllers/ResourceController.cs @@ -1,25 +1,17 @@ using System; using System.Collections.Generic; -using System.Drawing; -using System.Drawing.Imaging; using System.IO; using System.Linq; -using System.Net.Http.Headers; -using System.Text; -using System.Text.RegularExpressions; -using System.Threading.Tasks; -using Manager.Interfaces.DTO; -using Manager.Interfaces.Models; +using Manager.DTOs; using Manager.Services; +using ManagerService.Data; +using ManagerService.DTOs; using ManagerService.Helpers; -using ManagerService.Service.Services; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Server.IIS.Core; using Microsoft.Extensions.Logging; using Newtonsoft.Json; using NSwag.Annotations; -using static System.Net.Mime.MediaTypeNames; namespace ManagerService.Controllers { diff --git a/ManagerService/Controllers/SectionController.cs b/ManagerService/Controllers/SectionController.cs index 4ab7baa..9257beb 100644 --- a/ManagerService/Controllers/SectionController.cs +++ b/ManagerService/Controllers/SectionController.cs @@ -1,7 +1,8 @@ -using Manager.Helpers; -using Manager.Interfaces.DTO; -using Manager.Interfaces.Models; +using Manager.DTOs; +using Manager.Helpers; using Manager.Services; +using ManagerService.Data; +using ManagerService.DTOs; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; @@ -292,8 +293,8 @@ namespace ManagerService.Controllers section.IsSubSection = newSection.isSubSection; section.ParentId = newSection.parentId; section.Type = newSection.type; - section.Title = new List(); - section.Description = new List(); + section.Title = new List(); + section.Description = new List(); section.Order = _sectionService.GetAllFromConfiguration(newSection.configurationId).Count; section.IsBeacon = newSection.isBeacon; section.BeaconId = newSection.beaconId; @@ -304,7 +305,7 @@ namespace ManagerService.Controllers // Preparation List languages = _configuration.GetSection("SupportedLanguages").Get>(); - var contentArticle = new List(); + var contentArticle = new List(); var mapDTO = new MapDTO(); // For menu dto var sliderDTO = new SliderDTO(); // For menu dto @@ -349,8 +350,8 @@ namespace ManagerService.Controllers contentArticle.Add(content); }*/ - section.Title = section.Title.OrderBy(t => t.language).ToList(); - section.Description = section.Description.OrderBy(d => d.language).ToList(); + section.Title = section.Title.OrderBy(t => t.Language).ToList(); + section.Description = section.Description.OrderBy(d => d.Language).ToList(); switch (newSection.type) { case SectionType.Map: @@ -418,8 +419,8 @@ namespace ManagerService.Controllers case SectionType.Article: ArticleDTO articleDTO = new ArticleDTO(); articleDTO.contents = new List(); - articleDTO.content = contentArticle; - articleDTO.audioIds = LanguageInit.Init("Audio", languages, true); + articleDTO.content = contentArticle.Select(c => c.ToDTO()).ToList(); // TODO check + 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 break; @@ -535,8 +536,8 @@ namespace ManagerService.Controllers // Todo add some verification ? section.InstanceId = updatedSection.instanceId; section.Label = updatedSection.label; - section.Title = updatedSection.title; - section.Description = updatedSection.description; + section.Title = updatedSection.title.Select(t => new Translation().FromDTO(t)).ToList(); // TODO CHECK + section.Description = updatedSection.description.Select(t => new Translation().FromDTO(t)).ToList();// TODO CHECK section.Type = updatedSection.type; section.ImageId = updatedSection.imageId; section.ImageSource = updatedSection.imageSource; diff --git a/ManagerService/Controllers/UserController.cs b/ManagerService/Controllers/UserController.cs index 8e868ca..d4d9294 100644 --- a/ManagerService/Controllers/UserController.cs +++ b/ManagerService/Controllers/UserController.cs @@ -1,11 +1,10 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Threading.Tasks; -using Manager.Framework.Business; -using Manager.Interfaces.DTO; -using Manager.Interfaces.Models; using Manager.Services; +using ManagerService.Data; +using ManagerService.DTOs; +using ManagerService.Helpers; using ManagerService.Service.Services; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; diff --git a/Manager.Interfaces/Models/CityData.cs b/ManagerService/DTOs/CityData.cs similarity index 100% rename from Manager.Interfaces/Models/CityData.cs rename to ManagerService/DTOs/CityData.cs diff --git a/Manager.Interfaces/DTO/ConfigurationDTO.cs b/ManagerService/DTOs/ConfigurationDTO.cs similarity index 96% rename from Manager.Interfaces/DTO/ConfigurationDTO.cs rename to ManagerService/DTOs/ConfigurationDTO.cs index d2110a7..72c52b6 100644 --- a/Manager.Interfaces/DTO/ConfigurationDTO.cs +++ b/ManagerService/DTOs/ConfigurationDTO.cs @@ -1,9 +1,7 @@ using System; using System.Collections.Generic; -using System.Text; -using System.Xml.Linq; -namespace Manager.Interfaces.DTO +namespace ManagerService.DTOs { public class ConfigurationDTO { diff --git a/Manager.Interfaces/DTO/DeviceDTO.cs b/ManagerService/DTOs/DeviceDTO.cs similarity index 90% rename from Manager.Interfaces/DTO/DeviceDTO.cs rename to ManagerService/DTOs/DeviceDTO.cs index 0d991fa..a8a15f2 100644 --- a/Manager.Interfaces/DTO/DeviceDTO.cs +++ b/ManagerService/DTOs/DeviceDTO.cs @@ -1,8 +1,6 @@ using System; -using System.Collections.Generic; -using System.Text; -namespace Manager.Interfaces.DTO +namespace ManagerService.DTOs { public class DeviceDTO { diff --git a/Manager.Interfaces/DTO/ExportConfigurationDTO.cs b/ManagerService/DTOs/ExportConfigurationDTO.cs similarity index 69% rename from Manager.Interfaces/DTO/ExportConfigurationDTO.cs rename to ManagerService/DTOs/ExportConfigurationDTO.cs index 0f38b93..29cb62f 100644 --- a/Manager.Interfaces/DTO/ExportConfigurationDTO.cs +++ b/ManagerService/DTOs/ExportConfigurationDTO.cs @@ -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 { diff --git a/Manager.Interfaces/DTO/InstanceDTO.cs b/ManagerService/DTOs/InstanceDTO.cs similarity index 73% rename from Manager.Interfaces/DTO/InstanceDTO.cs rename to ManagerService/DTOs/InstanceDTO.cs index f600012..ba0a837 100644 --- a/Manager.Interfaces/DTO/InstanceDTO.cs +++ b/ManagerService/DTOs/InstanceDTO.cs @@ -1,8 +1,6 @@ using System; -using System.Collections.Generic; -using System.Text; -namespace Manager.Interfaces.DTO +namespace ManagerService.DTOs { public class InstanceDTO { diff --git a/Manager.Interfaces/DTO/LoginDTO.cs b/ManagerService/DTOs/LoginDTO.cs similarity index 79% rename from Manager.Interfaces/DTO/LoginDTO.cs rename to ManagerService/DTOs/LoginDTO.cs index bda6d0f..d47503d 100644 --- a/Manager.Interfaces/DTO/LoginDTO.cs +++ b/ManagerService/DTOs/LoginDTO.cs @@ -1,4 +1,4 @@ -namespace Manager.Interfaces.DTO +namespace ManagerService.DTOs { public class LoginDTO { diff --git a/Manager.Interfaces/DTO/PlayerMessageDTO.cs b/ManagerService/DTOs/PlayerMessageDTO.cs similarity index 57% rename from Manager.Interfaces/DTO/PlayerMessageDTO.cs rename to ManagerService/DTOs/PlayerMessageDTO.cs index 7ac6be5..6a5d2e4 100644 --- a/Manager.Interfaces/DTO/PlayerMessageDTO.cs +++ b/ManagerService/DTOs/PlayerMessageDTO.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Manager.Interfaces.Models +namespace ManagerService.DTOs { public class PlayerMessageDTO { diff --git a/Manager.Interfaces/Models/Policy.cs b/ManagerService/DTOs/Policy.cs similarity index 100% rename from Manager.Interfaces/Models/Policy.cs rename to ManagerService/DTOs/Policy.cs diff --git a/Manager.Interfaces/DTO/ResourceDTO.cs b/ManagerService/DTOs/ResourceDTO.cs similarity index 73% rename from Manager.Interfaces/DTO/ResourceDTO.cs rename to ManagerService/DTOs/ResourceDTO.cs index 156c932..8a4822f 100644 --- a/Manager.Interfaces/DTO/ResourceDTO.cs +++ b/ManagerService/DTOs/ResourceDTO.cs @@ -1,9 +1,7 @@ -using Manager.Interfaces.Models; +using ManagerService.Data; using System; -using System.Collections.Generic; -using System.Text; -namespace Manager.Interfaces.DTO +namespace ManagerService.DTOs { public class ResourceDTO { diff --git a/Manager.Interfaces/DTO/SectionDTO.cs b/ManagerService/DTOs/SectionDTO.cs similarity index 94% rename from Manager.Interfaces/DTO/SectionDTO.cs rename to ManagerService/DTOs/SectionDTO.cs index 096c828..c30a840 100644 --- a/Manager.Interfaces/DTO/SectionDTO.cs +++ b/ManagerService/DTOs/SectionDTO.cs @@ -1,9 +1,8 @@ -using Manager.Interfaces.Models; +using ManagerService.Data; using System; using System.Collections.Generic; -using System.Text; -namespace Manager.Interfaces.DTO +namespace ManagerService.DTOs { public class SectionDTO { diff --git a/Manager.Interfaces/DTO/SubSection/AgendaDTO.cs b/ManagerService/DTOs/SubSection/AgendaDTO.cs similarity index 78% rename from Manager.Interfaces/DTO/SubSection/AgendaDTO.cs rename to ManagerService/DTOs/SubSection/AgendaDTO.cs index 0630b3b..7c4f4b1 100644 --- a/Manager.Interfaces/DTO/SubSection/AgendaDTO.cs +++ b/ManagerService/DTOs/SubSection/AgendaDTO.cs @@ -1,8 +1,7 @@ -using System; +using ManagerService.DTOs; using System.Collections.Generic; -using System.Text; -namespace Manager.Interfaces.DTO +namespace Manager.DTOs { public class AgendaDTO { diff --git a/Manager.Interfaces/DTO/SubSection/ArticleDTO.cs b/ManagerService/DTOs/SubSection/ArticleDTO.cs similarity index 82% rename from Manager.Interfaces/DTO/SubSection/ArticleDTO.cs rename to ManagerService/DTOs/SubSection/ArticleDTO.cs index aefa629..3cab760 100644 --- a/Manager.Interfaces/DTO/SubSection/ArticleDTO.cs +++ b/ManagerService/DTOs/SubSection/ArticleDTO.cs @@ -1,9 +1,7 @@ -using Manager.Interfaces.Models; -using System; +using ManagerService.DTOs; using System.Collections.Generic; -using System.Text; -namespace Manager.Interfaces.DTO +namespace Manager.DTOs { public class ArticleDTO { diff --git a/Manager.Interfaces/DTO/SubSection/MapDTO.cs b/ManagerService/DTOs/SubSection/MapDTO.cs similarity index 97% rename from Manager.Interfaces/DTO/SubSection/MapDTO.cs rename to ManagerService/DTOs/SubSection/MapDTO.cs index 97616d0..9e28361 100644 --- a/Manager.Interfaces/DTO/SubSection/MapDTO.cs +++ b/ManagerService/DTOs/SubSection/MapDTO.cs @@ -1,9 +1,9 @@ using Manager.Interfaces.Models; -using System; +using ManagerService.Data; +using ManagerService.DTOs; using System.Collections.Generic; -using System.Text; -namespace Manager.Interfaces.DTO +namespace Manager.DTOs { public class MapDTO { diff --git a/Manager.Interfaces/DTO/SubSection/MenuDTO.cs b/ManagerService/DTOs/SubSection/MenuDTO.cs similarity index 76% rename from Manager.Interfaces/DTO/SubSection/MenuDTO.cs rename to ManagerService/DTOs/SubSection/MenuDTO.cs index 2d8ac20..3fd9bce 100644 --- a/Manager.Interfaces/DTO/SubSection/MenuDTO.cs +++ b/ManagerService/DTOs/SubSection/MenuDTO.cs @@ -1,8 +1,7 @@ -using System; +using ManagerService.DTOs; using System.Collections.Generic; -using System.Text; -namespace Manager.Interfaces.DTO +namespace Manager.DTOs { public class MenuDTO { diff --git a/Manager.Interfaces/DTO/SubSection/PdfDTO.cs b/ManagerService/DTOs/SubSection/PdfDTO.cs similarity index 81% rename from Manager.Interfaces/DTO/SubSection/PdfDTO.cs rename to ManagerService/DTOs/SubSection/PdfDTO.cs index fa3ea3f..7682e1a 100644 --- a/Manager.Interfaces/DTO/SubSection/PdfDTO.cs +++ b/ManagerService/DTOs/SubSection/PdfDTO.cs @@ -1,8 +1,7 @@ -using System; +using ManagerService.DTOs; using System.Collections.Generic; -using System.Text; -namespace Manager.Interfaces.DTO +namespace Manager.DTOs { public class PdfDTO { diff --git a/Manager.Interfaces/DTO/SubSection/PuzzleDTO.cs b/ManagerService/DTOs/SubSection/PuzzleDTO.cs similarity index 79% rename from Manager.Interfaces/DTO/SubSection/PuzzleDTO.cs rename to ManagerService/DTOs/SubSection/PuzzleDTO.cs index a70bdb6..02f1b3e 100644 --- a/Manager.Interfaces/DTO/SubSection/PuzzleDTO.cs +++ b/ManagerService/DTOs/SubSection/PuzzleDTO.cs @@ -1,9 +1,7 @@ -using Manager.Interfaces.Models; -using System; +using ManagerService.DTOs; using System.Collections.Generic; -using System.Text; -namespace Manager.Interfaces.DTO +namespace Manager.DTOs { public class PuzzleDTO { diff --git a/Manager.Interfaces/DTO/SubSection/QuizzDTO.cs b/ManagerService/DTOs/SubSection/QuizzDTO.cs similarity index 94% rename from Manager.Interfaces/DTO/SubSection/QuizzDTO.cs rename to ManagerService/DTOs/SubSection/QuizzDTO.cs index 2d80035..6ec4098 100644 --- a/Manager.Interfaces/DTO/SubSection/QuizzDTO.cs +++ b/ManagerService/DTOs/SubSection/QuizzDTO.cs @@ -1,9 +1,8 @@ -using System; +using ManagerService.DTOs; using System.Collections.Generic; using System.Security.AccessControl; -using System.Text; -namespace Manager.Interfaces.DTO +namespace Manager.DTOs { public class QuizzDTO { diff --git a/Manager.Interfaces/DTO/SubSection/SliderDTO.cs b/ManagerService/DTOs/SubSection/SliderDTO.cs similarity index 84% rename from Manager.Interfaces/DTO/SubSection/SliderDTO.cs rename to ManagerService/DTOs/SubSection/SliderDTO.cs index db3121b..e89e73b 100644 --- a/Manager.Interfaces/DTO/SubSection/SliderDTO.cs +++ b/ManagerService/DTOs/SubSection/SliderDTO.cs @@ -1,9 +1,8 @@ -using Manager.Interfaces.Models; -using System; +using ManagerService.Data; +using ManagerService.DTOs; using System.Collections.Generic; -using System.Text; -namespace Manager.Interfaces.DTO +namespace Manager.DTOs { public class SliderDTO { diff --git a/Manager.Interfaces/DTO/SubSection/VideoDTO.cs b/ManagerService/DTOs/SubSection/VideoDTO.cs similarity index 68% rename from Manager.Interfaces/DTO/SubSection/VideoDTO.cs rename to ManagerService/DTOs/SubSection/VideoDTO.cs index dfd18b2..62967fd 100644 --- a/Manager.Interfaces/DTO/SubSection/VideoDTO.cs +++ b/ManagerService/DTOs/SubSection/VideoDTO.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Manager.Interfaces.DTO +namespace Manager.DTOs { public class VideoDTO { diff --git a/Manager.Interfaces/DTO/SubSection/WeatherDTO.cs b/ManagerService/DTOs/SubSection/WeatherDTO.cs similarity index 76% rename from Manager.Interfaces/DTO/SubSection/WeatherDTO.cs rename to ManagerService/DTOs/SubSection/WeatherDTO.cs index f70b872..f3ca561 100644 --- a/Manager.Interfaces/DTO/SubSection/WeatherDTO.cs +++ b/ManagerService/DTOs/SubSection/WeatherDTO.cs @@ -1,8 +1,6 @@ using System; -using System.Collections.Generic; -using System.Text; -namespace Manager.Interfaces.DTO +namespace Manager.DTOs { public class WeatherDTO { diff --git a/Manager.Interfaces/DTO/SubSection/WebDTO.cs b/ManagerService/DTOs/SubSection/WebDTO.cs similarity index 68% rename from Manager.Interfaces/DTO/SubSection/WebDTO.cs rename to ManagerService/DTOs/SubSection/WebDTO.cs index f458ecf..4b042ab 100644 --- a/Manager.Interfaces/DTO/SubSection/WebDTO.cs +++ b/ManagerService/DTOs/SubSection/WebDTO.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Manager.Interfaces.DTO +namespace Manager.DTOs { public class WebDTO { diff --git a/Manager.Interfaces/DTO/SwaggerTokenRequest.cs b/ManagerService/DTOs/SwaggerTokenRequest.cs similarity index 91% rename from Manager.Interfaces/DTO/SwaggerTokenRequest.cs rename to ManagerService/DTOs/SwaggerTokenRequest.cs index 8873a9f..aec79e3 100644 --- a/Manager.Interfaces/DTO/SwaggerTokenRequest.cs +++ b/ManagerService/DTOs/SwaggerTokenRequest.cs @@ -1,4 +1,4 @@ -namespace Manager.Interfaces.DTO +namespace ManagerService.DTOs { /// /// Swagger test client authentication data diff --git a/Manager.Interfaces/DTO/TokenDTO.cs b/ManagerService/DTOs/TokenDTO.cs similarity index 92% rename from Manager.Interfaces/DTO/TokenDTO.cs rename to ManagerService/DTOs/TokenDTO.cs index 63bbe2f..2eb3ea2 100644 --- a/Manager.Interfaces/DTO/TokenDTO.cs +++ b/ManagerService/DTOs/TokenDTO.cs @@ -1,6 +1,6 @@ using System; -namespace Manager.Interfaces.DTO +namespace ManagerService.DTOs { public class TokenDTO { diff --git a/Manager.Interfaces/DTO/TranslationAndResourceDTO.cs b/ManagerService/DTOs/TranslationAndResourceDTO.cs similarity index 73% rename from Manager.Interfaces/DTO/TranslationAndResourceDTO.cs rename to ManagerService/DTOs/TranslationAndResourceDTO.cs index 95e59e5..a50b7bc 100644 --- a/Manager.Interfaces/DTO/TranslationAndResourceDTO.cs +++ b/ManagerService/DTOs/TranslationAndResourceDTO.cs @@ -1,9 +1,7 @@ -using Manager.Interfaces.Models; -using System; -using System.Collections.Generic; -using System.Text; + +using ManagerService.Data; -namespace Manager.Interfaces.DTO +namespace ManagerService.DTOs { public class TranslationAndResourceDTO { diff --git a/ManagerService/DTOs/TranslationDTO.cs b/ManagerService/DTOs/TranslationDTO.cs new file mode 100644 index 0000000..3bc5e58 --- /dev/null +++ b/ManagerService/DTOs/TranslationDTO.cs @@ -0,0 +1,8 @@ +namespace ManagerService.DTOs +{ + public class TranslationDTO + { + public string language { get; set; } + public string value { get; set; } + } +} diff --git a/Manager.Interfaces/DTO/UserDetailDTO.cs b/ManagerService/DTOs/UserDetailDTO.cs similarity index 67% rename from Manager.Interfaces/DTO/UserDetailDTO.cs rename to ManagerService/DTOs/UserDetailDTO.cs index e9d0a5e..44cf1a6 100644 --- a/Manager.Interfaces/DTO/UserDetailDTO.cs +++ b/ManagerService/DTOs/UserDetailDTO.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Manager.Interfaces.DTO +namespace ManagerService.DTOs { public class UserDetailDTO { diff --git a/Manager.Interfaces/Models/Configuration.cs b/ManagerService/Data/Configuration.cs similarity index 71% rename from Manager.Interfaces/Models/Configuration.cs rename to ManagerService/Data/Configuration.cs index 774fb96..87abbfb 100644 --- a/Manager.Interfaces/Models/Configuration.cs +++ b/ManagerService/Data/Configuration.cs @@ -1,88 +1,96 @@ -using Manager.Interfaces.DTO; +using ManagerService.DTOs; using MongoDB.Bson.Serialization.Attributes; using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text; -namespace Manager.Interfaces.Models +namespace ManagerService.Data { /// /// Configuration Information /// public class Configuration { - [BsonId] - [BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)] + [Key] + [Required] + /*[BsonId] + [BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)]*/ public string Id { get; set; } - [BsonElement("Label")] - [BsonRequired] + /*[BsonElement("Label")] + [BsonRequired]*/ + [Required] public string Label { get; set; } - [BsonElement("Title")] - [BsonRequired] - public List Title { get; set; } + /*[BsonElement("Title")] + [BsonRequired]*/ + [Required] + [Column(TypeName = "jsonb")] + public List Title { get; set; } - [BsonElement("ImageId")] + /*[BsonElement("ImageId")]*/ public string ImageId { get; set; } - [BsonElement("ImageSource")] + /*[BsonElement("ImageSource")]*/ public string ImageSource { get; set; } - [BsonElement("PrimaryColor")] + /*[BsonElement("PrimaryColor")]*/ public string PrimaryColor { get; set; } - [BsonElement("SecondaryColor")] + /*[BsonElement("SecondaryColor")]*/ public string SecondaryColor { get; set; } - [BsonElement("Languages")] + /*[BsonElement("Languages")]*/ public List 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; } - [BsonElement("IsMobile")] + /*[BsonElement("IsMobile")]*/ public bool IsMobile { get; set; } - [BsonElement("IsTablet")] + /*[BsonElement("IsTablet")]*/ public bool IsTablet { get; set; } - [BsonElement("IsOffline")] + /*[BsonElement("IsOffline")]*/ public bool IsOffline { get; set; } - [BsonElement("InstanceId")] - [BsonRequired] + /*[BsonElement("InstanceId")] + [BsonRequired]*/ + [Required] public string InstanceId { get; set; } - [BsonElement("LoaderImageId")] + /*[BsonElement("LoaderImageId")]*/ public string LoaderImageId { get; set; } - [BsonElement("LoaderImageUrl")] + /*[BsonElement("LoaderImageUrl")]*/ public string LoaderImageUrl { get; set; } - [BsonElement("WeatherCity")] + /*[BsonElement("WeatherCity")]*/ public string WeatherCity { get; set; } - [BsonElement("WeatherUpdatedDate")] + /*[BsonElement("WeatherUpdatedDate")]*/ public DateTimeOffset? WeatherUpdatedDate { get; set; } - [BsonElement("WeatherResult")] + /*[BsonElement("WeatherResult")]*/ public string WeatherResult { get; set; } - [BsonElement("IsDate")] + /*[BsonElement("IsDate")]*/ public bool IsDate { get; set; } - [BsonElement("IsHour")] + /*[BsonElement("IsHour")]*/ public bool IsHour { get; set; } - [BsonElement("IsSectionImageBackground")] + /*[BsonElement("IsSectionImageBackground")]*/ public bool IsSectionImageBackground { get; set; } - [BsonElement("RoundedValue")] + /*[BsonElement("RoundedValue")]*/ public int? RoundedValue { get; set; } - [BsonElement("ScreenPercentageSectionsMainPage")] + /*[BsonElement("ScreenPercentageSectionsMainPage")]*/ public int? ScreenPercentageSectionsMainPage { get; set; } public ConfigurationDTO ToDTO(List sectionIds) @@ -91,7 +99,7 @@ namespace Manager.Interfaces.Models { id = Id, label = Label, - title = Title, + title = Title.Select(c => c.ToDTO()).ToList(), imageId = ImageId, imageSource = ImageSource, loaderImageId = LoaderImageId, @@ -121,7 +129,7 @@ namespace Manager.Interfaces.Models { id = Id, label = Label, - title= Title, + title= Title.Select(c => c.ToDTO()).ToList(), imageId = ImageId, imageSource = ImageSource, loaderImageId = LoaderImageId, diff --git a/Manager.Interfaces/Models/Device.cs b/ManagerService/Data/Device.cs similarity index 69% rename from Manager.Interfaces/Models/Device.cs rename to ManagerService/Data/Device.cs index e862a3d..ceab8d9 100644 --- a/Manager.Interfaces/Models/Device.cs +++ b/ManagerService/Data/Device.cs @@ -1,67 +1,72 @@ -using Manager.Interfaces.DTO; -using MongoDB.Bson.Serialization.Attributes; +using ManagerService.DTOs; using System; -using System.Collections.Generic; -using System.Text; +using System.ComponentModel.DataAnnotations; -namespace Manager.Interfaces.Models +namespace ManagerService.Data { /// /// Device Information (Tablet) /// public class Device { - [BsonId] - [BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)] + [Key] + [Required] + /*[BsonId] + [BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)]*/ public string Id { get; set; } - [BsonElement("Identifier")] + //[BsonElement("Identifier")] public string Identifier { get; set; } - [BsonElement("Name")] + //[BsonElement("Name")] public string Name { get; set; } - [BsonElement("IpAddressWLAN")] - [BsonRequired] + /*[BsonElement("IpAddressWLAN")] + [BsonRequired]*/ + [Required] public string IpAddressWLAN { get; set; } - [BsonElement("IpAddressETH")] - [BsonRequired] + //[BsonElement("IpAddressETH")] + //[BsonRequired] + [Required] public string IpAddressETH { get; set; } - [BsonElement("Configuration")] + //[BsonElement("Configuration")] public string Configuration { get; set; } - [BsonElement("ConfigurationId")] - [BsonRequired] + //[BsonElement("ConfigurationId")] + //[BsonRequired] + [Required] public string ConfigurationId { get; set; } - [BsonElement("Connected")] - [BsonRequired] + //[BsonElement("Connected")] + //[BsonRequired] + [Required] public bool Connected { get; set; } - [BsonElement("DateCreation")] + //[BsonElement("DateCreation")] public DateTime DateCreation { get; set; } - [BsonElement("DateUpdate")] + //[BsonElement("DateUpdate")] public DateTime DateUpdate { get; set; } // BatteryLevel in case of powered devices - [BsonElement("BatteryLevel")] + //[BsonElement("BatteryLevel")] public string BatteryLevel { get; set; } - [BsonElement("LastBatteryLevel")] + //[BsonElement("LastBatteryLevel")] public DateTime LastBatteryLevel { get; set; } // ConnectionLevel wifi strength level - [BsonElement("ConnectionLevel")] + //[BsonElement("ConnectionLevel")] public string ConnectionLevel { get; set; } - [BsonElement("LastConnectionLevel")] + //[BsonElement("LastConnectionLevel")] public DateTime LastConnectionLevel { get; set; } - [BsonElement("InstanceId")] - [BsonRequired] + /*[BsonElement("InstanceId")] + [BsonRequired]*/ + [Required] public string InstanceId { get; set; } public DeviceDTO ToDTO() diff --git a/Manager.Interfaces/Models/Instance.cs b/ManagerService/Data/Instance.cs similarity index 60% rename from Manager.Interfaces/Models/Instance.cs rename to ManagerService/Data/Instance.cs index 6d541c8..c79b3fb 100644 --- a/Manager.Interfaces/Models/Instance.cs +++ b/ManagerService/Data/Instance.cs @@ -1,28 +1,29 @@ -using Manager.Interfaces.DTO; -using MongoDB.Bson.Serialization.Attributes; +using ManagerService.DTOs; using System; -using System.Collections.Generic; -using System.Text; +using System.ComponentModel.DataAnnotations; -namespace Manager.Interfaces.Models +namespace ManagerService.Data { /// /// Instance Information /// public class Instance { - [BsonId] - [BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)] + [Key] + [Required] + /*[BsonId] + [BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)]*/ public string Id { get; set; } - [BsonElement("Name")] - [BsonRequired] + /*[BsonElement("Name")] + [BsonRequired]*/ + [Required] public string Name { get; set; } // UNIQUE !.. - [BsonElement("DateCreation")] + /*[BsonElement("DateCreation")]*/ public DateTime DateCreation { get; set; } - [BsonElement("PinCode")] + /*[BsonElement("PinCode")]*/ public int? PinCode { get; set; } public InstanceDTO ToDTO() diff --git a/ManagerService/Data/MyInfoMateDbContext.cs b/ManagerService/Data/MyInfoMateDbContext.cs new file mode 100644 index 0000000..b056541 --- /dev/null +++ b/ManagerService/Data/MyInfoMateDbContext.cs @@ -0,0 +1,33 @@ +using Microsoft.EntityFrameworkCore; + +namespace ManagerService.Data +{ + public class MyInfoMateDbContext : DbContext + { + public MyInfoMateDbContext(DbContextOptions options) : base(options) { } + + public DbSet Instances { get; set; } + public DbSet Configurations { get; set; } + public DbSet
Sections { get; set; } + public DbSet Devices { get; set; } + public DbSet Resources { get; set; } + public DbSet Users { get; set; } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + base.OnModelCreating(modelBuilder); + modelBuilder.Entity() + .Property(s => s.Title) + .HasColumnType("jsonb"); + + modelBuilder.Entity
() + .Property(s => s.Title) + .HasColumnType("jsonb"); + + modelBuilder.Entity
() + .Property(s => s.Description) + .HasColumnType("jsonb"); + + } + } +} diff --git a/Manager.Interfaces/Models/Resource.cs b/ManagerService/Data/Resource.cs similarity index 62% rename from Manager.Interfaces/Models/Resource.cs rename to ManagerService/Data/Resource.cs index 95e71ba..5257d1d 100644 --- a/Manager.Interfaces/Models/Resource.cs +++ b/ManagerService/Data/Resource.cs @@ -1,37 +1,39 @@ -using Manager.Interfaces.DTO; -using MongoDB.Bson.Serialization.Attributes; +using ManagerService.DTOs; using System; -using System.Collections.Generic; -using System.Text; +using System.ComponentModel.DataAnnotations; - -namespace Manager.Interfaces.Models +namespace ManagerService.Data { /// /// Resource Information /// public class Resource { - [BsonId] - [BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)] + [Key] + [Required] + /*[BsonId] + [BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)]*/ public string Id { get; set; } - [BsonElement("Type")] - [BsonRequired] + /*[BsonElement("Type")] + [BsonRequired]*/ + [Required] public ResourceType Type { get; set; } - [BsonElement("Label")] - [BsonRequired] + /*[BsonElement("Label")] + [BsonRequired]*/ + [Required] public string Label { get; set; } - [BsonElement("DateCreation")] + /*[BsonElement("DateCreation")]*/ public DateTime DateCreation { get; set; } - [BsonElement("InstanceId")] - [BsonRequired] + /*[BsonElement("InstanceId")] + [BsonRequired]*/ + [Required] public string InstanceId { get; set; } - [BsonElement("URL")] + /*[BsonElement("URL")]*/ public string Url { get; set; } // Firebase url public ResourceDTO ToDTO() diff --git a/Manager.Interfaces/Models/Section.cs b/ManagerService/Data/Section.cs similarity index 54% rename from Manager.Interfaces/Models/Section.cs rename to ManagerService/Data/Section.cs index 5f73c39..c0ce943 100644 --- a/Manager.Interfaces/Models/Section.cs +++ b/ManagerService/Data/Section.cs @@ -1,83 +1,96 @@ -using Manager.Interfaces.DTO; -using MongoDB.Bson.Serialization.Attributes; +using ManagerService.DTOs; using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; using System.Linq; -using System.Text; -namespace Manager.Interfaces.Models +namespace ManagerService.Data { /// /// Section Information /// public class Section { - [BsonId] - [BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)] + [Key] + [Required] + /*[BsonId] + [BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)]*/ public string Id { get; set; } - [BsonElement("Label")] - [BsonRequired] + //[BsonElement("Label")] + //[BsonRequired] + [Required] public string Label { get; set; } // Use in manager - [BsonElement("Title")] - [BsonRequired] - public List Title { get; set; } + //[BsonElement("Title")] + //[BsonRequired] + [Required] + [Column(TypeName = "jsonb")] + public List Title { get; set; } - [BsonElement("Description")] - public List Description { get; set; } + //[BsonElement("Description")] + [Column(TypeName = "jsonb")] + public List Description { get; set; } - [BsonElement("Order")] + //[BsonElement("Order")] public int Order { get; set; } - [BsonElement("ConfigurationId")] - [BsonRequired] + //[BsonElement("ConfigurationId")] + //[BsonRequired] + [Required] public string ConfigurationId { get; set; } // Parent id - [BsonElement("ImageId")] - [BsonRequired] + //[BsonElement("ImageId")] + //[BsonRequired] + [Required] public string ImageId { get; set; } - [BsonElement("ImageSource")] - [BsonRequired] + //[BsonElement("ImageSource")] + //[BsonRequired] + [Required] public string ImageSource { get; set; } - [BsonElement("Type")] - [BsonRequired] + //[BsonElement("Type")] + //[BsonRequired] + [Required] public SectionType Type { get; set; } - [BsonElement("IsSubSection")] - [BsonRequired] + //[BsonElement("IsSubSection")] + //[BsonRequired] + [Required] public bool IsSubSection { get; set; } - [BsonElement("ParentId")] + //[BsonElement("ParentId")] public string ParentId { get; set; } // only if it's an subsection - [BsonElement("DateCreation")] + //[BsonElement("DateCreation")] public DateTime DateCreation { get; set; } - [BsonElement("Data")] - [BsonRequired] + //[BsonElement("Data")] + //[BsonRequired] + [Required] public string Data { get; set; } // Json encapsulated section info - [BsonElement("InstanceId")] - [BsonRequired] + //[BsonElement("InstanceId")] + //[BsonRequired] + [Required] public string InstanceId { get; set; } - [BsonElement("IsBeacon")] + //[BsonElement("IsBeacon")] public bool IsBeacon { get; set; } - [BsonElement("BeaconId")] + //[BsonElement("BeaconId")] public int? BeaconId { get; set; } - [BsonElement("Latitude")] + //[BsonElement("Latitude")] public string Latitude { get; set; } - [BsonElement("Longitude")] + //[BsonElement("Longitude")] public string Longitude { get; set; } - [BsonElement("MeterZoneGPS")] + //[BsonElement("MeterZoneGPS")] public int? MeterZoneGPS { get; set; } public SectionDTO ToDTO() @@ -86,8 +99,8 @@ namespace Manager.Interfaces.Models { id = Id, label = Label, - title = Title.OrderBy(t => t.language).ToList(), - description = Description.OrderBy(d => d.language).ToList(), + title = Title.OrderBy(t => t.Language).Select(l => l.ToDTO()).ToList(), + description = Description.OrderBy(d => d.Language).Select(l => l.ToDTO()).ToList(), order = Order, type = Type, imageId = ImageId, diff --git a/ManagerService/Data/Translation.cs b/ManagerService/Data/Translation.cs new file mode 100644 index 0000000..3d3abc9 --- /dev/null +++ b/ManagerService/Data/Translation.cs @@ -0,0 +1,46 @@ +using ManagerService.DTOs; +using System; +using System.ComponentModel.DataAnnotations; + +namespace ManagerService.Data +{ + /// + /// Translation + /// + 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 + } + } +} diff --git a/Manager.Interfaces/Models/User.cs b/ManagerService/Data/User.cs similarity index 51% rename from Manager.Interfaces/Models/User.cs rename to ManagerService/Data/User.cs index 29d1ff0..cf75539 100644 --- a/Manager.Interfaces/Models/User.cs +++ b/ManagerService/Data/User.cs @@ -1,45 +1,50 @@ -using Manager.Interfaces.DTO; -using MongoDB.Bson.Serialization.Attributes; +using ManagerService.DTOs; using System; -using System.Collections.Generic; -using System.Text; +using System.ComponentModel.DataAnnotations; -namespace Manager.Interfaces.Models +namespace ManagerService.Data { /// /// User Information /// public class User { - [BsonId] - [BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)] + [Key] + [Required] + /*[BsonId] + [BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)]*/ public string Id { get; set; } - [BsonElement("Email")] - [BsonRequired] + //[BsonElement("Email")] + //[BsonRequired] + [Required] public string Email { get; set; } // UNIQUE !.. - [BsonElement("Password")] - [BsonRequired] + //[BsonElement("Password")] + //[BsonRequired] + [Required] public string Password { get; set; } - [BsonElement("FirstName")] - [BsonRequired] + //[BsonElement("FirstName")] + //[BsonRequired] public string FirstName { get; set; } - [BsonElement("LastName")] - [BsonRequired] + //[BsonElement("LastName")] + //[BsonRequired] + [Required] public string LastName { get; set; } - [BsonElement("Token")] - [BsonRequired] + //[BsonElement("Token")] + //[BsonRequired] + [Required] public string Token { get; set; } - [BsonElement("DateCreation")] + //[BsonElement("DateCreation")] public DateTime DateCreation { get; set; } - [BsonElement("InstanceId")] - [BsonRequired] + /*[BsonElement("InstanceId")] + [BsonRequired]*/ + [Required] public string InstanceId { get; set; } public UserDetailDTO ToDTO() diff --git a/ManagerService/Deployment/.dockerignore b/ManagerService/Deployment/.dockerignore new file mode 100644 index 0000000..3729ff0 --- /dev/null +++ b/ManagerService/Deployment/.dockerignore @@ -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 \ No newline at end of file diff --git a/ManagerService/Deployment/.env b/ManagerService/Deployment/.env new file mode 100644 index 0000000..7494ecb --- /dev/null +++ b/ManagerService/Deployment/.env @@ -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 diff --git a/ManagerService/Deployment/.env.docker-compose.example b/ManagerService/Deployment/.env.docker-compose.example new file mode 100644 index 0000000..7494ecb --- /dev/null +++ b/ManagerService/Deployment/.env.docker-compose.example @@ -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 diff --git a/ManagerService/Deployment/docker-compose.dev.yaml b/ManagerService/Deployment/docker-compose.dev.yaml new file mode 100644 index 0000000..52be163 --- /dev/null +++ b/ManagerService/Deployment/docker-compose.dev.yaml @@ -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 + diff --git a/ManagerService/Extensions/MqttClientService.cs b/ManagerService/Extensions/MqttClientService.cs index d8881a7..0b586ef 100644 --- a/ManagerService/Extensions/MqttClientService.cs +++ b/ManagerService/Extensions/MqttClientService.cs @@ -1,5 +1,6 @@ using Manager.Interfaces.Models; using Manager.Services; +using ManagerService.Data; using MQTTnet; using MQTTnet.Client; using MQTTnet.Client.Connecting; @@ -19,8 +20,9 @@ namespace Mqtt.Client.AspNetCore.Services { private static IMqttClient mqttClient; private IMqttClientOptions options; - static DeviceDatabaseService _deviceDatabaseService; - static ConfigurationDatabaseService _configurationDatabaseService; + /*static DeviceDatabaseService _deviceDatabaseService; + static ConfigurationDatabaseService _configurationDatabaseService;*/ + static MyInfoMateDbContext _myInfoMateDbContext; public static string lastTopic; public static long lastTimeTopic; @@ -74,13 +76,19 @@ namespace Mqtt.Client.AspNetCore.Services var deviceId = (string)deserialized["deviceId"]; var connectedStatus = (bool)deserialized["connected"]; - Device device = _deviceDatabaseService.GetById(deviceId); + // TODO + + + + Device device = _myInfoMateDbContext.Devices.Find(deviceId); //_deviceDatabaseService.GetById(deviceId); if (device != null) { device.Connected = connectedStatus; - _deviceDatabaseService.Update(device.Id, device); + _myInfoMateDbContext.SaveChanges(); + + //_deviceDatabaseService.Update(device.Id, device); } } break; @@ -145,10 +153,10 @@ namespace Mqtt.Client.AspNetCore.Services await mqttClient.PublishAsync(mqttMessage); } - public static void SetServices(DeviceDatabaseService _DeviceDatabaseService, ConfigurationDatabaseService _ConfigurationDatabaseService) + public static void SetServices(MyInfoMateDbContext myInfoMateDbContext/*DeviceDatabaseService _DeviceDatabaseService, ConfigurationDatabaseService _ConfigurationDatabaseService*/) { - _deviceDatabaseService = _DeviceDatabaseService; - _configurationDatabaseService = _ConfigurationDatabaseService; + _myInfoMateDbContext = myInfoMateDbContext; + //_configurationDatabaseService = _ConfigurationDatabaseService; } } } diff --git a/ManagerService/Helpers/LanguageInit.cs b/ManagerService/Helpers/LanguageInit.cs index fbeece7..37733fc 100644 --- a/ManagerService/Helpers/LanguageInit.cs +++ b/ManagerService/Helpers/LanguageInit.cs @@ -1,24 +1,18 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Manager.Interfaces.DTO; -using Manager.Interfaces.Models; -using Microsoft.Extensions.Configuration; -using MongoDB.Driver; +using System.Collections.Generic; +using ManagerService.Data; namespace Manager.Helpers { public class LanguageInit { - public static List Init(string label, List languages, bool toNull = false) + public static List Init(string label, List languages, bool toNull = false) { - List translations = new List(); + List translations = new List(); foreach (var language in languages) { 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; } diff --git a/Manager.Framework/Helpers/Passwords/PasswordUtils.cs b/ManagerService/Helpers/PasswordUtils.cs similarity index 99% rename from Manager.Framework/Helpers/Passwords/PasswordUtils.cs rename to ManagerService/Helpers/PasswordUtils.cs index db264ba..120525c 100644 --- a/Manager.Framework/Helpers/Passwords/PasswordUtils.cs +++ b/ManagerService/Helpers/PasswordUtils.cs @@ -6,7 +6,7 @@ using System.Security.Cryptography; using System.Text; using System.Text.RegularExpressions; -namespace Manager.Framework.Helpers +namespace ManagerService.Helpers { /// /// Password utils diff --git a/Manager.Framework/Business/ProfileLogic.cs b/ManagerService/Helpers/ProfileLogic.cs similarity index 89% rename from Manager.Framework/Business/ProfileLogic.cs rename to ManagerService/Helpers/ProfileLogic.cs index 81f0772..2ea56d5 100644 --- a/Manager.Framework/Business/ProfileLogic.cs +++ b/ManagerService/Helpers/ProfileLogic.cs @@ -1,11 +1,7 @@ -using Manager.Framework.Helpers; -using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging; using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -namespace Manager.Framework.Business +namespace ManagerService.Helpers { public class ProfileLogic { diff --git a/Manager.Interfaces/Models/TokensSettings.cs b/ManagerService/Helpers/TokensSettings.cs similarity index 100% rename from Manager.Interfaces/Models/TokensSettings.cs rename to ManagerService/Helpers/TokensSettings.cs diff --git a/ManagerService/ManagerService.csproj b/ManagerService/ManagerService.csproj index e110133..2225efa 100644 --- a/ManagerService/ManagerService.csproj +++ b/ManagerService/ManagerService.csproj @@ -1,26 +1,27 @@  - net6.0 + net8.0 Linux d2e1a747-e204-4b43-bf93-abbd19c46417 + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + - - - - - diff --git a/ManagerService/Migrations/20250305163047_InitialCreate.Designer.cs b/ManagerService/Migrations/20250305163047_InitialCreate.Designer.cs new file mode 100644 index 0000000..89106bb --- /dev/null +++ b/ManagerService/Migrations/20250305163047_InitialCreate.Designer.cs @@ -0,0 +1,320 @@ +// +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 + { + /// + 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("Id") + .HasColumnType("text"); + + b.Property("DateCreation") + .HasColumnType("timestamp with time zone"); + + b.Property("ImageId") + .HasColumnType("text"); + + b.Property("ImageSource") + .HasColumnType("text"); + + b.Property("InstanceId") + .IsRequired() + .HasColumnType("text"); + + b.Property("IsDate") + .HasColumnType("boolean"); + + b.Property("IsHour") + .HasColumnType("boolean"); + + b.Property("IsMobile") + .HasColumnType("boolean"); + + b.Property("IsOffline") + .HasColumnType("boolean"); + + b.Property("IsSectionImageBackground") + .HasColumnType("boolean"); + + b.Property("IsTablet") + .HasColumnType("boolean"); + + b.Property("Label") + .IsRequired() + .HasColumnType("text"); + + b.PrimitiveCollection>("Languages") + .HasColumnType("text[]"); + + b.Property("LoaderImageId") + .HasColumnType("text"); + + b.Property("LoaderImageUrl") + .HasColumnType("text"); + + b.Property("PrimaryColor") + .HasColumnType("text"); + + b.Property("RoundedValue") + .HasColumnType("integer"); + + b.Property("ScreenPercentageSectionsMainPage") + .HasColumnType("integer"); + + b.Property("SecondaryColor") + .HasColumnType("text"); + + b.Property>("Title") + .IsRequired() + .HasColumnType("jsonb"); + + b.Property("WeatherCity") + .HasColumnType("text"); + + b.Property("WeatherResult") + .HasColumnType("text"); + + b.Property("WeatherUpdatedDate") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.ToTable("Configurations"); + }); + + modelBuilder.Entity("ManagerService.Data.Device", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("BatteryLevel") + .HasColumnType("text"); + + b.Property("Configuration") + .HasColumnType("text"); + + b.Property("ConfigurationId") + .IsRequired() + .HasColumnType("text"); + + b.Property("Connected") + .HasColumnType("boolean"); + + b.Property("ConnectionLevel") + .HasColumnType("text"); + + b.Property("DateCreation") + .HasColumnType("timestamp with time zone"); + + b.Property("DateUpdate") + .HasColumnType("timestamp with time zone"); + + b.Property("Identifier") + .HasColumnType("text"); + + b.Property("InstanceId") + .IsRequired() + .HasColumnType("text"); + + b.Property("IpAddressETH") + .IsRequired() + .HasColumnType("text"); + + b.Property("IpAddressWLAN") + .IsRequired() + .HasColumnType("text"); + + b.Property("LastBatteryLevel") + .HasColumnType("timestamp with time zone"); + + b.Property("LastConnectionLevel") + .HasColumnType("timestamp with time zone"); + + b.Property("Name") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Devices"); + }); + + modelBuilder.Entity("ManagerService.Data.Instance", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("DateCreation") + .HasColumnType("timestamp with time zone"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("PinCode") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Instances"); + }); + + modelBuilder.Entity("ManagerService.Data.Resource", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("DateCreation") + .HasColumnType("timestamp with time zone"); + + b.Property("InstanceId") + .IsRequired() + .HasColumnType("text"); + + b.Property("Label") + .IsRequired() + .HasColumnType("text"); + + b.Property("Type") + .HasColumnType("integer"); + + b.Property("Url") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Resources"); + }); + + modelBuilder.Entity("ManagerService.Data.Section", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("BeaconId") + .HasColumnType("integer"); + + b.Property("ConfigurationId") + .IsRequired() + .HasColumnType("text"); + + b.Property("Data") + .IsRequired() + .HasColumnType("text"); + + b.Property("DateCreation") + .HasColumnType("timestamp with time zone"); + + b.Property>("Description") + .HasColumnType("jsonb"); + + b.Property("ImageId") + .IsRequired() + .HasColumnType("text"); + + b.Property("ImageSource") + .IsRequired() + .HasColumnType("text"); + + b.Property("InstanceId") + .IsRequired() + .HasColumnType("text"); + + b.Property("IsBeacon") + .HasColumnType("boolean"); + + b.Property("IsSubSection") + .HasColumnType("boolean"); + + b.Property("Label") + .IsRequired() + .HasColumnType("text"); + + b.Property("Latitude") + .HasColumnType("text"); + + b.Property("Longitude") + .HasColumnType("text"); + + b.Property("MeterZoneGPS") + .HasColumnType("integer"); + + b.Property("Order") + .HasColumnType("integer"); + + b.Property("ParentId") + .HasColumnType("text"); + + b.Property>("Title") + .IsRequired() + .HasColumnType("jsonb"); + + b.Property("Type") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Sections"); + }); + + modelBuilder.Entity("ManagerService.Data.User", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("DateCreation") + .HasColumnType("timestamp with time zone"); + + b.Property("Email") + .IsRequired() + .HasColumnType("text"); + + b.Property("FirstName") + .HasColumnType("text"); + + b.Property("InstanceId") + .IsRequired() + .HasColumnType("text"); + + b.Property("LastName") + .IsRequired() + .HasColumnType("text"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text"); + + b.Property("Token") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Users"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/ManagerService/Migrations/20250305163047_InitialCreate.cs b/ManagerService/Migrations/20250305163047_InitialCreate.cs new file mode 100644 index 0000000..8fbff0d --- /dev/null +++ b/ManagerService/Migrations/20250305163047_InitialCreate.cs @@ -0,0 +1,174 @@ +using System; +using System.Collections.Generic; +using ManagerService.Data; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace ManagerService.Migrations +{ + /// + public partial class InitialCreate : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Configurations", + columns: table => new + { + Id = table.Column(type: "text", nullable: false), + Label = table.Column(type: "text", nullable: false), + Title = table.Column>(type: "jsonb", nullable: false), + ImageId = table.Column(type: "text", nullable: true), + ImageSource = table.Column(type: "text", nullable: true), + PrimaryColor = table.Column(type: "text", nullable: true), + SecondaryColor = table.Column(type: "text", nullable: true), + Languages = table.Column>(type: "text[]", nullable: true), + DateCreation = table.Column(type: "timestamp with time zone", nullable: false), + IsMobile = table.Column(type: "boolean", nullable: false), + IsTablet = table.Column(type: "boolean", nullable: false), + IsOffline = table.Column(type: "boolean", nullable: false), + InstanceId = table.Column(type: "text", nullable: false), + LoaderImageId = table.Column(type: "text", nullable: true), + LoaderImageUrl = table.Column(type: "text", nullable: true), + WeatherCity = table.Column(type: "text", nullable: true), + WeatherUpdatedDate = table.Column(type: "timestamp with time zone", nullable: true), + WeatherResult = table.Column(type: "text", nullable: true), + IsDate = table.Column(type: "boolean", nullable: false), + IsHour = table.Column(type: "boolean", nullable: false), + IsSectionImageBackground = table.Column(type: "boolean", nullable: false), + RoundedValue = table.Column(type: "integer", nullable: true), + ScreenPercentageSectionsMainPage = table.Column(type: "integer", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Configurations", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Devices", + columns: table => new + { + Id = table.Column(type: "text", nullable: false), + Identifier = table.Column(type: "text", nullable: true), + Name = table.Column(type: "text", nullable: true), + IpAddressWLAN = table.Column(type: "text", nullable: false), + IpAddressETH = table.Column(type: "text", nullable: false), + Configuration = table.Column(type: "text", nullable: true), + ConfigurationId = table.Column(type: "text", nullable: false), + Connected = table.Column(type: "boolean", nullable: false), + DateCreation = table.Column(type: "timestamp with time zone", nullable: false), + DateUpdate = table.Column(type: "timestamp with time zone", nullable: false), + BatteryLevel = table.Column(type: "text", nullable: true), + LastBatteryLevel = table.Column(type: "timestamp with time zone", nullable: false), + ConnectionLevel = table.Column(type: "text", nullable: true), + LastConnectionLevel = table.Column(type: "timestamp with time zone", nullable: false), + InstanceId = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Devices", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Instances", + columns: table => new + { + Id = table.Column(type: "text", nullable: false), + Name = table.Column(type: "text", nullable: false), + DateCreation = table.Column(type: "timestamp with time zone", nullable: false), + PinCode = table.Column(type: "integer", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Instances", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Resources", + columns: table => new + { + Id = table.Column(type: "text", nullable: false), + Type = table.Column(type: "integer", nullable: false), + Label = table.Column(type: "text", nullable: false), + DateCreation = table.Column(type: "timestamp with time zone", nullable: false), + InstanceId = table.Column(type: "text", nullable: false), + Url = table.Column(type: "text", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Resources", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Sections", + columns: table => new + { + Id = table.Column(type: "text", nullable: false), + Label = table.Column(type: "text", nullable: false), + Title = table.Column>(type: "jsonb", nullable: false), + Description = table.Column>(type: "jsonb", nullable: true), + Order = table.Column(type: "integer", nullable: false), + ConfigurationId = table.Column(type: "text", nullable: false), + ImageId = table.Column(type: "text", nullable: false), + ImageSource = table.Column(type: "text", nullable: false), + Type = table.Column(type: "integer", nullable: false), + IsSubSection = table.Column(type: "boolean", nullable: false), + ParentId = table.Column(type: "text", nullable: true), + DateCreation = table.Column(type: "timestamp with time zone", nullable: false), + Data = table.Column(type: "text", nullable: false), + InstanceId = table.Column(type: "text", nullable: false), + IsBeacon = table.Column(type: "boolean", nullable: false), + BeaconId = table.Column(type: "integer", nullable: true), + Latitude = table.Column(type: "text", nullable: true), + Longitude = table.Column(type: "text", nullable: true), + MeterZoneGPS = table.Column(type: "integer", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Sections", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Users", + columns: table => new + { + Id = table.Column(type: "text", nullable: false), + Email = table.Column(type: "text", nullable: false), + Password = table.Column(type: "text", nullable: false), + FirstName = table.Column(type: "text", nullable: true), + LastName = table.Column(type: "text", nullable: false), + Token = table.Column(type: "text", nullable: false), + DateCreation = table.Column(type: "timestamp with time zone", nullable: false), + InstanceId = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Users", x => x.Id); + }); + } + + /// + 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"); + } + } +} diff --git a/ManagerService/Migrations/MyInfoMateDbContextModelSnapshot.cs b/ManagerService/Migrations/MyInfoMateDbContextModelSnapshot.cs new file mode 100644 index 0000000..6346fb0 --- /dev/null +++ b/ManagerService/Migrations/MyInfoMateDbContextModelSnapshot.cs @@ -0,0 +1,317 @@ +// +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("Id") + .HasColumnType("text"); + + b.Property("DateCreation") + .HasColumnType("timestamp with time zone"); + + b.Property("ImageId") + .HasColumnType("text"); + + b.Property("ImageSource") + .HasColumnType("text"); + + b.Property("InstanceId") + .IsRequired() + .HasColumnType("text"); + + b.Property("IsDate") + .HasColumnType("boolean"); + + b.Property("IsHour") + .HasColumnType("boolean"); + + b.Property("IsMobile") + .HasColumnType("boolean"); + + b.Property("IsOffline") + .HasColumnType("boolean"); + + b.Property("IsSectionImageBackground") + .HasColumnType("boolean"); + + b.Property("IsTablet") + .HasColumnType("boolean"); + + b.Property("Label") + .IsRequired() + .HasColumnType("text"); + + b.PrimitiveCollection>("Languages") + .HasColumnType("text[]"); + + b.Property("LoaderImageId") + .HasColumnType("text"); + + b.Property("LoaderImageUrl") + .HasColumnType("text"); + + b.Property("PrimaryColor") + .HasColumnType("text"); + + b.Property("RoundedValue") + .HasColumnType("integer"); + + b.Property("ScreenPercentageSectionsMainPage") + .HasColumnType("integer"); + + b.Property("SecondaryColor") + .HasColumnType("text"); + + b.Property>("Title") + .IsRequired() + .HasColumnType("jsonb"); + + b.Property("WeatherCity") + .HasColumnType("text"); + + b.Property("WeatherResult") + .HasColumnType("text"); + + b.Property("WeatherUpdatedDate") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.ToTable("Configurations"); + }); + + modelBuilder.Entity("ManagerService.Data.Device", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("BatteryLevel") + .HasColumnType("text"); + + b.Property("Configuration") + .HasColumnType("text"); + + b.Property("ConfigurationId") + .IsRequired() + .HasColumnType("text"); + + b.Property("Connected") + .HasColumnType("boolean"); + + b.Property("ConnectionLevel") + .HasColumnType("text"); + + b.Property("DateCreation") + .HasColumnType("timestamp with time zone"); + + b.Property("DateUpdate") + .HasColumnType("timestamp with time zone"); + + b.Property("Identifier") + .HasColumnType("text"); + + b.Property("InstanceId") + .IsRequired() + .HasColumnType("text"); + + b.Property("IpAddressETH") + .IsRequired() + .HasColumnType("text"); + + b.Property("IpAddressWLAN") + .IsRequired() + .HasColumnType("text"); + + b.Property("LastBatteryLevel") + .HasColumnType("timestamp with time zone"); + + b.Property("LastConnectionLevel") + .HasColumnType("timestamp with time zone"); + + b.Property("Name") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Devices"); + }); + + modelBuilder.Entity("ManagerService.Data.Instance", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("DateCreation") + .HasColumnType("timestamp with time zone"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("PinCode") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Instances"); + }); + + modelBuilder.Entity("ManagerService.Data.Resource", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("DateCreation") + .HasColumnType("timestamp with time zone"); + + b.Property("InstanceId") + .IsRequired() + .HasColumnType("text"); + + b.Property("Label") + .IsRequired() + .HasColumnType("text"); + + b.Property("Type") + .HasColumnType("integer"); + + b.Property("Url") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Resources"); + }); + + modelBuilder.Entity("ManagerService.Data.Section", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("BeaconId") + .HasColumnType("integer"); + + b.Property("ConfigurationId") + .IsRequired() + .HasColumnType("text"); + + b.Property("Data") + .IsRequired() + .HasColumnType("text"); + + b.Property("DateCreation") + .HasColumnType("timestamp with time zone"); + + b.Property>("Description") + .HasColumnType("jsonb"); + + b.Property("ImageId") + .IsRequired() + .HasColumnType("text"); + + b.Property("ImageSource") + .IsRequired() + .HasColumnType("text"); + + b.Property("InstanceId") + .IsRequired() + .HasColumnType("text"); + + b.Property("IsBeacon") + .HasColumnType("boolean"); + + b.Property("IsSubSection") + .HasColumnType("boolean"); + + b.Property("Label") + .IsRequired() + .HasColumnType("text"); + + b.Property("Latitude") + .HasColumnType("text"); + + b.Property("Longitude") + .HasColumnType("text"); + + b.Property("MeterZoneGPS") + .HasColumnType("integer"); + + b.Property("Order") + .HasColumnType("integer"); + + b.Property("ParentId") + .HasColumnType("text"); + + b.Property>("Title") + .IsRequired() + .HasColumnType("jsonb"); + + b.Property("Type") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Sections"); + }); + + modelBuilder.Entity("ManagerService.Data.User", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("DateCreation") + .HasColumnType("timestamp with time zone"); + + b.Property("Email") + .IsRequired() + .HasColumnType("text"); + + b.Property("FirstName") + .HasColumnType("text"); + + b.Property("InstanceId") + .IsRequired() + .HasColumnType("text"); + + b.Property("LastName") + .IsRequired() + .HasColumnType("text"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text"); + + b.Property("Token") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Users"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/ManagerService/Readme.md b/ManagerService/Readme.md new file mode 100644 index 0000000..11be3d5 --- /dev/null +++ b/ManagerService/Readme.md @@ -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 + +# Mise à jour de la base de données + +>dotnet ef database update diff --git a/ManagerService/Services/ConfigurationDatabaseService.cs b/ManagerService/Services/ConfigurationDatabaseService.cs index 19bd1c4..a09a455 100644 --- a/ManagerService/Services/ConfigurationDatabaseService.cs +++ b/ManagerService/Services/ConfigurationDatabaseService.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Manager.Interfaces.Models; +using ManagerService.Data; using Microsoft.Extensions.Configuration; using MongoDB.Driver; diff --git a/ManagerService/Services/DeviceDatabaseService.cs b/ManagerService/Services/DeviceDatabaseService.cs index 37d2d1b..e859d7d 100644 --- a/ManagerService/Services/DeviceDatabaseService.cs +++ b/ManagerService/Services/DeviceDatabaseService.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Manager.Interfaces.Models; +using ManagerService.Data; using Microsoft.Extensions.Configuration; using MongoDB.Driver; diff --git a/Manager.Framework/Models/Exceptions/RequestException.cs b/ManagerService/Services/Exceptions/RequestException.cs similarity index 100% rename from Manager.Framework/Models/Exceptions/RequestException.cs rename to ManagerService/Services/Exceptions/RequestException.cs diff --git a/ManagerService/Services/InstanceDatabaseService.cs b/ManagerService/Services/InstanceDatabaseService.cs index 35ccbad..043ccf8 100644 --- a/ManagerService/Services/InstanceDatabaseService.cs +++ b/ManagerService/Services/InstanceDatabaseService.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Manager.Interfaces.Models; +using ManagerService.Data; using Microsoft.Extensions.Configuration; using MongoDB.Driver; diff --git a/ManagerService/Services/ResourceDatabaseService.cs b/ManagerService/Services/ResourceDatabaseService.cs index 7264a35..aafaf96 100644 --- a/ManagerService/Services/ResourceDatabaseService.cs +++ b/ManagerService/Services/ResourceDatabaseService.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Manager.Interfaces.Models; +using ManagerService.Data; using Microsoft.Extensions.Configuration; using MongoDB.Driver; diff --git a/ManagerService/Services/SectionDatabaseService.cs b/ManagerService/Services/SectionDatabaseService.cs index 8c53c63..da7cfdc 100644 --- a/ManagerService/Services/SectionDatabaseService.cs +++ b/ManagerService/Services/SectionDatabaseService.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Manager.Interfaces.Models; +using ManagerService.Data; using Microsoft.Extensions.Configuration; using MongoDB.Driver; diff --git a/ManagerService/Services/TokensService.cs b/ManagerService/Services/TokensService.cs index 30c269e..85a11a8 100644 --- a/ManagerService/Services/TokensService.cs +++ b/ManagerService/Services/TokensService.cs @@ -1,19 +1,17 @@ -using Microsoft.AspNetCore.Http; -using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using System; using System.Collections.Generic; -using System.Linq; using System.Security.Claims; using System.Text; -using System.Threading.Tasks; using System.Security.Cryptography; using Manager.Interfaces.Models; using Microsoft.IdentityModel.Tokens; -using Manager.Framework.Business; -using Manager.Interfaces.DTO; using System.IdentityModel.Tokens.Jwt; using Manager.Services; +using ManagerService.Helpers; +using ManagerService.DTOs; +using ManagerService.Data; namespace ManagerService.Service.Services { @@ -25,7 +23,8 @@ namespace ManagerService.Service.Services private readonly ILogger _logger; private readonly TokensSettings _tokenSettings; private readonly ProfileLogic _profileLogic; - private InstanceDatabaseService _instanceService; + /*private InstanceDatabaseService _instanceService;*/ + private readonly MyInfoMateDbContext _myInfoMateDbContext; private readonly SigningCredentials _signingCredentials; @@ -37,12 +36,12 @@ namespace ManagerService.Service.Services /// Database context /// Profile logic /// Email client - public TokensService(ILogger logger, IOptions tokenSettings, ProfileLogic profileLogic, InstanceDatabaseService instanceService) + public TokensService(ILogger logger, IOptions tokenSettings, ProfileLogic profileLogic, MyInfoMateDbContext myInfoMateDbContext) { _logger = logger; _tokenSettings = tokenSettings.Value; _profileLogic = profileLogic; - _instanceService = instanceService; + _myInfoMateDbContext = myInfoMateDbContext; var key = Encoding.UTF8.GetBytes(_tokenSettings.Secret); _signingCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature); @@ -76,7 +75,9 @@ namespace ManagerService.Service.Services }; 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() { diff --git a/ManagerService/Services/UserDatabaseService.cs b/ManagerService/Services/UserDatabaseService.cs index cf3ab2b..16c682a 100644 --- a/ManagerService/Services/UserDatabaseService.cs +++ b/ManagerService/Services/UserDatabaseService.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Manager.Interfaces.Models; +using ManagerService.Data; using Microsoft.Extensions.Configuration; using MongoDB.Driver; diff --git a/ManagerService/Startup.cs b/ManagerService/Startup.cs index 5473c42..8a21d0e 100644 --- a/ManagerService/Startup.cs +++ b/ManagerService/Startup.cs @@ -1,9 +1,11 @@ -using Manager.Framework.Business; using Manager.Framework.Models; using Manager.Helpers; +using Manager.Interfaces; using Manager.Interfaces.Models; using Manager.Services; +using ManagerService.Data; using ManagerService.Extensions; +using ManagerService.Helpers; using ManagerService.Service; using ManagerService.Service.Services; using Microsoft.AspNetCore.Authentication.JwtBearer; @@ -14,6 +16,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.HttpsPolicy; using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.FileProviders; @@ -138,13 +141,18 @@ namespace ManagerService #endif services.AddScoped(typeof(ProfileLogic)); services.AddScoped(); - services.AddScoped(); + /*services.AddScoped(); services.AddScoped(); services.AddScoped(); - services.AddScoped(); + services.AddScoped();*/ services.AddScoped(); - services.AddScoped(); - services.AddScoped(); + /*services.AddScoped(); + services.AddScoped();*/ + + var connectionString = Configuration.GetConnectionString("PostgresConnection"); + + services.AddDbContext(options => + options.UseNpgsql(connectionString)); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. diff --git a/ManagerService/appsettings.Development.json b/ManagerService/appsettings.Development.json index 8983e0f..83741d7 100644 --- a/ManagerService/appsettings.Development.json +++ b/ManagerService/appsettings.Development.json @@ -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": { "LogLevel": { "Default": "Information", diff --git a/ManagerService/appsettings.json b/ManagerService/appsettings.json index b5dbff2..8b4dae3 100644 --- a/ManagerService/appsettings.json +++ b/ManagerService/appsettings.json @@ -1,12 +1,13 @@ { - "ConnectionStrings": { + /*"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 - }, + "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": { "LogLevel": { "Default": "Information",