Update code for event, agenda and map controllers -> added DTOs + misc

This commit is contained in:
Thomas Fransolet 2025-07-16 14:57:13 +02:00
parent a0aaf6e601
commit 62e302a0f0
16 changed files with 1007 additions and 315 deletions

View File

@ -1,20 +1,17 @@
using Manager.DTOs; using ManagerService.Data;
using Manager.Helpers;
using ManagerService.Data;
using ManagerService.Data.SubSection; using ManagerService.Data.SubSection;
using ManagerService.DTOs;
using ManagerService.Services; using ManagerService.Services;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Mqtt.Client.AspNetCore.Services;
using Newtonsoft.Json;
using NSwag.Annotations; using NSwag.Annotations;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text.Json; using System;
using ManagerService.DTOs;
using ManagerService.Helpers;
namespace ManagerService.Controllers namespace ManagerService.Controllers
{ {
@ -37,137 +34,76 @@ namespace ManagerService.Controllers
} }
/// <summary> /// <summary>
/// Create a new section /// Get all event from section
/// </summary> /// </summary>
/// <param name="newSection">New section info</param> /// <param name="sectionAgendaId">Section id</param>
/*[ProducesResponseType(typeof(SectionDTO), 200)] [AllowAnonymous]
[ProducesResponseType(typeof(string), 400)] [ProducesResponseType(typeof(List<EventAgendaDTO>), 200)]
[ProducesResponseType(typeof(string), 409)] [ProducesResponseType(typeof(string), 404)]
[ProducesResponseType(typeof(string), 500)] [ProducesResponseType(typeof(string), 500)]
[HttpPost()] [HttpGet("{sectionAgendaId}/events")]
public ObjectResult Create([FromBody] SectionDTO newSection) public ObjectResult GetAllEventAgendaFromSection(string sectionAgendaId)
{ {
try try
{ {
if (newSection == null) SectionAgenda sectionAgenda = _myInfoMateDbContext.Sections.OfType<SectionAgenda>().Include(sa => sa.EventAgendas).ThenInclude(sa => sa.Resource).FirstOrDefault(sa => sa.Id == sectionAgendaId);
throw new ArgumentNullException("Section param is null");
if (newSection.configurationId == null) if (sectionAgenda == null)
throw new ArgumentNullException("Configuration param is null"); throw new KeyNotFoundException("Section agenda does not exist");
var configuration = _myInfoMateDbContext.Configurations.FirstOrDefault(c => c.Id == newSection.configurationId); /*List<ProgrammeBlock> programmeBlocks = new List<ProgrammeBlock>();
if (configuration == null) foreach (var program in sectionEvent.Programme)
throw new KeyNotFoundException("Configuration does not exist"); {
foreach (var mapAnnotation in program.MapAnnotations) {
var resource = _myInfoMateDbContext.Resources.FirstOrDefault(r => r.Id == mapAnnotation.IconResourceId);
if (resource != null)
{
mapAnnotation.IconResource = resource; // TO check.. use DTO instead ?
}
}
}*/
// Todo add some verification ? return new OkObjectResult(sectionAgenda.EventAgendas.Select(ea => ea.ToDTO()));
Section section = new Section(); }
catch (KeyNotFoundException ex)
// Preparation
List<string> languages = _configuration.GetSection("SupportedLanguages").Get<List<string>>();
switch (newSection.type)
{ {
case SectionType.Map: return new NotFoundObjectResult(ex.Message) { };
section = new SectionMap }
catch (Exception ex)
{ {
MapMapType = MapTypeApp.hybrid, return new ObjectResult(ex.Message) { StatusCode = 500 };
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 = LanguageInit.Init("Content", languages),
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; /// <summary>
section.Label = newSection.label; /// Create new event
section.ImageId = newSection.imageId; /// </summary>
section.ImageSource = newSection.imageSource; /// <param name="sectionAgendaId">Section agenda Id</param>
section.ConfigurationId = newSection.configurationId; /// <param name="eventAgendaDTO">EventAgenda</param>
section.DateCreation = DateTime.Now.ToUniversalTime(); [ProducesResponseType(typeof(EventAgendaDTO), 200)]
section.IsSubSection = newSection.isSubSection; [ProducesResponseType(typeof(string), 400)]
section.ParentId = newSection.parentId; [ProducesResponseType(typeof(string), 409)]
section.Type = newSection.type; [ProducesResponseType(typeof(string), 500)]
[HttpPost("{sectionAgendaId}/event")]
public ObjectResult CreateEventAgenda(string sectionAgendaId, [FromBody] EventAgendaDTO eventAgendaDTO)
{
try
{
if (sectionAgendaId == null)
throw new ArgumentNullException("Section param is null");
section.Order = _myInfoMateDbContext.Sections.Count(s => s.ConfigurationId == newSection.configurationId && !s.IsSubSection) + 1; if (eventAgendaDTO == null)
throw new ArgumentNullException("EventAgenda param is null");
section.IsBeacon = newSection.isBeacon; var existingSection = _myInfoMateDbContext.Sections.OfType<SectionAgenda>().Include(sa => sa.EventAgendas).FirstOrDefault(sa => sa.Id == sectionAgendaId);
section.BeaconId = newSection.beaconId; if (existingSection == null)
section.Latitude = newSection.latitude; throw new KeyNotFoundException("Section agenda does not exist");
section.Longitude = newSection.longitude;
section.MeterZoneGPS = newSection.meterZoneGPS;
section.Title = LanguageInit.Init("Title", languages); EventAgenda eventAgenda = new EventAgenda().FromDTO(eventAgendaDTO);
section.Description = LanguageInit.Init("Description", languages); _myInfoMateDbContext.EventAgendas.Add(eventAgenda);
section.Id = idService.GenerateHexId();
//_sectionService.Create(section);
_myInfoMateDbContext.Add(section);
_myInfoMateDbContext.SaveChanges(); _myInfoMateDbContext.SaveChanges();
return new OkObjectResult(section.ToDTO()); return new OkObjectResult(eventAgenda.ToDTO());
} }
catch (ArgumentNullException ex) catch (ArgumentNullException ex)
{ {
@ -181,47 +117,61 @@ namespace ManagerService.Controllers
{ {
return new ObjectResult(ex.Message) { StatusCode = 500 }; return new ObjectResult(ex.Message) { StatusCode = 500 };
} }
}*/ }
/// <summary> /// <summary>
/// Update sections order /// Update an event agenda
/// </summary> /// </summary>
/// <param name="updatedSectionsOrder">New sections order</param> /// <param name="eventAgendaDTO">EventAgenda to update</param>
/*[ProducesResponseType(typeof(string), 200)] [ProducesResponseType(typeof(EventAgendaDTO), 200)]
[ProducesResponseType(typeof(string), 400)] [ProducesResponseType(typeof(string), 400)]
[ProducesResponseType(typeof(string), 404)] [ProducesResponseType(typeof(string), 404)]
[ProducesResponseType(typeof(string), 500)] [ProducesResponseType(typeof(string), 500)]
[HttpPut("order")] [HttpPut("event")]
public ObjectResult UpdateOrder([FromBody] List<SectionDTO> updatedSectionsOrder) public ObjectResult UpdateEventAgenda([FromBody] EventAgendaDTO eventAgendaDTO)
{ {
// TODO REWRITE LOGIC..
try try
{ {
if (updatedSectionsOrder == null) if (eventAgendaDTO == null)
throw new ArgumentNullException("Sections param is null"); throw new ArgumentNullException("EventAgenda param is null");
foreach (var section in updatedSectionsOrder) var existing = _myInfoMateDbContext.EventAgendas.FirstOrDefault(ea => ea.Id == eventAgendaDTO.Id);
if (existing == null)
throw new KeyNotFoundException("EventAgenda does not exist");
existing.Label = eventAgendaDTO.Label;
existing.Description = eventAgendaDTO.Description;
existing.Type = eventAgendaDTO.Type;
existing.DateAdded = eventAgendaDTO.DateAdded;
existing.DateFrom = eventAgendaDTO.DateFrom;
existing.DateTo = eventAgendaDTO.DateTo;
existing.Website = eventAgendaDTO.Website;
existing.ResourceId = eventAgendaDTO.ResourceId;
existing.Phone = eventAgendaDTO.Phone;
existing.Email = eventAgendaDTO.Email;
existing.SectionAgendaId = eventAgendaDTO.SectionAgendaId;
existing.SectionEventId = eventAgendaDTO.SectionEventId;
if (eventAgendaDTO.Address != null)
{ {
var sectionDB = _myInfoMateDbContext.Sections.FirstOrDefault(s => s.Id == section.id); existing.Address = new EventAddress
if (sectionDB == null) {
throw new KeyNotFoundException($"Section {section.label} with id {section.id} does not exist"); Address = eventAgendaDTO.Address.Address,
StreetNumber = eventAgendaDTO.Address.StreetNumber,
StreetName = eventAgendaDTO.Address.StreetName,
City = eventAgendaDTO.Address.City,
State = eventAgendaDTO.Address.State,
PostCode = eventAgendaDTO.Address.PostCode,
Country = eventAgendaDTO.Address.Country,
Geometry = eventAgendaDTO.Address.Geometry?.FromDto(),
PolyColor = eventAgendaDTO.Address.PolyColor,
Zoom = eventAgendaDTO.Address.Zoom
};
} }
foreach (var updatedSection in updatedSectionsOrder)
{
var section = _myInfoMateDbContext.Sections.FirstOrDefault(s => s.Id == updatedSection.id);
//OldSection section = _sectionService.GetById(updatedSection.id);
section.Order = updatedSection.order.GetValueOrDefault();
_myInfoMateDbContext.SaveChanges(); _myInfoMateDbContext.SaveChanges();
//_sectionService.Update(section.Id, section); return new OkObjectResult(existing.ToDTO());
}
if (updatedSectionsOrder.Count > 0) {
MqttClientService.PublishMessage($"config/{updatedSectionsOrder[0].configurationId}", JsonConvert.SerializeObject(new PlayerMessageDTO() { configChanged = true }));
}
return new ObjectResult("Sections order has been successfully modified") { StatusCode = 200 };
} }
catch (ArgumentNullException ex) catch (ArgumentNullException ex)
{ {
@ -235,45 +185,28 @@ namespace ManagerService.Controllers
{ {
return new ObjectResult(ex.Message) { StatusCode = 500 }; return new ObjectResult(ex.Message) { StatusCode = 500 };
} }
}*/ }
/// <summary> /// <summary>
/// Delete a section /// Delete an eventAgenda
/// </summary> /// </summary>
/// <param name="id">Id of section to delete</param> /// <param name="eventAgendaId">Id of the eventAgenda to delete</param>
/*[ProducesResponseType(typeof(string), 202)] [ProducesResponseType(typeof(string), 202)]
[ProducesResponseType(typeof(string), 400)]
[ProducesResponseType(typeof(string), 404)] [ProducesResponseType(typeof(string), 404)]
[ProducesResponseType(typeof(string), 500)] [ProducesResponseType(typeof(string), 500)]
[HttpDelete("{id}")] [HttpDelete("event/{eventAgendaId}")]
public ObjectResult Delete(string id) public ObjectResult DeleteEventAgenda(int eventAgendaId)
{ {
try try
{ {
if (id == null) var eventAgenda = _myInfoMateDbContext.EventAgendas.FirstOrDefault(ea => ea.Id == eventAgendaId);
throw new ArgumentNullException("Section param is null"); if (eventAgenda == null)
throw new KeyNotFoundException("EventAgenda does not exist");
var section = _myInfoMateDbContext.Sections.FirstOrDefault(s => s.Id == id);
if (section == null)
throw new KeyNotFoundException("Section does not exist");
_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.Remove(eventAgenda);
_myInfoMateDbContext.SaveChanges(); _myInfoMateDbContext.SaveChanges();
return new ObjectResult("The section has been deleted") { StatusCode = 202 }; return new ObjectResult("The eventAgenda has been deleted") { StatusCode = 202 };
} }
catch (ArgumentNullException ex) catch (ArgumentNullException ex)
{ {
@ -287,6 +220,6 @@ namespace ManagerService.Controllers
{ {
return new ObjectResult(ex.Message) { StatusCode = 500 }; return new ObjectResult(ex.Message) { StatusCode = 500 };
} }
}*/ }
} }
} }

