Resource controller done + section WIP

This commit is contained in:
Thomas Fransolet 2025-03-20 16:25:23 +01:00
parent 1242d6c790
commit 9aa5e7df5e
24 changed files with 1830 additions and 356 deletions

View File

@ -1,18 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0" />
<PackageReference Include="Scrypt.NET" Version="1.3.0" />
</ItemGroup>
<ItemGroup>
<Folder Include="Business\" />
<Folder Include="Helpers\Passwords\" />
<Folder Include="Models\" />
</ItemGroup>
</Project>

View File

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

View File

@ -5,8 +5,10 @@ using System.Linq;
using Manager.DTOs;
using Manager.Services;
using ManagerService.Data;
using ManagerService.Data.SubSection;
using ManagerService.DTOs;
using ManagerService.Helpers;
using ManagerService.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
@ -20,20 +22,24 @@ namespace ManagerService.Controllers
[OpenApiTag("Resource", Description = "Resource management")]
public class ResourceController : ControllerBase
{
private readonly MyInfoMateDbContext _myInfoMateDbContext;
private ResourceDatabaseService _resourceService;
private SectionDatabaseService _sectionService;
private ConfigurationDatabaseService _configurationService;
private readonly ILogger<ResourceController> _logger;
IHexIdGeneratorService idService = new HexIdGeneratorService();
private static int MaxWidth = 1024;
private static int MaxHeight = 1024;
public ResourceController(ILogger<ResourceController> logger, ResourceDatabaseService resourceService, SectionDatabaseService sectionService, ConfigurationDatabaseService configurationService)
public ResourceController(ILogger<ResourceController> logger, ResourceDatabaseService resourceService, SectionDatabaseService sectionService, ConfigurationDatabaseService configurationService, MyInfoMateDbContext myInfoMateDbContext)
{
_logger = logger;
_resourceService = resourceService;
_sectionService = sectionService;
_configurationService = configurationService;
_myInfoMateDbContext = myInfoMateDbContext;
}
/// <summary>
@ -50,14 +56,17 @@ namespace ManagerService.Controllers
{
if (instanceId == null)
throw new ArgumentNullException("InstanceId needed");
List<OldResource> resources = new List<OldResource>();
List<Resource> resources = new List<Resource>();
if (types.Count > 0)
{
resources = _resourceService.GetAllByType(instanceId, types);
resources = _myInfoMateDbContext.Resources.Where(r => r.InstanceId == instanceId && types.Contains(r.Type)).ToList();
//resources = _resourceService.GetAllByType(instanceId, types);
}
else
{
resources = _resourceService.GetAll(instanceId);
resources = _myInfoMateDbContext.Resources.Where(r => r.InstanceId == instanceId).ToList();
//resources = _resourceService.GetAll(instanceId);
}
List<ResourceDTO> resourceDTOs = new List<ResourceDTO>();
@ -89,7 +98,8 @@ namespace ManagerService.Controllers
{
try
{
OldResource resource = _resourceService.GetById(id);
Resource resource = _myInfoMateDbContext.Resources.FirstOrDefault(r => r.Id == id);
//Resource resource = _resourceService.GetById(id);
if (resource == null)
throw new KeyNotFoundException("This resource was not found");
@ -149,7 +159,8 @@ namespace ManagerService.Controllers
{
try
{
OldResource resource = _resourceService.GetById(id);
Resource resource = _myInfoMateDbContext.Resources.FirstOrDefault(r => r.Id == id);
//OldResource resource = _resourceService.GetById(id);
if (resource == null)
throw new KeyNotFoundException("This resource was not found");
@ -219,7 +230,7 @@ namespace ManagerService.Controllers
throw new ArgumentNullException("One of resource params is null");
var resourceType = (ResourceType)Enum.Parse(typeof(ResourceType), type);
List<OldResource> resources = new List<OldResource>();
List<Resource> resources = new List<Resource>();
foreach (var file in Request.Form.Files)
{
@ -250,13 +261,18 @@ namespace ManagerService.Controllers
throw new FileLoadException(message: "Fichier inexistant ou trop volumineux (max 4Mb)");
}
// Todo add some verification ?
OldResource resource = new OldResource();
Resource resource = new Resource();
resource.Label = label;
resource.Type = resourceType;
resource.DateCreation = DateTime.Now;
resource.DateCreation = DateTime.Now.ToUniversalTime();
resource.InstanceId = instanceId;
OldResource resourceCreated = _resourceService.Create(resource);
resources.Add(resourceCreated);
resource.Id = idService.GenerateHexId();
_myInfoMateDbContext.Add(resource);
_myInfoMateDbContext.SaveChanges();
//Resource resourceCreated = _resourceService.Create(resource);
resources.Add(resource);
}
}
return Ok(resources.Select(r => r.ToDTO()));
@ -296,18 +312,21 @@ namespace ManagerService.Controllers
throw new ArgumentNullException("Resource param is null");
// Todo add some verification ?
OldResource resource = new OldResource();
Resource resource = new Resource();
resource.InstanceId = newResource.instanceId;
resource.Label = newResource.label;
resource.Type = newResource.type;
resource.Url = newResource.url;
resource.DateCreation = DateTime.Now;
resource.DateCreation = DateTime.Now.ToUniversalTime();
//resource.Data = newResource.data;
resource.InstanceId = newResource.instanceId;
resource.Id = idService.GenerateHexId();
OldResource resourceCreated = _resourceService.Create(resource);
_myInfoMateDbContext.Add(resource);
_myInfoMateDbContext.SaveChanges();
//OldResource resourceCreated = _resourceService.Create(resource);
return new OkObjectResult(resourceCreated.ToDTO()); // WITHOUT DATA
return new OkObjectResult(resource.ToDTO()); // WITHOUT DATA
}
catch (ArgumentNullException ex)
{
@ -340,21 +359,24 @@ namespace ManagerService.Controllers
if (updatedResource == null)
throw new ArgumentNullException("Resource param is null");
OldResource resource = _resourceService.GetById(updatedResource.id);
//OldResource resource = _resourceService.GetById(updatedResource.id);
Resource resource = _myInfoMateDbContext.Resources.FirstOrDefault(r => r.Id == updatedResource.id);
if (resource == null)
throw new KeyNotFoundException("Resource does not exist");
// Todo add some verification ?
resource.InstanceId = updatedResource.instanceId;
resource.Label = updatedResource.label;
resource.Type = updatedResource.type;
resource.Url = updatedResource.url;
resource.InstanceId = updatedResource.instanceId != null ? updatedResource.instanceId : resource.InstanceId;
resource.Label = updatedResource.label != null ? updatedResource.label : resource.Label;
resource.Type = updatedResource.type != null ? updatedResource.type : resource.Type;
resource.Url = updatedResource.url != null ? updatedResource.url: resource.Url;
//resource.Data = updatedResource.data; // NOT ALLOWED
OldResource resourceModified = _resourceService.Update(updatedResource.id, resource);
_myInfoMateDbContext.SaveChanges();
return new OkObjectResult(resourceModified.ToDTO());
//OldResource resourceModified = _resourceService.Update(updatedResource.id, resource);
return new OkObjectResult(resource.ToDTO());
}
catch (ArgumentNullException ex)
{
@ -387,12 +409,14 @@ namespace ManagerService.Controllers
if (id == null)
throw new ArgumentNullException("Resource param is null");
var ressource = _resourceService.GetById(id);
if (ressource == null)
//var ressource = _resourceService.GetById(id);
Resource resource = _myInfoMateDbContext.Resources.FirstOrDefault(r => r.Id == id);
if (resource == null)
throw new KeyNotFoundException("Resource does not exist");
foreach (var configuration in _configurationService.GetAll(ressource.InstanceId))
List<Configuration> configurations = _myInfoMateDbContext.Configurations.Where(c => c.InstanceId == resource.InstanceId).ToList();
foreach (var configuration in configurations)
{
if (configuration.ImageId == id)
{
@ -401,9 +425,9 @@ namespace ManagerService.Controllers
}
}
List<Section> sections = _myInfoMateDbContext.Sections.Where(s => s.InstanceId == resource.InstanceId).ToList();
// Delete all resource occurence
foreach (var section in _sectionService.GetAll(ressource.InstanceId))
foreach (var section in sections)
{
if (section.ImageId == id)
{
@ -411,39 +435,40 @@ namespace ManagerService.Controllers
section.ImageSource = null;
}
switch (section.Type)
switch (section)
{
case SectionType.Map:
MapDTO mapDTO = JsonConvert.DeserializeObject<MapDTO>(section.Data);
mapDTO.iconResourceId = mapDTO.iconResourceId == id ? null : mapDTO.iconResourceId;
foreach (var point in mapDTO.points)
case SectionMap map:
//MapDTO mapDTO = JsonConvert.DeserializeObject<MapDTO>(section.Data);
map.MapResourceId = map.MapResourceId == id ? null : map.MapResourceId;
foreach (var point in map.MapPoints)
{
point.imageResourceId = point.imageResourceId == id ? null : point.imageResourceId;
foreach (var content in point.contents)
point.ImageResourceId = point.ImageResourceId == id ? null : point.ImageResourceId;
foreach (var content in point.Contents)
{
content.resourceUrl = content.resourceId == id ? null : content.resourceUrl;
content.resourceId = content.resourceId == id ? null : content.resourceId;
content.Url = content.Id == id ? null : content.Url;
content.Id = content.Id == id ? null : content.Id;
}
}
foreach (var categorie in mapDTO.categories)
foreach (var categorie in map.MapCategories)
{
// TODO
/*categorie.iconUrl = categorie.iconResourceId == id ? null : categorie.iconUrl;
categorie.iconResourceId = categorie.iconResourceId == id ? null : categorie.iconResourceId;*/
}
section.Data = JsonConvert.SerializeObject(mapDTO);
//section.Data = JsonConvert.SerializeObject(mapDTO);
break;
case SectionType.Slider:
SliderDTO sliderDTO = JsonConvert.DeserializeObject<SliderDTO>(section.Data);
List<ContentDTO> contentsToKeep = new List<ContentDTO>();
foreach (var content in sliderDTO.contents)
case SectionSlider slider:
//SliderDTO sliderDTO = JsonConvert.DeserializeObject<SliderDTO>(section.Data);
/*List<ContentDTO> contentsToKeep = new List<ContentDTO>();
foreach (var content in slider.Contents)
{
if (content.resourceId != id)
if (content.ResourceId != id)
contentsToKeep.Add(content);
}
sliderDTO.contents = contentsToKeep;
section.Data = JsonConvert.SerializeObject(sliderDTO);
}*/
// TODO TEST
slider.SliderContents = slider.SliderContents.Where(c => c.ResourceId != id).ToList();
//section.Data = JsonConvert.SerializeObject(sliderDTO);
break;
// TODO
/*case SectionType.Quizz:
@ -521,23 +546,28 @@ namespace ManagerService.Controllers
}
section.Data = JsonConvert.SerializeObject(quizzDTO);
break;*/
case SectionType.Article:
ArticleDTO articleDTO = JsonConvert.DeserializeObject<ArticleDTO>(section.Data);
List<ContentDTO> contentsArticleToKeep = new List<ContentDTO>();
foreach (var content in articleDTO.contents)
case SectionArticle article:
/*ArticleDTO articleDTO = JsonConvert.DeserializeObject<ArticleDTO>(section.Data);
List<ContentDTO> contentsArticleToKeep = new List<ContentDTO>();*/
/*foreach (var content in article.contents)
{
if (content.resourceId != id)
contentsArticleToKeep.Add(content);
}
articleDTO.contents = contentsArticleToKeep;
section.Data = JsonConvert.SerializeObject(articleDTO);
}*/
// TODO TEEEEEEEEEEESST
//articleDTO.contents = contentsArticleToKeep;
article.ArticleContents = article.ArticleContents.Where(c => c.ResourceId != id).ToList();
//section.Data = JsonConvert.SerializeObject(articleDTO);
break;
}
_sectionService.Update(section.Id, section);
_myInfoMateDbContext.SaveChanges();
//_sectionService.Update(section.Id, section);
}
_resourceService.Remove(id);
//_resourceService.Remove(id);
_myInfoMateDbContext.Remove(resource);
_myInfoMateDbContext.SaveChanges();
return new ObjectResult("The resource has been deleted") { StatusCode = 202 };

View File

@ -4,6 +4,7 @@ using Manager.Services;
using ManagerService.Data;
using ManagerService.Data.SubSection;
using ManagerService.DTOs;
using ManagerService.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
@ -22,17 +23,21 @@ namespace ManagerService.Controllers
[OpenApiTag("Section", Description = "Section management")]
public class SectionController : ControllerBase
{
private readonly MyInfoMateDbContext _myInfoMateDbContext;
private SectionDatabaseService _sectionService;
private ConfigurationDatabaseService _configurationService;
private readonly ILogger<SectionController> _logger;
private readonly IConfiguration _configuration;
IHexIdGeneratorService idService = new HexIdGeneratorService();
public SectionController(IConfiguration configuration, ILogger<SectionController> logger, SectionDatabaseService sectionService, ConfigurationDatabaseService configurationService)
public SectionController(IConfiguration configuration, ILogger<SectionController> logger, SectionDatabaseService sectionService, ConfigurationDatabaseService configurationService, MyInfoMateDbContext myInfoMateDbContext)
{
_logger = logger;
_configuration = configuration;
_sectionService = sectionService;
_configurationService = configurationService;
_myInfoMateDbContext = myInfoMateDbContext;
}
/// <summary>
@ -46,7 +51,8 @@ namespace ManagerService.Controllers
{
try
{
List<OldSection> sections = _sectionService.GetAll(instanceId);
//List<OldSection> sections = _sectionService.GetAll(instanceId);
List<Section> sections = _myInfoMateDbContext.Sections.ToList();
/* CLEAN ARTICLE AUDIO - Init new field AudioIds */
@ -92,9 +98,12 @@ namespace ManagerService.Controllers
if (id == null)
throw new ArgumentNullException("Param is null");
if (_configurationService.IsExist(id))
Configuration configuration = _myInfoMateDbContext.Configurations.FirstOrDefault(c => c.Id == id);
if (configuration != null)
{
List<OldSection> sections = _sectionService.GetAllFromConfiguration(id);
List<Section> sections = _myInfoMateDbContext.Sections.Where(s => s.ConfigurationId == id && !s.IsSubSection).ToList();
//List<OldSection> sections = _sectionService.GetAllFromConfiguration(id);
return new OkObjectResult(sections.Select(r => r.ToDTO()));
}
@ -126,7 +135,10 @@ namespace ManagerService.Controllers
if (id == null)
throw new ArgumentNullException("Param is null");
_sectionService.DeleteAllFromConfiguration(id);
//_sectionService.DeleteAllFromConfiguration(id);
List<Section> sections = _myInfoMateDbContext.Sections.Where(s => s.ConfigurationId == id).ToList();
// TODO test
_myInfoMateDbContext.RemoveRange(sections);
return new ObjectResult("All section from the specified configuration has been deleted") { StatusCode = 202 };
}
@ -155,7 +167,8 @@ namespace ManagerService.Controllers
if (id == null)
throw new ArgumentNullException("Param is null");
List<OldSection> sections = _sectionService.GetAllSubSection(id);
List<Section> sections = _myInfoMateDbContext.Sections.Where(s => s.ParentId == id && s.IsSubSection).ToList();
//List<OldSection> sections = _sectionService.GetAllSubSection(id);
return new OkObjectResult(sections.Select(r => r.ToDTO()));
}
@ -183,7 +196,8 @@ namespace ManagerService.Controllers
{
try
{
OldSection section = _sectionService.GetById(id);
//OldSection section = _sectionService.GetById(id);
Section section = _myInfoMateDbContext.Sections.FirstOrDefault(s => s.Id == id);
if (section == null)
throw new KeyNotFoundException("This section was not found");
@ -245,9 +259,10 @@ namespace ManagerService.Controllers
{
try
{
List<OldSection> sections = _sectionService.GetAll(instanceId);
List<Section> sections = _myInfoMateDbContext.Sections.Where(s => s.InstanceId == instanceId && s.IsBeacon && s.BeaconId != null).ToList();
//List<OldSection> sections = _sectionService.GetAll(instanceId);
sections = sections.Where(s => s.IsBeacon && s.BeaconId != null).ToList();
//sections = sections.Where(s => s.IsBeacon && s.BeaconId != null).ToList();
return new OkObjectResult(sections.Select(s => s.ToDTO()));
}
@ -284,37 +299,113 @@ namespace ManagerService.Controllers
throw new KeyNotFoundException("Configuration does not exist");
// Todo add some verification ?
Section section = new Section();
section.InstanceId = newSection.instanceId;
section.Label = newSection.label;
section.ImageId = newSection.imageId;
section.ImageSource = newSection.imageSource;
section.ConfigurationId = newSection.configurationId;
section.DateCreation = DateTime.Now;
section.IsSubSection = newSection.isSubSection;
section.ParentId = newSection.parentId;
section.Type = newSection.type;
section.Title = new List<Translation>();
section.Description = new List<Translation>();
section.Order = _sectionService.GetAllFromConfiguration(newSection.configurationId).Count;
section.IsBeacon = newSection.isBeacon;
section.BeaconId = newSection.beaconId;
section.Latitude = newSection.latitude;
section.Longitude = newSection.longitude;
section.MeterZoneGPS = newSection.meterZoneGPS;
Section section = SectionFactory.Create(newSection);
// Preparation
List<string> languages = _configuration.GetSection("SupportedLanguages").Get<List<string>>();
var contentArticle = new List<Translation>();
var mapDTO = new MapDTO(); // For menu dto
var sliderDTO = new SliderDTO(); // For menu dto
section.Title = LanguageInit.Init("Title", languages);
section.Description = LanguageInit.Init("Description", languages);
contentArticle = LanguageInit.Init("Content", languages);
switch (newSection.type) {
case SectionType.Map:
section = new SectionMap
{
MapMapType = MapTypeApp.hybrid,
MapTypeMapbox = MapTypeMapBox.standard,
MapMapProvider = MapProvider.Google,
MapZoom = 18,
MapPoints = new List<GeoPoint>(),
MapCategories = new List<Categorie>()
};
break;
case SectionType.Slider:
section = new SectionSlider
{
SliderContents = new List<Content>()
};
break;
case SectionType.Video:
section = new SectionVideo
{
VideoSource = "",
};
break;
case SectionType.Web:
section = new SectionWeb
{
WebSource = "",
};
break;
case SectionType.Menu:
section = new SectionMenu
{
MenuSections = new List<Section>(),
};
break;
case SectionType.Quiz:
section = new SectionQuiz
{
QuizQuestions = new List<QuizQuestion>(),
// TODO levels ?
};
break;
case SectionType.Article:
section = new SectionArticle
{
ArticleContents = new List<Content>(),
ArticleContent = contentArticle,
ArticleAudioIds = LanguageInit.Init("Audio", languages, true)
};
break;
case SectionType.PDF:
section = new SectionPdf
{
PDFOrderedTranslationAndResources = []
};
break;
case SectionType.Puzzle:
section = new SectionPuzzle
{
PuzzleMessageDebut = [],
PuzzleMessageFin = []
};
break;
case SectionType.Agenda:
section = new SectionAgenda
{
AgendaResourceIds = new List<Translation>()
};
break;
case SectionType.Weather:
section = new SectionWeather();
break;
}
section.InstanceId = newSection.instanceId;
section.Label = newSection.label;
section.ImageId = newSection.imageId;
section.ImageSource = newSection.imageSource;
section.ConfigurationId = newSection.configurationId;
section.DateCreation = DateTime.Now.ToUniversalTime();
section.IsSubSection = newSection.isSubSection;
section.ParentId = newSection.parentId;
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 = _sectionService.GetAllFromConfiguration(newSection.configurationId).Count;
section.IsBeacon = newSection.isBeacon;
section.BeaconId = newSection.beaconId;
section.Latitude = newSection.latitude;
section.Longitude = newSection.longitude;
section.MeterZoneGPS = newSection.meterZoneGPS;
/*foreach (var language in languages)
{
TranslationDTO title = new TranslationDTO();
@ -354,99 +445,11 @@ namespace ManagerService.Controllers
section.Title = section.Title.OrderBy(t => t.Language).ToList();
section.Description = section.Description.OrderBy(d => d.Language).ToList();
switch (newSection.type) {
case SectionType.Map:
mapDTO = new MapDTO();
mapDTO.mapType = MapTypeApp.hybrid;
mapDTO.mapTypeMapbox = MapTypeMapBox.standard;
mapDTO.mapProvider = MapProvider.Google;
mapDTO.zoom = 18;
//_sectionService.Create(section);
_myInfoMateDbContext.Add(section);
_myInfoMateDbContext.SaveChanges();
mapDTO.points = new List<GeoPointDTO>();
mapDTO.categories = new List<CategorieDTO>();
//section.Data = JsonConvert.SerializeObject(mapDTO); // Include all info from specific section as JSON
break;
case SectionType.Slider:
sliderDTO = new SliderDTO();
sliderDTO.contents = new List<ContentDTO>();
//section.Data = JsonConvert.SerializeObject(sliderDTO); // Include all info from specific section as JSON
break;
case SectionType.Video:
VideoDTO videoDTO = new VideoDTO();
videoDTO.source = "";
//section.Data = JsonConvert.SerializeObject(videoDTO); // Include all info from specific section as JSON
break;
case SectionType.Web:
WebDTO webDTO = new WebDTO();
webDTO.source = "";
//section.Data = JsonConvert.SerializeObject(webDTO); // Include all info from specific section as JSON
break;
case SectionType.Menu:
MenuDTO menuDTO = new MenuDTO();
menuDTO.sections = new List<SectionDTO>();
/*SectionDTO section0DTO = new SectionDTO();
section0DTO.IsSubSection = true;
section0DTO.Label = newSection.Label;
section0DTO.ImageId = newSection.ImageId;
section0DTO.ConfigurationId = newSection.ConfigurationId;
section0DTO.DateCreation = DateTime.Now;
section0DTO.ParentId = null;
section0DTO.Type = SectionType.Map;
section0DTO.Data = JsonConvert.SerializeObject(mapDTO);
SectionDTO section1DTO = new SectionDTO();
section0DTO.IsSubSection = true;
section0DTO.Label = newSection.Label;
section0DTO.ImageId = newSection.ImageId;
section0DTO.ConfigurationId = newSection.ConfigurationId;
section0DTO.DateCreation = DateTime.Now;
section0DTO.ParentId = null;
section0DTO.Type = SectionType.Slider;
section1DTO.IsSubSection = true;
section1DTO.Data = JsonConvert.SerializeObject(sliderDTO);*/
/*menuDTO.Sections.Add(section0DTO);
menuDTO.Sections.Add(section1DTO);*/
//section.Data = JsonConvert.SerializeObject(menuDTO); // Include all info from specific section as JSON
break;
case SectionType.Quizz:
QuizDTO quizzDTO = new QuizDTO();
quizzDTO.questions = new List<QuestionDTO>();
//section.Data = JsonConvert.SerializeObject(quizzDTO); // Include all info from specific section as JSON
break;
case SectionType.Article:
ArticleDTO articleDTO = new ArticleDTO();
articleDTO.contents = new List<ContentDTO>();
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;
case SectionType.PDF:
PdfDTO pdfDTO = new PdfDTO();
//section.Data = JsonConvert.SerializeObject(pdfDTO); // Include all info from specific section as JSON
break;
case SectionType.Puzzle:
PuzzleDTO puzzleDTO = new PuzzleDTO();
//section.Data = JsonConvert.SerializeObject(puzzleDTO); // Include all info from specific section as JSON
break;
case SectionType.Agenda:
AgendaDTO agendaDTO = new AgendaDTO();
//section.Data = JsonConvert.SerializeObject(agendaDTO); // Include all info from specific section as JSON
break;
case SectionType.Weather:
WeatherDTO weatherDTO = new WeatherDTO();
//section.Data = JsonConvert.SerializeObject(weatherDTO); // Include all info from specific section as JSON
break;
}
// TODO
OldSection sectionCreated = new OldSection();//_sectionService.Create(section);
return new OkObjectResult(sectionCreated.ToDTO());
return new OkObjectResult(section.ToDTO());
}
catch (ArgumentNullException ex)
{
@ -530,11 +533,17 @@ namespace ManagerService.Controllers
if (updatedSection == null)
throw new ArgumentNullException("Section param is null");
OldSection section = _sectionService.GetById(updatedSection.id);
//OldSection section = _sectionService.GetById(updatedSection.id);
Section existingSection = _myInfoMateDbContext.Sections.FirstOrDefault(s => s.Id == updatedSection.id);
if (section == null)
if (existingSection == null)
throw new KeyNotFoundException("Section does not exist");
if (existingSection.Type != updatedSection.type)
return BadRequest("Type mismatch: cannot change section type");
var updatedSectionDB = SectionFactory.Create(updatedSection);
// Todo add some verification ?
/*section.InstanceId = updatedSection.instanceId;
section.Label = updatedSection.label;
@ -546,20 +555,41 @@ namespace ManagerService.Controllers
section.ConfigurationId = updatedSection.configurationId;
section.IsSubSection = updatedSection.isSubSection;
section.ParentId = updatedSection.parentId;
section.Data = updatedSection.data;
//section.Data = updatedSection.data;
section.IsBeacon = updatedSection.isBeacon;
section.BeaconId = updatedSection.beaconId;
section.Latitude = updatedSection.latitude;
section.Longitude = updatedSection.longitude;
section.MeterZoneGPS = updatedSection.meterZoneGPS;
section.MeterZoneGPS = updatedSection.meterZoneGPS;*/
Section sectionModified = _sectionService.Update(updatedSection.id, section);*/
// todo
Section sectionModified = new Section();
switch (updatedSectionDB)
{
case SectionMap map:
// TODO specific
MqttClientService.PublishMessage($"config/{sectionModified.ConfigurationId}", JsonConvert.SerializeObject(new PlayerMessageDTO() { configChanged = true }));
/*map.Categories = [];
map.Points = [];*/
return new OkObjectResult(sectionModified.ToDTO());
//weather.Latitude = updatedSection.latitude;
break;
case SectionMenu menu:
//menu.Sections = new List<Section>();
break;
case SectionQuiz quiz:
quiz.QuizQuestions = [];
break;
// Ajoute d'autres types ici
}
_myInfoMateDbContext.Entry(existingSection).CurrentValues.SetValues(updatedSection);
_myInfoMateDbContext.SaveChanges();
//Section sectionModified = _sectionService.Update(updatedSection.id, section);
MqttClientService.PublishMessage($"config/{existingSection.ConfigurationId}", JsonConvert.SerializeObject(new PlayerMessageDTO() { configChanged = true }));
return new OkObjectResult(updatedSectionDB.ToDTO());
}
catch (ArgumentNullException ex)
{
@ -586,6 +616,7 @@ namespace ManagerService.Controllers
[HttpPut("order")]
public ObjectResult UpdateOrder([FromBody] List<SectionDTO> updatedSectionsOrder)
{
// TODO REWRITE LOGIC..
try
{
if (updatedSectionsOrder == null)
@ -593,16 +624,19 @@ namespace ManagerService.Controllers
foreach (var section in updatedSectionsOrder)
{
if (!_sectionService.IsExist(section.id))
var sectionDB = _myInfoMateDbContext.Sections.FirstOrDefault(s => s.Id == section.id);
if (sectionDB == null)
throw new KeyNotFoundException($"Section {section.label} with id {section.id} does not exist");
}
foreach (var updatedSection in updatedSectionsOrder)
{
OldSection section = _sectionService.GetById(updatedSection.id);
var section = _myInfoMateDbContext.Sections.FirstOrDefault(s => s.Id == updatedSection.id);
//OldSection section = _sectionService.GetById(updatedSection.id);
section.Order = updatedSection.order.GetValueOrDefault();
_myInfoMateDbContext.SaveChanges();
_sectionService.Update(section.Id, section);
//_sectionService.Update(section.Id, section);
}
if (updatedSectionsOrder.Count > 0) {
@ -642,10 +676,23 @@ namespace ManagerService.Controllers
if (id == null)
throw new ArgumentNullException("Section param is null");
if (!_sectionService.IsExist(id))
var section = _myInfoMateDbContext.Sections.FirstOrDefault(s => s.Id == id);
if (section == null)
throw new KeyNotFoundException("Section does not exist");
_sectionService.Remove(id);
_myInfoMateDbContext.Remove(section);
//_sectionService.Remove(id);
// update order from rest // TODO TEST
List<Section> sections = _myInfoMateDbContext.Sections.Where(s => s.ConfigurationId == section.ConfigurationId && !s.IsSubSection).ToList();
int i = 1;
foreach (var sectionDb in sections.OrderBy(s => s.Order))
{
sectionDb.Order = i;
i++;
}
_myInfoMateDbContext.SaveChanges();
return new ObjectResult("The section has been deleted") { StatusCode = 202 };

View File

@ -7,7 +7,7 @@
Video,
Web,
Menu,
Quizz,
Quiz,
Article,
PDF,
Puzzle,

View File

@ -6,6 +6,6 @@ namespace Manager.DTOs
public class AgendaDTO : SectionDTO
{
public List<TranslationDTO> resourceIds { get; set; } // All json files for all languages
public MapProvider? mapProvider { get; set; } // Default = Google
public MapProvider? agendaMapProvider { get; set; } // Default = Google
}
}

View File

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

View File

@ -7,7 +7,8 @@ namespace Manager.DTOs
{
public List<TranslationAndResourceDTO> messageDebut { get; set; }
public List<TranslationAndResourceDTO> messageFin { get; set; }
public ContentDTO image { get; set; } // But only image is possible
public ResourceDTO puzzleImage { get; set; } // But only image is possible
public string puzzleImageId { get; set; } // But only image is possible
public int rows { get; set; } = 3;
public int cols { get; set; } = 3;
}

View File

@ -7,10 +7,10 @@ namespace Manager.DTOs
public class QuizDTO : SectionDTO
{
public List<QuestionDTO> questions { get; set; }
public LevelDTO bad_level { get; set; }
public LevelDTO medium_level { get; set; }
public LevelDTO good_level { get; set; }
public LevelDTO great_level { get; set; }
public List<TranslationAndResourceDTO> bad_level { get; set; }
public List<TranslationAndResourceDTO> medium_level { get; set; }
public List<TranslationAndResourceDTO> good_level { get; set; }
public List<TranslationAndResourceDTO> great_level { get; set; }
}
public class QuestionDTO

View File

@ -16,9 +16,9 @@ namespace ManagerService.Data.SubSection
{
[Required]
[Column(TypeName = "jsonb")]
public List<Translation> resourceIds { get; set; } // All json files for all languages
public List<Translation> AgendaResourceIds { get; set; } // All json files for all languages
public MapProvider? mapProvider { get; set; } // Default = Google
public MapProvider? AgendaMapProvider { get; set; } // Default = Google
public AgendaDTO ToDTO()
{
@ -42,8 +42,8 @@ namespace ManagerService.Data.SubSection
latitude = Latitude,
longitude = Longitude,
meterZoneGPS = MeterZoneGPS,
resourceIds = resourceIds.OrderBy(t => t.Language).Select(l => l.ToDTO()).ToList(),
mapProvider = mapProvider
resourceIds = AgendaResourceIds.OrderBy(t => t.Language).Select(l => l.ToDTO()).ToList(),
agendaMapProvider = AgendaMapProvider
};
}
}

View File

@ -16,18 +16,18 @@ namespace ManagerService.Data.SubSection
{
[Required]
[Column(TypeName = "jsonb")]
public List<Translation> content { get; set; }
public List<Translation> ArticleContent { get; set; }
public bool isContentTop { get; set; } // MyVisit - True if content is displayed at top, false otherwise
public bool ArticleIsContentTop { get; set; } // MyVisit - True if content is displayed at top, false otherwise
[Required]
[Column(TypeName = "jsonb")]
public List<Translation> audioIds { get; set; }
public List<Translation> ArticleAudioIds { get; set; }
public bool isReadAudioAuto { get; set; } // MyVisit - True for audio play when open the article / false otherwise
public bool ArticleIsReadAudioAuto { get; set; } // MyVisit - True for audio play when open the article / false otherwise
[Required]
public List<Content> contents { get; set; }
public List<Content> ArticleContents { get; set; }
public ArticleDTO ToDTO()
{
@ -51,11 +51,11 @@ namespace ManagerService.Data.SubSection
latitude = Latitude,
longitude = Longitude,
meterZoneGPS = MeterZoneGPS,
content = content.OrderBy(t => t.Language).Select(l => l.ToDTO()).ToList(),
isContentTop = isContentTop,
audioIds = audioIds.Select(a=> a.ToDTO()).ToList(),
isReadAudioAuto = isReadAudioAuto,
contents = contents.Select(c => c.ToDTO()).ToList(),
content = ArticleContent.OrderBy(t => t.Language).Select(l => l.ToDTO()).ToList(),
isContentTop = ArticleIsContentTop,
audioIds = ArticleAudioIds.Select(a=> a.ToDTO()).ToList(),
isReadAudioAuto = ArticleIsReadAudioAuto,
contents = ArticleContents.Select(c => c.ToDTO()).ToList(),
};
}
}

View File

@ -14,16 +14,16 @@ namespace ManagerService.Data.SubSection
/// </summary>
public class SectionMap : Section
{
public int Zoom { get; set; } // Default = 18
public MapTypeApp? MapType { get; set; } // Default = Hybrid for Google
public int MapZoom { get; set; } // Default = 18
public MapTypeApp? MapMapType { get; set; } // Default = Hybrid for Google
public MapTypeMapBox? MapTypeMapbox { get; set; } // Default = standard for MapBox
public MapProvider? MapProvider { get; set; } // Default = Google
public List<GeoPoint> Points { get; set; }
public string ResourceId { get; set; }
public Resource Resource { get; set; } // Icon
public List<Categorie> Categories { get; set; }
public string CenterLatitude { get; set; } // Center on
public string CenterLongitude { get; set; } // Center on
public MapProvider? MapMapProvider { get; set; } // Default = Google
public List<GeoPoint> MapPoints { get; set; }
public string MapResourceId { get; set; }
public Resource MapResource { get; set; } // Icon
public List<Categorie> MapCategories { get; set; }
public string MapCenterLatitude { get; set; } // Center on
public string MapCenterLongitude { get; set; } // Center on
public MapDTO ToDTO()
@ -48,15 +48,15 @@ namespace ManagerService.Data.SubSection
latitude = Latitude,
longitude = Longitude,
meterZoneGPS = MeterZoneGPS,
zoom = Zoom,
mapType = MapType,
zoom = MapZoom,
mapType = MapMapType,
mapTypeMapbox = MapTypeMapbox,
mapProvider = MapProvider,
mapProvider = MapMapProvider,
//points = Points.Select(p => p.ToDTO()).ToList(), // TODO
iconResourceId = ResourceId,
categories = Categories.Select(c => c.ToDTO()).ToList(),
centerLatitude = CenterLatitude,
centerLongitude = CenterLongitude
iconResourceId = MapResourceId,
categories = MapCategories.Select(c => c.ToDTO()).ToList(),
centerLatitude = MapCenterLatitude,
centerLongitude = MapCenterLongitude
};
}
}

View File

@ -15,7 +15,7 @@ namespace ManagerService.Data.SubSection
public class SectionMenu : Section
{
[Required]
public List<Section> Sections { get; set; } // All json files for all languages
public List<Section> MenuSections { get; set; } // All json files for all languages
public MenuDTO ToDTO()
{
@ -39,7 +39,7 @@ namespace ManagerService.Data.SubSection
latitude = Latitude,
longitude = Longitude,
meterZoneGPS = MeterZoneGPS,
sections = Sections.Select(s => s.ToDTO()).ToList()
sections = MenuSections.Select(s => s.ToDTO()).ToList()
};
}
}

View File

@ -12,7 +12,7 @@ namespace ManagerService.Data.SubSection
public class SectionPdf : Section
{
[Required]
public List<OrderedTranslationAndResource> orderedTranslationAndResources { get; set; } // All json files for all languages
public List<OrderedTranslationAndResource> PDFOrderedTranslationAndResources { get; set; } // All json files for all languages
public PdfDTO ToDTO()
{
@ -36,7 +36,7 @@ namespace ManagerService.Data.SubSection
latitude = Latitude,
longitude = Longitude,
meterZoneGPS = MeterZoneGPS,
pdfs = orderedTranslationAndResources.Select(otar => otar.ToDTO()).ToList()
pdfs = PDFOrderedTranslationAndResources.Select(otar => otar.ToDTO()).ToList()
};
}
}

View File

@ -16,20 +16,20 @@ namespace ManagerService.Data.SubSection
{
[Required]
[Column(TypeName = "jsonb")]
public List<TranslationAndResource> MessageDebut { get; set; }
public List<TranslationAndResource> PuzzleMessageDebut { get; set; }
[Required]
[Column(TypeName = "jsonb")]
public List<TranslationAndResource> MessageFin { get; set; }
public List<TranslationAndResource> PuzzleMessageFin { get; set; }
public string ContentId { get; set; } // But only image is possible
public Content Content { get; set; } // But only image is possible
public string PuzzleImageId { get; set; } // But only image is possible
public Resource PuzzleImage { get; set; } // But only image is possible
[Required]
public int Rows { get; set; } = 3;
public int PuzzleRows { get; set; } = 3;
[Required]
public int Cols { get; set; } = 3;
public int PuzzleCols { get; set; } = 3;
public PuzzleDTO ToDTO()
@ -54,11 +54,12 @@ namespace ManagerService.Data.SubSection
latitude = Latitude,
longitude = Longitude,
meterZoneGPS = MeterZoneGPS,
messageDebut = MessageDebut.Select(md => md.ToDTO()).ToList(),
messageFin = MessageFin.Select(mf => mf.ToDTO()).ToList(),
image = Content.ToDTO(),
rows = Rows,
cols = Cols
messageDebut = PuzzleMessageDebut.Select(md => md.ToDTO()).ToList(),
messageFin = PuzzleMessageFin.Select(mf => mf.ToDTO()).ToList(),
puzzleImage = PuzzleImage.ToDTO(),
puzzleImageId = PuzzleImageId,
rows = PuzzleRows,
cols = PuzzleCols
};
}
}

View File

@ -15,23 +15,23 @@ namespace ManagerService.Data.SubSection
public class SectionQuiz : Section
{
[Required]
public List<QuizQuestion> Questions { get; set; }
public List<QuizQuestion> QuizQuestions { get; set; }
[Required]
[Column(TypeName = "jsonb")]
public List<TranslationAndResource> BadLevel { get; set; }
public List<TranslationAndResource> QuizBadLevel { get; set; }
[Required]
[Column(TypeName = "jsonb")]
public List<TranslationAndResource> MediumLevel { get; set; }
public List<TranslationAndResource> QuizMediumLevel { get; set; }
[Required]
[Column(TypeName = "jsonb")]
public List<TranslationAndResource> GoodLevel { get; set; }
public List<TranslationAndResource> QuizGoodLevel { get; set; }
[Required]
[Column(TypeName = "jsonb")]
public List<TranslationAndResource> GreatLevel { get; set; }
public List<TranslationAndResource> QuizGreatLevel { get; set; }
public QuizDTO ToDTO()

View File

@ -15,7 +15,7 @@ namespace ManagerService.Data.SubSection
public class SectionSlider : Section
{
[Required]
public List<Content> Contents { get; set; } // TODO check
public List<Content> SliderContents { get; set; } // TODO check
public SliderDTO ToDTO()
{
@ -39,7 +39,7 @@ namespace ManagerService.Data.SubSection
latitude = Latitude,
longitude = Longitude,
meterZoneGPS = MeterZoneGPS,
contents = Contents.Select(c => c.ToDTO()).ToList(),
contents = SliderContents.Select(c => c.ToDTO()).ToList(),
};
}
}

View File

@ -10,7 +10,7 @@ namespace ManagerService.Data.SubSection
public class SectionVideo : Section
{
[Required]
public string Source { get; set; } // url to resource id (local) or on internet
public string VideoSource { get; set; } // url to resource id (local) or on internet
public VideoDTO ToDTO()
{
@ -34,7 +34,7 @@ namespace ManagerService.Data.SubSection
latitude = Latitude,
longitude = Longitude,
meterZoneGPS = MeterZoneGPS,
source = Source
source = VideoSource
};
}
}

