ApplicationInstance done but not tested + SectionEvent done but to be tested + wip sectioncontroller update + misc
This commit is contained in:
parent
9671361a34
commit
a0aaf6e601
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Update an application instance
|
||||
/// </summary>
|
||||
@ -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 };
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new application Link to specified application instance
|
||||
/// </summary>
|
||||
/// <param name="applicationInstanceId">Application instance id</param>
|
||||
/// <param name="appConfigurationLinkDTO">Info to link config and application instance</param>
|
||||
[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 };
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove configuration from instance
|
||||
/// </summary>
|
||||
/// <param name="applicationInstanceId">Application instance id</param>
|
||||
/// <param name="appConfigurationLinkId">AppConfiguration id</param>
|
||||
[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 };
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,11 +25,11 @@ namespace ManagerService.Controllers
|
||||
{
|
||||
private readonly MyInfoMateDbContext _myInfoMateDbContext;
|
||||
|
||||
private readonly ILogger<SectionController> _logger;
|
||||
private readonly ILogger<SectionAgendaController> _logger;
|
||||
private readonly IConfiguration _configuration;
|
||||
IHexIdGeneratorService idService = new HexIdGeneratorService();
|
||||
|
||||
public SectionAgendaController(IConfiguration configuration, ILogger<SectionController> logger, MyInfoMateDbContext myInfoMateDbContext)
|
||||
public SectionAgendaController(IConfiguration configuration, ILogger<SectionAgendaController> logger, MyInfoMateDbContext myInfoMateDbContext)
|
||||
{
|
||||
_logger = logger;
|
||||
_configuration = configuration;
|
||||
|
||||
@ -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<SectionEvent>().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<SectionAgenda>().Include(sa => sa.EventAgendas).FirstOrDefault(sa => sa.Id == id);
|
||||
|
||||
_myInfoMateDbContext.RemoveRange(sectionAgenda.EventAgendas);
|
||||
}
|
||||
|
||||
_myInfoMateDbContext.Remove(section);
|
||||
//_sectionService.Remove(id);
|
||||
|
||||
|
||||
367
ManagerService/Controllers/SectionEventController.cs
Normal file
367
ManagerService/Controllers/SectionEventController.cs
Normal file
@ -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<SectionEventController> _logger;
|
||||
private readonly IConfiguration _configuration;
|
||||
IHexIdGeneratorService idService = new HexIdGeneratorService();
|
||||
|
||||
public SectionEventController(IConfiguration configuration, ILogger<SectionEventController> logger, MyInfoMateDbContext myInfoMateDbContext)
|
||||
{
|
||||
_logger = logger;
|
||||
_configuration = configuration;
|
||||
_myInfoMateDbContext = myInfoMateDbContext;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get all programme block from section
|
||||
/// </summary>
|
||||
/// <param name="sectionEventId">Section id</param>
|
||||
[AllowAnonymous]
|
||||
[ProducesResponseType(typeof(List<ProgrammeBlock>), 200)]
|
||||
[ProducesResponseType(typeof(string), 404)]
|
||||
[ProducesResponseType(typeof(string), 500)]
|
||||
[HttpGet("{sectionId}/programmes")]
|
||||
public ObjectResult GetAllProgrammeBlockFromSection(string sectionEventId)
|
||||
{
|
||||
try
|
||||
{
|
||||
SectionEvent sectionEvent = _myInfoMateDbContext.Sections.OfType<SectionEvent>().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<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(sectionEvent.Programme);
|
||||
}
|
||||
catch (KeyNotFoundException ex)
|
||||
{
|
||||
return new NotFoundObjectResult(ex.Message) { };
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new ObjectResult(ex.Message) { StatusCode = 500 };
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create new programme block
|
||||
/// </summary>
|
||||
/// <param name="sectionEventId">Section event Id</param>
|
||||
/// <param name="programmeBlock">Programme block</param>
|
||||
[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<SectionEvent>().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 };
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update a program block
|
||||
/// </summary>
|
||||
/// <param name="programmeBlock">ProgramBlock to update</param>
|
||||
[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 };
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete a programBlock
|
||||
/// </summary>
|
||||
/// <param name="programBlockId">Id of program block to delete</param>
|
||||
[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 };
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get all map annotation from program block
|
||||
/// </summary>
|
||||
/// <param name="programBlockId">Program block id</param>
|
||||
[AllowAnonymous]
|
||||
[ProducesResponseType(typeof(List<MapAnnotation>), 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<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(programmeBlock.MapAnnotations);
|
||||
}
|
||||
catch (KeyNotFoundException ex)
|
||||
{
|
||||
return new NotFoundObjectResult(ex.Message) { };
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new ObjectResult(ex.Message) { StatusCode = 500 };
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create new map annotation
|
||||
/// </summary>
|
||||
/// <param name="programmeBlockId">Programme block id</param>
|
||||
/// <param name="mapAnnotation">Map annotation</param>
|
||||
[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 };
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update a map annotation
|
||||
/// </summary>
|
||||
/// <param name="mapAnnotation">mapAnnotation to update</param>
|
||||
[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 };
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete a mapAnnotation
|
||||
/// </summary>
|
||||
/// <param name="mapAnnotationId">Id of map annotation to delete</param>
|
||||
[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 };
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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<SectionController> _logger;
|
||||
private readonly ILogger<SectionMapController> _logger;
|
||||
private readonly IConfiguration _configuration;
|
||||
IHexIdGeneratorService idService = new HexIdGeneratorService();
|
||||
|
||||
public SectionMapController(IConfiguration configuration, ILogger<SectionController> logger, MyInfoMateDbContext myInfoMateDbContext)
|
||||
public SectionMapController(IConfiguration configuration, ILogger<SectionMapController> logger, MyInfoMateDbContext myInfoMateDbContext)
|
||||
{
|
||||
_logger = logger;
|
||||
_configuration = configuration;
|
||||
@ -48,7 +47,10 @@ namespace ManagerService.Controllers
|
||||
try
|
||||
{
|
||||
SectionMap sectionMap = _myInfoMateDbContext.Sections.OfType<SectionMap>().Include(sm => sm.MapPoints).FirstOrDefault(sm => sm.Id == sectionId);
|
||||
|
||||
|
||||
if (sectionMap == null)
|
||||
throw new KeyNotFoundException("Section map does not exist");
|
||||
|
||||
List<GeoPointDTO> geoPointDTOs = new List<GeoPointDTO>();
|
||||
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
|
||||
|
||||
@ -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<SectionController> _logger;
|
||||
private readonly IConfiguration _configuration;
|
||||
IHexIdGeneratorService idService = new HexIdGeneratorService();
|
||||
|
||||
public SectionMenuController(IConfiguration configuration, ILogger<SectionController> logger, MyInfoMateDbContext myInfoMateDbContext)
|
||||
{
|
||||
_logger = logger;
|
||||
_configuration = configuration;
|
||||
_myInfoMateDbContext = myInfoMateDbContext;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new section
|
||||
/// </summary>
|
||||
/// <param name="newSection">New section info</param>
|
||||
/*[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<string> languages = _configuration.GetSection("SupportedLanguages").Get<List<string>>();
|
||||
|
||||
switch (newSection.type)
|
||||
{
|
||||
case SectionType.Map:
|
||||
section = new SectionMap
|
||||
{
|
||||
MapMapType = MapTypeApp.hybrid,
|
||||
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;
|
||||
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 };
|
||||
}
|
||||
}*/
|
||||
|
||||
/// <summary>
|
||||
/// Update sections order
|
||||
/// </summary>
|
||||
/// <param name="updatedSectionsOrder">New sections order</param>
|
||||
/*[ProducesResponseType(typeof(string), 200)]
|
||||
[ProducesResponseType(typeof(string), 400)]
|
||||
[ProducesResponseType(typeof(string), 404)]
|
||||
[ProducesResponseType(typeof(string), 500)]
|
||||
[HttpPut("order")]
|
||||
public ObjectResult UpdateOrder([FromBody] List<SectionDTO> 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 };
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Delete a section
|
||||
/// </summary>
|
||||
/// <param name="id">Id of section to delete</param>
|
||||
/*[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<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.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 };
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
@ -28,11 +28,11 @@ namespace ManagerService.Controllers
|
||||
{
|
||||
private readonly MyInfoMateDbContext _myInfoMateDbContext;
|
||||
|
||||
private readonly ILogger<SectionController> _logger;
|
||||
private readonly ILogger<SectionQuizController> _logger;
|
||||
private readonly IConfiguration _configuration;
|
||||
IHexIdGeneratorService idService = new HexIdGeneratorService();
|
||||
|
||||
public SectionQuizController(IConfiguration configuration, ILogger<SectionController> logger, MyInfoMateDbContext myInfoMateDbContext)
|
||||
public SectionQuizController(IConfiguration configuration, ILogger<SectionQuizController> logger, MyInfoMateDbContext myInfoMateDbContext)
|
||||
{
|
||||
_logger = logger;
|
||||
_configuration = configuration;
|
||||
|
||||
@ -12,6 +12,7 @@
|
||||
PDF,
|
||||
Puzzle,
|
||||
Agenda,
|
||||
Weather
|
||||
Weather,
|
||||
Event
|
||||
}
|
||||
}
|
||||
|
||||
15
ManagerService/DTOs/SubSection/SectionEventDTO.cs
Normal file
15
ManagerService/DTOs/SubSection/SectionEventDTO.cs
Normal file
@ -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<string> ParcoursIds { get; set; }
|
||||
public List<ProgrammeBlock> Programme { get; set; } = new();
|
||||
}
|
||||
}
|
||||
@ -34,6 +34,7 @@ namespace ManagerService.Data
|
||||
|
||||
// Events
|
||||
public DbSet<ProgrammeBlock> ProgrammeBlocks { get; set; }
|
||||
public DbSet<MapAnnotation> MapAnnotations { get; set; }
|
||||
|
||||
// Agenda
|
||||
public DbSet<EventAgenda> EventAgendas { get; set; }
|
||||
|
||||
@ -29,7 +29,6 @@ namespace ManagerService.Data.SubSection
|
||||
public List<TranslationDTO> Description { get; set; }
|
||||
public DateTime StartTime { get; set; }
|
||||
public DateTime EndTime { get; set; }
|
||||
|
||||
public List<MapAnnotation> MapAnnotations { get; set; }
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user