View File

@ -161,6 +161,19 @@ namespace ManagerService.Controllers
switch (section.Type) switch (section.Type)
{ {
case SectionType.Agenda:
var eventAgendas = _myInfoMateDbContext.EventAgendas.Where(ea => ea.SectionAgendaId == section.Id)/*.OrderBy(gp => gp.or)*/.ToList();
List<EventAgendaDTO> eventAgendaDTOs = new List<EventAgendaDTO>();
foreach (var eventAgenda in eventAgendas)
{
eventAgendaDTOs.Add(eventAgenda.ToDTO());
}
(dto as AgendaDTO).events = eventAgendaDTOs;
break;
case SectionType.Event:
var sectionEvent = _myInfoMateDbContext.Sections.OfType<SectionEvent>().Include(se => se.Programme).ThenInclude(se => se.MapAnnotations).FirstOrDefault(s => s.Id == id);
(dto as SectionEventDTO).Programme = sectionEvent.Programme; // TODO test ! Need dto ?
break;
case SectionType.Puzzle: case SectionType.Puzzle:
Resource resource = _myInfoMateDbContext.Resources.FirstOrDefault(r => r.Id == (dto as PuzzleDTO).puzzleImageId); Resource resource = _myInfoMateDbContext.Resources.FirstOrDefault(r => r.Id == (dto as PuzzleDTO).puzzleImageId);
(dto as PuzzleDTO).puzzleImage = resource.ToDTO(); (dto as PuzzleDTO).puzzleImage = resource.ToDTO();
@ -515,7 +528,30 @@ namespace ManagerService.Controllers
// Preparation // Preparation
List<string> languages = _configuration.GetSection("SupportedLanguages").Get<List<string>>(); List<string> languages = _configuration.GetSection("SupportedLanguages").Get<List<string>>();
switch (newSection.type) { switch (newSection.type)
{
case SectionType.Agenda:
section = new SectionAgenda
{
AgendaResourceIds = new List<TranslationDTO>(),
EventAgendas = new List<EventAgenda>()
};
break;
case SectionType.Article:
section = new SectionArticle
{
ArticleContents = new List<ContentDTO>(),
ArticleContent = LanguageInit.Init("Content", languages),
ArticleAudioIds = LanguageInit.Init("Audio", languages, true)
};
break;
case SectionType.Event:
section = new SectionEvent
{
Programme = new List<ProgrammeBlock>(),
ParcoursIds = new List<string>()
};
break;
case SectionType.Map: case SectionType.Map:
section = new SectionMap section = new SectionMap
{ {
@ -527,45 +563,12 @@ namespace ManagerService.Controllers
MapCategories = new List<CategorieDTO>() MapCategories = new List<CategorieDTO>()
}; };
break; break;
case SectionType.Slider:
section = new SectionSlider
{
SliderContents = new List<ContentDTO>()
};
break;
case SectionType.Video:
section = new SectionVideo
{
VideoSource = "",
};
break;
case SectionType.Web:
section = new SectionWeb
{
WebSource = "",
};
break;
case SectionType.Menu: case SectionType.Menu:
section = new SectionMenu section = new SectionMenu
{ {
MenuSections = new List<Section>(), MenuSections = new List<Section>(),
}; };
break; break;
case SectionType.Quiz:
section = new SectionQuiz
{
QuizQuestions = new List<QuizQuestion>(),
// TODO levels ?
};
break;
case SectionType.Article:
section = new SectionArticle
{
ArticleContents = new List<ContentDTO>(),
ArticleContent = LanguageInit.Init("Content", languages),
ArticleAudioIds = LanguageInit.Init("Audio", languages, true)
};
break;
case SectionType.PDF: case SectionType.PDF:
section = new SectionPdf section = new SectionPdf
{ {
@ -579,15 +582,34 @@ namespace ManagerService.Controllers
PuzzleMessageFin = [] PuzzleMessageFin = []
}; };
break; break;
case SectionType.Agenda: case SectionType.Quiz:
section = new SectionAgenda section = new SectionQuiz
{ {
AgendaResourceIds = new List<TranslationDTO>() QuizQuestions = new List<QuizQuestion>(),
// TODO levels ?
};
break;
case SectionType.Slider:
section = new SectionSlider
{
SliderContents = new List<ContentDTO>()
};
break;
case SectionType.Video:
section = new SectionVideo
{
VideoSource = "",
}; };
break; break;
case SectionType.Weather: case SectionType.Weather:
section = new SectionWeather(); section = new SectionWeather();
break; break;
case SectionType.Web:
section = new SectionWeb
{
WebSource = "",
};
break;
} }
section.InstanceId = newSection.instanceId; section.InstanceId = newSection.instanceId;
@ -869,26 +891,11 @@ namespace ManagerService.Controllers
if (section == null) if (section == null)
throw new KeyNotFoundException("Section does not exist"); throw new KeyNotFoundException("Section does not exist");
if (section.Type == SectionType.Agenda)
if (section.Type == SectionType.Map)
{ {
// REMOVE ALL POINTS var sectionAgenda = _myInfoMateDbContext.Sections.OfType<SectionAgenda>().Include(sa => sa.EventAgendas).FirstOrDefault(sa => sa.Id == id);
var geoPoints = _myInfoMateDbContext.GeoPoints.Where(gp => gp.SectionMapId == section.Id).ToList();
_myInfoMateDbContext.RemoveRange(geoPoints);
var guidedPaths = _myInfoMateDbContext.GuidedPaths.Include(gp => gp.Steps).Where(gp => gp.SectionMapId == id); _myInfoMateDbContext.RemoveRange(sectionAgenda.EventAgendas);
foreach (var guidedPath in guidedPaths)
{
_myInfoMateDbContext.RemoveRange(guidedPath.Steps);
_myInfoMateDbContext.Remove(guidedPath);
}
}
if (section.Type == SectionType.Quiz)
{
// REMOVE ALL Questions
var quizQuestions = _myInfoMateDbContext.QuizQuestions.Where(qq => qq.SectionQuizId == section.Id).ToList();
_myInfoMateDbContext.RemoveRange(quizQuestions);
} }
if (section.Type == SectionType.Event) if (section.Type == SectionType.Event)
@ -911,23 +918,35 @@ namespace ManagerService.Controllers
var applicationInstances = _myInfoMateDbContext.ApplicationInstances.Where(ai => ai.SectionEventId == id); var applicationInstances = _myInfoMateDbContext.ApplicationInstances.Where(ai => ai.SectionEventId == id);
foreach (var applicationInstance in applicationInstances) foreach (var applicationInstance in applicationInstances)
{ {
applicationInstance.SectionEventId = null; // Is that enough ? applicationInstance.SectionEventId = null;
} }
} }
if (section.Type == SectionType.Agenda) if (section.Type == SectionType.Map)
{ {
var sectionAgenda = _myInfoMateDbContext.Sections.OfType<SectionAgenda>().Include(sa => sa.EventAgendas).FirstOrDefault(sa => sa.Id == id); // REMOVE ALL POINTS
var geoPoints = _myInfoMateDbContext.GeoPoints.Where(gp => gp.SectionMapId == section.Id).ToList();
_myInfoMateDbContext.RemoveRange(geoPoints);
_myInfoMateDbContext.RemoveRange(sectionAgenda.EventAgendas); var guidedPaths = _myInfoMateDbContext.GuidedPaths.Include(gp => gp.Steps).Where(gp => gp.SectionMapId == id);
foreach (var guidedPath in guidedPaths)
{
_myInfoMateDbContext.RemoveRange(guidedPath.Steps);
_myInfoMateDbContext.Remove(guidedPath);
}
}
if (section.Type == SectionType.Quiz)
{
// REMOVE ALL Questions
var quizQuestions = _myInfoMateDbContext.QuizQuestions.Where(qq => qq.SectionQuizId == section.Id).ToList();
_myInfoMateDbContext.RemoveRange(quizQuestions);
} }
_myInfoMateDbContext.Remove(section); _myInfoMateDbContext.Remove(section);
//_sectionService.Remove(id);
var configuration = _myInfoMateDbContext.Configurations.FirstOrDefault(c => c.Id == section.ConfigurationId); var configuration = _myInfoMateDbContext.Configurations.FirstOrDefault(c => c.Id == section.ConfigurationId);
// TODO TEST that in new format
List<Section> sections = _myInfoMateDbContext.Sections.Where(s => s.ConfigurationId == section.ConfigurationId && !s.IsSubSection).ToList(); List<Section> sections = _myInfoMateDbContext.Sections.Where(s => s.ConfigurationId == section.ConfigurationId && !s.IsSubSection).ToList();
int i = 1; int i = 1;
List<Section> orderedSection = sections.OrderBy(s => s.Order).ToList(); List<Section> orderedSection = sections.OrderBy(s => s.Order).ToList();