View File

@ -14,11 +14,11 @@ namespace ManagerService.Data.SubSection
/// </summary>
public class SectionWeather : Section
{
public string City { get; set; } // Weather City
public string WeatherCity { get; set; } // Weather City
public DateTimeOffset? UpdatedDate { get; set; } // Weather date update (to only refresh)
public DateTimeOffset? WeatherUpdatedDate { get; set; } // Weather date update (to only refresh)
public string Result { get; set; } // Weather result
public string WeatherResult { get; set; } // Weather result
public WeatherDTO ToDTO()
{
@ -42,9 +42,9 @@ namespace ManagerService.Data.SubSection
latitude = Latitude,
longitude = Longitude,
meterZoneGPS = MeterZoneGPS,
city = City,
updatedDate = UpdatedDate,
result = Result,
city = WeatherCity,
updatedDate = WeatherUpdatedDate,
result = WeatherResult,
};
}
}

View File

@ -11,7 +11,7 @@ namespace ManagerService.Data.SubSection
public class SectionWeb : Section
{
[Required]
public string Source { get; set; } // url to resource id (local) or on internet
public string WebSource { get; set; } // url to resource id (local) or on internet
public WebDTO ToDTO()
{
@ -35,7 +35,7 @@ namespace ManagerService.Data.SubSection
latitude = Latitude,
longitude = Longitude,
meterZoneGPS = MeterZoneGPS,
source = Source
source = WebSource
};
}
}

