From 9e54ba1886596c1de836cce509b495681cb91494 Mon Sep 17 00:00:00 2001 From: Thomas Fransolet Date: Wed, 7 Apr 2021 17:52:37 +0200 Subject: [PATCH] Update section info --- Manager.Interfaces/DTO/DisplayDTO.cs | 1 + Manager.Interfaces/DTO/SectionDTO.cs | 4 +- .../DTO/SubSection/{Map.cs => MapDTO.cs} | 21 +-- Manager.Interfaces/DTO/SubSection/Menu.cs | 12 -- Manager.Interfaces/DTO/SubSection/MenuDTO.cs | 12 ++ .../SubSection/{Slider.cs => SliderDTO.cs} | 9 +- .../DTO/SubSection/{Video.cs => VideoDTO.cs} | 6 +- .../DTO/SubSection/{Web.cs => WebDTO.cs} | 6 +- Manager.Interfaces/Models/Section.cs | 10 +- Manager.Interfaces/Models/SubSection/Map.cs | 78 +++++++++++ .../Models/SubSection/Slider.cs | 48 +++++++ .../Controllers/DisplayController.cs | 5 +- .../Controllers/RessourceController.cs | 5 +- .../Controllers/SectionController.cs | 128 +++++++++++++++--- ManagerService/Controllers/UserController.cs | 3 +- ManagerService/ManagerService.csproj | 1 + ManagerService/Startup.cs | 10 +- 17 files changed, 291 insertions(+), 68 deletions(-) rename Manager.Interfaces/DTO/SubSection/{Map.cs => MapDTO.cs} (68%) delete mode 100644 Manager.Interfaces/DTO/SubSection/Menu.cs create mode 100644 Manager.Interfaces/DTO/SubSection/MenuDTO.cs rename Manager.Interfaces/DTO/SubSection/{Slider.cs => SliderDTO.cs} (61%) rename Manager.Interfaces/DTO/SubSection/{Video.cs => VideoDTO.cs} (51%) rename Manager.Interfaces/DTO/SubSection/{Web.cs => WebDTO.cs} (51%) create mode 100644 Manager.Interfaces/Models/SubSection/Map.cs create mode 100644 Manager.Interfaces/Models/SubSection/Slider.cs diff --git a/Manager.Interfaces/DTO/DisplayDTO.cs b/Manager.Interfaces/DTO/DisplayDTO.cs index 045b717..c9bfadd 100644 --- a/Manager.Interfaces/DTO/DisplayDTO.cs +++ b/Manager.Interfaces/DTO/DisplayDTO.cs @@ -11,6 +11,7 @@ namespace Manager.Interfaces.DTO public List SectionIds { get; set; } public string PrimaryColor { get; set; } public string SecondaryColor { get; set; } + public List Languages { get; set; } // fr, en, de, nl => Sélection dans une liste déjà établie dans l'application ! public DateTime DateCreation { get; set; } } } diff --git a/Manager.Interfaces/DTO/SectionDTO.cs b/Manager.Interfaces/DTO/SectionDTO.cs index ee2558f..6b91cc5 100644 --- a/Manager.Interfaces/DTO/SectionDTO.cs +++ b/Manager.Interfaces/DTO/SectionDTO.cs @@ -9,10 +9,12 @@ namespace Manager.Interfaces.DTO { public string Id { get; set; } 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 Data { get; set; } // == RessourceId 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 ! + public string Data { get; set; } // == Include section type info + public DateTime DateCreation { get; set; } // == Include section type info } } diff --git a/Manager.Interfaces/DTO/SubSection/Map.cs b/Manager.Interfaces/DTO/SubSection/MapDTO.cs similarity index 68% rename from Manager.Interfaces/DTO/SubSection/Map.cs rename to Manager.Interfaces/DTO/SubSection/MapDTO.cs index b3f1932..25a1af6 100644 --- a/Manager.Interfaces/DTO/SubSection/Map.cs +++ b/Manager.Interfaces/DTO/SubSection/MapDTO.cs @@ -1,18 +1,19 @@ -using System; +using Manager.Interfaces.Models; +using System; using System.Collections.Generic; using System.Text; -namespace Manager.Interfaces.DTO.SubSection +namespace Manager.Interfaces.DTO { - public class Map + public class MapDTO : SectionDTO { public int Zoom { get; set; } // Default = 18 - public MapType Type { get; set; } // Default = Hybrid - public List Points { get; set; } + public MapType MapType { get; set; } // Default = Hybrid + public List Points { get; set; } public string Icon { get; set; } // url to ressource id (local) or on internet } - public class GeoPoint + public class GeoPointDTO { public int Id { get; set; } public string Title { get; set; } // Dictionary with all languages @@ -22,12 +23,4 @@ namespace Manager.Interfaces.DTO.SubSection public string Latitude { get; set; } public string Longitude { get; set; } } - - public enum MapType { - none, - normal, - satellite, - terrain, - hybrid - } } diff --git a/Manager.Interfaces/DTO/SubSection/Menu.cs b/Manager.Interfaces/DTO/SubSection/Menu.cs deleted file mode 100644 index 102bfd4..0000000 --- a/Manager.Interfaces/DTO/SubSection/Menu.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Manager.Interfaces.DTO.SubSection -{ - public class Menu - { - public string Title { get; set; } // Dictionary with all languages - public List Sections { get; set; } - } -} diff --git a/Manager.Interfaces/DTO/SubSection/MenuDTO.cs b/Manager.Interfaces/DTO/SubSection/MenuDTO.cs new file mode 100644 index 0000000..ca1011f --- /dev/null +++ b/Manager.Interfaces/DTO/SubSection/MenuDTO.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Manager.Interfaces.DTO +{ + public class MenuDTO : SectionDTO + { + //public string Title { get; set; } // Dictionary with all languages + public List Sections { get; set; } + } +} diff --git a/Manager.Interfaces/DTO/SubSection/Slider.cs b/Manager.Interfaces/DTO/SubSection/SliderDTO.cs similarity index 61% rename from Manager.Interfaces/DTO/SubSection/Slider.cs rename to Manager.Interfaces/DTO/SubSection/SliderDTO.cs index 906e6ec..a37b203 100644 --- a/Manager.Interfaces/DTO/SubSection/Slider.cs +++ b/Manager.Interfaces/DTO/SubSection/SliderDTO.cs @@ -2,15 +2,14 @@ using System.Collections.Generic; using System.Text; -namespace Manager.Interfaces.DTO.SubSection +namespace Manager.Interfaces.DTO { - public class Slider + public class SliderDTO : SectionDTO { - public string Title { get; set; } // Dictionary with all languages - public List Images { get; set; } + public List Images { get; set; } } - public class Image { + public class ImageDTO { public string Title { get; set; } // Dictionary with all languages public string Description { get; set; } // Dictionary with all languages public string Source { get; set; } // url to ressource id (local) or on internet diff --git a/Manager.Interfaces/DTO/SubSection/Video.cs b/Manager.Interfaces/DTO/SubSection/VideoDTO.cs similarity index 51% rename from Manager.Interfaces/DTO/SubSection/Video.cs rename to Manager.Interfaces/DTO/SubSection/VideoDTO.cs index 25a37e8..137e73d 100644 --- a/Manager.Interfaces/DTO/SubSection/Video.cs +++ b/Manager.Interfaces/DTO/SubSection/VideoDTO.cs @@ -2,11 +2,11 @@ using System.Collections.Generic; using System.Text; -namespace Manager.Interfaces.DTO.SubSection +namespace Manager.Interfaces.DTO { - public class Video + public class VideoDTO : SectionDTO { - public string Title { get; set; } // Dictionary with all languages + //public string Title { get; set; } // Dictionary with all languages public string Source { get; set; } // url to ressource id (local) or on internet } } diff --git a/Manager.Interfaces/DTO/SubSection/Web.cs b/Manager.Interfaces/DTO/SubSection/WebDTO.cs similarity index 51% rename from Manager.Interfaces/DTO/SubSection/Web.cs rename to Manager.Interfaces/DTO/SubSection/WebDTO.cs index ede322e..1ceb28b 100644 --- a/Manager.Interfaces/DTO/SubSection/Web.cs +++ b/Manager.Interfaces/DTO/SubSection/WebDTO.cs @@ -2,11 +2,11 @@ using System.Collections.Generic; using System.Text; -namespace Manager.Interfaces.DTO.SubSection +namespace Manager.Interfaces.DTO { - public class Web + public class WebDTO : SectionDTO { - public string Title { get; set; } // Dictionary with all languages + //public string Title { get; set; } // Dictionary with all languages public string Source { get; set; } // url to ressource id (local) or on internet } } diff --git a/Manager.Interfaces/Models/Section.cs b/Manager.Interfaces/Models/Section.cs index d797477..e98a5ce 100644 --- a/Manager.Interfaces/Models/Section.cs +++ b/Manager.Interfaces/Models/Section.cs @@ -20,6 +20,9 @@ namespace Manager.Interfaces.Models [BsonRequired] public string Label { get; set; } // Dictionary with all languages + [BsonElement("Description")] + public string Description { get; set; } // Dictionary with all languages + [BsonElement("ImageId")] [BsonRequired] public string ImageId { get; set; } @@ -35,12 +38,13 @@ namespace Manager.Interfaces.Models [BsonElement("ParentId")] public string ParentId { get; set; } // only if it's an subsection - [BsonElement("Data")] - public string Data { get; set; } // Json encapsulated info - [BsonElement("DateCreation")] public DateTime DateCreation { get; set; } + [BsonElement("Data")] + [BsonRequired] + public string Data { get; set; } // Json encapsulated section info + public SectionDTO ToDTO() { return new SectionDTO() diff --git a/Manager.Interfaces/Models/SubSection/Map.cs b/Manager.Interfaces/Models/SubSection/Map.cs new file mode 100644 index 0000000..c62804f --- /dev/null +++ b/Manager.Interfaces/Models/SubSection/Map.cs @@ -0,0 +1,78 @@ +using Manager.Interfaces.DTO; +using MongoDB.Bson.Serialization.Attributes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + + +namespace Manager.Interfaces.Models +{ + /// + /// Section Information - MAP + /// + public class Map : Section + { + [BsonElement("Map")] + [BsonRequired] + public MapType MapType { get; set; } = MapType.hybrid; + + [BsonElement("Zoom")] + public int Zoom { get; set; } = 18; + + [BsonElement("Points")] + public List Points { get; set; } + + [BsonElement("Icon")] + public string Icon { get; set; } // url to ressource id (local) or on internet + + public MapDTO ToDetailDTO() + { + return new MapDTO() + { + Id = Id, + Label = Label, + Type = Type, + ImageId = ImageId, + MapType = MapType, + Zoom = Zoom, + Points = Points.Select(p => p.ToDTO()).ToList(), + Icon = Icon + }; + } + } + + public class GeoPoint + { + public int Id { get; set; } + public string Title { get; set; } // Dictionary with all languages + public string Description { get; set; } // Dictionary with all languages + public string Image { get; set; } // url to ressource id (local) or on internet + public string Text { get; set; } // Dictionary with all languages + public string Latitude { get; set; } + public string Longitude { get; set; } + + public GeoPointDTO ToDTO() + { + return new GeoPointDTO() + { + Id = Id, + Title = Title, + Description = Description, + Image = Image, + Text = Text, + Latitude = Latitude, + Longitude = Longitude + }; + } + } + + public enum MapType + { + none, + normal, + satellite, + terrain, + hybrid + } +} diff --git a/Manager.Interfaces/Models/SubSection/Slider.cs b/Manager.Interfaces/Models/SubSection/Slider.cs new file mode 100644 index 0000000..4d94cef --- /dev/null +++ b/Manager.Interfaces/Models/SubSection/Slider.cs @@ -0,0 +1,48 @@ +using Manager.Interfaces.DTO; +using MongoDB.Bson.Serialization.Attributes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + + +namespace Manager.Interfaces.Models +{ + /// + /// Section Information - Slider + /// + public class Slider : Section + { + [BsonElement("Images")] + public List Images { get; set; } + + public SliderDTO ToDetailDTO() + { + return new SliderDTO() + { + Id = Id, + Label = Label, + Type = Type, + ImageId = ImageId, + Images = Images.Select(p => p.ToDTO()).ToList(), + }; + } + } + + public class Image + { + public string Title { get; set; } // Dictionary with all languages + public string Description { get; set; } // Dictionary with all languages + public string Source { get; set; } // url to ressource id (local) or on internet + + public ImageDTO ToDTO() + { + return new ImageDTO() + { + Title = Title, + Description = Description, + Source = Source + }; + } + } +} diff --git a/ManagerService/Controllers/DisplayController.cs b/ManagerService/Controllers/DisplayController.cs index df12c1e..d980a73 100644 --- a/ManagerService/Controllers/DisplayController.cs +++ b/ManagerService/Controllers/DisplayController.cs @@ -14,8 +14,7 @@ using NSwag.Annotations; namespace ManagerService.Controllers { [Authorize] // TODO Add ROLES (Roles = "Admin") - [Route("[controller]")] - [ApiController] + [ApiController, Route("api/[controller]")] [OpenApiTag("Display", Description = "Display management")] public class DisplayController : ControllerBase { @@ -101,6 +100,7 @@ namespace ManagerService.Controllers display.PrimaryColor = newDisplay.PrimaryColor; display.SecondaryColor = newDisplay.SecondaryColor; display.SectionIds = newDisplay.SectionIds; + display.Languages = newDisplay.Languages; display.DateCreation = DateTime.Now; Display displayCreated = _displayService.Create(display); @@ -147,6 +147,7 @@ namespace ManagerService.Controllers display.Label = updatedDisplay.Label; display.PrimaryColor = updatedDisplay.PrimaryColor; display.SecondaryColor = updatedDisplay.SecondaryColor; + display.Languages = updatedDisplay.Languages; display.SectionIds = updatedDisplay.SectionIds; Display displayModified = _displayService.Update(updatedDisplay.Id, display); diff --git a/ManagerService/Controllers/RessourceController.cs b/ManagerService/Controllers/RessourceController.cs index 4f22449..22ea333 100644 --- a/ManagerService/Controllers/RessourceController.cs +++ b/ManagerService/Controllers/RessourceController.cs @@ -17,8 +17,7 @@ using NSwag.Annotations; namespace ManagerService.Controllers { [Authorize] // TODO Add ROLES (Roles = "Admin") - [Route("[controller]")] - [ApiController] + [ApiController, Route("api/[controller]")] [OpenApiTag("Ressource", Description = "Ressource management")] public class RessourceController : ControllerBase { @@ -119,6 +118,8 @@ namespace ManagerService.Controllers } } + // TODO upload ! + /// /// Create a new ressource /// diff --git a/ManagerService/Controllers/SectionController.cs b/ManagerService/Controllers/SectionController.cs index c426dcc..76902e4 100644 --- a/ManagerService/Controllers/SectionController.cs +++ b/ManagerService/Controllers/SectionController.cs @@ -1,21 +1,19 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Manager.Interfaces.DTO; +using Manager.Interfaces.DTO; using Manager.Interfaces.Models; using Manager.Services; -using ManagerService.Service.Services; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; +using Newtonsoft.Json; using NSwag.Annotations; +using System; +using System.Collections.Generic; +using System.Linq; namespace ManagerService.Controllers { [Authorize] // TODO Add ROLES (Roles = "Admin") - [Route("[controller]")] - [ApiController] + [ApiController, Route("api/[controller]")] [OpenApiTag("Section", Description = "Section management")] public class SectionController : ControllerBase { @@ -52,7 +50,7 @@ namespace ManagerService.Controllers /// Get a list of all subsection (summary) of a specific section /// /// section id - [ProducesResponseType(typeof(List), 200)] + [ProducesResponseType(typeof(List), 200)] [ProducesResponseType(typeof(string), 500)] [HttpGet("{id}/subsections")] public ObjectResult GetAllSectionSubSections(string id) @@ -75,7 +73,7 @@ namespace ManagerService.Controllers /// /// section id [AllowAnonymous] - [ProducesResponseType(typeof(SectionDTO), 200)] + [ProducesResponseType(typeof(object), 200)] [ProducesResponseType(typeof(string), 404)] [ProducesResponseType(typeof(string), 500)] [HttpGet("{id}")] @@ -88,7 +86,38 @@ namespace ManagerService.Controllers if (section == null) throw new KeyNotFoundException("This section was not found"); - return new OkObjectResult(section.ToDTO()); + switch (section.Type) { + case SectionType.Map: + MapDTO mapDTO = JsonConvert.DeserializeObject(section.Data); + mapDTO.Id = section.Id; + mapDTO.Label = section.Label; + mapDTO.Description = section.Description; + mapDTO.Type = section.Type; + mapDTO.ImageId = section.ImageId; + mapDTO.IsSubSection = section.IsSubSection; + mapDTO.DateCreation = section.DateCreation; + mapDTO.Data = section.Data; + return new OkObjectResult(mapDTO); + case SectionType.Slider: + SliderDTO sliderDTO = JsonConvert.DeserializeObject(section.Data); + sliderDTO.Id = section.Id; + sliderDTO.Label = section.Label; + sliderDTO.Description = section.Description; + sliderDTO.Type = section.Type; + sliderDTO.ImageId = section.ImageId; + sliderDTO.IsSubSection = section.IsSubSection; + sliderDTO.DateCreation = section.DateCreation; + sliderDTO.Data = section.Data; + return new OkObjectResult(section.ToDTO()); + case SectionType.Menu: + return new OkObjectResult(section.ToDTO()); + case SectionType.Web: + return new OkObjectResult(section.ToDTO()); + case SectionType.Video: + return new OkObjectResult(section.ToDTO()); + default: + return new OkObjectResult(section.ToDTO()); + } } catch (KeyNotFoundException ex) { @@ -108,7 +137,7 @@ namespace ManagerService.Controllers [ProducesResponseType(typeof(string), 400)] [ProducesResponseType(typeof(string), 409)] [ProducesResponseType(typeof(string), 500)] - [HttpPost] + [HttpPost()] public ObjectResult Create([FromBody] SectionDTO newSection) { try @@ -120,11 +149,26 @@ namespace ManagerService.Controllers Section section = new Section(); section.Label = newSection.Label; section.ImageId = newSection.ImageId; - section.IsSubSection = newSection.IsSubSection; - section.ParentId = newSection.ParentId; - section.Type = newSection.Type; - section.Data = newSection.Data; section.DateCreation = DateTime.Now; + section.IsSubSection = false; + section.ParentId = null; + section.Type = newSection.Type; + + section.Data = newSection.Data; // Include all info from specific section as JSON + + /*section.MapType = newSectionMap.MapType; + section.Zoom = newSectionMap.Zoom; + section.Icon = newSectionMap.Icon; + section.Points = newSectionMap.Points.Select(p => + new GeoPoint() { + Id = p.Id, + Title = p.Title, + Description = p.Description, + Image = p.Image, + Text = p.Text, + Latitude = p.Latitude, + Longitude = p.Longitude + }).ToList();*/ Section sectionCreated = _sectionService.Create(section); @@ -144,6 +188,57 @@ namespace ManagerService.Controllers } } + /*/// + /// Create a new section - slider + /// + /// New section info - slider + [ProducesResponseType(typeof(SliderDTO), 200)] + [ProducesResponseType(typeof(string), 400)] + [ProducesResponseType(typeof(string), 409)] + [ProducesResponseType(typeof(string), 500)] + [HttpPost("Slider")] + public ObjectResult CreateSlider([FromBody] SliderDTO newSectionSlider) + { + try + { + if (newSectionSlider == null) + throw new ArgumentNullException("Section param is null"); + + // Todo add some verification ? + Slider sliderSection = new Slider(); + sliderSection.Label = newSectionSlider.Label; + sliderSection.ImageId = newSectionSlider.ImageId; + sliderSection.DateCreation = DateTime.Now; + + sliderSection.IsSubSection = false; + sliderSection.ParentId = null; + sliderSection.Type = SectionType.Slider; + + sliderSection.Images = newSectionSlider.Images.Select(p => + new Image() + { + Title = p.Title, + Description = p.Description, + Source = p.Source, + }).ToList(); + + Slider sectionCreated = _sectionService.CreateSlider(sliderSection); + + return new OkObjectResult(sectionCreated.ToDTO()); + } + catch (ArgumentNullException ex) + { + return new BadRequestObjectResult(ex.Message) { }; + } + catch (InvalidOperationException ex) + { + return new ConflictObjectResult(ex.Message) { }; + } + catch (Exception ex) + { + return new ObjectResult(ex.Message) { StatusCode = 500 }; + } + }*/ /// /// Update a section @@ -172,7 +267,6 @@ namespace ManagerService.Controllers section.IsSubSection = updatedSection.IsSubSection; section.ParentId = updatedSection.ParentId; section.Type = updatedSection.Type; - section.Data = updatedSection.Data; Section sectionModified = _sectionService.Update(updatedSection.Id, section); diff --git a/ManagerService/Controllers/UserController.cs b/ManagerService/Controllers/UserController.cs index a0764c2..d5840ef 100644 --- a/ManagerService/Controllers/UserController.cs +++ b/ManagerService/Controllers/UserController.cs @@ -14,8 +14,7 @@ using NSwag.Annotations; namespace ManagerService.Controllers { [Authorize] // TODO Add ROLES (Roles = "Admin") - [Route("[controller]")] - [ApiController] + [ApiController, Route("api/[controller]")] [OpenApiTag("User", Description = "User management")] public class UserController : ControllerBase { diff --git a/ManagerService/ManagerService.csproj b/ManagerService/ManagerService.csproj index 59c045a..a90c988 100644 --- a/ManagerService/ManagerService.csproj +++ b/ManagerService/ManagerService.csproj @@ -9,6 +9,7 @@ + diff --git a/ManagerService/Startup.cs b/ManagerService/Startup.cs index ba7385c..f1fec68 100644 --- a/ManagerService/Startup.cs +++ b/ManagerService/Startup.cs @@ -98,10 +98,12 @@ namespace ManagerService }; }); - services.AddScoped(); services.AddScoped(typeof(ProfileLogic)); - + services.AddScoped(); services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. @@ -159,8 +161,8 @@ namespace ManagerService config.PostProcess = document => { document.Info.Title = "Manager Service"; - document.Info.Description = "API description"; - document.Info.Version = "Version Pre-Alpha"; + document.Info.Description = "API Manager Service"; + document.Info.Version = "Version Alpha"; }; }