View File

@ -1,14 +1,12 @@
using Manager.DTOs; using ManagerService.Data;
using ManagerService.Data;
using ManagerService.Data.SubSection; using ManagerService.Data.SubSection;
using ManagerService.Helpers; using ManagerService.DTOs;
using ManagerService.Services; using ManagerService.Services;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Namotion.Reflection;
using NSwag.Annotations; using NSwag.Annotations;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -81,33 +79,33 @@ namespace ManagerService.Controllers
/// Create new programme block /// Create new programme block
/// </summary> /// </summary>
/// <param name="sectionEventId">Section event Id</param> /// <param name="sectionEventId">Section event Id</param>
/// <param name="programmeBlock">Programme block</param> /// <param name="programmeBlockDTO">Programme block</param>
[ProducesResponseType(typeof(ProgrammeBlock), 200)] [ProducesResponseType(typeof(ProgrammeBlockDTO), 200)]
[ProducesResponseType(typeof(string), 400)] [ProducesResponseType(typeof(string), 400)]
[ProducesResponseType(typeof(string), 409)] [ProducesResponseType(typeof(string), 409)]
[ProducesResponseType(typeof(string), 500)] [ProducesResponseType(typeof(string), 500)]
[HttpPost("{sectionEventId}/programmes")] [HttpPost("{sectionEventId}/programmes")]
public ObjectResult CreateProgrammeBlock(string sectionEventId, [FromBody] ProgrammeBlock programmeBlock) public ObjectResult CreateProgrammeBlock(string sectionEventId, [FromBody] ProgrammeBlockDTO programmeBlockDTO)
{ {
try try
{ {
if (sectionEventId == null) if (sectionEventId == null)
throw new ArgumentNullException("Section param is null"); throw new ArgumentNullException("Section param is null");
if (programmeBlock == null) if (programmeBlockDTO == null)
throw new ArgumentNullException("ProgrammeBlock param is null"); throw new ArgumentNullException("ProgrammeBlock param is null");
var existingSection = _myInfoMateDbContext.Sections.OfType<SectionEvent>().Include(se => se.Programme).FirstOrDefault(se => se.Id == sectionEventId); var existingSection = _myInfoMateDbContext.Sections.OfType<SectionEvent>().Include(se => se.Programme).FirstOrDefault(se => se.Id == sectionEventId);
if (existingSection == null) if (existingSection == null)
throw new KeyNotFoundException("Section event does not exist"); throw new KeyNotFoundException("Section event does not exist");
// TODO verification ? ProgrammeBlock programmeBlock = new ProgrammeBlock().FromDTO(programmeBlockDTO);
programmeBlock.Id = idService.GenerateHexId(); programmeBlock.Id = idService.GenerateHexId();
existingSection.Programme.Add(programmeBlock); existingSection.Programme.Add(programmeBlock);
_myInfoMateDbContext.SaveChanges(); _myInfoMateDbContext.SaveChanges();
return new OkObjectResult(programmeBlock); return new OkObjectResult(programmeBlock.ToDTO());
} }
catch (ArgumentNullException ex) catch (ArgumentNullException ex)
{ {
@ -127,23 +125,27 @@ namespace ManagerService.Controllers
/// Update a program block /// Update a program block
/// </summary> /// </summary>
/// <param name="programmeBlock">ProgramBlock to update</param> /// <param name="programmeBlock">ProgramBlock to update</param>
[ProducesResponseType(typeof(ProgrammeBlock), 200)] [ProducesResponseType(typeof(ProgrammeBlockDTO), 200)]
[ProducesResponseType(typeof(string), 400)] [ProducesResponseType(typeof(string), 400)]
[ProducesResponseType(typeof(string), 404)] [ProducesResponseType(typeof(string), 404)]
[ProducesResponseType(typeof(string), 500)] [ProducesResponseType(typeof(string), 500)]
[HttpPut("programmes")] [HttpPut("programmes")]
public ObjectResult UpdateProgrammeBlock([FromBody] ProgrammeBlock programmeBlock) public ObjectResult UpdateProgrammeBlock([FromBody] ProgrammeBlockDTO programmeBlockDTO)
{ {
try try
{ {
if (programmeBlock == null) if (programmeBlockDTO == null)
throw new ArgumentNullException("ProgrammeBlock param is null"); throw new ArgumentNullException("ProgrammeBlock param is null");
var existingProgramBlock = _myInfoMateDbContext.ProgrammeBlocks.FirstOrDefault(pb => pb.Id == programmeBlock.Id); var existingProgramBlock = _myInfoMateDbContext.ProgrammeBlocks.FirstOrDefault(pb => pb.Id == programmeBlockDTO.Id);
if (existingProgramBlock == null) if (existingProgramBlock == null)
throw new KeyNotFoundException("ProgrammeBlock does not exist"); throw new KeyNotFoundException("ProgrammeBlock does not exist");
existingProgramBlock = programmeBlock; // TO TEST .. existingProgramBlock.Title = programmeBlockDTO.Title;
existingProgramBlock.Description = programmeBlockDTO.Description;
existingProgramBlock.StartTime = programmeBlockDTO.StartTime;
existingProgramBlock.EndTime = programmeBlockDTO.EndTime;
_myInfoMateDbContext.SaveChanges(); _myInfoMateDbContext.SaveChanges();
return new OkObjectResult(existingProgramBlock); return new OkObjectResult(existingProgramBlock);
@ -207,7 +209,7 @@ namespace ManagerService.Controllers
/// </summary> /// </summary>
/// <param name="programBlockId">Program block id</param> /// <param name="programBlockId">Program block id</param>
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(typeof(List<MapAnnotation>), 200)] [ProducesResponseType(typeof(List<MapAnnotationDTO>), 200)]
[ProducesResponseType(typeof(string), 404)] [ProducesResponseType(typeof(string), 404)]
[ProducesResponseType(typeof(string), 500)] [ProducesResponseType(typeof(string), 500)]
[HttpGet("{programBlockId}/map-annotations")] [HttpGet("{programBlockId}/map-annotations")]
@ -232,7 +234,7 @@ namespace ManagerService.Controllers
} }
}*/ }*/
return new OkObjectResult(programmeBlock.MapAnnotations); return new OkObjectResult(programmeBlock.MapAnnotations.Select(ma => ma.ToDTO()));
} }
catch (KeyNotFoundException ex) catch (KeyNotFoundException ex)
{ {
@ -249,19 +251,19 @@ namespace ManagerService.Controllers
/// </summary> /// </summary>
/// <param name="programmeBlockId">Programme block id</param> /// <param name="programmeBlockId">Programme block id</param>
/// <param name="mapAnnotation">Map annotation</param> /// <param name="mapAnnotation">Map annotation</param>
[ProducesResponseType(typeof(MapAnnotation), 200)] [ProducesResponseType(typeof(MapAnnotationDTO), 200)]
[ProducesResponseType(typeof(string), 400)] [ProducesResponseType(typeof(string), 400)]
[ProducesResponseType(typeof(string), 409)] [ProducesResponseType(typeof(string), 409)]
[ProducesResponseType(typeof(string), 500)] [ProducesResponseType(typeof(string), 500)]
[HttpPost("{programmeBlockId}/map-annotations")] [HttpPost("{programmeBlockId}/map-annotations")]
public ObjectResult CreateMapAnnotation(string programmeBlockId, [FromBody] MapAnnotation mapAnnotation) public ObjectResult CreateMapAnnotation(string programmeBlockId, [FromBody] MapAnnotationDTO mapAnnotationDTO)
{ {
try try
{ {
if (programmeBlockId == null) if (programmeBlockId == null)
throw new ArgumentNullException("ProgrammeBlockId param is null"); throw new ArgumentNullException("ProgrammeBlockId param is null");
if (mapAnnotation == null) if (mapAnnotationDTO == null)
throw new ArgumentNullException("MapAnnotation param is null"); throw new ArgumentNullException("MapAnnotation param is null");
var existingProgrammeBloc = _myInfoMateDbContext.ProgrammeBlocks.Include(pb => pb.MapAnnotations).FirstOrDefault(pb => pb.Id == programmeBlockId); var existingProgrammeBloc = _myInfoMateDbContext.ProgrammeBlocks.Include(pb => pb.MapAnnotations).FirstOrDefault(pb => pb.Id == programmeBlockId);
@ -269,6 +271,7 @@ namespace ManagerService.Controllers
throw new KeyNotFoundException("ProgrammeBlock does not exist"); throw new KeyNotFoundException("ProgrammeBlock does not exist");
// TODO verification ? // TODO verification ?
MapAnnotation mapAnnotation = new MapAnnotation().FromDTO(mapAnnotationDTO);
mapAnnotation.Id = idService.GenerateHexId(); mapAnnotation.Id = idService.GenerateHexId();
existingProgrammeBloc.MapAnnotations.Add(mapAnnotation); existingProgrammeBloc.MapAnnotations.Add(mapAnnotation);
@ -294,23 +297,30 @@ namespace ManagerService.Controllers
/// Update a map annotation /// Update a map annotation
/// </summary> /// </summary>
/// <param name="mapAnnotation">mapAnnotation to update</param> /// <param name="mapAnnotation">mapAnnotation to update</param>
[ProducesResponseType(typeof(MapAnnotation), 200)] [ProducesResponseType(typeof(MapAnnotationDTO), 200)]
[ProducesResponseType(typeof(string), 400)] [ProducesResponseType(typeof(string), 400)]
[ProducesResponseType(typeof(string), 404)] [ProducesResponseType(typeof(string), 404)]
[ProducesResponseType(typeof(string), 500)] [ProducesResponseType(typeof(string), 500)]
[HttpPut("map-annotations")] [HttpPut("map-annotations")]
public ObjectResult UpdateMapAnnotation([FromBody] MapAnnotation mapAnnotation) public ObjectResult UpdateMapAnnotation([FromBody] MapAnnotationDTO mapAnnotationDTO)
{ {
try try
{ {
if (mapAnnotation == null) if (mapAnnotationDTO == null)
throw new ArgumentNullException("MapAnnotation param is null"); throw new ArgumentNullException("MapAnnotation param is null");
var existingMapAnnotation = _myInfoMateDbContext.MapAnnotations.FirstOrDefault(ma => ma.Id == mapAnnotation.Id); var existingMapAnnotation = _myInfoMateDbContext.MapAnnotations.Include(ma => ma.IconResource).FirstOrDefault(ma => ma.Id == mapAnnotationDTO.Id);
if (existingMapAnnotation == null) if (existingMapAnnotation == null)
throw new KeyNotFoundException("MapAnnotation does not exist"); throw new KeyNotFoundException("MapAnnotation does not exist");
existingMapAnnotation = mapAnnotation; // TO TEST .. existingMapAnnotation.Type = mapAnnotationDTO.Type;
existingMapAnnotation.Label = mapAnnotationDTO.Label;
existingMapAnnotation.GeometryType = mapAnnotationDTO.GeometryType;
existingMapAnnotation.Geometry = mapAnnotationDTO.Geometry;
existingMapAnnotation.PolyColor = mapAnnotationDTO.PolyColor;
existingMapAnnotation.Icon = mapAnnotationDTO.Icon;
existingMapAnnotation.IconResourceId = mapAnnotationDTO.IconResourceId;
_myInfoMateDbContext.SaveChanges(); _myInfoMateDbContext.SaveChanges();
return new OkObjectResult(existingMapAnnotation); return new OkObjectResult(existingMapAnnotation);

View File

@ -1,6 +1,7 @@
using Manager.DTOs; using Manager.DTOs;
using ManagerService.Data; using ManagerService.Data;
using ManagerService.Data.SubSection; using ManagerService.Data.SubSection;
using ManagerService.DTOs;
using ManagerService.Helpers; using ManagerService.Helpers;
using ManagerService.Services; using ManagerService.Services;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
@ -8,10 +9,12 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using NetTopologySuite.Geometries;
using NSwag.Annotations; using NSwag.Annotations;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using static ManagerService.Data.SubSection.SectionEvent;
namespace ManagerService.Controllers namespace ManagerService.Controllers
{ {
@ -323,5 +326,349 @@ namespace ManagerService.Controllers
return new ObjectResult(ex.Message) { StatusCode = 500 }; return new ObjectResult(ex.Message) { StatusCode = 500 };
} }
} }
/// <summary>
/// Get all guided path from section
/// </summary>
/// <param name="sectionMapId">Section id</param>
[AllowAnonymous]
[ProducesResponseType(typeof(List<GuidedPathDTO>), 200)]
[ProducesResponseType(typeof(string), 404)]
[ProducesResponseType(typeof(string), 500)]
[HttpGet("{sectionMapId}/guided-path")]
public ObjectResult GetAllGuidedPathFromSection(string sectionMapId)
{
try
{
List<GuidedPath> guidedPaths = _myInfoMateDbContext.GuidedPaths
.Include(gp => gp.Steps).ThenInclude(gp => gp.QuizQuestions)
.Include(gp => gp.Steps).ThenInclude(gp => gp.TriggerGeoPoint)
.Where(gp => gp.SectionMapId == sectionMapId).ToList();
/*List<ProgrammeBlock> programmeBlocks = new List<ProgrammeBlock>();
foreach (var program in sectionEvent.Programme)
{
foreach (var mapAnnotation in program.MapAnnotations) {
var resource = _myInfoMateDbContext.Resources.FirstOrDefault(r => r.Id == mapAnnotation.IconResourceId);
if (resource != null)
{
mapAnnotation.IconResource = resource; // TO check.. use DTO instead ?
}
}
}*/
return new OkObjectResult(guidedPaths.Select(gp => gp.ToDTO()));
}
catch (KeyNotFoundException ex)
{
return new NotFoundObjectResult(ex.Message) { };
}
catch (Exception ex)
{
return new ObjectResult(ex.Message) { StatusCode = 500 };
}
}
/// <summary>
/// Create new guided path
/// </summary>
/// <param name="sectionMapId">Section map Id</param>
/// <param name="guidedPath">guidedPath</param>
[ProducesResponseType(typeof(GuidedPathDTO), 200)]
[ProducesResponseType(typeof(string), 400)]
[ProducesResponseType(typeof(string), 409)]
[ProducesResponseType(typeof(string), 500)]
[HttpPost("{sectionMapId}/guided-path")]
public ObjectResult CreateGuidedPath(string sectionMapId, [FromBody] GuidedPathDTO guidedPathDTO)
{
try
{
if (sectionMapId == null)
throw new ArgumentNullException("Section param is null");
if (guidedPathDTO == null)
throw new ArgumentNullException("GuidedPath param is null");
var existingSection = _myInfoMateDbContext.Sections.OfType<SectionMap>().FirstOrDefault(sm => sm.Id == sectionMapId);
if (existingSection == null)
throw new KeyNotFoundException("Section map does not exist");
GuidedPath guidedPath = new GuidedPath().FromDTO(guidedPathDTO);
guidedPath.Id = idService.GenerateHexId();
_myInfoMateDbContext.GuidedPaths.Add(guidedPath);
_myInfoMateDbContext.SaveChanges();
return new OkObjectResult(guidedPath.ToDTO());
}
catch (ArgumentNullException ex)
{
return new BadRequestObjectResult(ex.Message) { };
}
catch (InvalidOperationException ex)
{
return new ConflictObjectResult(ex.Message) { };
}
catch (Exception ex)
{
return new ObjectResult(ex.Message) { StatusCode = 500 };
}
}
/// <summary>
/// Update a guided path
/// </summary>
/// <param name="guidedPath">GuidedPath to update</param>
[ProducesResponseType(typeof(GuidedPathDTO), 200)]
[ProducesResponseType(typeof(string), 400)]
[ProducesResponseType(typeof(string), 404)]
[ProducesResponseType(typeof(string), 500)]
[HttpPut("guided-path")]
public ObjectResult UpdateGuidedPath([FromBody] GuidedPathDTO guidedPathDTO)
{
try
{
if (guidedPathDTO == null)
throw new ArgumentNullException("GuidedPath param is null");
var existingGuidedPath = _myInfoMateDbContext.GuidedPaths.FirstOrDefault(gp => gp.Id == guidedPathDTO.Id);
if (existingGuidedPath == null)
throw new KeyNotFoundException("GuidedPath does not exist");
existingGuidedPath.InstanceId = guidedPathDTO.InstanceId;
existingGuidedPath.Title = guidedPathDTO.Title ?? new List<TranslationDTO>();
existingGuidedPath.Description = guidedPathDTO.Description ?? new List<TranslationDTO>();
existingGuidedPath.SectionMapId = guidedPathDTO.SectionMapId;
existingGuidedPath.SectionEventId = guidedPathDTO.SectionEventId;
existingGuidedPath.IsLinear = guidedPathDTO.IsLinear;
existingGuidedPath.RequireSuccessToAdvance = guidedPathDTO.RequireSuccessToAdvance;
existingGuidedPath.HideNextStepsUntilComplete = guidedPathDTO.HideNextStepsUntilComplete;
existingGuidedPath.Order = guidedPathDTO.Order;
_myInfoMateDbContext.SaveChanges();
return new OkObjectResult(existingGuidedPath);
}
catch (ArgumentNullException ex)
{
return new BadRequestObjectResult(ex.Message) { };
}
catch (KeyNotFoundException ex)
{
return new NotFoundObjectResult(ex.Message) { };
}
catch (Exception ex)
{
return new ObjectResult(ex.Message) { StatusCode = 500 };
}
}
/// <summary>
/// Delete a guided path
/// </summary>
/// <param name="guidedPathId">Id of the guidedPath to delete</param>
[ProducesResponseType(typeof(string), 202)]
[ProducesResponseType(typeof(string), 404)]
[ProducesResponseType(typeof(string), 500)]
[HttpDelete("guided-path/{guidedPathId}")]
public ObjectResult DeleteGuidedPath(string guidedPathId)
{
try
{
var guidedPath = _myInfoMateDbContext.GuidedPaths.FirstOrDefault(gp => gp.Id == guidedPathId);
if (guidedPath == null)
throw new KeyNotFoundException("GuidedPath does not exist");
_myInfoMateDbContext.Remove(guidedPath);
_myInfoMateDbContext.SaveChanges();
return new ObjectResult("The guidedPath has been deleted") { StatusCode = 202 };
}
catch (ArgumentNullException ex)
{
return new BadRequestObjectResult(ex.Message) { };
}
catch (KeyNotFoundException ex)
{
return new NotFoundObjectResult(ex.Message) { };
}
catch (Exception ex)
{
return new ObjectResult(ex.Message) { StatusCode = 500 };
}
}
/// <summary>
/// Get all guided step from guided path
/// </summary>
/// <param name="guidedPathId">Guided path id</param>
[AllowAnonymous]
[ProducesResponseType(typeof(List<GuidedStepDTO>), 200)]
[ProducesResponseType(typeof(string), 404)]
[ProducesResponseType(typeof(string), 500)]
[HttpGet("guided-path/{guidedPathId}/guided-step")]
public ObjectResult GetAllGuidedStepFromGuidedPath(string guidedPathId)
{
try
{
List<GuidedStep> guidedSteps = _myInfoMateDbContext.GuidedSteps
.Include(gs => gs.QuizQuestions)
.Include(gs => gs.TriggerGeoPoint)
.Where(gs => gs.GuidedPathId == guidedPathId).ToList();
/*List<ProgrammeBlock> programmeBlocks = new List<ProgrammeBlock>();
foreach (var program in sectionEvent.Programme)
{
foreach (var mapAnnotation in program.MapAnnotations) {
var resource = _myInfoMateDbContext.Resources.FirstOrDefault(r => r.Id == mapAnnotation.IconResourceId);
if (resource != null)
{
mapAnnotation.IconResource = resource; // TO check.. use DTO instead ?
}
}
}*/
return new OkObjectResult(guidedSteps.Select(gs => gs.ToDTO()));
}
catch (KeyNotFoundException ex)
{
return new NotFoundObjectResult(ex.Message) { };
}
catch (Exception ex)
{
return new ObjectResult(ex.Message) { StatusCode = 500 };
}
}
/// <summary>
/// Create new guided step
/// </summary>
/// <param name="guidedPathId">guidedPath Id</param>
/// <param name="guidedStep">guidedStep</param>
[ProducesResponseType(typeof(GuidedStepDTO), 200)]
[ProducesResponseType(typeof(string), 400)]
[ProducesResponseType(typeof(string), 409)]
[ProducesResponseType(typeof(string), 500)]
[HttpPost("guided-path/{guidedPathId}/guided-step")]
public ObjectResult CreateGuidedStep(string guidedPathId, [FromBody] GuidedStepDTO guidedStepDTO)
{
try
{
if (guidedPathId == null)
throw new ArgumentNullException("GuidedPathId param is null");
if (guidedStepDTO == null)
throw new ArgumentNullException("GuidedStep param is null");
GuidedStep guidedStep = new GuidedStep().FromDTO(guidedStepDTO);
guidedStep.Id = idService.GenerateHexId();
_myInfoMateDbContext.GuidedSteps.Add(guidedStep);
_myInfoMateDbContext.SaveChanges();
return new OkObjectResult(guidedStep.ToDTO());
}
catch (ArgumentNullException ex)
{
return new BadRequestObjectResult(ex.Message) { };
}
catch (InvalidOperationException ex)
{
return new ConflictObjectResult(ex.Message) { };
}
catch (Exception ex)
{
return new ObjectResult(ex.Message) { StatusCode = 500 };
}
}
/// <summary>
/// Update a guided step
/// </summary>
/// <param name="guidedStep">GuidedStep to update</param>
[ProducesResponseType(typeof(GuidedStepDTO), 200)]
[ProducesResponseType(typeof(string), 400)]
[ProducesResponseType(typeof(string), 404)]
[ProducesResponseType(typeof(string), 500)]
[HttpPut("guided-step")]
public ObjectResult UpdateGuidedStep([FromBody] GuidedStepDTO guidedStepDTO)
{
try
{
if (guidedStepDTO == null)
throw new ArgumentNullException("GuidedStep param is null");
var existingGuidedStep = _myInfoMateDbContext.GuidedSteps.FirstOrDefault(gs => gs.Id == guidedStepDTO.Id);
if (existingGuidedStep == null)
throw new KeyNotFoundException("GuidedStep does not exist");
existingGuidedStep.GuidedPathId = guidedStepDTO.GuidedPathId;
existingGuidedStep.Order = guidedStepDTO.Order;
existingGuidedStep.Title = guidedStepDTO.Title;
existingGuidedStep.Description = guidedStepDTO.Description;
existingGuidedStep.Geometry = guidedStepDTO.Geometry != null ? guidedStepDTO.Geometry : null; // TO TEST
existingGuidedStep.ZoneRadiusMeters = guidedStepDTO.ZoneRadiusMeters;
existingGuidedStep.ImageUrl = guidedStepDTO.ImageUrl;
existingGuidedStep.TriggerGeoPointId = guidedStepDTO.TriggerGeoPointId;
existingGuidedStep.IsHiddenInitially = guidedStepDTO.IsHiddenInitially;
existingGuidedStep.QuizQuestions = guidedStepDTO.QuizQuestions; // à convertir si besoin ?
existingGuidedStep.IsStepTimer = guidedStepDTO.IsStepTimer;
existingGuidedStep.IsStepLocked = guidedStepDTO.IsStepLocked;
existingGuidedStep.TimerSeconds = guidedStepDTO.TimerSeconds;
existingGuidedStep.TimerExpiredMessage = guidedStepDTO.TimerExpiredMessage;
_myInfoMateDbContext.SaveChanges();
return new OkObjectResult(existingGuidedStep);
}
catch (ArgumentNullException ex)
{
return new BadRequestObjectResult(ex.Message) { };
}
catch (KeyNotFoundException ex)
{
return new NotFoundObjectResult(ex.Message) { };
}
catch (Exception ex)
{
return new ObjectResult(ex.Message) { StatusCode = 500 };
}
}
/// <summary>
/// Delete a guided step
/// </summary>
/// <param name="guidedStepId">Id of the guidedStep to delete</param>
[ProducesResponseType(typeof(string), 202)]
[ProducesResponseType(typeof(string), 404)]
[ProducesResponseType(typeof(string), 500)]
[HttpDelete("guided-step/{guidedStepId}")]
public ObjectResult DeleteGuidedStep(string guidedStepId)
{
try
{
var guidedStep = _myInfoMateDbContext.GuidedSteps.Include(gs => gs.QuizQuestions).FirstOrDefault(gs => gs.Id == guidedStepId);
if (guidedStep == null)
throw new KeyNotFoundException("GuidedStep does not exist");
guidedStep.QuizQuestions.Clear();
_myInfoMateDbContext.Remove(guidedStep);
_myInfoMateDbContext.SaveChanges();
return new ObjectResult("The guidedStep has been deleted") { StatusCode = 202 };
}
catch (ArgumentNullException ex)
{
return new BadRequestObjectResult(ex.Message) { };
}
catch (KeyNotFoundException ex)
{
return new NotFoundObjectResult(ex.Message) { };
}
catch (Exception ex)
{
return new ObjectResult(ex.Message) { StatusCode = 500 };
}
}
} }
} }

View File

@ -1,7 +1,5 @@
using ManagerService.Data.SubSection; using System.Collections.Generic;
using System.Collections.Generic;
using System; using System;
using static ManagerService.Data.SubSection.SectionEvent;
using Manager.DTOs; using Manager.DTOs;
namespace ManagerService.DTOs namespace ManagerService.DTOs
@ -10,9 +8,9 @@ namespace ManagerService.DTOs
{ {
public int Id { get; set; } public int Id { get; set; }
public List<TranslationAndResourceDTO> Label { get; set; } public List<TranslationDTO> Label { get; set; }
public List<TranslationAndResourceDTO> Description { get; set; } public List<TranslationDTO> Description { get; set; }
public string Type { get; set; } public string Type { get; set; }
@ -35,6 +33,7 @@ namespace ManagerService.DTOs
public string Email { get; set; } public string Email { get; set; }
public string SectionAgendaId { get; set; } public string SectionAgendaId { get; set; }
public string SectionEventId { get; set; }
} }

View File

@ -0,0 +1,19 @@
using System.Collections.Generic;
namespace ManagerService.DTOs
{
public class GuidedPathDTO
{
public string Id { get; set; }
public string InstanceId { get; set; }
public List<TranslationDTO> Title { get; set; }
public List<TranslationDTO> Description { get; set; }
public string? SectionMapId { get; set; }
public string? SectionEventId { get; set; }
public bool IsLinear { get; set; }
public bool RequireSuccessToAdvance { get; set; }
public bool HideNextStepsUntilComplete { get; set; }
public int Order { get; set; }
public List<GuidedStepDTO> Steps { get; set; }
}
}

View File

@ -0,0 +1,27 @@
using System.Collections.Generic;
using Manager.DTOs;
using ManagerService.Data.SubSection;
using NetTopologySuite.Geometries;
namespace ManagerService.DTOs
{
public class GuidedStepDTO
{
public string Id { get; set; }
public string GuidedPathId { get; set; }
public int Order { get; set; }
public List<TranslationDTO> Title { get; set; }
public List<TranslationDTO> Description { get; set; }
public Geometry Geometry { get; set; }
public double? ZoneRadiusMeters { get; set; }
public string ImageUrl { get; set; }
public int? TriggerGeoPointId { get; set; }
public GeoPointDTO? TriggerGeoPoint { get; set; }
public bool IsHiddenInitially { get; set; }
public bool IsStepTimer { get; set; }
public bool IsStepLocked { get; set; }
public int? TimerSeconds { get; set; }
public List<TranslationDTO> TimerExpiredMessage { get; set; }
public List<QuizQuestion> QuizQuestions { get; set; }
}
}

View File

@ -0,0 +1,19 @@
using NetTopologySuite.Geometries;
using System.Collections.Generic;
using ManagerService.Data.SubSection;
namespace ManagerService.DTOs
{
public class MapAnnotationDTO
{
public string Id { get; set; }
public List<TranslationDTO> Type { get; set; }
public List<TranslationDTO> Label { get; set; }
public SectionEvent.GeometryType GeometryType { get; set; }
public Geometry Geometry { get; set; }
public string PolyColor { get; set; }
public string Icon { get; set; }
public string IconResourceId { get; set; }
public ResourceDTO IconResource { get; set; }
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
namespace ManagerService.DTOs
{
public class ProgrammeBlockDTO
{
public string Id { get; set; }
public List<TranslationDTO> Title { get; set; }
public List<TranslationDTO> Description { get; set; }
public DateTime StartTime { get; set; }
public DateTime EndTime { get; set; }
public List<MapAnnotationDTO> MapAnnotations { get; set; }
}
}

View File

@ -7,5 +7,6 @@ namespace Manager.DTOs
{ {
public List<TranslationDTO> resourceIds { get; set; } // All json files for all languages public List<TranslationDTO> resourceIds { get; set; } // All json files for all languages
public MapProvider? agendaMapProvider { get; set; } // Default = Google public MapProvider? agendaMapProvider { get; set; } // Default = Google
public List<EventAgendaDTO> events { get; set; }
} }
} }

View File

@ -33,6 +33,8 @@ namespace Manager.DTOs
public List<TranslationDTO> site { get; set; } public List<TranslationDTO> site { get; set; }
public GeometryDTO geometry { get; set; } public GeometryDTO geometry { get; set; }
public string polyColor { get; set; } // color of the polyline or polygon public string polyColor { get; set; } // color of the polyline or polygon
public string sectionMapId { get; set; }
public string sectionEventId { get; set; }
} }
public class CategorieDTO public class CategorieDTO

View File

@ -1,12 +1,11 @@
using Manager.DTOs; using Manager.DTOs;
using ManagerService.DTOs; using ManagerService.DTOs;
using ManagerService.Helpers;
using NetTopologySuite.Geometries; using NetTopologySuite.Geometries;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using System.Drawing.Drawing2D;
using static ManagerService.Data.SubSection.SectionEvent;
namespace ManagerService.Data.SubSection namespace ManagerService.Data.SubSection
{ {
@ -58,8 +57,77 @@ namespace ManagerService.Data.SubSection
[ForeignKey("SectionEventId")] [ForeignKey("SectionEventId")]
public SectionEvent? SectionEvent { get; set; } // Genre lancer l'event (vue vraiment detail d'un event) public SectionEvent? SectionEvent { get; set; } // Genre lancer l'event (vue vraiment detail d'un event)
public EventAgendaDTO ToDTO()
{
return new EventAgendaDTO()
{
Id = Id,
Label = Label,
Description = Description,
Type = Type,
DateAdded = DateAdded,
DateFrom = DateFrom,
DateTo = DateTo,
Website = Website,
ResourceId = ResourceId,
Resource = Resource?.ToDTO(),
Address = Address != null ? new EventAddressDTO
{
Address = Address.Address,
StreetNumber = Address.StreetNumber,
StreetName = Address.StreetName,
City = Address.City,
State = Address.State,
PostCode = Address.PostCode,
Country = Address.Country,
Geometry = Address.Geometry != null ? new GeometryDTO
{
Type = Address.Geometry.GeometryType,
Coordinates = Address.Geometry.Coordinates,
} : null,
PolyColor = Address.PolyColor,
Zoom = Address.Zoom
} : null,
Phone = Phone,
Email = Email,
SectionAgendaId = SectionAgendaId
};
} }
public EventAgenda FromDTO(EventAgendaDTO dto)
{
return new EventAgenda
{
Id = dto.Id,
Label = dto.Label,
Description = dto.Description,
Type = dto.Type,
DateAdded = dto.DateAdded,
DateFrom = dto.DateFrom,
DateTo = dto.DateTo,
Website = dto.Website,
ResourceId = dto.ResourceId,
//Resource = dto.Resource != null ? Resource.From(dto.Resource) : null,
Address = dto.Address != null ? new EventAddress
{
Address = dto.Address.Address,
StreetNumber = dto.Address.StreetNumber,
StreetName = dto.Address.StreetName,
City = dto.Address.City,
State = dto.Address.State,
PostCode = dto.Address.PostCode,
Country = dto.Address.Country,
Geometry = dto.Address.Geometry!= null ? dto.Address.Geometry.FromDto() : null,
PolyColor = dto.Address.PolyColor,
Zoom = dto.Address.Zoom
} : null,
Phone = dto.Phone,
Email = dto.Email,
SectionAgendaId = dto.SectionAgendaId
};
}
}
public class EventAddress public class EventAddress
{ {
public string Address { get; set; } public string Address { get; set; }

View File

@ -48,7 +48,8 @@ namespace ManagerService.Data.SubSection
longitude = Longitude, longitude = Longitude,
meterZoneGPS = MeterZoneGPS, meterZoneGPS = MeterZoneGPS,
resourceIds = AgendaResourceIds, resourceIds = AgendaResourceIds,
agendaMapProvider = AgendaMapProvider agendaMapProvider = AgendaMapProvider,
events = EventAgendas.Select(e => e.ToDTO()).ToList(),
}; };
} }
} }

