diff --git a/ManagerService/Controllers/ConfigurationController.cs b/ManagerService/Controllers/ConfigurationController.cs index a75bff6..4654b52 100644 --- a/ManagerService/Controllers/ConfigurationController.cs +++ b/ManagerService/Controllers/ConfigurationController.cs @@ -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 devices = _myInfoMateDbContext.Devices.Where(d => d.ConfigurationId == id).ToList(); diff --git a/ManagerService/Controllers/SectionController.cs b/ManagerService/Controllers/SectionController.cs index a5e521a..43420d4 100644 --- a/ManagerService/Controllers/SectionController.cs +++ b/ManagerService/Controllers/SectionController.cs @@ -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 /// /// section id [AllowAnonymous] - [ProducesResponseType(typeof(SectionDTO), 200)] + [ProducesResponseType(typeof(object), 200)] [ProducesResponseType(typeof(string), 404)] [ProducesResponseType(typeof(string), 500)] [HttpGet("{id}")] diff --git a/ManagerService/Controllers/SectionMapController.cs b/ManagerService/Controllers/SectionMapController.cs index 5d85977..c876c7b 100644 --- a/ManagerService/Controllers/SectionMapController.cs +++ b/ManagerService/Controllers/SectionMapController.cs @@ -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; diff --git a/ManagerService/DTOs/SubSection/QuizzDTO.cs b/ManagerService/DTOs/SubSection/QuizzDTO.cs index 0a968bc..c49d0e4 100644 --- a/ManagerService/DTOs/SubSection/QuizzDTO.cs +++ b/ManagerService/DTOs/SubSection/QuizzDTO.cs @@ -31,8 +31,8 @@ namespace Manager.DTOs public int order { get; set; } // Order to show } - public class LevelDTO + /*public class LevelDTO { public List label { get; set; } - } + }*/ } diff --git a/ManagerService/Data/MyInfoMateDbContext.cs b/ManagerService/Data/MyInfoMateDbContext.cs index 05229bb..47a5f4c 100644 --- a/ManagerService/Data/MyInfoMateDbContext.cs +++ b/ManagerService/Data/MyInfoMateDbContext.cs @@ -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() - .Property(s => s.Title) - .HasColumnType("jsonb"); + .Property(s => s.Title) + .HasColumnType("jsonb") + .HasConversion( + v => JsonSerializer.Serialize(v, options), + v => JsonSerializer.Deserialize>(v, options)); modelBuilder.Entity
() .HasDiscriminator("Discriminator") @@ -44,11 +55,17 @@ namespace ManagerService.Data modelBuilder.Entity
() .Property(s => s.Title) - .HasColumnType("jsonb"); + .HasColumnType("jsonb") + .HasConversion( + v => JsonSerializer.Serialize(v, options), + v => JsonSerializer.Deserialize>(v, options)); modelBuilder.Entity
() .Property(s => s.Description) - .HasColumnType("jsonb"); + .HasColumnType("jsonb") + .HasConversion( + v => JsonSerializer.Serialize(v, options), + v => JsonSerializer.Deserialize>(v, options)); } } diff --git a/ManagerService/Services/SectionFactory.cs b/ManagerService/Services/SectionFactory.cs index e133468..4514ff7 100644 --- a/ManagerService/Services/SectionFactory.cs +++ b/ManagerService/Services/SectionFactory.cs @@ -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, diff --git a/ManagerService/Startup.cs b/ManagerService/Startup.cs index be449e2..4985d50 100644 --- a/ManagerService/Startup.cs +++ b/ManagerService/Startup.cs @@ -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()