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");
_myInfoMateDbContext.Remove(configuration);
_myInfoMateDbContext.SaveChanges();
// Delete config for all devices
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)
{
@ -195,7 +195,7 @@ namespace ManagerService.Controllers
/// </summary>
/// <param name="id">section id</param>
[AllowAnonymous]
[ProducesResponseType(typeof(SectionDTO), 200)]
[ProducesResponseType(typeof(object), 200)]
[ProducesResponseType(typeof(string), 404)]
[ProducesResponseType(typeof(string), 500)]
[HttpGet("{id}")]

View File

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

View File

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

View File

@ -1,5 +1,8 @@
using ManagerService.Data.SubSection;
using ManagerService.DTOs;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Text.Json;
namespace ManagerService.Data
{
@ -22,10 +25,18 @@ namespace ManagerService.Data
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
var options = new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true
};
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Configuration>()
.Property(s => s.Title)
.HasColumnType("jsonb");
.HasColumnType("jsonb")
.HasConversion(
v => JsonSerializer.Serialize(v, options),
v => JsonSerializer.Deserialize<List<TranslationDTO>>(v, options));
modelBuilder.Entity<Section>()
.HasDiscriminator<string>("Discriminator")
@ -44,11 +55,17 @@ namespace ManagerService.Data
modelBuilder.Entity<Section>()
.Property(s => s.Title)
.HasColumnType("jsonb");
.HasColumnType("jsonb")
.HasConversion(
v => JsonSerializer.Serialize(v, options),
v => JsonSerializer.Deserialize<List<TranslationDTO>>(v, options));
modelBuilder.Entity<Section>()
.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
{
Id = dto.id,
DateCreation = dto.dateCreation,
ConfigurationId = dto.configurationId,
InstanceId = dto.instanceId,
Label = dto.label,
@ -90,6 +91,7 @@ namespace ManagerService.Services
SectionType.Article => new SectionArticle
{
Id = dto.id,
DateCreation = dto.dateCreation,
ConfigurationId = dto.configurationId,
InstanceId = dto.instanceId,
Label = dto.label,
@ -115,6 +117,7 @@ namespace ManagerService.Services
SectionType.Map => new SectionMap
{
Id = dto.id,
DateCreation = dto.dateCreation,
ConfigurationId = dto.configurationId,
InstanceId = dto.instanceId,
Label = dto.label,
@ -144,6 +147,7 @@ namespace ManagerService.Services
SectionType.Menu => new SectionMenu
{
Id = dto.id,
DateCreation = dto.dateCreation,
ConfigurationId = dto.configurationId,
InstanceId = dto.instanceId,
Label = dto.label,
@ -165,6 +169,7 @@ namespace ManagerService.Services
SectionType.PDF => new SectionPdf
{
Id = dto.id,
DateCreation = dto.dateCreation,
ConfigurationId = dto.configurationId,
InstanceId = dto.instanceId,
Label = dto.label,
@ -186,6 +191,7 @@ namespace ManagerService.Services
SectionType.Puzzle => new SectionPuzzle
{
Id = dto.id,
DateCreation = dto.dateCreation,
ConfigurationId = dto.configurationId,
InstanceId = dto.instanceId,
Label = dto.label,
@ -211,6 +217,7 @@ namespace ManagerService.Services
SectionType.Quiz => new SectionQuiz
{
Id = dto.id,
DateCreation = dto.dateCreation,
ConfigurationId = dto.configurationId,
InstanceId = dto.instanceId,
Label = dto.label,
@ -236,6 +243,7 @@ namespace ManagerService.Services
SectionType.Slider => new SectionSlider
{
Id = dto.id,
DateCreation = dto.dateCreation,
ConfigurationId = dto.configurationId,
InstanceId = dto.instanceId,
Label = dto.label,
@ -257,6 +265,7 @@ namespace ManagerService.Services
SectionType.Video => new SectionVideo
{
Id = dto.id,
DateCreation = dto.dateCreation,
ConfigurationId = dto.configurationId,
InstanceId = dto.instanceId,
Label = dto.label,
@ -279,6 +288,7 @@ namespace ManagerService.Services
SectionType.Weather => new SectionWeather
{
Id = dto.id,
DateCreation = dto.dateCreation,
ConfigurationId = dto.configurationId,
InstanceId = dto.instanceId,
Label = dto.label,
@ -302,6 +312,7 @@ namespace ManagerService.Services
SectionType.Web => new SectionWeb
{
Id = dto.id,
DateCreation = dto.dateCreation,
ConfigurationId = dto.configurationId,
InstanceId = dto.instanceId,
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 ?
return section switch
@ -332,6 +343,7 @@ namespace ManagerService.Services
SectionAgenda agenda => new AgendaDTO
{
id = agenda.Id,
dateCreation = agenda.DateCreation,
configurationId = agenda.ConfigurationId,
instanceId = agenda.InstanceId,
label = agenda.Label,
@ -354,6 +366,7 @@ namespace ManagerService.Services
SectionArticle article => new ArticleDTO
{
id = article.Id,
dateCreation = article.DateCreation,
configurationId = article.ConfigurationId,
instanceId = article.InstanceId,
label = article.Label,
@ -379,6 +392,7 @@ namespace ManagerService.Services
SectionMap map => new MapDTO
{
id = map.Id,
dateCreation = map.DateCreation,
configurationId = map.ConfigurationId,
instanceId = map.InstanceId,
label = map.Label,
@ -408,6 +422,7 @@ namespace ManagerService.Services
SectionMenu menu => new MenuDTO
{
id = menu.Id,
dateCreation = menu.DateCreation,
configurationId = menu.ConfigurationId,
instanceId = menu.InstanceId,
label = menu.Label,
@ -429,6 +444,7 @@ namespace ManagerService.Services
SectionPdf pdf => new PdfDTO
{
id = pdf.Id,
dateCreation = pdf.DateCreation,
configurationId = pdf.ConfigurationId,
instanceId = pdf.InstanceId,
label = pdf.Label,
@ -450,6 +466,7 @@ namespace ManagerService.Services
SectionPuzzle puzzle => new PuzzleDTO
{
id = puzzle.Id,
dateCreation = puzzle.DateCreation,
configurationId = puzzle.ConfigurationId,
instanceId = puzzle.InstanceId,
label = puzzle.Label,
@ -475,6 +492,7 @@ namespace ManagerService.Services
SectionQuiz quiz => new QuizDTO
{
id = quiz.Id,
dateCreation = quiz.DateCreation,
configurationId = quiz.ConfigurationId,
instanceId = quiz.InstanceId,
label = quiz.Label,
@ -500,6 +518,7 @@ namespace ManagerService.Services
SectionSlider slider => new SliderDTO
{
id = slider.Id,
dateCreation = slider.DateCreation,
configurationId = slider.ConfigurationId,
instanceId = slider.InstanceId,
label = slider.Label,
@ -521,6 +540,7 @@ namespace ManagerService.Services
SectionVideo video => new VideoDTO
{
id = video.Id,
dateCreation = video.DateCreation,
configurationId = video.ConfigurationId,
instanceId = video.InstanceId,
label = video.Label,
@ -542,6 +562,7 @@ namespace ManagerService.Services
SectionWeather weather => new WeatherDTO
{
id = weather.Id,
dateCreation = weather.DateCreation,
configurationId = weather.ConfigurationId,
instanceId = weather.InstanceId,
label = weather.Label,
@ -565,6 +586,7 @@ namespace ManagerService.Services
SectionWeb web => new WebDTO
{
id = web.Id,
dateCreation = web.DateCreation,
configurationId = web.ConfigurationId,
instanceId = web.InstanceId,
label = web.Label,

View File

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