View File

@ -4,6 +4,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
namespace ManagerService.Data.SubSection namespace ManagerService.Data.SubSection
@ -30,6 +31,33 @@ namespace ManagerService.Data.SubSection
public DateTime StartTime { get; set; } public DateTime StartTime { get; set; }
public DateTime EndTime { get; set; } public DateTime EndTime { get; set; }
public List<MapAnnotation> MapAnnotations { get; set; } public List<MapAnnotation> MapAnnotations { get; set; }
public ProgrammeBlockDTO ToDTO()
{
return new ProgrammeBlockDTO
{
Id = this.Id,
Title = this.Title,
Description = this.Description,
StartTime = this.StartTime,
EndTime = this.EndTime,
MapAnnotations = this.MapAnnotations?.Select(ma => ma.ToDTO()).ToList()
};
}
public ProgrammeBlock FromDTO(ProgrammeBlockDTO dto)
{
return new ProgrammeBlock
{
Id = dto.Id,
Title = dto.Title,
Description = dto.Description,
StartTime = dto.StartTime,
EndTime = dto.EndTime,
//MapAnnotations = dto.MapAnnotations?.Select(ma => new MapAnnotation.FromDTO(ma)).ToList() // Other method
};
}
} }
public class MapAnnotation public class MapAnnotation
@ -46,6 +74,39 @@ namespace ManagerService.Data.SubSection
public string Icon { get; set; } // icon material if point public string Icon { get; set; } // icon material if point
public string IconResourceId { get; set; } // Icon resource id public string IconResourceId { get; set; } // Icon resource id
public Resource IconResource { get; set; } // Icon resource public Resource IconResource { get; set; } // Icon resource
public MapAnnotationDTO ToDTO()
{
return new MapAnnotationDTO
{
Id = Id,
Type = Type,
Label = Label,
GeometryType = GeometryType,
Geometry = Geometry,
PolyColor = PolyColor,
Icon = Icon,
IconResourceId = IconResourceId,
IconResource = IconResource?.ToDTO()
};
}
public MapAnnotation FromDTO(MapAnnotationDTO dto)
{
return new MapAnnotation
{
Id = dto.Id,
Type = dto.Type,
Label = dto.Label,
GeometryType = dto.GeometryType,
Geometry = dto.Geometry,
PolyColor = dto.PolyColor,
Icon = dto.Icon,
IconResourceId = dto.IconResourceId,
//IconResource = dto.IconResource?.ToModel()
};
}
} }
public enum GeometryType public enum GeometryType

