wip section controller

This commit is contained in:
Thomas Fransolet 2025-03-20 17:52:45 +01:00
parent 9aa5e7df5e
commit a4bde1a8f4
7 changed files with 1266 additions and 97 deletions

View File

@ -1,5 +1,6 @@
using Manager.DTOs; using Manager.DTOs;
using Manager.Helpers; using Manager.Helpers;
using Manager.Interfaces.Models;
using Manager.Services; using Manager.Services;
using ManagerService.Data; using ManagerService.Data;
using ManagerService.Data.SubSection; using ManagerService.Data.SubSection;
@ -14,7 +15,9 @@ using Newtonsoft.Json;
using NSwag.Annotations; using NSwag.Annotations;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq; using System.Linq;
using System.Text.Json;
namespace ManagerService.Controllers namespace ManagerService.Controllers
{ {
@ -46,13 +49,17 @@ namespace ManagerService.Controllers
/// <param name="id">id instance</param> /// <param name="id">id instance</param>
[ProducesResponseType(typeof(List<SectionDTO>), 200)] [ProducesResponseType(typeof(List<SectionDTO>), 200)]
[ProducesResponseType(typeof(string), 500)] [ProducesResponseType(typeof(string), 500)]
[ProducesResponseType(typeof(string), 400)]
[HttpGet] [HttpGet]
public ObjectResult Get([FromQuery] string instanceId) public ObjectResult Get([FromQuery] string instanceId)
{ {
try try
{ {
if (instanceId == null)
throw new ArgumentNullException("Param is null");
//List<OldSection> sections = _sectionService.GetAll(instanceId); //List<OldSection> sections = _sectionService.GetAll(instanceId);
List<Section> sections = _myInfoMateDbContext.Sections.ToList(); List<Section> sections = _myInfoMateDbContext.Sections.Where(s => s.InstanceId == instanceId).ToList();
/* CLEAN ARTICLE AUDIO - Init new field AudioIds */ /* CLEAN ARTICLE AUDIO - Init new field AudioIds */
@ -202,7 +209,9 @@ namespace ManagerService.Controllers
if (section == null) if (section == null)
throw new KeyNotFoundException("This section was not found"); throw new KeyNotFoundException("This section was not found");
return new OkObjectResult(section.ToDTO()); var dto = SectionFactory.ToDTO(section);
return new OkObjectResult(dto);
/*switch (section.Type) { /*switch (section.Type) {
case SectionType.Map: case SectionType.Map:
MapDTO mapDTO = JsonConvert.DeserializeObject<MapDTO>(section.Data); MapDTO mapDTO = JsonConvert.DeserializeObject<MapDTO>(section.Data);
@ -295,21 +304,16 @@ namespace ManagerService.Controllers
if (newSection.configurationId == null) if (newSection.configurationId == null)
throw new ArgumentNullException("Configuration param is null"); throw new ArgumentNullException("Configuration param is null");
if (!_configurationService.IsExist(newSection.configurationId) ) var configuration = _myInfoMateDbContext.Configurations.FirstOrDefault(c => c.Id == newSection.configurationId);
if (configuration == null)
throw new KeyNotFoundException("Configuration does not exist"); throw new KeyNotFoundException("Configuration does not exist");
// Todo add some verification ? // Todo add some verification ?
Section section = SectionFactory.Create(newSection); Section section = new Section();
// Preparation // Preparation
List<string> languages = _configuration.GetSection("SupportedLanguages").Get<List<string>>(); List<string> languages = _configuration.GetSection("SupportedLanguages").Get<List<string>>();
var contentArticle = new List<Translation>();
section.Title = LanguageInit.Init("Title", languages);
section.Description = LanguageInit.Init("Description", languages);
contentArticle = LanguageInit.Init("Content", languages);
switch (newSection.type) { switch (newSection.type) {
case SectionType.Map: case SectionType.Map:
section = new SectionMap section = new SectionMap
@ -357,7 +361,7 @@ namespace ManagerService.Controllers
section = new SectionArticle section = new SectionArticle
{ {
ArticleContents = new List<Content>(), ArticleContents = new List<Content>(),
ArticleContent = contentArticle, ArticleContent = LanguageInit.Init("Content", languages),
ArticleAudioIds = LanguageInit.Init("Audio", languages, true) ArticleAudioIds = LanguageInit.Init("Audio", languages, true)
}; };
break; break;
@ -394,11 +398,8 @@ namespace ManagerService.Controllers
section.IsSubSection = newSection.isSubSection; section.IsSubSection = newSection.isSubSection;
section.ParentId = newSection.parentId; section.ParentId = newSection.parentId;
section.Type = newSection.type; section.Type = newSection.type;
section.Title = new List<Translation>();
section.Description = new List<Translation>();
section.Order = _myInfoMateDbContext.Sections.Count(s => s.ConfigurationId == newSection.configurationId && !s.IsSubSection); section.Order = _myInfoMateDbContext.Sections.Count(s => s.ConfigurationId == newSection.configurationId && !s.IsSubSection)+1;
//section.Order = _sectionService.GetAllFromConfiguration(newSection.configurationId).Count;
section.IsBeacon = newSection.isBeacon; section.IsBeacon = newSection.isBeacon;
section.BeaconId = newSection.beaconId; section.BeaconId = newSection.beaconId;
@ -406,45 +407,10 @@ namespace ManagerService.Controllers
section.Longitude = newSection.longitude; section.Longitude = newSection.longitude;
section.MeterZoneGPS = newSection.meterZoneGPS; section.MeterZoneGPS = newSection.meterZoneGPS;
/*foreach (var language in languages) section.Title = LanguageInit.Init("Title", languages);
{ section.Description = LanguageInit.Init("Description", languages);
TranslationDTO title = new TranslationDTO();
TranslationDTO description = new TranslationDTO();
TranslationDTO content = new TranslationDTO();
title.language = language.ToUpper();
description.language = language.ToUpper();
content.language = language.ToUpper();
switch (language.ToUpper())
{
case "FR":
title.value = "Titre en français";
description.value = "Description en français";
content.value = "Contenu en français";
break;
case "EN":
title.value = "Title in english";
description.value = "Description en anglais";
content.value = "Contenu en anglais";
break;
case "NL":
title.value = "Titre in dutch";
description.value = "Description en néerlandais";
content.value = "Contenu en néerlandais";
break;
case "DE":
title.value = "Titre en allemand";
description.value = "Description en allemand";
content.value = "Contenu en allemand";
break;
}
section.Title.Add(title);
section.Description.Add(description);
contentArticle.Add(content);
}*/
section.Title = section.Title.OrderBy(t => t.Language).ToList();
section.Description = section.Description.OrderBy(d => d.Language).ToList();
section.Id = idService.GenerateHexId();
//_sectionService.Create(section); //_sectionService.Create(section);
_myInfoMateDbContext.Add(section); _myInfoMateDbContext.Add(section);
_myInfoMateDbContext.SaveChanges(); _myInfoMateDbContext.SaveChanges();
@ -526,23 +492,36 @@ namespace ManagerService.Controllers
[ProducesResponseType(typeof(string), 404)] [ProducesResponseType(typeof(string), 404)]
[ProducesResponseType(typeof(string), 500)] [ProducesResponseType(typeof(string), 500)]
[HttpPut] [HttpPut]
public ObjectResult Update([FromBody] SectionDTO updatedSection) public ObjectResult Update([FromBody] dynamic updatedSection)
{ {
try try
{ {
if (updatedSection == null) if (updatedSection.ValueKind == JsonValueKind.Null)
throw new ArgumentNullException("Section param is null"); throw new ArgumentNullException("Section param is null");
//OldSection section = _sectionService.GetById(updatedSection.id); SectionDTO sectionDTO;
Section existingSection = _myInfoMateDbContext.Sections.FirstOrDefault(s => s.Id == updatedSection.id); if (updatedSection is JsonElement jsonElement)
{
if (jsonElement.ValueKind == JsonValueKind.Null)
throw new ArgumentNullException("Section param is null");
// Désérialisation de jsonElement en SectionDTO
sectionDTO = JsonConvert.DeserializeObject<SectionDTO>(jsonElement.ToString());
}
else
{
throw new InvalidOperationException("Expected a JsonElement");
}
Section existingSection = _myInfoMateDbContext.Sections.FirstOrDefault(s => s.Id == sectionDTO.id);
if (existingSection == null) if (existingSection == null)
throw new KeyNotFoundException("Section does not exist"); throw new KeyNotFoundException("Section does not exist");
if (existingSection.Type != updatedSection.type) if (existingSection.Type != sectionDTO.type)
return BadRequest("Type mismatch: cannot change section type"); return BadRequest("Type mismatch: cannot change section type");
var updatedSectionDB = SectionFactory.Create(updatedSection); var updatedSectionDB = SectionFactory.Create(updatedSection, sectionDTO);
// Todo add some verification ? // Todo add some verification ?
/*section.InstanceId = updatedSection.instanceId; /*section.InstanceId = updatedSection.instanceId;
@ -583,7 +562,7 @@ namespace ManagerService.Controllers
// Ajoute d'autres types ici // Ajoute d'autres types ici
} }
_myInfoMateDbContext.Entry(existingSection).CurrentValues.SetValues(updatedSection); _myInfoMateDbContext.Entry(existingSection).CurrentValues.SetValues(updatedSectionDB);
_myInfoMateDbContext.SaveChanges(); _myInfoMateDbContext.SaveChanges();
//Section sectionModified = _sectionService.Update(updatedSection.id, section); //Section sectionModified = _sectionService.Update(updatedSection.id, section);

View File

@ -1,5 +1,4 @@
using ManagerService.Data; using System;
using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace ManagerService.DTOs namespace ManagerService.DTOs

View File

@ -33,10 +33,8 @@ namespace ManagerService.Data
[Required] [Required]
public string ConfigurationId { get; set; } // Parent id public string ConfigurationId { get; set; } // Parent id
[Required]
public string ImageId { get; set; } public string ImageId { get; set; }
[Required]
public string ImageSource { get; set; } public string ImageSource { get; set; }
[Required] [Required]

View File

@ -0,0 +1,815 @@
// <auto-generated />
using System;
using System.Collections.Generic;
using Manager.DTOs;
using ManagerService.DTOs;
using ManagerService.Data;
using ManagerService.Data.SubSection;
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("20250320154439_UpdateMix1")]
partial class UpdateMix1
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "9.0.2")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("ManagerService.Data.Configuration", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<DateTime>("DateCreation")
.HasColumnType("timestamp with time zone");
b.Property<string>("ImageId")
.HasColumnType("text");
b.Property<string>("ImageSource")
.HasColumnType("text");
b.Property<string>("InstanceId")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("IsDate")
.HasColumnType("boolean");
b.Property<bool>("IsHour")
.HasColumnType("boolean");
b.Property<bool>("IsMobile")
.HasColumnType("boolean");
b.Property<bool>("IsOffline")
.HasColumnType("boolean");
b.Property<bool>("IsSectionImageBackground")
.HasColumnType("boolean");
b.Property<bool>("IsTablet")
.HasColumnType("boolean");
b.Property<string>("Label")
.IsRequired()
.HasColumnType("text");
b.PrimitiveCollection<List<string>>("Languages")
.HasColumnType("text[]");
b.Property<string>("LoaderImageId")
.HasColumnType("text");
b.Property<string>("LoaderImageUrl")
.HasColumnType("text");
b.Property<string>("PrimaryColor")
.HasColumnType("text");
b.Property<int?>("RoundedValue")
.HasColumnType("integer");
b.Property<int?>("ScreenPercentageSectionsMainPage")
.HasColumnType("integer");
b.Property<string>("SecondaryColor")
.HasColumnType("text");
b.Property<List<Translation>>("Title")
.IsRequired()
.HasColumnType("jsonb");
b.HasKey("Id");
b.ToTable("Configurations");
});
modelBuilder.Entity("ManagerService.Data.Device", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("BatteryLevel")
.HasColumnType("text");
b.Property<string>("ConfigurationId")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("Connected")
.HasColumnType("boolean");
b.Property<string>("ConnectionLevel")
.HasColumnType("text");
b.Property<DateTime>("DateCreation")
.HasColumnType("timestamp with time zone");
b.Property<DateTime>("DateUpdate")
.HasColumnType("timestamp with time zone");
b.Property<string>("Identifier")
.HasColumnType("text");
b.Property<string>("InstanceId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("IpAddressETH")
.IsRequired()
.HasColumnType("text");
b.Property<string>("IpAddressWLAN")
.IsRequired()
.HasColumnType("text");
b.Property<DateTime>("LastBatteryLevel")
.HasColumnType("timestamp with time zone");
b.Property<DateTime>("LastConnectionLevel")
.HasColumnType("timestamp with time zone");
b.Property<string>("Name")
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("ConfigurationId");
b.ToTable("Devices");
});
modelBuilder.Entity("ManagerService.Data.Instance", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<DateTime>("DateCreation")
.HasColumnType("timestamp with time zone");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<string>("PinCode")
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Instances");
});
modelBuilder.Entity("ManagerService.Data.Resource", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<DateTime>("DateCreation")
.HasColumnType("timestamp with time zone");
b.Property<string>("InstanceId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Label")
.IsRequired()
.HasColumnType("text");
b.Property<int>("Type")
.HasColumnType("integer");
b.Property<string>("Url")
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Resources");
});
modelBuilder.Entity("ManagerService.Data.Section", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<int?>("BeaconId")
.HasColumnType("integer");
b.Property<string>("ConfigurationId")
.IsRequired()
.HasColumnType("text");
b.Property<DateTime>("DateCreation")
.HasColumnType("timestamp with time zone");
b.Property<List<Translation>>("Description")
.HasColumnType("jsonb");
b.Property<string>("Discriminator")
.IsRequired()
.HasMaxLength(8)
.HasColumnType("character varying(8)");
b.Property<string>("ImageId")
.HasColumnType("text");
b.Property<string>("ImageSource")
.HasColumnType("text");
b.Property<string>("InstanceId")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("IsBeacon")
.HasColumnType("boolean");
b.Property<bool>("IsSubSection")
.HasColumnType("boolean");
b.Property<string>("Label")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Latitude")
.HasColumnType("text");
b.Property<string>("Longitude")
.HasColumnType("text");
b.Property<int?>("MeterZoneGPS")
.HasColumnType("integer");
b.Property<int>("Order")
.HasColumnType("integer");
b.Property<string>("ParentId")
.HasColumnType("text");
b.Property<string>("SectionMenuId")
.HasColumnType("text");
b.Property<List<Translation>>("Title")
.IsRequired()
.HasColumnType("jsonb");
b.Property<int>("Type")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("SectionMenuId");
b.ToTable("Sections");
b.HasDiscriminator().HasValue("Base");
b.UseTphMappingStrategy();
});
modelBuilder.Entity("ManagerService.Data.SubSection.Categorie", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Icon")
.HasColumnType("text");
b.Property<List<Translation>>("Label")
.IsRequired()
.HasColumnType("jsonb");
b.Property<int?>("Order")
.HasColumnType("integer");
b.Property<string>("ResourceId")
.HasColumnType("text");
b.Property<string>("SectionMapId")
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("ResourceId");
b.HasIndex("SectionMapId");
b.ToTable("Categorie");
});
modelBuilder.Entity("ManagerService.Data.SubSection.Content", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<List<Translation>>("Description")
.IsRequired()
.HasColumnType("jsonb");
b.Property<int>("Order")
.HasColumnType("integer");
b.Property<string>("ResourceId")
.HasColumnType("text");
b.Property<string>("SectionArticleId")
.HasColumnType("text");
b.Property<string>("SectionSliderId")
.HasColumnType("text");
b.Property<List<Translation>>("Title")
.IsRequired()
.HasColumnType("jsonb");
b.HasKey("Id");
b.HasIndex("ResourceId");
b.HasIndex("SectionArticleId");
b.HasIndex("SectionSliderId");
b.ToTable("Content");
});
modelBuilder.Entity("ManagerService.Data.SubSection.GeoPoint", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int?>("CategorieId")
.HasColumnType("integer");
b.Property<List<Resource>>("Contents")
.IsRequired()
.HasColumnType("jsonb");
b.Property<List<Translation>>("Description")
.IsRequired()
.HasColumnType("jsonb");
b.Property<List<TranslationDTO>>("Email")
.IsRequired()
.HasColumnType("jsonb");
b.Property<string>("ImageResourceId")
.HasColumnType("text");
b.Property<string>("ImageUrl")
.HasColumnType("text");
b.Property<string>("Latitude")
.HasColumnType("text");
b.Property<string>("Longitude")
.HasColumnType("text");
b.Property<List<TranslationDTO>>("Phone")
.IsRequired()
.HasColumnType("jsonb");
b.Property<List<TranslationDTO>>("Prices")
.IsRequired()
.HasColumnType("jsonb");
b.Property<List<TranslationDTO>>("Schedules")
.IsRequired()
.HasColumnType("jsonb");
b.Property<string>("SectionMapId")
.HasColumnType("text");
b.Property<List<TranslationDTO>>("Site")
.IsRequired()
.HasColumnType("jsonb");
b.Property<List<Translation>>("Title")
.IsRequired()
.HasColumnType("jsonb");
b.HasKey("Id");
b.HasIndex("SectionMapId");
b.ToTable("GeoPoint");
});
modelBuilder.Entity("ManagerService.Data.SubSection.OrderedTranslationAndResource", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("Order")
.HasColumnType("integer");
b.Property<string>("SectionPdfId")
.HasColumnType("text");
b.Property<List<TranslationAndResource>>("TranslationAndResources")
.IsRequired()
.HasColumnType("jsonb");
b.HasKey("Id");
b.HasIndex("SectionPdfId");
b.ToTable("OrderedTranslationAndResource");
});
modelBuilder.Entity("ManagerService.Data.SubSection.QuizQuestion", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<List<TranslationAndResourceDTO>>("Label")
.IsRequired()
.HasColumnType("jsonb");
b.Property<int>("Order")
.HasColumnType("integer");
b.Property<string>("ResourceId")
.HasColumnType("text");
b.Property<List<ResponseDTO>>("Responses")
.IsRequired()
.HasColumnType("jsonb");
b.Property<string>("SectionQuizId")
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("ResourceId");
b.HasIndex("SectionQuizId");
b.ToTable("QuizQuestion");
});
modelBuilder.Entity("ManagerService.Data.User", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<DateTime>("DateCreation")
.HasColumnType("timestamp with time zone");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("text");
b.Property<string>("FirstName")
.HasColumnType("text");
b.Property<string>("InstanceId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("LastName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Token")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Users");
});
modelBuilder.Entity("ManagerService.Data.SubSection.SectionAgenda", b =>
{
b.HasBaseType("ManagerService.Data.Section");
b.Property<int?>("AgendaMapProvider")
.HasColumnType("integer");
b.Property<List<Translation>>("AgendaResourceIds")
.IsRequired()
.HasColumnType("jsonb");
b.HasDiscriminator().HasValue("Agenda");
});
modelBuilder.Entity("ManagerService.Data.SubSection.SectionArticle", b =>
{
b.HasBaseType("ManagerService.Data.Section");
b.Property<List<Translation>>("ArticleAudioIds")
.IsRequired()
.HasColumnType("jsonb");
b.Property<List<Translation>>("ArticleContent")
.IsRequired()
.HasColumnType("jsonb");
b.Property<bool>("ArticleIsContentTop")
.HasColumnType("boolean");
b.Property<bool>("ArticleIsReadAudioAuto")
.HasColumnType("boolean");
b.HasDiscriminator().HasValue("Article");
});
modelBuilder.Entity("ManagerService.Data.SubSection.SectionMap", b =>
{
b.HasBaseType("ManagerService.Data.Section");
b.Property<string>("MapCenterLatitude")
.HasColumnType("text");
b.Property<string>("MapCenterLongitude")
.HasColumnType("text");
b.Property<int?>("MapMapProvider")
.HasColumnType("integer");
b.Property<int?>("MapMapType")
.HasColumnType("integer");
b.Property<string>("MapResourceId")
.HasColumnType("text");
b.Property<int?>("MapTypeMapbox")
.HasColumnType("integer");
b.Property<int>("MapZoom")
.HasColumnType("integer");
b.HasIndex("MapResourceId");
b.HasDiscriminator().HasValue("Map");
});
modelBuilder.Entity("ManagerService.Data.SubSection.SectionMenu", b =>
{
b.HasBaseType("ManagerService.Data.Section");
b.HasDiscriminator().HasValue("Menu");
});
modelBuilder.Entity("ManagerService.Data.SubSection.SectionPdf", b =>
{
b.HasBaseType("ManagerService.Data.Section");
b.HasDiscriminator().HasValue("PDF");
});
modelBuilder.Entity("ManagerService.Data.SubSection.SectionPuzzle", b =>
{
b.HasBaseType("ManagerService.Data.Section");
b.Property<int>("PuzzleCols")
.HasColumnType("integer");
b.Property<string>("PuzzleImageId")
.HasColumnType("text");
b.Property<List<TranslationAndResource>>("PuzzleMessageDebut")
.IsRequired()
.HasColumnType("jsonb");
b.Property<List<TranslationAndResource>>("PuzzleMessageFin")
.IsRequired()
.HasColumnType("jsonb");
b.Property<int>("PuzzleRows")
.HasColumnType("integer");
b.HasIndex("PuzzleImageId");
b.HasDiscriminator().HasValue("Puzzle");
});
modelBuilder.Entity("ManagerService.Data.SubSection.SectionQuiz", b =>
{
b.HasBaseType("ManagerService.Data.Section");
b.Property<List<TranslationAndResource>>("QuizBadLevel")
.IsRequired()
.HasColumnType("jsonb");
b.Property<List<TranslationAndResource>>("QuizGoodLevel")
.IsRequired()
.HasColumnType("jsonb");
b.Property<List<TranslationAndResource>>("QuizGreatLevel")
.IsRequired()
.HasColumnType("jsonb");
b.Property<List<TranslationAndResource>>("QuizMediumLevel")
.IsRequired()
.HasColumnType("jsonb");
b.HasDiscriminator().HasValue("Quiz");
});
modelBuilder.Entity("ManagerService.Data.SubSection.SectionSlider", b =>
{
b.HasBaseType("ManagerService.Data.Section");
b.HasDiscriminator().HasValue("Slider");
});
modelBuilder.Entity("ManagerService.Data.SubSection.SectionVideo", b =>
{
b.HasBaseType("ManagerService.Data.Section");
b.Property<string>("VideoSource")
.IsRequired()
.HasColumnType("text");
b.HasDiscriminator().HasValue("Video");
});
modelBuilder.Entity("ManagerService.Data.SubSection.SectionWeather", b =>
{
b.HasBaseType("ManagerService.Data.Section");
b.Property<string>("WeatherCity")
.HasColumnType("text");
b.Property<string>("WeatherResult")
.HasColumnType("text");
b.Property<DateTimeOffset?>("WeatherUpdatedDate")
.HasColumnType("timestamp with time zone");
b.HasDiscriminator().HasValue("Weather");
});
modelBuilder.Entity("ManagerService.Data.SubSection.SectionWeb", b =>
{
b.HasBaseType("ManagerService.Data.Section");
b.Property<string>("WebSource")
.IsRequired()
.HasColumnType("text");
b.HasDiscriminator().HasValue("Web");
});
modelBuilder.Entity("ManagerService.Data.Device", b =>
{
b.HasOne("ManagerService.Data.Configuration", "Configuration")
.WithMany()
.HasForeignKey("ConfigurationId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Configuration");
});
modelBuilder.Entity("ManagerService.Data.Section", b =>
{
b.HasOne("ManagerService.Data.SubSection.SectionMenu", null)
.WithMany("MenuSections")
.HasForeignKey("SectionMenuId");
});
modelBuilder.Entity("ManagerService.Data.SubSection.Categorie", b =>
{
b.HasOne("ManagerService.Data.Resource", "Resource")
.WithMany()
.HasForeignKey("ResourceId");
b.HasOne("ManagerService.Data.SubSection.SectionMap", null)
.WithMany("MapCategories")
.HasForeignKey("SectionMapId");
b.Navigation("Resource");
});
modelBuilder.Entity("ManagerService.Data.SubSection.Content", b =>
{
b.HasOne("ManagerService.Data.Resource", "Resource")
.WithMany()
.HasForeignKey("ResourceId");
b.HasOne("ManagerService.Data.SubSection.SectionArticle", null)
.WithMany("ArticleContents")
.HasForeignKey("SectionArticleId");
b.HasOne("ManagerService.Data.SubSection.SectionSlider", null)
.WithMany("SliderContents")
.HasForeignKey("SectionSliderId");
b.Navigation("Resource");
});
modelBuilder.Entity("ManagerService.Data.SubSection.GeoPoint", b =>
{
b.HasOne("ManagerService.Data.SubSection.SectionMap", null)
.WithMany("MapPoints")
.HasForeignKey("SectionMapId");
});
modelBuilder.Entity("ManagerService.Data.SubSection.OrderedTranslationAndResource", b =>
{
b.HasOne("ManagerService.Data.SubSection.SectionPdf", null)
.WithMany("PDFOrderedTranslationAndResources")
.HasForeignKey("SectionPdfId");
});
modelBuilder.Entity("ManagerService.Data.SubSection.QuizQuestion", b =>
{
b.HasOne("ManagerService.Data.Resource", "Resource")
.WithMany()
.HasForeignKey("ResourceId");
b.HasOne("ManagerService.Data.SubSection.SectionQuiz", null)
.WithMany("QuizQuestions")
.HasForeignKey("SectionQuizId");
b.Navigation("Resource");
});
modelBuilder.Entity("ManagerService.Data.SubSection.SectionMap", b =>
{
b.HasOne("ManagerService.Data.Resource", "MapResource")
.WithMany()
.HasForeignKey("MapResourceId");
b.Navigation("MapResource");
});
modelBuilder.Entity("ManagerService.Data.SubSection.SectionPuzzle", b =>
{
b.HasOne("ManagerService.Data.Resource", "PuzzleImage")
.WithMany()
.HasForeignKey("PuzzleImageId");
b.Navigation("PuzzleImage");
});
modelBuilder.Entity("ManagerService.Data.SubSection.SectionArticle", b =>
{
b.Navigation("ArticleContents");
});
modelBuilder.Entity("ManagerService.Data.SubSection.SectionMap", b =>
{
b.Navigation("MapCategories");
b.Navigation("MapPoints");
});
modelBuilder.Entity("ManagerService.Data.SubSection.SectionMenu", b =>
{
b.Navigation("MenuSections");
});
modelBuilder.Entity("ManagerService.Data.SubSection.SectionPdf", b =>
{
b.Navigation("PDFOrderedTranslationAndResources");
});
modelBuilder.Entity("ManagerService.Data.SubSection.SectionQuiz", b =>
{
b.Navigation("QuizQuestions");
});
modelBuilder.Entity("ManagerService.Data.SubSection.SectionSlider", b =>
{
b.Navigation("SliderContents");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,54 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace ManagerService.Migrations
{
/// <inheritdoc />
public partial class UpdateMix1 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "ImageSource",
table: "Sections",
type: "text",
nullable: true,
oldClrType: typeof(string),
oldType: "text");
migrationBuilder.AlterColumn<string>(
name: "ImageId",
table: "Sections",
type: "text",
nullable: true,
oldClrType: typeof(string),
oldType: "text");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "ImageSource",
table: "Sections",
type: "text",
nullable: false,
defaultValue: "",
oldClrType: typeof(string),
oldType: "text",
oldNullable: true);
migrationBuilder.AlterColumn<string>(
name: "ImageId",
table: "Sections",
type: "text",
nullable: false,
defaultValue: "",
oldClrType: typeof(string),
oldType: "text",
oldNullable: true);
}
}
}

View File

@ -222,11 +222,9 @@ namespace ManagerService.Migrations
.HasColumnType("character varying(8)"); .HasColumnType("character varying(8)");
b.Property<string>("ImageId") b.Property<string>("ImageId")
.IsRequired()
.HasColumnType("text"); .HasColumnType("text");
b.Property<string>("ImageSource") b.Property<string>("ImageSource")
.IsRequired()
.HasColumnType("text"); .HasColumnType("text");
b.Property<string>("InstanceId") b.Property<string>("InstanceId")

View File

@ -2,20 +2,74 @@
using ManagerService.Data; using ManagerService.Data;
using ManagerService.Data.SubSection; using ManagerService.Data.SubSection;
using ManagerService.DTOs; using ManagerService.DTOs;
using MongoDB.Bson;
using Newtonsoft.Json;
using System; using System;
using System.Linq; using System.Linq;
using System.Text.Json;
namespace ManagerService.Services namespace ManagerService.Services
{ {
public static class SectionFactory public static class SectionFactory
{ {
public static Section Create(SectionDTO dto) public static Section Create(JsonElement jsonElement, SectionDTO dto)
{ {
AgendaDTO agendaDTO = new AgendaDTO();
ArticleDTO articleDTO = new ArticleDTO();
MapDTO mapDTO = new MapDTO();
MenuDTO menuDTO = new MenuDTO();
PdfDTO pdfDTO = new PdfDTO();
PuzzleDTO puzzleDTO = new PuzzleDTO();
QuizDTO quizDTO = new QuizDTO();
SliderDTO sliderDTO = new SliderDTO();
VideoDTO videoDTO = new VideoDTO();
WeatherDTO weatherDTO = new WeatherDTO();
WebDTO webDTO = new WebDTO();
switch (dto.type)
{
case SectionType.Agenda:
agendaDTO = JsonConvert.DeserializeObject<AgendaDTO>(jsonElement.ToString());
break;
case SectionType.Article:
articleDTO = JsonConvert.DeserializeObject<ArticleDTO>(jsonElement.ToString());
break;
case SectionType.Map:
mapDTO = JsonConvert.DeserializeObject<MapDTO>(jsonElement.ToString());
break;
case SectionType.Menu:
menuDTO = JsonConvert.DeserializeObject<MenuDTO>(jsonElement.ToString());
break;
case SectionType.PDF:
pdfDTO = JsonConvert.DeserializeObject<PdfDTO>(jsonElement.ToString());
break;
case SectionType.Puzzle:
puzzleDTO = JsonConvert.DeserializeObject<PuzzleDTO>(jsonElement.ToString());
break;
case SectionType.Quiz:
quizDTO = JsonConvert.DeserializeObject<QuizDTO>(jsonElement.ToString());
break;
case SectionType.Slider:
sliderDTO = JsonConvert.DeserializeObject<SliderDTO>(jsonElement.ToString());
break;
case SectionType.Video:
videoDTO = JsonConvert.DeserializeObject<VideoDTO>(jsonElement.ToString());
break;
case SectionType.Weather:
weatherDTO = JsonConvert.DeserializeObject<WeatherDTO>(jsonElement.ToString());
break;
case SectionType.Web:
webDTO = JsonConvert.DeserializeObject<WebDTO>(jsonElement.ToString());
break;
}
return dto.type switch return dto.type switch
{ {
SectionType.Agenda => new SectionAgenda SectionType.Agenda => new SectionAgenda
{ {
Id = dto.id, Id = dto.id,
ConfigurationId = dto.configurationId,
InstanceId = dto.instanceId,
Label = dto.label, Label = dto.label,
Title = dto.title.Select(t => new Translation().FromDTO(t)).ToList(), Title = dto.title.Select(t => new Translation().FromDTO(t)).ToList(),
Description = dto.description.Select(d => new Translation().FromDTO(d)).ToList(), Description = dto.description.Select(d => new Translation().FromDTO(d)).ToList(),
@ -30,12 +84,14 @@ namespace ManagerService.Services
Longitude = dto.longitude, Longitude = dto.longitude,
MeterZoneGPS = dto.meterZoneGPS, MeterZoneGPS = dto.meterZoneGPS,
Type = dto.type, Type = dto.type,
AgendaResourceIds = ((AgendaDTO)dto).resourceIds.Select(r => new Translation().FromDTO(r)).ToList(), AgendaResourceIds = agendaDTO.resourceIds.Select(r => new Translation().FromDTO(r)).ToList(),
AgendaMapProvider = ((AgendaDTO)dto).agendaMapProvider AgendaMapProvider = agendaDTO.agendaMapProvider
}, },
SectionType.Article => new SectionArticle SectionType.Article => new SectionArticle
{ {
Id = dto.id, Id = dto.id,
ConfigurationId = dto.configurationId,
InstanceId = dto.instanceId,
Label = dto.label, Label = dto.label,
Title = dto.title.Select(t => new Translation().FromDTO(t)).ToList(), Title = dto.title.Select(t => new Translation().FromDTO(t)).ToList(),
Description = dto.description.Select(d => new Translation().FromDTO(d)).ToList(), Description = dto.description.Select(d => new Translation().FromDTO(d)).ToList(),
@ -50,15 +106,17 @@ namespace ManagerService.Services
Longitude = dto.longitude, Longitude = dto.longitude,
MeterZoneGPS = dto.meterZoneGPS, MeterZoneGPS = dto.meterZoneGPS,
Type = dto.type, Type = dto.type,
ArticleContent = ((ArticleDTO)dto).content.Select(r => new Translation().FromDTO(r)).ToList(), ArticleContent = articleDTO.content.Select(r => new Translation().FromDTO(r)).ToList(),
ArticleIsContentTop = ((ArticleDTO)dto).isContentTop, ArticleIsContentTop = articleDTO.isContentTop,
ArticleAudioIds = ((ArticleDTO)dto).audioIds.Select(a => new Translation().FromDTO(a)).ToList(), ArticleAudioIds = articleDTO.audioIds.Select(a => new Translation().FromDTO(a)).ToList(),
ArticleIsReadAudioAuto = ((ArticleDTO)dto).isReadAudioAuto, ArticleIsReadAudioAuto = articleDTO.isReadAudioAuto,
ArticleContents = ((ArticleDTO)dto).contents.Select(c => new Content().FromDTO(c)).ToList() ArticleContents = articleDTO.contents.Select(c => new Content().FromDTO(c)).ToList()
}, },
SectionType.Map => new SectionMap SectionType.Map => new SectionMap
{ {
Id = dto.id, Id = dto.id,
ConfigurationId = dto.configurationId,
InstanceId = dto.instanceId,
Label = dto.label, Label = dto.label,
Title = dto.title.Select(t => new Translation().FromDTO(t)).ToList(), Title = dto.title.Select(t => new Translation().FromDTO(t)).ToList(),
Description = dto.description.Select(d => new Translation().FromDTO(d)).ToList(), Description = dto.description.Select(d => new Translation().FromDTO(d)).ToList(),
@ -73,19 +131,21 @@ namespace ManagerService.Services
Longitude = dto.longitude, Longitude = dto.longitude,
MeterZoneGPS = dto.meterZoneGPS, MeterZoneGPS = dto.meterZoneGPS,
Type = dto.type, Type = dto.type,
MapZoom = ((MapDTO)dto).zoom, MapZoom = mapDTO.zoom,
MapMapType = ((MapDTO)dto).mapType, MapMapType = mapDTO.mapType,
MapTypeMapbox = ((MapDTO)dto).mapTypeMapbox, MapTypeMapbox = mapDTO.mapTypeMapbox,
MapMapProvider = ((MapDTO)dto).mapProvider, MapMapProvider = mapDTO.mapProvider,
MapResourceId = ((MapDTO)dto).iconResourceId, MapResourceId = mapDTO.iconResourceId,
MapCenterLatitude = ((MapDTO)dto).centerLatitude, MapCenterLatitude = mapDTO.centerLatitude,
MapCenterLongitude = ((MapDTO)dto).centerLongitude, MapCenterLongitude = mapDTO.centerLongitude,
MapCategories = null, //((MapDTO)dto).categories, // TODO specific MapCategories = null, //((MapDTO)dto).categories, // TODO specific
MapPoints = null // ((MapDTO)dto).points, // TODO specific MapPoints = null // ((MapDTO)dto).points, // TODO specific
}, },
SectionType.Menu => new SectionMenu SectionType.Menu => new SectionMenu
{ {
Id = dto.id, Id = dto.id,
ConfigurationId = dto.configurationId,
InstanceId = dto.instanceId,
Label = dto.label, Label = dto.label,
Title = dto.title.Select(t => new Translation().FromDTO(t)).ToList(), Title = dto.title.Select(t => new Translation().FromDTO(t)).ToList(),
Description = dto.description.Select(d => new Translation().FromDTO(d)).ToList(), Description = dto.description.Select(d => new Translation().FromDTO(d)).ToList(),
@ -105,6 +165,8 @@ namespace ManagerService.Services
SectionType.PDF => new SectionPdf SectionType.PDF => new SectionPdf
{ {
Id = dto.id, Id = dto.id,
ConfigurationId = dto.configurationId,
InstanceId = dto.instanceId,
Label = dto.label, Label = dto.label,
Title = dto.title.Select(t => new Translation().FromDTO(t)).ToList(), Title = dto.title.Select(t => new Translation().FromDTO(t)).ToList(),
Description = dto.description.Select(d => new Translation().FromDTO(d)).ToList(), Description = dto.description.Select(d => new Translation().FromDTO(d)).ToList(),
@ -119,11 +181,13 @@ namespace ManagerService.Services
Longitude = dto.longitude, Longitude = dto.longitude,
MeterZoneGPS = dto.meterZoneGPS, MeterZoneGPS = dto.meterZoneGPS,
Type = dto.type, Type = dto.type,
PDFOrderedTranslationAndResources = ((PdfDTO)dto).pdfs.Select(p => new OrderedTranslationAndResource().FromDTO(p)).ToList() PDFOrderedTranslationAndResources = pdfDTO.pdfs.Select(p => new OrderedTranslationAndResource().FromDTO(p)).ToList()
}, },
SectionType.Puzzle => new SectionPuzzle SectionType.Puzzle => new SectionPuzzle
{ {
Id = dto.id, Id = dto.id,
ConfigurationId = dto.configurationId,
InstanceId = dto.instanceId,
Label = dto.label, Label = dto.label,
Title = dto.title.Select(t => new Translation().FromDTO(t)).ToList(), Title = dto.title.Select(t => new Translation().FromDTO(t)).ToList(),
Description = dto.description.Select(d => new Translation().FromDTO(d)).ToList(), Description = dto.description.Select(d => new Translation().FromDTO(d)).ToList(),
@ -138,15 +202,17 @@ namespace ManagerService.Services
Longitude = dto.longitude, Longitude = dto.longitude,
MeterZoneGPS = dto.meterZoneGPS, MeterZoneGPS = dto.meterZoneGPS,
Type = dto.type, Type = dto.type,
PuzzleMessageDebut = ((PuzzleDTO)dto).messageDebut.Select(md => new TranslationAndResource().FromDTO(md)).ToList(), PuzzleMessageDebut = puzzleDTO.messageDebut.Select(md => new TranslationAndResource().FromDTO(md)).ToList(),
PuzzleMessageFin = ((PuzzleDTO)dto).messageFin.Select(mf => new TranslationAndResource().FromDTO(mf)).ToList(), PuzzleMessageFin = puzzleDTO.messageFin.Select(mf => new TranslationAndResource().FromDTO(mf)).ToList(),
PuzzleImageId = ((PuzzleDTO)dto).puzzleImageId, PuzzleImageId = puzzleDTO.puzzleImageId,
PuzzleRows = ((PuzzleDTO)dto).rows, PuzzleRows = puzzleDTO.rows,
PuzzleCols = ((PuzzleDTO)dto).cols PuzzleCols = puzzleDTO.cols
}, },
SectionType.Quiz => new SectionQuiz SectionType.Quiz => new SectionQuiz
{ {
Id = dto.id, Id = dto.id,
ConfigurationId = dto.configurationId,
InstanceId = dto.instanceId,
Label = dto.label, Label = dto.label,
Title = dto.title.Select(t => new Translation().FromDTO(t)).ToList(), Title = dto.title.Select(t => new Translation().FromDTO(t)).ToList(),
Description = dto.description.Select(d => new Translation().FromDTO(d)).ToList(), Description = dto.description.Select(d => new Translation().FromDTO(d)).ToList(),
@ -161,15 +227,17 @@ namespace ManagerService.Services
Longitude = dto.longitude, Longitude = dto.longitude,
MeterZoneGPS = dto.meterZoneGPS, MeterZoneGPS = dto.meterZoneGPS,
Type = dto.type, Type = dto.type,
QuizBadLevel = ((QuizDTO)dto).bad_level.Select(bl => new TranslationAndResource().FromDTO(bl)).ToList(), QuizBadLevel = quizDTO.bad_level.Select(bl => new TranslationAndResource().FromDTO(bl)).ToList(),
QuizMediumLevel = ((QuizDTO)dto).medium_level.Select(ml => new TranslationAndResource().FromDTO(ml)).ToList(), QuizMediumLevel = quizDTO.medium_level.Select(ml => new TranslationAndResource().FromDTO(ml)).ToList(),
QuizGoodLevel = ((QuizDTO)dto).good_level.Select(gol => new TranslationAndResource().FromDTO(gol)).ToList(), QuizGoodLevel = quizDTO.good_level.Select(gol => new TranslationAndResource().FromDTO(gol)).ToList(),
QuizGreatLevel = ((QuizDTO)dto).great_level.Select(gl => new TranslationAndResource().FromDTO(gl)).ToList(), QuizGreatLevel = quizDTO.great_level.Select(gl => new TranslationAndResource().FromDTO(gl)).ToList(),
//Questions = ((QuizDTO)dto).questions, // TODO specific //Questions = ((QuizDTO)dto).questions, // TODO specific
}, },
SectionType.Slider => new SectionSlider SectionType.Slider => new SectionSlider
{ {
Id = dto.id, Id = dto.id,
ConfigurationId = dto.configurationId,
InstanceId = dto.instanceId,
Label = dto.label, Label = dto.label,
Title = dto.title.Select(t => new Translation().FromDTO(t)).ToList(), Title = dto.title.Select(t => new Translation().FromDTO(t)).ToList(),
Description = dto.description.Select(d => new Translation().FromDTO(d)).ToList(), Description = dto.description.Select(d => new Translation().FromDTO(d)).ToList(),
@ -184,11 +252,13 @@ namespace ManagerService.Services
Longitude = dto.longitude, Longitude = dto.longitude,
MeterZoneGPS = dto.meterZoneGPS, MeterZoneGPS = dto.meterZoneGPS,
Type = dto.type, Type = dto.type,
SliderContents = ((SliderDTO)dto).contents.Select(c => new Content().FromDTO(c)).ToList(), // TODO TEST SliderContents = sliderDTO.contents.Select(c => new Content().FromDTO(c)).ToList(), // TODO TEST
}, },
SectionType.Video => new SectionVideo SectionType.Video => new SectionVideo
{ {
Id = dto.id, Id = dto.id,
ConfigurationId = dto.configurationId,
InstanceId = dto.instanceId,
Label = dto.label, Label = dto.label,
Title = dto.title.Select(t => new Translation().FromDTO(t)).ToList(), Title = dto.title.Select(t => new Translation().FromDTO(t)).ToList(),
Description = dto.description.Select(d => new Translation().FromDTO(d)).ToList(), Description = dto.description.Select(d => new Translation().FromDTO(d)).ToList(),
@ -203,12 +273,14 @@ namespace ManagerService.Services
Longitude = dto.longitude, Longitude = dto.longitude,
MeterZoneGPS = dto.meterZoneGPS, MeterZoneGPS = dto.meterZoneGPS,
Type = dto.type, Type = dto.type,
VideoSource = ((VideoDTO)dto).source, VideoSource = videoDTO.source,
}, },
SectionType.Weather => new SectionWeather SectionType.Weather => new SectionWeather
{ {
Id = dto.id, Id = dto.id,
ConfigurationId = dto.configurationId,
InstanceId = dto.instanceId,
Label = dto.label, Label = dto.label,
Title = dto.title.Select(t => new Translation().FromDTO(t)).ToList(), Title = dto.title.Select(t => new Translation().FromDTO(t)).ToList(),
Description = dto.description.Select(d => new Translation().FromDTO(d)).ToList(), Description = dto.description.Select(d => new Translation().FromDTO(d)).ToList(),
@ -223,13 +295,15 @@ namespace ManagerService.Services
Longitude = dto.longitude, Longitude = dto.longitude,
MeterZoneGPS = dto.meterZoneGPS, MeterZoneGPS = dto.meterZoneGPS,
Type = dto.type, Type = dto.type,
WeatherCity = ((WeatherDTO)dto).city, WeatherCity = weatherDTO.city,
WeatherUpdatedDate = ((WeatherDTO)dto).updatedDate, WeatherUpdatedDate = weatherDTO.updatedDate,
WeatherResult = ((WeatherDTO)dto).result WeatherResult = weatherDTO.result
}, },
SectionType.Web => new SectionWeb SectionType.Web => new SectionWeb
{ {
Id = dto.id, Id = dto.id,
ConfigurationId = dto.configurationId,
InstanceId = dto.instanceId,
Label = dto.label, Label = dto.label,
Title = dto.title.Select(t => new Translation().FromDTO(t)).ToList(), Title = dto.title.Select(t => new Translation().FromDTO(t)).ToList(),
Description = dto.description.Select(d => new Translation().FromDTO(d)).ToList(), Description = dto.description.Select(d => new Translation().FromDTO(d)).ToList(),
@ -244,9 +318,261 @@ namespace ManagerService.Services
Longitude = dto.longitude, Longitude = dto.longitude,
MeterZoneGPS = dto.meterZoneGPS, MeterZoneGPS = dto.meterZoneGPS,
Type = dto.type, Type = dto.type,
WebSource = ((WebDTO)dto).source, WebSource = webDTO.source,
}, },
_ => throw new NotImplementedException("Section type not handled")
};
}
public static SectionDTO ToDTO(Section section)
{
return section switch
{
SectionAgenda agenda => new AgendaDTO
{
id = agenda.Id,
configurationId = agenda.ConfigurationId,
instanceId = agenda.InstanceId,
label = agenda.Label,
title = agenda.Title.Select(t => t.ToDTO()).ToList(),
description = agenda.Description.Select(t => t.ToDTO()).ToList(),
order = agenda.Order,
imageId = agenda.ImageId,
imageSource = agenda.ImageSource,
isSubSection = agenda.IsSubSection,
parentId = agenda.ParentId,
isBeacon = agenda.IsBeacon,
beaconId = agenda.BeaconId,
latitude = agenda.Latitude,
longitude = agenda.Longitude,
meterZoneGPS = agenda.MeterZoneGPS,
type = agenda.Type,
resourceIds = agenda.AgendaResourceIds.Select(r => r.ToDTO()).ToList(),
agendaMapProvider = agenda.AgendaMapProvider
},
SectionArticle article => new ArticleDTO
{
id = article.Id,
configurationId = article.ConfigurationId,
instanceId = agenda.InstanceId,
label = article.Label,
title = article.Title.Select(t => t.ToDTO()).ToList(),
description = article.Description.Select(d => d.ToDTO()).ToList(),
order = article.Order,
imageId = article.ImageId,
imageSource = article.ImageSource,
isSubSection = article.IsSubSection,
parentId = article.ParentId,
isBeacon = article.IsBeacon,
beaconId = article.BeaconId,
latitude = article.Latitude,
longitude = article.Longitude,
meterZoneGPS = article.MeterZoneGPS,
type = article.Type,
content = article.ArticleContent.Select(r => r.ToDTO()).ToList(),
isContentTop = article.ArticleIsContentTop,
audioIds = article.ArticleAudioIds.Select(a => a.ToDTO()).ToList(),
isReadAudioAuto = article.ArticleIsReadAudioAuto,
contents = article.ArticleContents.Select(c => c.ToDTO()).ToList()
},
SectionMap map => new MapDTO
{
id = map.Id,
configurationId = map.ConfigurationId,
label = map.Label,
title = map.Title.Select(t => t.ToDTO()).ToList(),
description = map.Description.Select(d => d.ToDTO()).ToList(),
order = map.Order,
imageId = map.ImageId,
imageSource = map.ImageSource,
isSubSection = map.IsSubSection,
parentId = map.ParentId,
isBeacon = map.IsBeacon,
beaconId = map.BeaconId,
latitude = map.Latitude,
longitude = map.Longitude,
meterZoneGPS = map.MeterZoneGPS,
type = map.Type,
zoom = map.MapZoom,
mapType = map.MapMapType,
mapTypeMapbox = map.MapTypeMapbox,
mapProvider = map.MapMapProvider,
iconResourceId = map.MapResourceId,
centerLatitude = map.MapCenterLatitude,
centerLongitude = map.MapCenterLongitude,
categories = null, // map.MapCategories, // TODO specific
points = null // map.MapPoints // TODO specific
},
SectionMenu menu => new MenuDTO
{
id = menu.Id,
configurationId = menu.ConfigurationId,
label = menu.Label,
title = menu.Title.Select(t => t.ToDTO()).ToList(),
description = menu.Description.Select(d => d.ToDTO()).ToList(),
order = menu.Order,
imageId = menu.ImageId,
imageSource = menu.ImageSource,
isSubSection = menu.IsSubSection,
parentId = menu.ParentId,
isBeacon = menu.IsBeacon,
beaconId = menu.BeaconId,
latitude = menu.Latitude,
longitude = menu.Longitude,
meterZoneGPS = menu.MeterZoneGPS,
type = menu.Type,
sections = null // menu.Sections, // TODO specific
},
SectionPdf pdf => new PdfDTO
{
id = pdf.Id,
configurationId = pdf.ConfigurationId,
label = pdf.Label,
title = pdf.Title.Select(t => t.ToDTO()).ToList(),
description = pdf.Description.Select(d => d.ToDTO()).ToList(),
order = pdf.Order,
imageId = pdf.ImageId,
imageSource = pdf.ImageSource,
isSubSection = pdf.IsSubSection,
parentId = pdf.ParentId,
isBeacon = pdf.IsBeacon,
beaconId = pdf.BeaconId,
latitude = pdf.Latitude,
longitude = pdf.Longitude,
meterZoneGPS = pdf.MeterZoneGPS,
type = pdf.Type,
pdfs = pdf.PDFOrderedTranslationAndResources.Select(p => p.ToDTO()).ToList()
},
SectionPuzzle puzzle => new PuzzleDTO
{
id = puzzle.Id,
configurationId = puzzle.ConfigurationId,
label = puzzle.Label,
title = puzzle.Title.Select(t => t.ToDTO()).ToList(),
description = puzzle.Description.Select(d => d.ToDTO()).ToList(),
order = puzzle.Order,
imageId = puzzle.ImageId,
imageSource = puzzle.ImageSource,
isSubSection = puzzle.IsSubSection,
parentId = puzzle.ParentId,
isBeacon = puzzle.IsBeacon,
beaconId = puzzle.BeaconId,
latitude = puzzle.Latitude,
longitude = puzzle.Longitude,
meterZoneGPS = puzzle.MeterZoneGPS,
type = puzzle.Type,
messageDebut = puzzle.PuzzleMessageDebut.Select(md => md.ToDTO()).ToList(),
messageFin = puzzle.PuzzleMessageFin.Select(mf => mf.ToDTO()).ToList(),
puzzleImageId = puzzle.PuzzleImageId,
rows = puzzle.PuzzleRows,
cols = puzzle.PuzzleCols
},
SectionQuiz quiz => new QuizDTO
{
id = quiz.Id,
configurationId = quiz.ConfigurationId,
label = quiz.Label,
title = quiz.Title.Select(t => t.ToDTO()).ToList(),
description = quiz.Description.Select(d => d.ToDTO()).ToList(),
order = quiz.Order,
imageId = quiz.ImageId,
imageSource = quiz.ImageSource,
isSubSection = quiz.IsSubSection,
parentId = quiz.ParentId,
isBeacon = quiz.IsBeacon,
beaconId = quiz.BeaconId,
latitude = quiz.Latitude,
longitude = quiz.Longitude,
meterZoneGPS = quiz.MeterZoneGPS,
type = quiz.Type,
bad_level = quiz.QuizBadLevel.Select(bl => bl.ToDTO()).ToList(),
medium_level = quiz.QuizMediumLevel.Select(ml => ml.ToDTO()).ToList(),
good_level = quiz.QuizGoodLevel.Select(gol => gol.ToDTO()).ToList(),
great_level = quiz.QuizGreatLevel.Select(gl => gl.ToDTO()).ToList(),
questions = null // quiz.Questions, // TODO specific
},
SectionSlider slider => new SliderDTO
{
id = slider.Id,
configurationId = slider.ConfigurationId,
label = slider.Label,
title = slider.Title.Select(t => t.ToDTO()).ToList(),
description = slider.Description.Select(d => d.ToDTO()).ToList(),
order = slider.Order,
imageId = slider.ImageId,
imageSource = slider.ImageSource,
isSubSection = slider.IsSubSection,
parentId = slider.ParentId,
isBeacon = slider.IsBeacon,
beaconId = slider.BeaconId,
latitude = slider.Latitude,
longitude = slider.Longitude,
meterZoneGPS = slider.MeterZoneGPS,
type = slider.Type,
contents = slider.SliderContents.Select(c => c.ToDTO()).ToList()
},
SectionVideo video => new VideoDTO
{
id = video.Id,
configurationId = video.ConfigurationId,
label = video.Label,
title = video.Title.Select(t => t.ToDTO()).ToList(),
description = video.Description.Select(d => d.ToDTO()).ToList(),
order = video.Order,
imageId = video.ImageId,
imageSource = video.ImageSource,
isSubSection = video.IsSubSection,
parentId = video.ParentId,
isBeacon = video.IsBeacon,
beaconId = video.BeaconId,
latitude = video.Latitude,
longitude = video.Longitude,
meterZoneGPS = video.MeterZoneGPS,
type = video.Type,
source = video.VideoSource
},
SectionWeather weather => new WeatherDTO
{
id = weather.Id,
configurationId = weather.ConfigurationId,
label = weather.Label,
title = weather.Title.Select(t => t.ToDTO()).ToList(),
description = weather.Description.Select(d => d.ToDTO()).ToList(),
order = weather.Order,
imageId = weather.ImageId,
imageSource = weather.ImageSource,
isSubSection = weather.IsSubSection,
parentId = weather.ParentId,
isBeacon = weather.IsBeacon,
beaconId = weather.BeaconId,
latitude = weather.Latitude,
longitude = weather.Longitude,
meterZoneGPS = weather.MeterZoneGPS,
type = weather.Type,
city = weather.WeatherCity,
updatedDate = weather.WeatherUpdatedDate,
result = weather.WeatherResult
},
SectionWeb web => new WebDTO
{
id = web.Id,
configurationId = web.ConfigurationId,
label = web.Label,
title = web.Title.Select(t => t.ToDTO()).ToList(),
description = web.Description.Select(d => d.ToDTO()).ToList(),
order = web.Order,
imageId = web.ImageId,
imageSource = web.ImageSource,
isSubSection = web.IsSubSection,
parentId = web.ParentId,
isBeacon = web.IsBeacon,
beaconId = web.BeaconId,
latitude = web.Latitude,
longitude = web.Longitude,
meterZoneGPS = web.MeterZoneGPS,
type = web.Type,
source = web.WebSource
},
_ => throw new NotImplementedException("Section type not handled") _ => throw new NotImplementedException("Section type not handled")
}; };
} }