View File

@ -0,0 +1,817 @@
// <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("20250320151926_UpdateMix")]
partial class UpdateMix
{
/// <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")
.IsRequired()
.HasColumnType("text");
b.Property<string>("ImageSource")
.IsRequired()
.HasColumnType("text");
b.Property<string>("InstanceId")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("IsBeacon")
.HasColumnType("boolean");
b.Property<bool>("IsSubSection")
.HasColumnType("boolean");
b.Property<string>("Label")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Latitude")
.HasColumnType("text");
b.Property<string>("Longitude")
.HasColumnType("text");
b.Property<int?>("MeterZoneGPS")
.HasColumnType("integer");
b.Property<int>("Order")
.HasColumnType("integer");
b.Property<string>("ParentId")
.HasColumnType("text");
b.Property<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,368 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace ManagerService.Migrations
{
/// <inheritdoc />
public partial class UpdateMix : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Sections_Content_ContentId1",
table: "Sections");
migrationBuilder.DropForeignKey(
name: "FK_Sections_Resources_ResourceId",
table: "Sections");
migrationBuilder.DropIndex(
name: "IX_Sections_ContentId1",
table: "Sections");
migrationBuilder.DropIndex(
name: "IX_Sections_ResourceId",
table: "Sections");
migrationBuilder.DropColumn(
name: "Cols",
table: "Sections");
migrationBuilder.RenameColumn(
name: "resourceIds",
table: "Sections",
newName: "QuizMediumLevel");
migrationBuilder.RenameColumn(
name: "mapProvider",
table: "Sections",
newName: "PuzzleRows");
migrationBuilder.RenameColumn(
name: "isReadAudioAuto",
table: "Sections",
newName: "ArticleIsReadAudioAuto");
migrationBuilder.RenameColumn(
name: "isContentTop",
table: "Sections",
newName: "ArticleIsContentTop");
migrationBuilder.RenameColumn(
name: "content",
table: "Sections",
newName: "QuizGreatLevel");
migrationBuilder.RenameColumn(
name: "audioIds",
table: "Sections",
newName: "QuizGoodLevel");
migrationBuilder.RenameColumn(
name: "Zoom",
table: "Sections",
newName: "PuzzleCols");
migrationBuilder.RenameColumn(
name: "UpdatedDate",
table: "Sections",
newName: "WeatherUpdatedDate");
migrationBuilder.RenameColumn(
name: "Source",
table: "Sections",
newName: "WebSource");
migrationBuilder.RenameColumn(
name: "SectionWeb_Source",
table: "Sections",
newName: "WeatherResult");
migrationBuilder.RenameColumn(
name: "Rows",
table: "Sections",
newName: "MapZoom");
migrationBuilder.RenameColumn(
name: "Result",
table: "Sections",
newName: "WeatherCity");
migrationBuilder.RenameColumn(
name: "ResourceId",
table: "Sections",
newName: "VideoSource");
migrationBuilder.RenameColumn(
name: "MessageFin",
table: "Sections",
newName: "QuizBadLevel");
migrationBuilder.RenameColumn(
name: "MessageDebut",
table: "Sections",
newName: "PuzzleMessageFin");
migrationBuilder.RenameColumn(
name: "MediumLevel",
table: "Sections",
newName: "PuzzleMessageDebut");
migrationBuilder.RenameColumn(
name: "MapType",
table: "Sections",
newName: "MapMapType");
migrationBuilder.RenameColumn(
name: "MapProvider",
table: "Sections",
newName: "MapMapProvider");
migrationBuilder.RenameColumn(
name: "GreatLevel",
table: "Sections",
newName: "ArticleContent");
migrationBuilder.RenameColumn(
name: "GoodLevel",
table: "Sections",
newName: "ArticleAudioIds");
migrationBuilder.RenameColumn(
name: "ContentId1",
table: "Sections",
newName: "AgendaMapProvider");
migrationBuilder.RenameColumn(
name: "ContentId",
table: "Sections",
newName: "PuzzleImageId");
migrationBuilder.RenameColumn(
name: "City",
table: "Sections",
newName: "MapResourceId");
migrationBuilder.RenameColumn(
name: "CenterLongitude",
table: "Sections",
newName: "MapCenterLongitude");
migrationBuilder.RenameColumn(
name: "CenterLatitude",
table: "Sections",
newName: "MapCenterLatitude");
migrationBuilder.RenameColumn(
name: "BadLevel",
table: "Sections",
newName: "AgendaResourceIds");
migrationBuilder.CreateIndex(
name: "IX_Sections_MapResourceId",
table: "Sections",
column: "MapResourceId");
migrationBuilder.CreateIndex(
name: "IX_Sections_PuzzleImageId",
table: "Sections",
column: "PuzzleImageId");
migrationBuilder.AddForeignKey(
name: "FK_Sections_Resources_MapResourceId",
table: "Sections",
column: "MapResourceId",
principalTable: "Resources",
principalColumn: "Id");
migrationBuilder.AddForeignKey(
name: "FK_Sections_Resources_PuzzleImageId",
table: "Sections",
column: "PuzzleImageId",
principalTable: "Resources",
principalColumn: "Id");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Sections_Resources_MapResourceId",
table: "Sections");
migrationBuilder.DropForeignKey(
name: "FK_Sections_Resources_PuzzleImageId",
table: "Sections");
migrationBuilder.DropIndex(
name: "IX_Sections_MapResourceId",
table: "Sections");
migrationBuilder.DropIndex(
name: "IX_Sections_PuzzleImageId",
table: "Sections");
migrationBuilder.RenameColumn(
name: "WebSource",
table: "Sections",
newName: "Source");
migrationBuilder.RenameColumn(
name: "WeatherUpdatedDate",
table: "Sections",
newName: "UpdatedDate");
migrationBuilder.RenameColumn(
name: "WeatherResult",
table: "Sections",
newName: "SectionWeb_Source");
migrationBuilder.RenameColumn(
name: "WeatherCity",
table: "Sections",
newName: "Result");
migrationBuilder.RenameColumn(
name: "VideoSource",
table: "Sections",
newName: "ResourceId");
migrationBuilder.RenameColumn(
name: "QuizMediumLevel",
table: "Sections",
newName: "resourceIds");
migrationBuilder.RenameColumn(
name: "QuizGreatLevel",
table: "Sections",
newName: "content");
migrationBuilder.RenameColumn(
name: "QuizGoodLevel",
table: "Sections",
newName: "audioIds");
migrationBuilder.RenameColumn(
name: "QuizBadLevel",
table: "Sections",
newName: "MessageFin");
migrationBuilder.RenameColumn(
name: "PuzzleRows",
table: "Sections",
newName: "mapProvider");
migrationBuilder.RenameColumn(
name: "PuzzleMessageFin",
table: "Sections",
newName: "MessageDebut");
migrationBuilder.RenameColumn(
name: "PuzzleMessageDebut",
table: "Sections",
newName: "MediumLevel");
migrationBuilder.RenameColumn(
name: "PuzzleImageId",
table: "Sections",
newName: "ContentId");
migrationBuilder.RenameColumn(
name: "PuzzleCols",
table: "Sections",
newName: "Zoom");
migrationBuilder.RenameColumn(
name: "MapZoom",
table: "Sections",
newName: "Rows");
migrationBuilder.RenameColumn(
name: "MapResourceId",
table: "Sections",
newName: "City");
migrationBuilder.RenameColumn(
name: "MapMapType",
table: "Sections",
newName: "MapType");
migrationBuilder.RenameColumn(
name: "MapMapProvider",
table: "Sections",
newName: "MapProvider");
migrationBuilder.RenameColumn(
name: "MapCenterLongitude",
table: "Sections",
newName: "CenterLongitude");
migrationBuilder.RenameColumn(
name: "MapCenterLatitude",
table: "Sections",
newName: "CenterLatitude");
migrationBuilder.RenameColumn(
name: "ArticleIsReadAudioAuto",
table: "Sections",
newName: "isReadAudioAuto");
migrationBuilder.RenameColumn(
name: "ArticleIsContentTop",
table: "Sections",
newName: "isContentTop");
migrationBuilder.RenameColumn(
name: "ArticleContent",
table: "Sections",
newName: "GreatLevel");
migrationBuilder.RenameColumn(
name: "ArticleAudioIds",
table: "Sections",
newName: "GoodLevel");
migrationBuilder.RenameColumn(
name: "AgendaResourceIds",
table: "Sections",
newName: "BadLevel");
migrationBuilder.RenameColumn(
name: "AgendaMapProvider",
table: "Sections",
newName: "ContentId1");
migrationBuilder.AddColumn<int>(
name: "Cols",
table: "Sections",
type: "integer",
nullable: true);
migrationBuilder.CreateIndex(
name: "IX_Sections_ContentId1",
table: "Sections",
column: "ContentId1");
migrationBuilder.CreateIndex(
name: "IX_Sections_ResourceId",
table: "Sections",
column: "ResourceId");
migrationBuilder.AddForeignKey(
name: "FK_Sections_Content_ContentId1",
table: "Sections",
column: "ContentId1",
principalTable: "Content",
principalColumn: "Id");
migrationBuilder.AddForeignKey(
name: "FK_Sections_Resources_ResourceId",
table: "Sections",
column: "ResourceId",
principalTable: "Resources",
principalColumn: "Id");
}
}
}