View File

@ -1,10 +1,12 @@
using Manager.DTOs; using Manager.DTOs;
using ManagerService.DTOs; using ManagerService.DTOs;
using ManagerService.Helpers;
using NetTopologySuite.Geometries; using NetTopologySuite.Geometries;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using System.Linq; using System.Linq;
using System.Net;
namespace ManagerService.Data.SubSection namespace ManagerService.Data.SubSection
{ {
@ -117,6 +119,34 @@ namespace ManagerService.Data.SubSection
[ForeignKey(nameof(SectionEventId))] [ForeignKey(nameof(SectionEventId))]
public SectionEvent? SectionEvent { get; set; } public SectionEvent? SectionEvent { get; set; }
public GeoPointDTO ToDTO()
{
return new GeoPointDTO
{
id = Id,
title = Title,
description = Description,
contents = Contents,
categorieId = CategorieId,
geometry = Geometry != null ? new GeometryDTO
{
Type = Geometry.GeometryType,
Coordinates = Geometry.Coordinates,
} : null,
polyColor = PolyColor,
imageResourceId = ImageResourceId,
imageUrl = ImageUrl,
schedules = Schedules,
prices = Prices,
phone = Phone,
email = Email,
site = Site,
sectionMapId = SectionMapId,
sectionEventId = SectionEventId
};
}
} }
public class GuidedPath // Parcours public class GuidedPath // Parcours
@ -152,6 +182,45 @@ namespace ManagerService.Data.SubSection
public int Order { get; set; } public int Order { get; set; }
public List<GuidedStep> Steps { get; set; } = new(); public List<GuidedStep> Steps { get; set; } = new();
public GuidedPathDTO ToDTO()
{
return new GuidedPathDTO
{
Id = Id,
InstanceId = InstanceId,
Title = Title,
Description = Description,
SectionMapId = SectionMapId,
SectionEventId = SectionEventId,
IsLinear = IsLinear,
RequireSuccessToAdvance = RequireSuccessToAdvance,
HideNextStepsUntilComplete = HideNextStepsUntilComplete,
Order = Order,
Steps = Steps?.Select(s => s.ToDTO()).ToList()
};
}
public GuidedPath FromDTO(GuidedPathDTO dto)
{
if (dto == null) return null;
return new GuidedPath
{
Id = dto.Id,
InstanceId = dto.InstanceId,
Title = dto.Title ?? new List<TranslationDTO>(),
Description = dto.Description ?? new List<TranslationDTO>(),
SectionMapId = dto.SectionMapId,
SectionEventId = dto.SectionEventId,
IsLinear = dto.IsLinear,
RequireSuccessToAdvance = dto.RequireSuccessToAdvance,
HideNextStepsUntilComplete = dto.HideNextStepsUntilComplete,
Order = dto.Order,
//Steps = dto.Steps?.Select(s => s.FromDTO()).ToList() ?? new List<GuidedStep>() // Other method
};
}
} }
public class GuidedStep // Étape dun parcours public class GuidedStep // Étape dun parcours
@ -202,6 +271,54 @@ namespace ManagerService.Data.SubSection
// Option : message ou action à effectuer si timer expire (ex: afficher aide, fin du jeu...) // Option : message ou action à effectuer si timer expire (ex: afficher aide, fin du jeu...)
[Column(TypeName = "jsonb")] [Column(TypeName = "jsonb")]
public List<TranslationDTO> TimerExpiredMessage { get; set; } public List<TranslationDTO> TimerExpiredMessage { get; set; }
public GuidedStepDTO ToDTO()
{
return new GuidedStepDTO
{
Id = Id,
GuidedPathId = GuidedPathId,
Order = Order,
Title = Title,
Description = Description,
Geometry = Geometry,
ZoneRadiusMeters = ZoneRadiusMeters,
ImageUrl = ImageUrl,
TriggerGeoPointId = TriggerGeoPointId,
TriggerGeoPoint = TriggerGeoPoint.ToDTO(),
IsHiddenInitially = IsHiddenInitially,
IsStepTimer = IsStepTimer,
IsStepLocked = IsStepLocked,
TimerSeconds = TimerSeconds,
TimerExpiredMessage = TimerExpiredMessage,
QuizQuestions = QuizQuestions
};
}
public GuidedStep FromDTO(GuidedStepDTO dto)
{
if (dto == null) return null;
return new GuidedStep
{
Id = dto.Id,
GuidedPathId = dto.GuidedPathId,
Title = dto.Title ?? new List<TranslationDTO>(),
Description = dto.Description ?? new List<TranslationDTO>(),
Geometry = dto.Geometry,
ZoneRadiusMeters = dto.ZoneRadiusMeters,
ImageUrl = dto.ImageUrl,
TriggerGeoPointId = dto.TriggerGeoPointId,
IsHiddenInitially = dto.IsHiddenInitially,
IsStepTimer = dto.IsStepTimer,
IsStepLocked = dto.IsStepLocked,
TimerSeconds = dto.TimerSeconds,
TimerExpiredMessage = dto.TimerExpiredMessage ?? new List<TranslationDTO>(),
Order = dto.Order,
QuizQuestions = dto.QuizQuestions
};
}
} }

