This commit is contained in:
Thomas Fransolet 2025-05-13 17:18:59 +02:00
parent cef69a61df
commit f4919801b7
7 changed files with 51 additions and 11 deletions

View File

@ -364,6 +364,7 @@ namespace ManagerService.Controllers
throw new KeyNotFoundException("Configuration does not exist"); throw new KeyNotFoundException("Configuration does not exist");
_myInfoMateDbContext.Remove(configuration); _myInfoMateDbContext.Remove(configuration);
_myInfoMateDbContext.SaveChanges();
// Delete config for all devices // Delete config for all devices
List<Device> devices = _myInfoMateDbContext.Devices.Where(d => d.ConfigurationId == id).ToList(); List<Device> devices = _myInfoMateDbContext.Devices.Where(d => d.ConfigurationId == id).ToList();

View File

@ -81,7 +81,7 @@ namespace ManagerService.Controllers
} }
}*/ }*/
return new OkObjectResult(sections.Select(r => r.ToDTO())); return new OkObjectResult(sections.Select(s => s.ToDTO()));
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -195,7 +195,7 @@ namespace ManagerService.Controllers
/// </summary> /// </summary>
/// <param name="id">section id</param> /// <param name="id">section id</param>
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(typeof(SectionDTO), 200)] [ProducesResponseType(typeof(object), 200)]
[ProducesResponseType(typeof(string), 404)] [ProducesResponseType(typeof(string), 404)]
[ProducesResponseType(typeof(string), 500)] [ProducesResponseType(typeof(string), 500)]
[HttpGet("{id}")] [HttpGet("{id}")]

View File

@ -123,7 +123,7 @@ namespace ManagerService.Controllers
geoPoint.Latitude = geoPointDTO.latitude; geoPoint.Latitude = geoPointDTO.latitude;
geoPoint.Longitude = geoPointDTO.longitude; geoPoint.Longitude = geoPointDTO.longitude;
geoPoint.ImageResourceId = geoPointDTO.imageResourceId; geoPoint.ImageResourceId = geoPointDTO.imageResourceId;
geoPoint.ImageUrl = geoPointDTO.imageUrl; geoPoint.ImageUrl = geoPointDTO.imageUrl; // TO BE TESTED ? Depends on front
geoPoint.Schedules = geoPointDTO.schedules; geoPoint.Schedules = geoPointDTO.schedules;
geoPoint.Prices = geoPointDTO.prices; geoPoint.Prices = geoPointDTO.prices;
geoPoint.Phone = geoPointDTO.phone; geoPoint.Phone = geoPointDTO.phone;

View File

@ -31,8 +31,8 @@ namespace Manager.DTOs
public int order { get; set; } // Order to show public int order { get; set; } // Order to show
} }
public class LevelDTO /*public class LevelDTO
{ {
public List<TranslationAndResourceDTO> label { get; set; } public List<TranslationAndResourceDTO> label { get; set; }
} }*/
} }

View File

@ -1,5 +1,8 @@
using ManagerService.Data.SubSection; using ManagerService.Data.SubSection;
using ManagerService.DTOs;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Text.Json;
namespace ManagerService.Data namespace ManagerService.Data
{ {
@ -22,10 +25,18 @@ namespace ManagerService.Data
protected override void OnModelCreating(ModelBuilder modelBuilder) protected override void OnModelCreating(ModelBuilder modelBuilder)
{ {
var options = new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true
};
base.OnModelCreating(modelBuilder); base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Configuration>() modelBuilder.Entity<Configuration>()
.Property(s => s.Title) .Property(s => s.Title)
.HasColumnType("jsonb"); .HasColumnType("jsonb")
.HasConversion(
v => JsonSerializer.Serialize(v, options),
v => JsonSerializer.Deserialize<List<TranslationDTO>>(v, options));
modelBuilder.Entity<Section>() modelBuilder.Entity<Section>()
.HasDiscriminator<string>("Discriminator") .HasDiscriminator<string>("Discriminator")
@ -44,11 +55,17 @@ namespace ManagerService.Data
modelBuilder.Entity<Section>() modelBuilder.Entity<Section>()
.Property(s => s.Title) .Property(s => s.Title)
.HasColumnType("jsonb"); .HasColumnType("jsonb")
.HasConversion(
v => JsonSerializer.Serialize(v, options),
v => JsonSerializer.Deserialize<List<TranslationDTO>>(v, options));
modelBuilder.Entity<Section>() modelBuilder.Entity<Section>()
.Property(s => s.Description) .Property(s => s.Description)
.HasColumnType("jsonb"); .HasColumnType("jsonb")
.HasConversion(
v => JsonSerializer.Serialize(v, options),
v => JsonSerializer.Deserialize<List<TranslationDTO>>(v, options));
} }
} }

View File

