diff --git a/ManagerService/Controllers/ApplicationInstanceController.cs b/ManagerService/Controllers/ApplicationInstanceController.cs index 758c387..ea925ca 100644 --- a/ManagerService/Controllers/ApplicationInstanceController.cs +++ b/ManagerService/Controllers/ApplicationInstanceController.cs @@ -9,6 +9,7 @@ using ManagerService.Helpers; using ManagerService.Services; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using NSwag.Annotations; @@ -99,8 +100,6 @@ namespace ManagerService.Controllers } } - - /// /// Update an application instance /// @@ -123,7 +122,6 @@ namespace ManagerService.Controllers throw new KeyNotFoundException("application instance does not exist"); applicationInstance.FromDTO(updatedApplicationInstanceDTO); - _myInfoMateDbContext.SaveChanges(); return new OkObjectResult(applicationInstance.ToDTO()); @@ -184,5 +182,108 @@ namespace ManagerService.Controllers return new ObjectResult(ex.Message) { StatusCode = 500 }; } } + + /// + /// Create a new application Link to specified application instance + /// + /// Application instance id + /// Info to link config and application instance + [ProducesResponseType(typeof(AppConfigurationLinkDTO), 200)] + [ProducesResponseType(typeof(string), 400)] + [ProducesResponseType(typeof(string), 409)] + [ProducesResponseType(typeof(string), 500)] + [HttpPost("{applicationInstanceId}/application-link")] + public ObjectResult AddConfigurationToApplicationInstance(string applicationInstanceId, [FromBody] AppConfigurationLinkDTO appConfigurationLinkDTO) + { + try + { + if (applicationInstanceId == null) + throw new ArgumentNullException("Application instance param is null"); + + if (appConfigurationLinkDTO == null) + throw new ArgumentNullException("Configuration param is null"); + + ApplicationInstance applicationInstance = _myInfoMateDbContext.ApplicationInstances.Include(ai => ai.Configurations).FirstOrDefault(ai => ai.Id == applicationInstanceId); + + if (applicationInstance == null) + throw new KeyNotFoundException("This application instance was not found"); + + Configuration configuration = _myInfoMateDbContext.Configurations.FirstOrDefault(c => c.Id == appConfigurationLinkDTO.ConfigurationId); + + if (configuration == null) + throw new KeyNotFoundException("This configuration was not found"); + + // Todo add some verification ? + AppConfigurationLink appConfigurationLink = new AppConfigurationLink(); + appConfigurationLink.Id = idService.GenerateHexId(); + appConfigurationLink.FromDTO(appConfigurationLinkDTO); + + _myInfoMateDbContext.AppConfigurationLinks.Add(appConfigurationLink); + _myInfoMateDbContext.SaveChanges(); + + return new OkObjectResult(appConfigurationLink.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 }; + } + } + + /// + /// Remove configuration from instance + /// + /// Application instance id + /// AppConfiguration id + [ProducesResponseType(typeof(string), 202)] + [ProducesResponseType(typeof(string), 400)] + [ProducesResponseType(typeof(string), 404)] + [ProducesResponseType(typeof(string), 500)] + [HttpDelete("{applicationInstanceId}/application-link/{appConfigurationLinkId}")] + public ObjectResult DeleteAppConfigurationLink(string applicationInstanceId, string appConfigurationLinkId) + { + try + { + if (applicationInstanceId == null) + throw new ArgumentNullException("application instance param is null"); + + if (appConfigurationLinkId == null) + throw new ArgumentNullException("Configuration param is null"); + + ApplicationInstance applicationInstance = _myInfoMateDbContext.ApplicationInstances.FirstOrDefault(ai => ai.Id == applicationInstanceId); + + if (applicationInstance == null) + throw new KeyNotFoundException("application instance does not exist"); + + AppConfigurationLink appConfigurationLink = _myInfoMateDbContext.AppConfigurationLinks.FirstOrDefault(acl => acl.Id == appConfigurationLinkId); + + if (appConfigurationLink == null) + throw new KeyNotFoundException("This app configuration link was not found"); + + _myInfoMateDbContext.AppConfigurationLinks.Remove(appConfigurationLink); + _myInfoMateDbContext.SaveChanges(); + + return new ObjectResult("The app configuration link 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 }; + } + } } } diff --git a/ManagerService/Controllers/SectionAgendaController.cs b/ManagerService/Controllers/SectionAgendaController.cs index 3981200..73634c9 100644 --- a/ManagerService/Controllers/SectionAgendaController.cs +++ b/ManagerService/Controllers/SectionAgendaController.cs @@ -25,11 +25,11 @@ namespace ManagerService.Controllers { private readonly MyInfoMateDbContext _myInfoMateDbContext; - private readonly ILogger _logger; + private readonly ILogger _logger; private readonly IConfiguration _configuration; IHexIdGeneratorService idService = new HexIdGeneratorService(); - public SectionAgendaController(IConfiguration configuration, ILogger logger, MyInfoMateDbContext myInfoMateDbContext) + public SectionAgendaController(IConfiguration configuration, ILogger logger, MyInfoMateDbContext myInfoMateDbContext) { _logger = logger; _configuration = configuration; diff --git a/ManagerService/Controllers/SectionController.cs b/ManagerService/Controllers/SectionController.cs index 58189d4..3a9608a 100644 --- a/ManagerService/Controllers/SectionController.cs +++ b/ManagerService/Controllers/SectionController.cs @@ -22,6 +22,7 @@ using System.Net.Http; using System.Security.Cryptography; using System.Text.Json; using System.Threading.Tasks; +using static ManagerService.Data.SubSection.SectionEvent; namespace ManagerService.Controllers { @@ -874,6 +875,13 @@ namespace ManagerService.Controllers // REMOVE ALL POINTS 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); + foreach (var guidedPath in guidedPaths) + { + _myInfoMateDbContext.RemoveRange(guidedPath.Steps); + _myInfoMateDbContext.Remove(guidedPath); + } } if (section.Type == SectionType.Quiz) @@ -883,6 +891,37 @@ namespace ManagerService.Controllers _myInfoMateDbContext.RemoveRange(quizQuestions); } + if (section.Type == SectionType.Event) + { + var sectionEvent = _myInfoMateDbContext.Sections.OfType().Include(se => se.Programme).ThenInclude(se => se.MapAnnotations).FirstOrDefault(s => s.Id == id); + + foreach (var programBlock in sectionEvent.Programme) + { + _myInfoMateDbContext.RemoveRange(programBlock.MapAnnotations); + _myInfoMateDbContext.Remove(programBlock); + } + + var guidedPaths = _myInfoMateDbContext.GuidedPaths.Include(gp => gp.Steps).Where(gp => gp.SectionEventId == id); + foreach (var guidedPath in guidedPaths) + { + _myInfoMateDbContext.RemoveRange(guidedPath.Steps); + _myInfoMateDbContext.Remove(guidedPath); + } + + var applicationInstances = _myInfoMateDbContext.ApplicationInstances.Where(ai => ai.SectionEventId == id); + foreach (var applicationInstance in applicationInstances) + { + applicationInstance.SectionEventId = null; // Is that enough ? + } + } + + if (section.Type == SectionType.Agenda) + { + var sectionAgenda = _myInfoMateDbContext.Sections.OfType().Include(sa => sa.EventAgendas).FirstOrDefault(sa => sa.Id == id); + + _myInfoMateDbContext.RemoveRange(sectionAgenda.EventAgendas); + } + _myInfoMateDbContext.Remove(section); //_sectionService.Remove(id); diff --git a/ManagerService/Controllers/SectionEventController.cs b/ManagerService/Controllers/SectionEventController.cs new file mode 100644 index 0000000..23f2596 --- /dev/null +++ b/ManagerService/Controllers/SectionEventController.cs @@ -0,0 +1,367 @@ +using Manager.DTOs; +using ManagerService.Data; +using ManagerService.Data.SubSection; +using ManagerService.Helpers; +using ManagerService.Services; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; +using Namotion.Reflection; +using NSwag.Annotations; +using System; +using System.Collections.Generic; +using System.Linq; +using static ManagerService.Data.SubSection.SectionEvent; + +namespace ManagerService.Controllers +{ + [Authorize] // TODO Add ROLES (Roles = "Admin") + [ApiController, Route("api/[controller]")] + [OpenApiTag("Section event", Description = "Section event management")] + public class SectionEventController : ControllerBase + { + private readonly MyInfoMateDbContext _myInfoMateDbContext; + + private readonly ILogger _logger; + private readonly IConfiguration _configuration; + IHexIdGeneratorService idService = new HexIdGeneratorService(); + + public SectionEventController(IConfiguration configuration, ILogger logger, MyInfoMateDbContext myInfoMateDbContext) + { + _logger = logger; + _configuration = configuration; + _myInfoMateDbContext = myInfoMateDbContext; + } + + /// + /// Get all programme block from section + /// + /// Section id + [AllowAnonymous] + [ProducesResponseType(typeof(List), 200)] + [ProducesResponseType(typeof(string), 404)] + [ProducesResponseType(typeof(string), 500)] + [HttpGet("{sectionId}/programmes")] + public ObjectResult GetAllProgrammeBlockFromSection(string sectionEventId) + { + try + { + SectionEvent sectionEvent = _myInfoMateDbContext.Sections.OfType().Include(se => se.Programme).ThenInclude(se => se.MapAnnotations).ThenInclude(se => se.IconResource).FirstOrDefault(se => se.Id == sectionEventId); + + if (sectionEvent == null) + throw new KeyNotFoundException("Section event does not exist"); + + /*List programmeBlocks = new List(); + 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(sectionEvent.Programme); + } + catch (KeyNotFoundException ex) + { + return new NotFoundObjectResult(ex.Message) { }; + } + catch (Exception ex) + { + return new ObjectResult(ex.Message) { StatusCode = 500 }; + } + } + + /// + /// Create new programme block + /// + /// Section event Id + /// Programme block + [ProducesResponseType(typeof(ProgrammeBlock), 200)] + [ProducesResponseType(typeof(string), 400)] + [ProducesResponseType(typeof(string), 409)] + [ProducesResponseType(typeof(string), 500)] + [HttpPost("{sectionEventId}/programmes")] + public ObjectResult CreateProgrammeBlock(string sectionEventId, [FromBody] ProgrammeBlock programmeBlock) + { + try + { + if (sectionEventId == null) + throw new ArgumentNullException("Section param is null"); + + if (programmeBlock == null) + throw new ArgumentNullException("ProgrammeBlock param is null"); + + var existingSection = _myInfoMateDbContext.Sections.OfType().Include(se => se.Programme).FirstOrDefault(se => se.Id == sectionEventId); + if (existingSection == null) + throw new KeyNotFoundException("Section event does not exist"); + + // TODO verification ? + programmeBlock.Id = idService.GenerateHexId(); + existingSection.Programme.Add(programmeBlock); + + _myInfoMateDbContext.SaveChanges(); + + return new OkObjectResult(programmeBlock); + } + 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 }; + } + } + + /// + /// Update a program block + /// + /// ProgramBlock to update + [ProducesResponseType(typeof(ProgrammeBlock), 200)] + [ProducesResponseType(typeof(string), 400)] + [ProducesResponseType(typeof(string), 404)] + [ProducesResponseType(typeof(string), 500)] + [HttpPut("programmes")] + public ObjectResult UpdateProgrammeBlock([FromBody] ProgrammeBlock programmeBlock) + { + try + { + if (programmeBlock == null) + throw new ArgumentNullException("ProgrammeBlock param is null"); + + var existingProgramBlock = _myInfoMateDbContext.ProgrammeBlocks.FirstOrDefault(pb => pb.Id == programmeBlock.Id); + if (existingProgramBlock == null) + throw new KeyNotFoundException("ProgrammeBlock does not exist"); + + existingProgramBlock = programmeBlock; // TO TEST .. + _myInfoMateDbContext.SaveChanges(); + + return new OkObjectResult(existingProgramBlock); + } + 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 }; + } + } + + /// + /// Delete a programBlock + /// + /// Id of program block to delete + [ProducesResponseType(typeof(string), 202)] + [ProducesResponseType(typeof(string), 404)] + [ProducesResponseType(typeof(string), 500)] + [HttpDelete("programmes/{programBlockId}")] + public ObjectResult DeleteProgrammeBlock(string programBlockId) + { + try + { + var programBlock = _myInfoMateDbContext.ProgrammeBlocks.Include(pb => pb.MapAnnotations).FirstOrDefault(pb => pb.Id == programBlockId); + if (programBlock == null) + throw new KeyNotFoundException("ProgramBlock does not exist"); + + foreach (var mapAnnotation in programBlock.MapAnnotations) // Is it really needed? + { + _myInfoMateDbContext.Remove(mapAnnotation); + } + + _myInfoMateDbContext.Remove(programBlock); + _myInfoMateDbContext.SaveChanges(); + + return new ObjectResult("The programBlock 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 }; + } + } + + /// + /// Get all map annotation from program block + /// + /// Program block id + [AllowAnonymous] + [ProducesResponseType(typeof(List), 200)] + [ProducesResponseType(typeof(string), 404)] + [ProducesResponseType(typeof(string), 500)] + [HttpGet("{programBlockId}/map-annotations")] + public ObjectResult GetAllMapAnnotationsFromProgrammeBlock(string programBlockId) + { + try + { + ProgrammeBlock programmeBlock = _myInfoMateDbContext.ProgrammeBlocks.Include(pb => pb.MapAnnotations).ThenInclude(pb => pb.IconResource).FirstOrDefault(pb => pb.Id == programBlockId); + + if (programmeBlock == null) + throw new KeyNotFoundException("ProgrammeBlock does not exist"); + + /*List programmeBlocks = new List(); + 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(programmeBlock.MapAnnotations); + } + catch (KeyNotFoundException ex) + { + return new NotFoundObjectResult(ex.Message) { }; + } + catch (Exception ex) + { + return new ObjectResult(ex.Message) { StatusCode = 500 }; + } + } + + /// + /// Create new map annotation + /// + /// Programme block id + /// Map annotation + [ProducesResponseType(typeof(MapAnnotation), 200)] + [ProducesResponseType(typeof(string), 400)] + [ProducesResponseType(typeof(string), 409)] + [ProducesResponseType(typeof(string), 500)] + [HttpPost("{programmeBlockId}/map-annotations")] + public ObjectResult CreateMapAnnotation(string programmeBlockId, [FromBody] MapAnnotation mapAnnotation) + { + try + { + if (programmeBlockId == null) + throw new ArgumentNullException("ProgrammeBlockId param is null"); + + if (mapAnnotation == null) + throw new ArgumentNullException("MapAnnotation param is null"); + + var existingProgrammeBloc = _myInfoMateDbContext.ProgrammeBlocks.Include(pb => pb.MapAnnotations).FirstOrDefault(pb => pb.Id == programmeBlockId); + if (existingProgrammeBloc == null) + throw new KeyNotFoundException("ProgrammeBlock does not exist"); + + // TODO verification ? + mapAnnotation.Id = idService.GenerateHexId(); + existingProgrammeBloc.MapAnnotations.Add(mapAnnotation); + + _myInfoMateDbContext.SaveChanges(); + + return new OkObjectResult(mapAnnotation); + } + 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 }; + } + } + + /// + /// Update a map annotation + /// + /// mapAnnotation to update + [ProducesResponseType(typeof(MapAnnotation), 200)] + [ProducesResponseType(typeof(string), 400)] + [ProducesResponseType(typeof(string), 404)] + [ProducesResponseType(typeof(string), 500)] + [HttpPut("map-annotations")] + public ObjectResult UpdateMapAnnotation([FromBody] MapAnnotation mapAnnotation) + { + try + { + if (mapAnnotation == null) + throw new ArgumentNullException("MapAnnotation param is null"); + + var existingMapAnnotation = _myInfoMateDbContext.MapAnnotations.FirstOrDefault(ma => ma.Id == mapAnnotation.Id); + if (existingMapAnnotation == null) + throw new KeyNotFoundException("MapAnnotation does not exist"); + + existingMapAnnotation = mapAnnotation; // TO TEST .. + _myInfoMateDbContext.SaveChanges(); + + return new OkObjectResult(existingMapAnnotation); + } + 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 }; + } + } + + /// + /// Delete a mapAnnotation + /// + /// Id of map annotation to delete + [ProducesResponseType(typeof(string), 202)] + [ProducesResponseType(typeof(string), 404)] + [ProducesResponseType(typeof(string), 500)] + [HttpDelete("map-annotations/{mapAnnotationId}")] + public ObjectResult DeleteMapAnnotation(string mapAnnotationId) + { + try + { + var mapAnnotation = _myInfoMateDbContext.MapAnnotations.FirstOrDefault(ma => ma.Id == mapAnnotationId); + if (mapAnnotation == null) + throw new KeyNotFoundException("MapAnnotation does not exist"); + + _myInfoMateDbContext.Remove(mapAnnotation); + _myInfoMateDbContext.SaveChanges(); + + return new ObjectResult("The mapAnnotation 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 }; + } + } + } +} diff --git a/ManagerService/Controllers/SectionMapController.cs b/ManagerService/Controllers/SectionMapController.cs index 81694aa..98b18b5 100644 --- a/ManagerService/Controllers/SectionMapController.cs +++ b/ManagerService/Controllers/SectionMapController.cs @@ -12,7 +12,6 @@ using NSwag.Annotations; using System; using System.Collections.Generic; using System.Linq; -using System.Security.Cryptography; namespace ManagerService.Controllers { @@ -23,11 +22,11 @@ namespace ManagerService.Controllers { private readonly MyInfoMateDbContext _myInfoMateDbContext; - private readonly ILogger _logger; + private readonly ILogger _logger; private readonly IConfiguration _configuration; IHexIdGeneratorService idService = new HexIdGeneratorService(); - public SectionMapController(IConfiguration configuration, ILogger logger, MyInfoMateDbContext myInfoMateDbContext) + public SectionMapController(IConfiguration configuration, ILogger logger, MyInfoMateDbContext myInfoMateDbContext) { _logger = logger; _configuration = configuration; @@ -48,7 +47,10 @@ namespace ManagerService.Controllers try { SectionMap sectionMap = _myInfoMateDbContext.Sections.OfType().Include(sm => sm.MapPoints).FirstOrDefault(sm => sm.Id == sectionId); - + + if (sectionMap == null) + throw new KeyNotFoundException("Section map does not exist"); + List geoPointDTOs = new List(); foreach (var point in sectionMap.MapPoints) { @@ -294,7 +296,7 @@ namespace ManagerService.Controllers [ProducesResponseType(typeof(string), 202)] [ProducesResponseType(typeof(string), 404)] [ProducesResponseType(typeof(string), 500)] - [HttpDelete("points/delete/{geoPointId}")] + [HttpDelete("points/{geoPointId}")] public ObjectResult Delete(int geoPointId) { try diff --git a/ManagerService/Controllers/SectionMenuController.cs b/ManagerService/Controllers/SectionMenuController.cs deleted file mode 100644 index fd37e63..0000000 --- a/ManagerService/Controllers/SectionMenuController.cs +++ /dev/null @@ -1,282 +0,0 @@ -using ManagerService.Data; -using ManagerService.Services; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Logging; -using NSwag.Annotations; - -namespace ManagerService.Controllers -{ - [Authorize] // TODO Add ROLES (Roles = "Admin") - [ApiController, Route("api/[controller]")] - [OpenApiTag("Section menu", Description = "Section menu management")] - public class SectionMenuController : ControllerBase - { - private readonly MyInfoMateDbContext _myInfoMateDbContext; - - private readonly ILogger _logger; - private readonly IConfiguration _configuration; - IHexIdGeneratorService idService = new HexIdGeneratorService(); - - public SectionMenuController(IConfiguration configuration, ILogger logger, MyInfoMateDbContext myInfoMateDbContext) - { - _logger = logger; - _configuration = configuration; - _myInfoMateDbContext = myInfoMateDbContext; - } - - /// - /// Create a new section - /// - /// New section info - /*[ProducesResponseType(typeof(SectionDTO), 200)] - [ProducesResponseType(typeof(string), 400)] - [ProducesResponseType(typeof(string), 409)] - [ProducesResponseType(typeof(string), 500)] - [HttpPost()] - public ObjectResult Create([FromBody] SectionDTO newSection) - { - try - { - if (newSection == null) - throw new ArgumentNullException("Section param is null"); - - if (newSection.configurationId == null) - throw new ArgumentNullException("Configuration param is null"); - - var configuration = _myInfoMateDbContext.Configurations.FirstOrDefault(c => c.Id == newSection.configurationId); - if (configuration == null) - throw new KeyNotFoundException("Configuration does not exist"); - - // Todo add some verification ? - Section section = new Section(); - - // Preparation - List languages = _configuration.GetSection("SupportedLanguages").Get>(); - - switch (newSection.type) - { - case SectionType.Map: - section = new SectionMap - { - MapMapType = MapTypeApp.hybrid, - MapTypeMapbox = MapTypeMapBox.standard, - MapMapProvider = MapProvider.Google, - MapZoom = 18, - MapPoints = new List(), - MapCategories = new List() - }; - break; - case SectionType.Slider: - section = new SectionSlider - { - SliderContents = new List() - }; - 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
(), - }; - break; - case SectionType.Quiz: - section = new SectionQuiz - { - QuizQuestions = new List(), - // TODO levels ? - }; - break; - case SectionType.Article: - section = new SectionArticle - { - ArticleContents = new List(), - 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() - }; - break; - case SectionType.Weather: - section = new SectionWeather(); - break; - } - - section.InstanceId = newSection.instanceId; - section.Label = newSection.label; - section.ImageId = newSection.imageId; - section.ImageSource = newSection.imageSource; - section.ConfigurationId = newSection.configurationId; - section.DateCreation = DateTime.Now.ToUniversalTime(); - section.IsSubSection = newSection.isSubSection; - section.ParentId = newSection.parentId; - section.Type = newSection.type; - - section.Order = _myInfoMateDbContext.Sections.Count(s => s.ConfigurationId == newSection.configurationId && !s.IsSubSection) + 1; - - section.IsBeacon = newSection.isBeacon; - section.BeaconId = newSection.beaconId; - section.Latitude = newSection.latitude; - section.Longitude = newSection.longitude; - section.MeterZoneGPS = newSection.meterZoneGPS; - - section.Title = LanguageInit.Init("Title", languages); - section.Description = LanguageInit.Init("Description", languages); - - section.Id = idService.GenerateHexId(); - //_sectionService.Create(section); - _myInfoMateDbContext.Add(section); - _myInfoMateDbContext.SaveChanges(); - - return new OkObjectResult(section.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 }; - } - }*/ - - /// - /// Update sections order - /// - /// New sections order - /*[ProducesResponseType(typeof(string), 200)] - [ProducesResponseType(typeof(string), 400)] - [ProducesResponseType(typeof(string), 404)] - [ProducesResponseType(typeof(string), 500)] - [HttpPut("order")] - public ObjectResult UpdateOrder([FromBody] List updatedSectionsOrder) - { - // TODO REWRITE LOGIC.. - try - { - if (updatedSectionsOrder == null) - throw new ArgumentNullException("Sections param is null"); - - foreach (var section in updatedSectionsOrder) - { - var sectionDB = _myInfoMateDbContext.Sections.FirstOrDefault(s => s.Id == section.id); - if (sectionDB == null) - throw new KeyNotFoundException($"Section {section.label} with id {section.id} does not exist"); - } - - foreach (var updatedSection in updatedSectionsOrder) - { - var section = _myInfoMateDbContext.Sections.FirstOrDefault(s => s.Id == updatedSection.id); - //OldSection section = _sectionService.GetById(updatedSection.id); - section.Order = updatedSection.order.GetValueOrDefault(); - _myInfoMateDbContext.SaveChanges(); - - //_sectionService.Update(section.Id, section); - } - - 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) - { - return new BadRequestObjectResult(ex.Message) { }; - } - catch (KeyNotFoundException ex) - { - return new NotFoundObjectResult(ex.Message) { }; - } - catch (Exception ex) - { - return new ObjectResult(ex.Message) { StatusCode = 500 }; - } - }*/ - - - /// - /// Delete a section - /// - /// Id of section to delete - /*[ProducesResponseType(typeof(string), 202)] - [ProducesResponseType(typeof(string), 400)] - [ProducesResponseType(typeof(string), 404)] - [ProducesResponseType(typeof(string), 500)] - [HttpDelete("{id}")] - public ObjectResult Delete(string id) - { - try - { - if (id == null) - throw new ArgumentNullException("Section param is null"); - - 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
sections = _myInfoMateDbContext.Sections.Where(s => s.ConfigurationId == section.ConfigurationId && !s.IsSubSection).ToList(); - int i = 1; - foreach (var sectionDb in sections.OrderBy(s => s.Order)) - { - sectionDb.Order = i; - i++; - } - - _myInfoMateDbContext.SaveChanges(); - - return new ObjectResult("The section has been deleted") { StatusCode = 202 }; - - } - 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 }; - } - }*/ - } -} diff --git a/ManagerService/Controllers/SectionQuizController.cs b/ManagerService/Controllers/SectionQuizController.cs index e0d0228..3ad22cf 100644 --- a/ManagerService/Controllers/SectionQuizController.cs +++ b/ManagerService/Controllers/SectionQuizController.cs @@ -28,11 +28,11 @@ namespace ManagerService.Controllers { private readonly MyInfoMateDbContext _myInfoMateDbContext; - private readonly ILogger _logger; + private readonly ILogger _logger; private readonly IConfiguration _configuration; IHexIdGeneratorService idService = new HexIdGeneratorService(); - public SectionQuizController(IConfiguration configuration, ILogger logger, MyInfoMateDbContext myInfoMateDbContext) + public SectionQuizController(IConfiguration configuration, ILogger logger, MyInfoMateDbContext myInfoMateDbContext) { _logger = logger; _configuration = configuration; diff --git a/ManagerService/DTOs/SectionType.cs b/ManagerService/DTOs/SectionType.cs index fc4cbb0..8c2e712 100644 --- a/ManagerService/DTOs/SectionType.cs +++ b/ManagerService/DTOs/SectionType.cs @@ -12,6 +12,7 @@ PDF, Puzzle, Agenda, - Weather + Weather, + Event } } diff --git a/ManagerService/DTOs/SubSection/SectionEventDTO.cs b/ManagerService/DTOs/SubSection/SectionEventDTO.cs new file mode 100644 index 0000000..8623307 --- /dev/null +++ b/ManagerService/DTOs/SubSection/SectionEventDTO.cs @@ -0,0 +1,15 @@ +using ManagerService.DTOs; +using System; +using System.Collections.Generic; +using static ManagerService.Data.SubSection.SectionEvent; + +namespace Manager.DTOs +{ + public class SectionEventDTO : SectionDTO + { + public DateTime StartDate { get; set; } + public DateTime EndDate { get; set; } + public List ParcoursIds { get; set; } + public List Programme { get; set; } = new(); + } +} diff --git a/ManagerService/Data/MyInfoMateDbContext.cs b/ManagerService/Data/MyInfoMateDbContext.cs index a3c7af8..02dc02a 100644 --- a/ManagerService/Data/MyInfoMateDbContext.cs +++ b/ManagerService/Data/MyInfoMateDbContext.cs @@ -34,6 +34,7 @@ namespace ManagerService.Data // Events public DbSet ProgrammeBlocks { get; set; } + public DbSet MapAnnotations { get; set; } // Agenda public DbSet EventAgendas { get; set; } diff --git a/ManagerService/Data/SubSection/SectionEvent.cs b/ManagerService/Data/SubSection/SectionEvent.cs index a145192..5cae162 100644 --- a/ManagerService/Data/SubSection/SectionEvent.cs +++ b/ManagerService/Data/SubSection/SectionEvent.cs @@ -29,7 +29,6 @@ namespace ManagerService.Data.SubSection public List Description { get; set; } public DateTime StartTime { get; set; } public DateTime EndTime { get; set; } - public List MapAnnotations { get; set; } } diff --git a/ManagerService/Data/SubSection/SectionMap.cs b/ManagerService/Data/SubSection/SectionMap.cs index b3b6803..cc3896e 100644 --- a/ManagerService/Data/SubSection/SectionMap.cs +++ b/ManagerService/Data/SubSection/SectionMap.cs @@ -1,13 +1,10 @@ using Manager.DTOs; using ManagerService.DTOs; using NetTopologySuite.Geometries; -using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; -using static ManagerService.Data.SubSection.SectionEvent; - namespace ManagerService.Data.SubSection {