View File

@ -515,10 +515,10 @@ namespace ManagerService.Migrations
{
b.HasBaseType("ManagerService.Data.Section");
b.Property<int?>("mapProvider")
b.Property<int?>("AgendaMapProvider")
.HasColumnType("integer");
b.Property<List<Translation>>("resourceIds")
b.Property<List<Translation>>("AgendaResourceIds")
.IsRequired()
.HasColumnType("jsonb");
@ -529,18 +529,18 @@ namespace ManagerService.Migrations
{
b.HasBaseType("ManagerService.Data.Section");
b.Property<List<Translation>>("audioIds")
b.Property<List<Translation>>("ArticleAudioIds")
.IsRequired()
.HasColumnType("jsonb");
b.Property<List<Translation>>("content")
b.Property<List<Translation>>("ArticleContent")
.IsRequired()
.HasColumnType("jsonb");
b.Property<bool>("isContentTop")
b.Property<bool>("ArticleIsContentTop")
.HasColumnType("boolean");
b.Property<bool>("isReadAudioAuto")
b.Property<bool>("ArticleIsReadAudioAuto")
.HasColumnType("boolean");
b.HasDiscriminator().HasValue("Article");
@ -550,28 +550,28 @@ namespace ManagerService.Migrations
{
b.HasBaseType("ManagerService.Data.Section");
b.Property<string>("CenterLatitude")
b.Property<string>("MapCenterLatitude")
.HasColumnType("text");
b.Property<string>("CenterLongitude")
b.Property<string>("MapCenterLongitude")
.HasColumnType("text");
b.Property<int?>("MapProvider")
b.Property<int?>("MapMapProvider")
.HasColumnType("integer");
b.Property<int?>("MapType")
b.Property<int?>("MapMapType")
.HasColumnType("integer");
b.Property<string>("MapResourceId")
.HasColumnType("text");
b.Property<int?>("MapTypeMapbox")
.HasColumnType("integer");
b.Property<string>("ResourceId")
.HasColumnType("text");
b.Property<int>("Zoom")
b.Property<int>("MapZoom")
.HasColumnType("integer");
b.HasIndex("ResourceId");
b.HasIndex("MapResourceId");
b.HasDiscriminator().HasValue("Map");
});
@ -594,27 +594,24 @@ namespace ManagerService.Migrations
{
b.HasBaseType("ManagerService.Data.Section");
b.Property<int>("Cols")
b.Property<int>("PuzzleCols")
.HasColumnType("integer");
b.Property<string>("ContentId")
b.Property<string>("PuzzleImageId")
.HasColumnType("text");
b.Property<int?>("ContentId1")
.HasColumnType("integer");
b.Property<List<TranslationAndResource>>("MessageDebut")
b.Property<List<TranslationAndResource>>("PuzzleMessageDebut")
.IsRequired()
.HasColumnType("jsonb");
b.Property<List<TranslationAndResource>>("MessageFin")
b.Property<List<TranslationAndResource>>("PuzzleMessageFin")
.IsRequired()
.HasColumnType("jsonb");
b.Property<int>("Rows")
b.Property<int>("PuzzleRows")
.HasColumnType("integer");
b.HasIndex("ContentId1");
b.HasIndex("PuzzleImageId");
b.HasDiscriminator().HasValue("Puzzle");
});
@ -623,19 +620,19 @@ namespace ManagerService.Migrations
{
b.HasBaseType("ManagerService.Data.Section");
b.Property<List<TranslationAndResource>>("BadLevel")
b.Property<List<TranslationAndResource>>("QuizBadLevel")
.IsRequired()
.HasColumnType("jsonb");
b.Property<List<TranslationAndResource>>("GoodLevel")
b.Property<List<TranslationAndResource>>("QuizGoodLevel")
.IsRequired()
.HasColumnType("jsonb");
b.Property<List<TranslationAndResource>>("GreatLevel")
b.Property<List<TranslationAndResource>>("QuizGreatLevel")
.IsRequired()
.HasColumnType("jsonb");
b.Property<List<TranslationAndResource>>("MediumLevel")
b.Property<List<TranslationAndResource>>("QuizMediumLevel")
.IsRequired()
.HasColumnType("jsonb");
@ -653,7 +650,7 @@ namespace ManagerService.Migrations
{
b.HasBaseType("ManagerService.Data.Section");
b.Property<string>("Source")
b.Property<string>("VideoSource")
.IsRequired()
.HasColumnType("text");
@ -664,13 +661,13 @@ namespace ManagerService.Migrations
{
b.HasBaseType("ManagerService.Data.Section");
b.Property<string>("City")
b.Property<string>("WeatherCity")
.HasColumnType("text");
b.Property<string>("Result")
b.Property<string>("WeatherResult")
.HasColumnType("text");
b.Property<DateTimeOffset?>("UpdatedDate")
b.Property<DateTimeOffset?>("WeatherUpdatedDate")
.HasColumnType("timestamp with time zone");
b.HasDiscriminator().HasValue("Weather");
@ -680,16 +677,10 @@ namespace ManagerService.Migrations
{
b.HasBaseType("ManagerService.Data.Section");
b.Property<string>("Source")
b.Property<string>("WebSource")
.IsRequired()
.HasColumnType("text");
b.ToTable("Sections", t =>
{
t.Property("Source")
.HasColumnName("SectionWeb_Source");
});
b.HasDiscriminator().HasValue("Web");
});
@ -707,7 +698,7 @@ namespace ManagerService.Migrations
modelBuilder.Entity("ManagerService.Data.Section", b =>
{
b.HasOne("ManagerService.Data.SubSection.SectionMenu", null)
.WithMany("Sections")
.WithMany("MenuSections")
.HasForeignKey("SectionMenuId");
});
@ -718,7 +709,7 @@ namespace ManagerService.Migrations
.HasForeignKey("ResourceId");
b.HasOne("ManagerService.Data.SubSection.SectionMap", null)
.WithMany("Categories")
.WithMany("MapCategories")
.HasForeignKey("SectionMapId");
b.Navigation("Resource");
@ -731,11 +722,11 @@ namespace ManagerService.Migrations
.HasForeignKey("ResourceId");
b.HasOne("ManagerService.Data.SubSection.SectionArticle", null)
.WithMany("contents")
.WithMany("ArticleContents")
.HasForeignKey("SectionArticleId");
b.HasOne("ManagerService.Data.SubSection.SectionSlider", null)
.WithMany("Contents")
.WithMany("SliderContents")
.HasForeignKey("SectionSliderId");
b.Navigation("Resource");
@ -744,14 +735,14 @@ namespace ManagerService.Migrations
modelBuilder.Entity("ManagerService.Data.SubSection.GeoPoint", b =>
{
b.HasOne("ManagerService.Data.SubSection.SectionMap", null)
.WithMany("Points")
.WithMany("MapPoints")
.HasForeignKey("SectionMapId");
});
modelBuilder.Entity("ManagerService.Data.SubSection.OrderedTranslationAndResource", b =>
{
b.HasOne("ManagerService.Data.SubSection.SectionPdf", null)
.WithMany("orderedTranslationAndResources")
.WithMany("PDFOrderedTranslationAndResources")
.HasForeignKey("SectionPdfId");
});
@ -762,7 +753,7 @@ namespace ManagerService.Migrations
.HasForeignKey("ResourceId");
b.HasOne("ManagerService.Data.SubSection.SectionQuiz", null)
.WithMany("Questions")
.WithMany("QuizQuestions")
.HasForeignKey("SectionQuizId");
b.Navigation("Resource");
@ -770,52 +761,52 @@ namespace ManagerService.Migrations
modelBuilder.Entity("ManagerService.Data.SubSection.SectionMap", b =>
{
b.HasOne("ManagerService.Data.Resource", "Resource")
b.HasOne("ManagerService.Data.Resource", "MapResource")
.WithMany()
.HasForeignKey("ResourceId");
.HasForeignKey("MapResourceId");
b.Navigation("Resource");
b.Navigation("MapResource");
});
modelBuilder.Entity("ManagerService.Data.SubSection.SectionPuzzle", b =>
{
b.HasOne("ManagerService.Data.SubSection.Content", "Content")
b.HasOne("ManagerService.Data.Resource", "PuzzleImage")
.WithMany()
.HasForeignKey("ContentId1");
.HasForeignKey("PuzzleImageId");
b.Navigation("Content");
b.Navigation("PuzzleImage");
});
modelBuilder.Entity("ManagerService.Data.SubSection.SectionArticle", b =>
{
b.Navigation("contents");
b.Navigation("ArticleContents");
});
modelBuilder.Entity("ManagerService.Data.SubSection.SectionMap", b =>
{
b.Navigation("Categories");
b.Navigation("MapCategories");
b.Navigation("Points");
b.Navigation("MapPoints");
});
modelBuilder.Entity("ManagerService.Data.SubSection.SectionMenu", b =>
{
b.Navigation("Sections");
b.Navigation("MenuSections");
});
modelBuilder.Entity("ManagerService.Data.SubSection.SectionPdf", b =>
{
b.Navigation("orderedTranslationAndResources");
b.Navigation("PDFOrderedTranslationAndResources");
});
modelBuilder.Entity("ManagerService.Data.SubSection.SectionQuiz", b =>
{
b.Navigation("Questions");
b.Navigation("QuizQuestions");
});
modelBuilder.Entity("ManagerService.Data.SubSection.SectionSlider", b =>
{
b.Navigation("Contents");
b.Navigation("SliderContents");
});
#pragma warning restore 612, 618
}

View File

@ -0,0 +1,255 @@
using Manager.DTOs;
using ManagerService.Data;
using ManagerService.Data.SubSection;
using ManagerService.DTOs;
using System;
using System.Linq;
namespace ManagerService.Services
{
public static class SectionFactory
{
public static Section Create(SectionDTO dto)
{
return dto.type switch
{
SectionType.Agenda => new SectionAgenda
{
Id = dto.id,
Label = dto.label,
Title = dto.title.Select(t => new Translation().FromDTO(t)).ToList(),
Description = dto.description.Select(d => new Translation().FromDTO(d)).ToList(),
Order = dto.order.Value,
ImageId = dto.imageId,
ImageSource = dto.imageSource,
IsSubSection = dto.isSubSection,
ParentId = dto.parentId,
IsBeacon = dto.isBeacon,
BeaconId = dto.beaconId,
Latitude = dto.latitude,
Longitude = dto.longitude,
MeterZoneGPS = dto.meterZoneGPS,
Type = dto.type,
AgendaResourceIds = ((AgendaDTO)dto).resourceIds.Select(r => new Translation().FromDTO(r)).ToList(),
AgendaMapProvider = ((AgendaDTO)dto).agendaMapProvider
},
SectionType.Article => new SectionArticle
{
Id = dto.id,
Label = dto.label,
Title = dto.title.Select(t => new Translation().FromDTO(t)).ToList(),
Description = dto.description.Select(d => new Translation().FromDTO(d)).ToList(),
Order = dto.order.Value,
ImageId = dto.imageId,
ImageSource = dto.imageSource,
IsSubSection = dto.isSubSection,
ParentId = dto.parentId,
IsBeacon = dto.isBeacon,
BeaconId = dto.beaconId,
Latitude = dto.latitude,
Longitude = dto.longitude,
MeterZoneGPS = dto.meterZoneGPS,
Type = dto.type,
ArticleContent = ((ArticleDTO)dto).content.Select(r => new Translation().FromDTO(r)).ToList(),
ArticleIsContentTop = ((ArticleDTO)dto).isContentTop,
ArticleAudioIds = ((ArticleDTO)dto).audioIds.Select(a => new Translation().FromDTO(a)).ToList(),
ArticleIsReadAudioAuto = ((ArticleDTO)dto).isReadAudioAuto,
ArticleContents = ((ArticleDTO)dto).contents.Select(c => new Content().FromDTO(c)).ToList()
},
SectionType.Map => new SectionMap
{
Id = dto.id,
Label = dto.label,
Title = dto.title.Select(t => new Translation().FromDTO(t)).ToList(),
Description = dto.description.Select(d => new Translation().FromDTO(d)).ToList(),
Order = dto.order.Value,
ImageId = dto.imageId,
ImageSource = dto.imageSource,
IsSubSection = dto.isSubSection,
ParentId = dto.parentId,
IsBeacon = dto.isBeacon,
BeaconId = dto.beaconId,
Latitude = dto.latitude,
Longitude = dto.longitude,
MeterZoneGPS = dto.meterZoneGPS,
Type = dto.type,
MapZoom = ((MapDTO)dto).zoom,
MapMapType = ((MapDTO)dto).mapType,
MapTypeMapbox = ((MapDTO)dto).mapTypeMapbox,
MapMapProvider = ((MapDTO)dto).mapProvider,
MapResourceId = ((MapDTO)dto).iconResourceId,
MapCenterLatitude = ((MapDTO)dto).centerLatitude,
MapCenterLongitude = ((MapDTO)dto).centerLongitude,
MapCategories = null, //((MapDTO)dto).categories, // TODO specific
MapPoints = null // ((MapDTO)dto).points, // TODO specific
},
SectionType.Menu => new SectionMenu
{
Id = dto.id,
Label = dto.label,
Title = dto.title.Select(t => new Translation().FromDTO(t)).ToList(),
Description = dto.description.Select(d => new Translation().FromDTO(d)).ToList(),
Order = dto.order.Value,
ImageId = dto.imageId,
ImageSource = dto.imageSource,
IsSubSection = dto.isSubSection,
ParentId = dto.parentId,
IsBeacon = dto.isBeacon,
BeaconId = dto.beaconId,
Latitude = dto.latitude,
Longitude = dto.longitude,
MeterZoneGPS = dto.meterZoneGPS,
Type = dto.type,
//Sections = ((MenuDTO)dto).sections, // TODO specific
},
SectionType.PDF => new SectionPdf
{
Id = dto.id,
Label = dto.label,
Title = dto.title.Select(t => new Translation().FromDTO(t)).ToList(),
Description = dto.description.Select(d => new Translation().FromDTO(d)).ToList(),
Order = dto.order.Value,
ImageId = dto.imageId,
ImageSource = dto.imageSource,
IsSubSection = dto.isSubSection,
ParentId = dto.parentId,
IsBeacon = dto.isBeacon,
BeaconId = dto.beaconId,
Latitude = dto.latitude,
Longitude = dto.longitude,
MeterZoneGPS = dto.meterZoneGPS,
Type = dto.type,
PDFOrderedTranslationAndResources = ((PdfDTO)dto).pdfs.Select(p => new OrderedTranslationAndResource().FromDTO(p)).ToList()
},
SectionType.Puzzle => new SectionPuzzle
{
Id = dto.id,
Label = dto.label,
Title = dto.title.Select(t => new Translation().FromDTO(t)).ToList(),
Description = dto.description.Select(d => new Translation().FromDTO(d)).ToList(),
Order = dto.order.Value,
ImageId = dto.imageId,
ImageSource = dto.imageSource,
IsSubSection = dto.isSubSection,
ParentId = dto.parentId,
IsBeacon = dto.isBeacon,
BeaconId = dto.beaconId,
Latitude = dto.latitude,
Longitude = dto.longitude,
MeterZoneGPS = dto.meterZoneGPS,
Type = dto.type,
PuzzleMessageDebut = ((PuzzleDTO)dto).messageDebut.Select(md => new TranslationAndResource().FromDTO(md)).ToList(),
PuzzleMessageFin = ((PuzzleDTO)dto).messageFin.Select(mf => new TranslationAndResource().FromDTO(mf)).ToList(),
PuzzleImageId = ((PuzzleDTO)dto).puzzleImageId,
PuzzleRows = ((PuzzleDTO)dto).rows,
PuzzleCols = ((PuzzleDTO)dto).cols
},
SectionType.Quiz => new SectionQuiz
{
Id = dto.id,
Label = dto.label,
Title = dto.title.Select(t => new Translation().FromDTO(t)).ToList(),
Description = dto.description.Select(d => new Translation().FromDTO(d)).ToList(),
Order = dto.order.Value,
ImageId = dto.imageId,
ImageSource = dto.imageSource,
IsSubSection = dto.isSubSection,
ParentId = dto.parentId,
IsBeacon = dto.isBeacon,
BeaconId = dto.beaconId,
Latitude = dto.latitude,
Longitude = dto.longitude,
MeterZoneGPS = dto.meterZoneGPS,
Type = dto.type,
QuizBadLevel = ((QuizDTO)dto).bad_level.Select(bl => new TranslationAndResource().FromDTO(bl)).ToList(),
QuizMediumLevel = ((QuizDTO)dto).medium_level.Select(ml => new TranslationAndResource().FromDTO(ml)).ToList(),
QuizGoodLevel = ((QuizDTO)dto).good_level.Select(gol => new TranslationAndResource().FromDTO(gol)).ToList(),
QuizGreatLevel = ((QuizDTO)dto).great_level.Select(gl => new TranslationAndResource().FromDTO(gl)).ToList(),
//Questions = ((QuizDTO)dto).questions, // TODO specific
},
SectionType.Slider => new SectionSlider
{
Id = dto.id,
Label = dto.label,
Title = dto.title.Select(t => new Translation().FromDTO(t)).ToList(),
Description = dto.description.Select(d => new Translation().FromDTO(d)).ToList(),
Order = dto.order.Value,
ImageId = dto.imageId,
ImageSource = dto.imageSource,
IsSubSection = dto.isSubSection,
ParentId = dto.parentId,
IsBeacon = dto.isBeacon,
BeaconId = dto.beaconId,
Latitude = dto.latitude,
Longitude = dto.longitude,
MeterZoneGPS = dto.meterZoneGPS,
Type = dto.type,
SliderContents = ((SliderDTO)dto).contents.Select(c => new Content().FromDTO(c)).ToList(), // TODO TEST
},
SectionType.Video => new SectionVideo
{
Id = dto.id,
Label = dto.label,
Title = dto.title.Select(t => new Translation().FromDTO(t)).ToList(),
Description = dto.description.Select(d => new Translation().FromDTO(d)).ToList(),
Order = dto.order.Value,
ImageId = dto.imageId,
ImageSource = dto.imageSource,
IsSubSection = dto.isSubSection,
ParentId = dto.parentId,
IsBeacon = dto.isBeacon,
BeaconId = dto.beaconId,
Latitude = dto.latitude,
Longitude = dto.longitude,
MeterZoneGPS = dto.meterZoneGPS,
Type = dto.type,
VideoSource = ((VideoDTO)dto).source,
},
SectionType.Weather => new SectionWeather
{
Id = dto.id,
Label = dto.label,
Title = dto.title.Select(t => new Translation().FromDTO(t)).ToList(),
Description = dto.description.Select(d => new Translation().FromDTO(d)).ToList(),
Order = dto.order.Value,
ImageId = dto.imageId,
ImageSource = dto.imageSource,
IsSubSection = dto.isSubSection,
ParentId = dto.parentId,
IsBeacon = dto.isBeacon,
BeaconId = dto.beaconId,
Latitude = dto.latitude,
Longitude = dto.longitude,
MeterZoneGPS = dto.meterZoneGPS,
Type = dto.type,
WeatherCity = ((WeatherDTO)dto).city,
WeatherUpdatedDate = ((WeatherDTO)dto).updatedDate,
WeatherResult = ((WeatherDTO)dto).result
},
SectionType.Web => new SectionWeb
{
Id = dto.id,
Label = dto.label,
Title = dto.title.Select(t => new Translation().FromDTO(t)).ToList(),
Description = dto.description.Select(d => new Translation().FromDTO(d)).ToList(),
Order = dto.order.Value,
ImageId = dto.imageId,
ImageSource = dto.imageSource,
IsSubSection = dto.isSubSection,
ParentId = dto.parentId,
IsBeacon = dto.isBeacon,
BeaconId = dto.beaconId,
Latitude = dto.latitude,
Longitude = dto.longitude,
MeterZoneGPS = dto.meterZoneGPS,
Type = dto.type,
WebSource = ((WebDTO)dto).source,
},
_ => throw new NotImplementedException("Section type not handled")
};
}
}
}