@ -68,6 +68,7 @@ namespace ManagerService.Services
SectionType.Agenda => new SectionAgenda SectionType.Agenda => new SectionAgenda
{ {
Id = dto.id, Id = dto.id,
DateCreation = dto.dateCreation,
ConfigurationId = dto.configurationId, ConfigurationId = dto.configurationId,
InstanceId = dto.instanceId, InstanceId = dto.instanceId,
Label = dto.label, Label = dto.label,
@ -90,6 +91,7 @@ namespace ManagerService.Services
SectionType.Article => new SectionArticle SectionType.Article => new SectionArticle
{ {
Id = dto.id, Id = dto.id,
DateCreation = dto.dateCreation,
ConfigurationId = dto.configurationId, ConfigurationId = dto.configurationId,
InstanceId = dto.instanceId, InstanceId = dto.instanceId,
Label = dto.label, Label = dto.label,
@ -115,6 +117,7 @@ namespace ManagerService.Services
SectionType.Map => new SectionMap SectionType.Map => new SectionMap
{ {
Id = dto.id, Id = dto.id,
DateCreation = dto.dateCreation,
ConfigurationId = dto.configurationId, ConfigurationId = dto.configurationId,
InstanceId = dto.instanceId, InstanceId = dto.instanceId,
Label = dto.label, Label = dto.label,
@ -144,6 +147,7 @@ namespace ManagerService.Services
SectionType.Menu => new SectionMenu SectionType.Menu => new SectionMenu
{ {
Id = dto.id, Id = dto.id,
DateCreation = dto.dateCreation,
ConfigurationId = dto.configurationId, ConfigurationId = dto.configurationId,
InstanceId = dto.instanceId, InstanceId = dto.instanceId,
Label = dto.label, Label = dto.label,
@ -165,6 +169,7 @@ namespace ManagerService.Services
SectionType.PDF => new SectionPdf SectionType.PDF => new SectionPdf
{ {
Id = dto.id, Id = dto.id,
DateCreation = dto.dateCreation,
ConfigurationId = dto.configurationId, ConfigurationId = dto.configurationId,
InstanceId = dto.instanceId, InstanceId = dto.instanceId,
Label = dto.label, Label = dto.label,
@ -186,6 +191,7 @@ namespace ManagerService.Services
SectionType.Puzzle => new SectionPuzzle SectionType.Puzzle => new SectionPuzzle
{ {
Id = dto.id, Id = dto.id,
DateCreation = dto.dateCreation,
ConfigurationId = dto.configurationId, ConfigurationId = dto.configurationId,
InstanceId = dto.instanceId, InstanceId = dto.instanceId,
Label = dto.label, Label = dto.label,
@ -211,6 +217,7 @@ namespace ManagerService.Services
SectionType.Quiz => new SectionQuiz SectionType.Quiz => new SectionQuiz
{ {
Id = dto.id, Id = dto.id,
DateCreation = dto.dateCreation,
ConfigurationId = dto.configurationId, ConfigurationId = dto.configurationId,
InstanceId = dto.instanceId, InstanceId = dto.instanceId,
Label = dto.label, Label = dto.label,
@ -236,6 +243,7 @@ namespace ManagerService.Services
SectionType.Slider => new SectionSlider SectionType.Slider => new SectionSlider
{ {
Id = dto.id, Id = dto.id,
DateCreation = dto.dateCreation,
ConfigurationId = dto.configurationId, ConfigurationId = dto.configurationId,
InstanceId = dto.instanceId, InstanceId = dto.instanceId,
Label = dto.label, Label = dto.label,
@ -257,6 +265,7 @@ namespace ManagerService.Services
SectionType.Video => new SectionVideo SectionType.Video => new SectionVideo
{ {
Id = dto.id, Id = dto.id,
DateCreation = dto.dateCreation,
ConfigurationId = dto.configurationId, ConfigurationId = dto.configurationId,
InstanceId = dto.instanceId, InstanceId = dto.instanceId,
Label = dto.label, Label = dto.label,
@ -279,6 +288,7 @@ namespace ManagerService.Services
SectionType.Weather => new SectionWeather SectionType.Weather => new SectionWeather
{ {
Id = dto.id, Id = dto.id,
DateCreation = dto.dateCreation,
ConfigurationId = dto.configurationId, ConfigurationId = dto.configurationId,
InstanceId = dto.instanceId, InstanceId = dto.instanceId,
Label = dto.label, Label = dto.label,
@ -302,6 +312,7 @@ namespace ManagerService.Services
SectionType.Web => new SectionWeb SectionType.Web => new SectionWeb
{ {
Id = dto.id, Id = dto.id,
DateCreation = dto.dateCreation,
ConfigurationId = dto.configurationId, ConfigurationId = dto.configurationId,
InstanceId = dto.instanceId, InstanceId = dto.instanceId,
Label = dto.label, Label = dto.label,
@ -324,7 +335,7 @@ namespace ManagerService.Services
}; };
} }
public static SectionDTO ToDTO(Section section) public static object ToDTO(Section section)
{ {
// TODO retrieve specific elements ? // TODO retrieve specific elements ?
return section switch return section switch
@ -332,6 +343,7 @@ namespace ManagerService.Services
SectionAgenda agenda => new AgendaDTO SectionAgenda agenda => new AgendaDTO
{ {
id = agenda.Id, id = agenda.Id,
dateCreation = agenda.DateCreation,
configurationId = agenda.ConfigurationId, configurationId = agenda.ConfigurationId,
instanceId = agenda.InstanceId, instanceId = agenda.InstanceId,
label = agenda.Label, label = agenda.Label,
@ -354,6 +366,7 @@ namespace ManagerService.Services
SectionArticle article => new ArticleDTO SectionArticle article => new ArticleDTO
{ {
id = article.Id, id = article.Id,
dateCreation = article.DateCreation,
configurationId = article.ConfigurationId, configurationId = article.ConfigurationId,
instanceId = article.InstanceId, instanceId = article.InstanceId,
label = article.Label, label = article.Label,
@ -379,6 +392,7 @@ namespace ManagerService.Services
SectionMap map => new MapDTO SectionMap map => new MapDTO
{ {
id = map.Id, id = map.Id,
dateCreation = map.DateCreation,
configurationId = map.ConfigurationId, configurationId = map.ConfigurationId,
instanceId = map.InstanceId, instanceId = map.InstanceId,
label = map.Label, label = map.Label,
@ -408,6 +422,7 @@ namespace ManagerService.Services
SectionMenu menu => new MenuDTO SectionMenu menu => new MenuDTO
{ {
id = menu.Id, id = menu.Id,
dateCreation = menu.DateCreation,
configurationId = menu.ConfigurationId, configurationId = menu.ConfigurationId,
instanceId = menu.InstanceId, instanceId = menu.InstanceId,
label = menu.Label, label = menu.Label,
@ -429,6 +444,7 @@ namespace ManagerService.Services
SectionPdf pdf => new PdfDTO SectionPdf pdf => new PdfDTO
{ {
id = pdf.Id, id = pdf.Id,
dateCreation = pdf.DateCreation,
configurationId = pdf.ConfigurationId, configurationId = pdf.ConfigurationId,
instanceId = pdf.InstanceId, instanceId = pdf.InstanceId,
label = pdf.Label, label = pdf.Label,
@ -450,6 +466,7 @@ namespace ManagerService.Services
SectionPuzzle puzzle => new PuzzleDTO SectionPuzzle puzzle => new PuzzleDTO
{ {
id = puzzle.Id, id = puzzle.Id,
dateCreation = puzzle.DateCreation,
configurationId = puzzle.ConfigurationId, configurationId = puzzle.ConfigurationId,
instanceId = puzzle.InstanceId, instanceId = puzzle.InstanceId,
label = puzzle.Label, label = puzzle.Label,
@ -475,6 +492,7 @@ namespace ManagerService.Services
SectionQuiz quiz => new QuizDTO SectionQuiz quiz => new QuizDTO
{ {
id = quiz.Id, id = quiz.Id,
dateCreation = quiz.DateCreation,
configurationId = quiz.ConfigurationId, configurationId = quiz.ConfigurationId,
instanceId = quiz.InstanceId, instanceId = quiz.InstanceId,
label = quiz.Label, label = quiz.Label,
@ -500,6 +518,7 @@ namespace ManagerService.Services
SectionSlider slider => new SliderDTO SectionSlider slider => new SliderDTO
{ {
id = slider.Id, id = slider.Id,
dateCreation = slider.DateCreation,
configurationId = slider.ConfigurationId, configurationId = slider.ConfigurationId,
instanceId = slider.InstanceId, instanceId = slider.InstanceId,
label = slider.Label, label = slider.Label,
@ -521,6 +540,7 @@ namespace ManagerService.Services
SectionVideo video => new VideoDTO SectionVideo video => new VideoDTO
{ {
id = video.Id, id = video.Id,
dateCreation = video.DateCreation,
configurationId = video.ConfigurationId, configurationId = video.ConfigurationId,
instanceId = video.InstanceId, instanceId = video.InstanceId,
label = video.Label, label = video.Label,
@ -542,6 +562,7 @@ namespace ManagerService.Services
SectionWeather weather => new WeatherDTO SectionWeather weather => new WeatherDTO
{ {
id = weather.Id, id = weather.Id,
dateCreation = weather.DateCreation,
configurationId = weather.ConfigurationId, configurationId = weather.ConfigurationId,
instanceId = weather.InstanceId, instanceId = weather.InstanceId,
label = weather.Label, label = weather.Label,
@ -565,6 +586,7 @@ namespace ManagerService.Services
SectionWeb web => new WebDTO SectionWeb web => new WebDTO
{ {
id = web.Id, id = web.Id,
dateCreation = web.DateCreation,
configurationId = web.ConfigurationId, configurationId = web.ConfigurationId,
instanceId = web.InstanceId, instanceId = web.InstanceId,
label = web.Label, label = web.Label,

View File

@ -188,7 +188,7 @@ namespace ManagerService
app.UseCors( app.UseCors(
#if DEBUG #if DEBUG
options => options options => options
.SetIsOriginAllowed(origin => string.IsNullOrEmpty(origin) || origin == "http://localhost:8081") .SetIsOriginAllowed(origin => string.IsNullOrEmpty(origin) || origin == "http://localhost:49430")
.AllowAnyMethod() .AllowAnyMethod()
.AllowAnyHeader() .AllowAnyHeader()
.AllowCredentials() .AllowCredentials()