View File

@ -2,10 +2,8 @@
using ManagerService.Data; using ManagerService.Data;
using ManagerService.Data.SubSection; using ManagerService.Data.SubSection;
using ManagerService.DTOs; using ManagerService.DTOs;
using MongoDB.Bson;
using Newtonsoft.Json; using Newtonsoft.Json;
using System; using System;
using System.Linq;
using System.Text.Json; using System.Text.Json;
namespace ManagerService.Services namespace ManagerService.Services
@ -16,6 +14,7 @@ namespace ManagerService.Services
{ {
AgendaDTO agendaDTO = new AgendaDTO(); AgendaDTO agendaDTO = new AgendaDTO();
ArticleDTO articleDTO = new ArticleDTO(); ArticleDTO articleDTO = new ArticleDTO();
SectionEventDTO sectionEventDTO = new SectionEventDTO();
MapDTO mapDTO = new MapDTO(); MapDTO mapDTO = new MapDTO();
MenuDTO menuDTO = new MenuDTO(); MenuDTO menuDTO = new MenuDTO();
PdfDTO pdfDTO = new PdfDTO(); PdfDTO pdfDTO = new PdfDTO();
@ -34,6 +33,9 @@ namespace ManagerService.Services
case SectionType.Article: case SectionType.Article:
articleDTO = JsonConvert.DeserializeObject<ArticleDTO>(jsonElement.ToString()); articleDTO = JsonConvert.DeserializeObject<ArticleDTO>(jsonElement.ToString());
break; break;
case SectionType.Event:
sectionEventDTO = JsonConvert.DeserializeObject<SectionEventDTO>(jsonElement.ToString());
break;
case SectionType.Map: case SectionType.Map:
mapDTO = JsonConvert.DeserializeObject<MapDTO>(jsonElement.ToString()); mapDTO = JsonConvert.DeserializeObject<MapDTO>(jsonElement.ToString());
break; break;
@ -86,7 +88,8 @@ namespace ManagerService.Services
MeterZoneGPS = dto.meterZoneGPS, MeterZoneGPS = dto.meterZoneGPS,
Type = dto.type, Type = dto.type,
AgendaResourceIds = agendaDTO.resourceIds, AgendaResourceIds = agendaDTO.resourceIds,
AgendaMapProvider = agendaDTO.agendaMapProvider AgendaMapProvider = agendaDTO.agendaMapProvider,
//EventAgendas = // TODO specific
}, },
SectionType.Article => new SectionArticle SectionType.Article => new SectionArticle
{ {
@ -114,6 +117,31 @@ namespace ManagerService.Services
ArticleIsReadAudioAuto = articleDTO.isReadAudioAuto, ArticleIsReadAudioAuto = articleDTO.isReadAudioAuto,
ArticleContents = articleDTO.contents ArticleContents = articleDTO.contents
}, },
SectionType.Event => new SectionEvent
{
Id = dto.id,
DateCreation = dto.dateCreation.Value,
ConfigurationId = dto.configurationId,
InstanceId = dto.instanceId,
Label = dto.label,
Title = dto.title,
Description = dto.description,
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,
StartDate = sectionEventDTO.StartDate,
EndDate = sectionEventDTO.EndDate,
ParcoursIds = sectionEventDTO.ParcoursIds,
//Programmes = // TODO specific
},
SectionType.Map => new SectionMap SectionType.Map => new SectionMap
{ {
Id = dto.id, Id = dto.id,
@ -360,7 +388,8 @@ namespace ManagerService.Services
meterZoneGPS = agenda.MeterZoneGPS, meterZoneGPS = agenda.MeterZoneGPS,
type = agenda.Type, type = agenda.Type,
resourceIds = agenda.AgendaResourceIds, resourceIds = agenda.AgendaResourceIds,
agendaMapProvider = agenda.AgendaMapProvider agendaMapProvider = agenda.AgendaMapProvider,
// events => TODO specific
}, },
SectionArticle article => new ArticleDTO SectionArticle article => new ArticleDTO
{ {
@ -388,6 +417,31 @@ namespace ManagerService.Services
isReadAudioAuto = article.ArticleIsReadAudioAuto, isReadAudioAuto = article.ArticleIsReadAudioAuto,
contents = article.ArticleContents contents = article.ArticleContents
}, },
SectionEvent sectionEvent => new SectionEventDTO
{
id = sectionEvent.Id,
dateCreation = sectionEvent.DateCreation,
configurationId = sectionEvent.ConfigurationId,
instanceId = sectionEvent.InstanceId,
label = sectionEvent.Label,
title = sectionEvent.Title,
description = sectionEvent.Description,
order = sectionEvent.Order,
imageId = sectionEvent.ImageId,
imageSource = sectionEvent.ImageSource,
isSubSection = sectionEvent.IsSubSection,
parentId = sectionEvent.ParentId,
isBeacon = sectionEvent.IsBeacon,
beaconId = sectionEvent.BeaconId,
latitude = sectionEvent.Latitude,
longitude = sectionEvent.Longitude,
meterZoneGPS = sectionEvent.MeterZoneGPS,
type = sectionEvent.Type,
StartDate = sectionEvent.StartDate,
EndDate = sectionEvent.EndDate,
ParcoursIds = sectionEvent.ParcoursIds,
// Programme TODO specific
},
SectionMap map => new MapDTO SectionMap map => new MapDTO
{ {
id = map.Id, id = map.Id,