diff --git a/Manager.Interfaces/DTO/DisplayDTO.cs b/Manager.Interfaces/DTO/ConfigurationDTO.cs similarity index 94% rename from Manager.Interfaces/DTO/DisplayDTO.cs rename to Manager.Interfaces/DTO/ConfigurationDTO.cs index c9bfadd..14b767a 100644 --- a/Manager.Interfaces/DTO/DisplayDTO.cs +++ b/Manager.Interfaces/DTO/ConfigurationDTO.cs @@ -4,7 +4,7 @@ using System.Text; namespace Manager.Interfaces.DTO { - public class DisplayDTO + public class ConfigurationDTO { public string Id { get; set; } public string Label { get; set; } diff --git a/Manager.Interfaces/DTO/SectionDTO.cs b/Manager.Interfaces/DTO/SectionDTO.cs index 6b91cc5..4388c37 100644 --- a/Manager.Interfaces/DTO/SectionDTO.cs +++ b/Manager.Interfaces/DTO/SectionDTO.cs @@ -11,6 +11,7 @@ namespace Manager.Interfaces.DTO public string Label { get; set; } // Dictionary with all languages public string Description { get; set; } // Dictionary with all languages public string ImageId { get; set; } // == RessourceId + public string ConfigurationId { get; set; } public bool IsSubSection { get; set; } // true if part of menu type public string ParentId { get; set; } // only if it's an subsection public SectionType Type { get; set; } // !! If IsSubSection == true => Type can't not be menu ! diff --git a/Manager.Interfaces/Models/Display.cs b/Manager.Interfaces/Models/Configuration.cs similarity index 78% rename from Manager.Interfaces/Models/Display.cs rename to Manager.Interfaces/Models/Configuration.cs index d85ff2c..2c1bac9 100644 --- a/Manager.Interfaces/Models/Display.cs +++ b/Manager.Interfaces/Models/Configuration.cs @@ -7,9 +7,9 @@ using System.Text; namespace Manager.Interfaces.Models { /// - /// Display Information + /// Configuration Information /// - public class Display + public class Configuration { [BsonId] [BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)] @@ -26,7 +26,7 @@ namespace Manager.Interfaces.Models public string SecondaryColor { get; set; } [BsonElement("SectionIds")] - public List SectionIds { get; set; } + public List SectionIds { get; set; } // Get children [BsonElement("Languages")] public List Languages { get; set; } // fr, en, de, nl => Sélection dans une liste déjà établie dans l'application ! @@ -34,14 +34,16 @@ namespace Manager.Interfaces.Models [BsonElement("DateCreation")] public DateTime DateCreation { get; set; } - public DisplayDTO ToDTO() + public ConfigurationDTO ToDTO() { - return new DisplayDTO() + return new ConfigurationDTO() { Id = Id, Label = Label, DateCreation = DateCreation, PrimaryColor = PrimaryColor, + Languages = Languages, + SectionIds = SectionIds, // Maybe get direct from db SecondaryColor = SecondaryColor }; } diff --git a/Manager.Interfaces/Models/Section.cs b/Manager.Interfaces/Models/Section.cs index e98a5ce..074f286 100644 --- a/Manager.Interfaces/Models/Section.cs +++ b/Manager.Interfaces/Models/Section.cs @@ -23,6 +23,10 @@ namespace Manager.Interfaces.Models [BsonElement("Description")] public string Description { get; set; } // Dictionary with all languages + [BsonElement("ConfigurationId")] + [BsonRequired] + public string ConfigurationId { get; set; } // Parent id + [BsonElement("ImageId")] [BsonRequired] public string ImageId { get; set; } @@ -51,8 +55,14 @@ namespace Manager.Interfaces.Models { Id = Id, Label = Label, + Description = Description, Type = Type, - ImageId = ImageId + ImageId = ImageId, + ConfigurationId = ConfigurationId, + IsSubSection = IsSubSection, + ParentId = ParentId, + Data = Data, + DateCreation = DateCreation }; } } diff --git a/ManagerService/Controllers/DisplayController.cs b/ManagerService/Controllers/ConfigurationController.cs similarity index 50% rename from ManagerService/Controllers/DisplayController.cs rename to ManagerService/Controllers/ConfigurationController.cs index d980a73..aa9cd25 100644 --- a/ManagerService/Controllers/DisplayController.cs +++ b/ManagerService/Controllers/ConfigurationController.cs @@ -15,31 +15,31 @@ namespace ManagerService.Controllers { [Authorize] // TODO Add ROLES (Roles = "Admin") [ApiController, Route("api/[controller]")] - [OpenApiTag("Display", Description = "Display management")] - public class DisplayController : ControllerBase + [OpenApiTag("Configuration", Description = "Configuration management")] + public class ConfigurationController : ControllerBase { - private DisplayDatabaseService _displayService; - private readonly ILogger _logger; + private ConfigurationDatabaseService _configurationService; + private readonly ILogger _logger; - public DisplayController(ILogger logger, DisplayDatabaseService displayService) + public ConfigurationController(ILogger logger, ConfigurationDatabaseService configurationService) { _logger = logger; - _displayService = displayService; + _configurationService = configurationService; } /// - /// Get a list of all display (summary) + /// Get a list of all configuration (summary) /// - [ProducesResponseType(typeof(List), 200)] + [ProducesResponseType(typeof(List), 200)] [ProducesResponseType(typeof(string), 500)] [HttpGet] public ObjectResult Get() { try { - List displays = _displayService.GetAll(); + List configurations = _configurationService.GetAll(); - return new OkObjectResult(displays.Select(r => r.ToDTO())); + return new OkObjectResult(configurations.Select(r => r.ToDTO())); } catch (Exception ex) { @@ -49,11 +49,11 @@ namespace ManagerService.Controllers /// - /// Get a specific display + /// Get a specific display configuration /// - /// id display + /// id configuration [AllowAnonymous] - [ProducesResponseType(typeof(DisplayDTO), 200)] + [ProducesResponseType(typeof(ConfigurationDTO), 200)] [ProducesResponseType(typeof(string), 404)] [ProducesResponseType(typeof(string), 500)] [HttpGet("{id}")] @@ -61,12 +61,12 @@ namespace ManagerService.Controllers { try { - Display display = _displayService.GetById(id); + Configuration configuration = _configurationService.GetById(id); - if (display == null) - throw new KeyNotFoundException("This display was not found"); + if (configuration == null) + throw new KeyNotFoundException("This configuration was not found"); - return new OkObjectResult(display.ToDTO()); + return new OkObjectResult(configuration.ToDTO()); } catch (KeyNotFoundException ex) { @@ -79,33 +79,33 @@ namespace ManagerService.Controllers } /// - /// Create a new display + /// Create a new configuration /// - /// New display info + /// New configuration info [ProducesResponseType(typeof(RessourceDetailDTO), 200)] [ProducesResponseType(typeof(string), 400)] [ProducesResponseType(typeof(string), 409)] [ProducesResponseType(typeof(string), 500)] [HttpPost] - public ObjectResult Create([FromBody] DisplayDTO newDisplay) + public ObjectResult Create([FromBody] ConfigurationDTO newConfiguration) { try { - if (newDisplay == null) - throw new ArgumentNullException("Display param is null"); + if (newConfiguration == null) + throw new ArgumentNullException("Configuration param is null"); // Todo add some verification ? - Display display = new Display(); - display.Label = newDisplay.Label; - display.PrimaryColor = newDisplay.PrimaryColor; - display.SecondaryColor = newDisplay.SecondaryColor; - display.SectionIds = newDisplay.SectionIds; - display.Languages = newDisplay.Languages; - display.DateCreation = DateTime.Now; + Configuration configuration = new Configuration(); + configuration.Label = newConfiguration.Label; + configuration.PrimaryColor = newConfiguration.PrimaryColor; + configuration.SecondaryColor = newConfiguration.SecondaryColor; + configuration.SectionIds = newConfiguration.SectionIds; + configuration.Languages = newConfiguration.Languages; + configuration.DateCreation = DateTime.Now; - Display displayCreated = _displayService.Create(display); + Configuration configurationCreated = _configurationService.Create(configuration); - return new OkObjectResult(displayCreated.ToDTO()); + return new OkObjectResult(configurationCreated.ToDTO()); } catch (ArgumentNullException ex) { @@ -123,36 +123,36 @@ namespace ManagerService.Controllers /// - /// Update a display + /// Update a configuration /// - /// Display to update - [ProducesResponseType(typeof(DisplayDTO), 200)] + /// Configuration to update + [ProducesResponseType(typeof(ConfigurationDTO), 200)] [ProducesResponseType(typeof(string), 400)] [ProducesResponseType(typeof(string), 404)] [ProducesResponseType(typeof(string), 500)] [HttpPut] - public ObjectResult Update([FromBody] DisplayDTO updatedDisplay) + public ObjectResult Update([FromBody] ConfigurationDTO updatedConfiguration) { try { - if (updatedDisplay == null) - throw new ArgumentNullException("Display param is null"); + if (updatedConfiguration == null) + throw new ArgumentNullException("configuration param is null"); - Display display = _displayService.GetById(updatedDisplay.Id); + Configuration configuration = _configurationService.GetById(updatedConfiguration.Id); - if (display == null) - throw new KeyNotFoundException("Display does not exist"); + if (configuration == null) + throw new KeyNotFoundException("Configuration does not exist"); // Todo add some verification ? - display.Label = updatedDisplay.Label; - display.PrimaryColor = updatedDisplay.PrimaryColor; - display.SecondaryColor = updatedDisplay.SecondaryColor; - display.Languages = updatedDisplay.Languages; - display.SectionIds = updatedDisplay.SectionIds; + configuration.Label = updatedConfiguration.Label; + configuration.PrimaryColor = updatedConfiguration.PrimaryColor; + configuration.SecondaryColor = updatedConfiguration.SecondaryColor; + configuration.Languages = updatedConfiguration.Languages; + configuration.SectionIds = updatedConfiguration.SectionIds; - Display displayModified = _displayService.Update(updatedDisplay.Id, display); + Configuration configurationModified = _configurationService.Update(updatedConfiguration.Id, configuration); - return new OkObjectResult(displayModified.ToDTO()); + return new OkObjectResult(configurationModified.ToDTO()); } catch (ArgumentNullException ex) { @@ -170,9 +170,9 @@ namespace ManagerService.Controllers /// - /// Delete a display + /// Delete a configuration /// - /// Id of display to delete + /// Id of configuration to delete [ProducesResponseType(typeof(string), 202)] [ProducesResponseType(typeof(string), 400)] [ProducesResponseType(typeof(string), 404)] @@ -183,14 +183,14 @@ namespace ManagerService.Controllers try { if (id == null) - throw new ArgumentNullException("Display param is null"); + throw new ArgumentNullException("Configuration param is null"); - if (!_displayService.IsExist(id)) - throw new KeyNotFoundException("Display does not exist"); + if (!_configurationService.IsExist(id)) + throw new KeyNotFoundException("Configuration does not exist"); - _displayService.Remove(id); + _configurationService.Remove(id); - return new ObjectResult("The display has been deleted") { StatusCode = 202 }; + return new ObjectResult("The configuration has been deleted") { StatusCode = 202 }; } catch (ArgumentNullException ex) diff --git a/ManagerService/Controllers/SectionController.cs b/ManagerService/Controllers/SectionController.cs index 76902e4..1cc8891 100644 --- a/ManagerService/Controllers/SectionController.cs +++ b/ManagerService/Controllers/SectionController.cs @@ -18,12 +18,14 @@ namespace ManagerService.Controllers public class SectionController : ControllerBase { private SectionDatabaseService _sectionService; + private ConfigurationDatabaseService _configurationService; private readonly ILogger _logger; - public SectionController(ILogger logger, SectionDatabaseService sectionService) + public SectionController(ILogger logger, SectionDatabaseService sectionService, ConfigurationDatabaseService configurationService) { _logger = logger; _sectionService = sectionService; + _configurationService = configurationService; } /// @@ -145,10 +147,17 @@ namespace ManagerService.Controllers if (newSection == null) throw new ArgumentNullException("Section param is null"); + if (newSection.ConfigurationId == null) + throw new ArgumentNullException("Configuration param is null"); + + if (!_configurationService.IsExist(newSection.ConfigurationId) ) + throw new KeyNotFoundException("Configuration does not exist"); + // Todo add some verification ? Section section = new Section(); section.Label = newSection.Label; section.ImageId = newSection.ImageId; + section.ConfigurationId = newSection.ConfigurationId; section.DateCreation = DateTime.Now; section.IsSubSection = false; section.ParentId = null; diff --git a/ManagerService/Services/ConfigurationDatabaseService.cs b/ManagerService/Services/ConfigurationDatabaseService.cs new file mode 100644 index 0000000..45e416b --- /dev/null +++ b/ManagerService/Services/ConfigurationDatabaseService.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Manager.Interfaces.Models; +using Microsoft.Extensions.Configuration; +using MongoDB.Driver; + +namespace Manager.Services +{ + public class ConfigurationDatabaseService + { + private readonly IMongoCollection _Configurations; + + public ConfigurationDatabaseService(IConfiguration config) + { + var client = new MongoClient(config.GetConnectionString("TabletDb")); + var database = client.GetDatabase("TabletDb"); + _Configurations = database.GetCollection("Configurations"); + } + public List GetAll() + { + return _Configurations.Find(d => true).ToList(); + } + + public Configuration GetById(string id) + { + return _Configurations.Find(d => d.Id == id).FirstOrDefault(); + } + + public bool IsExist(string id) + { + return _Configurations.Find(d => d.Id == id).FirstOrDefault() != null ? true : false; + } + + public Configuration Create(Configuration configuration) + { + _Configurations.InsertOne(configuration); + return configuration; + } + + public Configuration Update(string id, Configuration configurationIn) + { + _Configurations.ReplaceOne(d => d.Id == id, configurationIn); + return configurationIn; + } + + public void Remove(string id) + { + _Configurations.DeleteOne(d => d.Id == id); + } + + } +} diff --git a/ManagerService/Services/DisplayDatabaseService.cs b/ManagerService/Services/DisplayDatabaseService.cs deleted file mode 100644 index 2fc2acb..0000000 --- a/ManagerService/Services/DisplayDatabaseService.cs +++ /dev/null @@ -1,54 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Manager.Interfaces.Models; -using Microsoft.Extensions.Configuration; -using MongoDB.Driver; - -namespace Manager.Services -{ - public class DisplayDatabaseService - { - private readonly IMongoCollection _Displays; - - public DisplayDatabaseService(IConfiguration config) - { - var client = new MongoClient(config.GetConnectionString("TabletDb")); - var database = client.GetDatabase("TabletDb"); - _Displays = database.GetCollection("Displays"); - } - public List GetAll() - { - return _Displays.Find(d => true).ToList(); - } - - public Display GetById(string id) - { - return _Displays.Find(d => d.Id == id).FirstOrDefault(); - } - - public bool IsExist(string id) - { - return _Displays.Find(d => d.Id == id).FirstOrDefault() != null ? true : false; - } - - public Display Create(Display display) - { - _Displays.InsertOne(display); - return display; - } - - public Display Update(string id, Display displayIn) - { - _Displays.ReplaceOne(d => d.Id == id, displayIn); - return displayIn; - } - - public void Remove(string id) - { - _Displays.DeleteOne(d => d.Id == id); - } - - } -} diff --git a/ManagerService/Startup.cs b/ManagerService/Startup.cs index f1fec68..3d37f57 100644 --- a/ManagerService/Startup.cs +++ b/ManagerService/Startup.cs @@ -102,7 +102,7 @@ namespace ManagerService services.AddScoped(); services.AddScoped(); services.AddScoped(); - services.AddScoped(); + services.AddScoped(); services.AddScoped(); } diff --git a/ManagerService/appsettings.json b/ManagerService/appsettings.json index 3496ab4..ef793a5 100644 --- a/ManagerService/appsettings.json +++ b/ManagerService/appsettings.json @@ -1,6 +1,7 @@ { "ConnectionStrings": { - "TabletDb": "mongodb://admin:MioTech4ever!@localhost:27017" //TO CHANGE + //"TabletDb": "mongodb://admin:MioTech4ever!@localhost:27017", //DEV + "TabletDb": "mongodb://admin:mdlf2021!@192.168.31.96:27017" //PROD }, "Logging": { "LogLevel": {