788 lines
32 KiB
C#
788 lines
32 KiB
C#
using Manager.DTOs;
|
|
using Manager.Helpers;
|
|
using Manager.Services;
|
|
using ManagerService.Data;
|
|
using ManagerService.Data.SubSection;
|
|
using ManagerService.DTOs;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.Logging;
|
|
using Mqtt.Client.AspNetCore.Services;
|
|
using Newtonsoft.Json;
|
|
using NSwag.Annotations;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace ManagerService.Controllers
|
|
{
|
|
[Authorize] // TODO Add ROLES (Roles = "Admin")
|
|
[ApiController, Route("api/[controller]")]
|
|
[OpenApiTag("Section", Description = "Section management")]
|
|
public class SectionController : ControllerBase
|
|
{
|
|
private SectionDatabaseService _sectionService;
|
|
private ConfigurationDatabaseService _configurationService;
|
|
private readonly ILogger<SectionController> _logger;
|
|
private readonly IConfiguration _configuration;
|
|
|
|
public SectionController(IConfiguration configuration, ILogger<SectionController> logger, SectionDatabaseService sectionService, ConfigurationDatabaseService configurationService)
|
|
{
|
|
_logger = logger;
|
|
_configuration = configuration;
|
|
_sectionService = sectionService;
|
|
_configurationService = configurationService;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get a list of all section (summary)
|
|
/// </summary>
|
|
/// <param name="id">id instance</param>
|
|
[ProducesResponseType(typeof(List<SectionDTO>), 200)]
|
|
[ProducesResponseType(typeof(string), 500)]
|
|
[HttpGet]
|
|
public ObjectResult Get([FromQuery] string instanceId)
|
|
{
|
|
try
|
|
{
|
|
List<OldSection> sections = _sectionService.GetAll(instanceId);
|
|
|
|
|
|
/* CLEAN ARTICLE AUDIO - Init new field AudioIds */
|
|
|
|
/*foreach (var article in sections.Where(s => s.Type == SectionType.Article))
|
|
{
|
|
try
|
|
{
|
|
ArticleDTO articleDTO = JsonConvert.DeserializeObject<ArticleDTO>(article.Data);
|
|
List<string> languages = _configuration.GetSection("SupportedLanguages").Get<List<string>>();
|
|
articleDTO.audioIds = LanguageInit.Init("Audio", languages, true);
|
|
article.Data = JsonConvert.SerializeObject(articleDTO); // Include all info from specific section as JSON
|
|
|
|
Section sectionModified = _sectionService.Update(article.Id, article);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
}
|
|
}*/
|
|
|
|
return new OkObjectResult(sections.Select(r => r.ToDTO()));
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ObjectResult(ex.Message) { StatusCode = 500 };
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get a list of all section from a specific configuration
|
|
/// </summary>
|
|
/// <param name="id">configuration id</param>
|
|
[AllowAnonymous]
|
|
[ProducesResponseType(typeof(List<SectionDTO>), 200)]
|
|
[ProducesResponseType(typeof(string), 500)]
|
|
[ProducesResponseType(typeof(string), 400)]
|
|
[HttpGet("configuration/{id}")]
|
|
public ObjectResult GetFromConfiguration(string id)
|
|
{
|
|
try
|
|
{
|
|
if (id == null)
|
|
throw new ArgumentNullException("Param is null");
|
|
|
|
if (_configurationService.IsExist(id))
|
|
{
|
|
List<OldSection> sections = _sectionService.GetAllFromConfiguration(id);
|
|
|
|
return new OkObjectResult(sections.Select(r => r.ToDTO()));
|
|
}
|
|
else
|
|
return new NotFoundObjectResult("Configuration not found");
|
|
}
|
|
catch (ArgumentNullException ex)
|
|
{
|
|
return new BadRequestObjectResult(ex.Message) { };
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ObjectResult(ex.Message) { StatusCode = 500 };
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Delete all section from a specific configuration
|
|
/// </summary>
|
|
/// <param name="id">configuration id</param>
|
|
[ProducesResponseType(typeof(string), 202)]
|
|
[ProducesResponseType(typeof(string), 500)]
|
|
[ProducesResponseType(typeof(string), 400)]
|
|
[HttpDelete("configuration/{id}")]
|
|
public ObjectResult DeleteAllForConfiguration(string id)
|
|
{
|
|
try
|
|
{
|
|
if (id == null)
|
|
throw new ArgumentNullException("Param is null");
|
|
|
|
_sectionService.DeleteAllFromConfiguration(id);
|
|
|
|
return new ObjectResult("All section from the specified configuration has been deleted") { StatusCode = 202 };
|
|
}
|
|
catch (ArgumentNullException ex)
|
|
{
|
|
return new BadRequestObjectResult(ex.Message) { };
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ObjectResult(ex.Message) { StatusCode = 500 };
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get a list of all subsection (summary) of a specific section
|
|
/// </summary>
|
|
/// <param name="id">section id</param>
|
|
[ProducesResponseType(typeof(List<object>), 200)]
|
|
[ProducesResponseType(typeof(string), 500)]
|
|
[ProducesResponseType(typeof(string), 400)]
|
|
[HttpGet("{id}/subsections")]
|
|
public ObjectResult GetAllSectionSubSections(string id)
|
|
{
|
|
try
|
|
{
|
|
if (id == null)
|
|
throw new ArgumentNullException("Param is null");
|
|
|
|
List<OldSection> sections = _sectionService.GetAllSubSection(id);
|
|
|
|
return new OkObjectResult(sections.Select(r => r.ToDTO()));
|
|
}
|
|
catch (ArgumentNullException ex)
|
|
{
|
|
return new BadRequestObjectResult(ex.Message) { };
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ObjectResult(ex.Message) { StatusCode = 500 };
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Get a specific section
|
|
/// </summary>
|
|
/// <param name="id">section id</param>
|
|
[AllowAnonymous]
|
|
[ProducesResponseType(typeof(SectionDTO), 200)]
|
|
[ProducesResponseType(typeof(string), 404)]
|
|
[ProducesResponseType(typeof(string), 500)]
|
|
[HttpGet("{id}")]
|
|
public ObjectResult GetDetail(string id)
|
|
{
|
|
try
|
|
{
|
|
OldSection section = _sectionService.GetById(id);
|
|
|
|
if (section == null)
|
|
throw new KeyNotFoundException("This section was not found");
|
|
|
|
return new OkObjectResult(section.ToDTO());
|
|
/*switch (section.Type) {
|
|
case SectionType.Map:
|
|
MapDTO mapDTO = JsonConvert.DeserializeObject<MapDTO>(section.Data);
|
|
mapDTO.Id = section.Id;
|
|
mapDTO.Label = section.Label;
|
|
mapDTO.Description = section.Description;
|
|
mapDTO.Type = section.Type;
|
|
mapDTO.ImageId = section.ImageId;
|
|
mapDTO.IsSubSection = section.IsSubSection;
|
|
mapDTO.DateCreation = section.DateCreation;
|
|
mapDTO.Data = section.Data;
|
|
return new OkObjectResult(mapDTO);
|
|
case SectionType.Slider:
|
|
SliderDTO sliderDTO = JsonConvert.DeserializeObject<SliderDTO>(section.Data);
|
|
sliderDTO.Id = section.Id;
|
|
sliderDTO.Label = section.Label;
|
|
sliderDTO.Description = section.Description;
|
|
sliderDTO.Type = section.Type;
|
|
sliderDTO.ImageId = section.ImageId;
|
|
sliderDTO.IsSubSection = section.IsSubSection;
|
|
sliderDTO.DateCreation = section.DateCreation;
|
|
sliderDTO.Data = section.Data;
|
|
return new OkObjectResult(section.ToDTO());
|
|
case SectionType.Menu:
|
|
return new OkObjectResult(section.ToDTO());
|
|
case SectionType.Web:
|
|
return new OkObjectResult(section.ToDTO());
|
|
case SectionType.Video:
|
|
return new OkObjectResult(section.ToDTO());
|
|
default:
|
|
return new OkObjectResult(section.ToDTO());
|
|
}*/
|
|
}
|
|
catch (KeyNotFoundException ex)
|
|
{
|
|
return new NotFoundObjectResult(ex.Message) {};
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ObjectResult(ex.Message) { StatusCode = 500 };
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get all section with beacon
|
|
/// </summary>
|
|
/// <param name="instanceId">Instance id</param>
|
|
[AllowAnonymous]
|
|
[ProducesResponseType(typeof(List<SectionDTO>), 200)]
|
|
[ProducesResponseType(typeof(string), 404)]
|
|
[ProducesResponseType(typeof(string), 500)]
|
|
[HttpGet("beacons/{instanceId}")]
|
|
public ObjectResult GetAllBeaconsForInstance(string instanceId)
|
|
{
|
|
try
|
|
{
|
|
List<OldSection> sections = _sectionService.GetAll(instanceId);
|
|
|
|
sections = sections.Where(s => s.IsBeacon && s.BeaconId != null).ToList();
|
|
|
|
return new OkObjectResult(sections.Select(s => s.ToDTO()));
|
|
}
|
|
catch (KeyNotFoundException ex)
|
|
{
|
|
return new NotFoundObjectResult(ex.Message) { };
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ObjectResult(ex.Message) { StatusCode = 500 };
|
|
}
|
|
}
|
|
|
|
/// <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");
|
|
|
|
if (!_configurationService.IsExist(newSection.configurationId) )
|
|
throw new KeyNotFoundException("Configuration does not exist");
|
|
|
|
// Todo add some verification ?
|
|
Section section = new Section();
|
|
section.InstanceId = newSection.instanceId;
|
|
section.Label = newSection.label;
|
|
section.ImageId = newSection.imageId;
|
|
section.ImageSource = newSection.imageSource;
|
|
section.ConfigurationId = newSection.configurationId;
|
|
section.DateCreation = DateTime.Now;
|
|
section.IsSubSection = newSection.isSubSection;
|
|
section.ParentId = newSection.parentId;
|
|
section.Type = newSection.type;
|
|
section.Title = new List<Translation>();
|
|
section.Description = new List<Translation>();
|
|
section.Order = _sectionService.GetAllFromConfiguration(newSection.configurationId).Count;
|
|
section.IsBeacon = newSection.isBeacon;
|
|
section.BeaconId = newSection.beaconId;
|
|
section.Latitude = newSection.latitude;
|
|
section.Longitude = newSection.longitude;
|
|
section.MeterZoneGPS = newSection.meterZoneGPS;
|
|
|
|
// Preparation
|
|
List<string> languages = _configuration.GetSection("SupportedLanguages").Get<List<string>>();
|
|
|
|
var contentArticle = new List<Translation>();
|
|
|
|
var mapDTO = new MapDTO(); // For menu dto
|
|
var sliderDTO = new SliderDTO(); // For menu dto
|
|
|
|
section.Title = LanguageInit.Init("Title", languages);
|
|
section.Description = LanguageInit.Init("Description", languages);
|
|
contentArticle = LanguageInit.Init("Content", languages);
|
|
|
|
/*foreach (var language in languages)
|
|
{
|
|
TranslationDTO title = new TranslationDTO();
|
|
TranslationDTO description = new TranslationDTO();
|
|
TranslationDTO content = new TranslationDTO();
|
|
title.language = language.ToUpper();
|
|
description.language = language.ToUpper();
|
|
content.language = language.ToUpper();
|
|
switch (language.ToUpper())
|
|
{
|
|
case "FR":
|
|
title.value = "Titre en français";
|
|
description.value = "Description en français";
|
|
content.value = "Contenu en français";
|
|
break;
|
|
case "EN":
|
|
title.value = "Title in english";
|
|
description.value = "Description en anglais";
|
|
content.value = "Contenu en anglais";
|
|
break;
|
|
case "NL":
|
|
title.value = "Titre in dutch";
|
|
description.value = "Description en néerlandais";
|
|
content.value = "Contenu en néerlandais";
|
|
break;
|
|
case "DE":
|
|
title.value = "Titre en allemand";
|
|
description.value = "Description en allemand";
|
|
content.value = "Contenu en allemand";
|
|
break;
|
|
}
|
|
section.Title.Add(title);
|
|
section.Description.Add(description);
|
|
contentArticle.Add(content);
|
|
}*/
|
|
|
|
section.Title = section.Title.OrderBy(t => t.Language).ToList();
|
|
section.Description = section.Description.OrderBy(d => d.Language).ToList();
|
|
|
|
switch (newSection.type) {
|
|
case SectionType.Map:
|
|
mapDTO = new MapDTO();
|
|
mapDTO.mapType = MapTypeApp.hybrid;
|
|
mapDTO.mapTypeMapbox = MapTypeMapBox.standard;
|
|
mapDTO.mapProvider = MapProvider.Google;
|
|
mapDTO.zoom = 18;
|
|
|
|
mapDTO.points = new List<GeoPointDTO>();
|
|
mapDTO.categories = new List<CategorieDTO>();
|
|
|
|
//section.Data = JsonConvert.SerializeObject(mapDTO); // Include all info from specific section as JSON
|
|
break;
|
|
case SectionType.Slider:
|
|
sliderDTO = new SliderDTO();
|
|
sliderDTO.contents = new List<ContentDTO>();
|
|
|
|
//section.Data = JsonConvert.SerializeObject(sliderDTO); // Include all info from specific section as JSON
|
|
break;
|
|
case SectionType.Video:
|
|
VideoDTO videoDTO = new VideoDTO();
|
|
videoDTO.source = "";
|
|
//section.Data = JsonConvert.SerializeObject(videoDTO); // Include all info from specific section as JSON
|
|
break;
|
|
case SectionType.Web:
|
|
WebDTO webDTO = new WebDTO();
|
|
webDTO.source = "";
|
|
//section.Data = JsonConvert.SerializeObject(webDTO); // Include all info from specific section as JSON
|
|
break;
|
|
case SectionType.Menu:
|
|
MenuDTO menuDTO = new MenuDTO();
|
|
menuDTO.sections = new List<SectionDTO>();
|
|
/*SectionDTO section0DTO = new SectionDTO();
|
|
section0DTO.IsSubSection = true;
|
|
section0DTO.Label = newSection.Label;
|
|
section0DTO.ImageId = newSection.ImageId;
|
|
section0DTO.ConfigurationId = newSection.ConfigurationId;
|
|
section0DTO.DateCreation = DateTime.Now;
|
|
section0DTO.ParentId = null;
|
|
section0DTO.Type = SectionType.Map;
|
|
section0DTO.Data = JsonConvert.SerializeObject(mapDTO);
|
|
|
|
|
|
SectionDTO section1DTO = new SectionDTO();
|
|
section0DTO.IsSubSection = true;
|
|
section0DTO.Label = newSection.Label;
|
|
section0DTO.ImageId = newSection.ImageId;
|
|
section0DTO.ConfigurationId = newSection.ConfigurationId;
|
|
section0DTO.DateCreation = DateTime.Now;
|
|
section0DTO.ParentId = null;
|
|
section0DTO.Type = SectionType.Slider;
|
|
section1DTO.IsSubSection = true;
|
|
section1DTO.Data = JsonConvert.SerializeObject(sliderDTO);*/
|
|
|
|
/*menuDTO.Sections.Add(section0DTO);
|
|
menuDTO.Sections.Add(section1DTO);*/
|
|
//section.Data = JsonConvert.SerializeObject(menuDTO); // Include all info from specific section as JSON
|
|
break;
|
|
case SectionType.Quizz:
|
|
QuizDTO quizzDTO = new QuizDTO();
|
|
quizzDTO.questions = new List<QuestionDTO>();
|
|
//section.Data = JsonConvert.SerializeObject(quizzDTO); // Include all info from specific section as JSON
|
|
break;
|
|
case SectionType.Article:
|
|
ArticleDTO articleDTO = new ArticleDTO();
|
|
articleDTO.contents = new List<ContentDTO>();
|
|
articleDTO.content = contentArticle.Select(c => c.ToDTO()).ToList(); // TODO check
|
|
articleDTO.audioIds = LanguageInit.Init("Audio", languages, true).Select(c => c.ToDTO()).ToList(); // TODO check
|
|
|
|
//section.Data = JsonConvert.SerializeObject(articleDTO); // Include all info from specific section as JSON
|
|
break;
|
|
case SectionType.PDF:
|
|
PdfDTO pdfDTO = new PdfDTO();
|
|
//section.Data = JsonConvert.SerializeObject(pdfDTO); // Include all info from specific section as JSON
|
|
break;
|
|
case SectionType.Puzzle:
|
|
PuzzleDTO puzzleDTO = new PuzzleDTO();
|
|
//section.Data = JsonConvert.SerializeObject(puzzleDTO); // Include all info from specific section as JSON
|
|
break;
|
|
case SectionType.Agenda:
|
|
AgendaDTO agendaDTO = new AgendaDTO();
|
|
//section.Data = JsonConvert.SerializeObject(agendaDTO); // Include all info from specific section as JSON
|
|
break;
|
|
case SectionType.Weather:
|
|
WeatherDTO weatherDTO = new WeatherDTO();
|
|
//section.Data = JsonConvert.SerializeObject(weatherDTO); // Include all info from specific section as JSON
|
|
break;
|
|
}
|
|
|
|
// TODO
|
|
OldSection sectionCreated = new OldSection();//_sectionService.Create(section);
|
|
|
|
return new OkObjectResult(sectionCreated.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>
|
|
/// Create a new section - slider
|
|
/// </summary>
|
|
/// <param name="newSection">New section info - slider</param>
|
|
[ProducesResponseType(typeof(SliderDTO), 200)]
|
|
[ProducesResponseType(typeof(string), 400)]
|
|
[ProducesResponseType(typeof(string), 409)]
|
|
[ProducesResponseType(typeof(string), 500)]
|
|
[HttpPost("Slider")]
|
|
public ObjectResult CreateSlider([FromBody] SliderDTO newSectionSlider)
|
|
{
|
|
try
|
|
{
|
|
if (newSectionSlider == null)
|
|
throw new ArgumentNullException("Section param is null");
|
|
|
|
// Todo add some verification ?
|
|
Slider sliderSection = new Slider();
|
|
sliderSection.Label = newSectionSlider.Label;
|
|
sliderSection.ImageId = newSectionSlider.ImageId;
|
|
sliderSection.DateCreation = DateTime.Now;
|
|
|
|
sliderSection.IsSubSection = false;
|
|
sliderSection.ParentId = null;
|
|
sliderSection.Type = SectionType.Slider;
|
|
|
|
sliderSection.Images = newSectionSlider.Images.Select(p =>
|
|
new Image()
|
|
{
|
|
Title = p.Title,
|
|
Description = p.Description,
|
|
Source = p.Source,
|
|
}).ToList();
|
|
|
|
Slider sectionCreated = _sectionService.CreateSlider(sliderSection);
|
|
|
|
return new OkObjectResult(sectionCreated.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 section
|
|
/// </summary>
|
|
/// <param name="updatedSection">Section to update</param>
|
|
[ProducesResponseType(typeof(SectionDTO), 200)]
|
|
[ProducesResponseType(typeof(string), 400)]
|
|
[ProducesResponseType(typeof(string), 404)]
|
|
[ProducesResponseType(typeof(string), 500)]
|
|
[HttpPut]
|
|
public ObjectResult Update([FromBody] SectionDTO updatedSection)
|
|
{
|
|
try
|
|
{
|
|
if (updatedSection == null)
|
|
throw new ArgumentNullException("Section param is null");
|
|
|
|
OldSection section = _sectionService.GetById(updatedSection.id);
|
|
|
|
if (section == null)
|
|
throw new KeyNotFoundException("Section does not exist");
|
|
|
|
// Todo add some verification ?
|
|
/*section.InstanceId = updatedSection.instanceId;
|
|
section.Label = updatedSection.label;
|
|
section.Title = updatedSection.title.Select(t => new Translation().FromDTO(t)).ToList(); // TODO CHECK
|
|
section.Description = updatedSection.description.Select(t => new Translation().FromDTO(t)).ToList();// TODO CHECK
|
|
section.Type = updatedSection.type;
|
|
section.ImageId = updatedSection.imageId;
|
|
section.ImageSource = updatedSection.imageSource;
|
|
section.ConfigurationId = updatedSection.configurationId;
|
|
section.IsSubSection = updatedSection.isSubSection;
|
|
section.ParentId = updatedSection.parentId;
|
|
section.Data = updatedSection.data;
|
|
section.IsBeacon = updatedSection.isBeacon;
|
|
section.BeaconId = updatedSection.beaconId;
|
|
section.Latitude = updatedSection.latitude;
|
|
section.Longitude = updatedSection.longitude;
|
|
section.MeterZoneGPS = updatedSection.meterZoneGPS;
|
|
|
|
Section sectionModified = _sectionService.Update(updatedSection.id, section);*/
|
|
// todo
|
|
Section sectionModified = new Section();
|
|
|
|
MqttClientService.PublishMessage($"config/{sectionModified.ConfigurationId}", JsonConvert.SerializeObject(new PlayerMessageDTO() { configChanged = true }));
|
|
|
|
return new OkObjectResult(sectionModified.ToDTO());
|
|
}
|
|
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>
|
|
/// 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)
|
|
{
|
|
try
|
|
{
|
|
if (updatedSectionsOrder == null)
|
|
throw new ArgumentNullException("Sections param is null");
|
|
|
|
foreach (var section in updatedSectionsOrder)
|
|
{
|
|
if (!_sectionService.IsExist(section.id))
|
|
throw new KeyNotFoundException($"Section {section.label} with id {section.id} does not exist");
|
|
}
|
|
|
|
foreach (var updatedSection in updatedSectionsOrder)
|
|
{
|
|
OldSection section = _sectionService.GetById(updatedSection.id);
|
|
section.Order = updatedSection.order.GetValueOrDefault();
|
|
|
|
_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");
|
|
|
|
if (!_sectionService.IsExist(id))
|
|
throw new KeyNotFoundException("Section does not exist");
|
|
|
|
_sectionService.Remove(id);
|
|
|
|
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 };
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Useless, just to generate dto code
|
|
/// </summary>
|
|
[ProducesResponseType(typeof(MapDTO), 200)]
|
|
[HttpGet("MapDTO")]
|
|
public ObjectResult GetMapDTO()
|
|
{
|
|
return new ObjectResult("MapDTO") { StatusCode = 200 };
|
|
}
|
|
|
|
/// <summary>
|
|
/// Useless, just to generate dto code
|
|
/// </summary>
|
|
[ProducesResponseType(typeof(SliderDTO), 200)]
|
|
[HttpGet("SliderDTO")]
|
|
public ObjectResult GetSliderDTO()
|
|
{
|
|
return new ObjectResult("SliderDTO") { StatusCode = 200 };
|
|
}
|
|
|
|
/// <summary>
|
|
/// Useless, just to generate dto code
|
|
/// </summary>
|
|
[ProducesResponseType(typeof(VideoDTO), 200)]
|
|
[HttpGet("VideoDTO")]
|
|
public ObjectResult GetVideoDTO()
|
|
{
|
|
return new ObjectResult("VideoDTO") { StatusCode = 200 };
|
|
}
|
|
|
|
/// <summary>
|
|
/// Useless, just to generate dto code
|
|
/// </summary>
|
|
[ProducesResponseType(typeof(WebDTO), 200)]
|
|
[HttpGet("WebDTO")]
|
|
public ObjectResult GetWebDTO()
|
|
{
|
|
return new ObjectResult("WebDTO") { StatusCode = 200 };
|
|
}
|
|
|
|
/// <summary>
|
|
/// Useless, just to generate dto code
|
|
/// </summary>
|
|
[ProducesResponseType(typeof(MenuDTO), 200)]
|
|
[HttpGet("MenuDTO")]
|
|
public ObjectResult GetMenuDTO()
|
|
{
|
|
return new ObjectResult("MenuDTO") { StatusCode = 200 };
|
|
}
|
|
|
|
/// <summary>
|
|
/// Useless, just to generate dto code
|
|
/// </summary>
|
|
[ProducesResponseType(typeof(PlayerMessageDTO), 200)]
|
|
[HttpGet("PlayerMessageDTO")]
|
|
public ObjectResult PlayerMessageDTO()
|
|
{
|
|
return new ObjectResult("PlayerMessageDTO") { StatusCode = 200 };
|
|
}
|
|
|
|
/// <summary>
|
|
/// Useless, just to generate dto code
|
|
/// </summary>
|
|
[ProducesResponseType(typeof(QuizDTO), 200)]
|
|
[HttpGet("QuizDTO")]
|
|
public ObjectResult GetQuizDTO()
|
|
{
|
|
return new ObjectResult("QuizDTO") { StatusCode = 200 };
|
|
}
|
|
|
|
/// <summary>
|
|
/// Useless, just to generate dto code
|
|
/// </summary>
|
|
[ProducesResponseType(typeof(ArticleDTO), 200)]
|
|
[HttpGet("ArticleDTO")]
|
|
public ObjectResult GetArticleDTO()
|
|
{
|
|
return new ObjectResult("ArticleDTO") { StatusCode = 200 };
|
|
}
|
|
|
|
/// <summary>
|
|
/// Useless, just to generate dto code
|
|
/// </summary>
|
|
[ProducesResponseType(typeof(PdfDTO), 200)]
|
|
[HttpGet("PdfDTO")]
|
|
public ObjectResult GetPdfDTO()
|
|
{
|
|
return new ObjectResult("PdfDTO") { StatusCode = 200 };
|
|
}
|
|
|
|
/// <summary>
|
|
/// Useless, just to generate dto code
|
|
/// </summary>
|
|
[ProducesResponseType(typeof(PuzzleDTO), 200)]
|
|
[HttpGet("PuzzleDTO")]
|
|
public ObjectResult GetPuzzleDTO()
|
|
{
|
|
return new ObjectResult("PuzzleDTO") { StatusCode = 200 };
|
|
}
|
|
|
|
/// <summary>
|
|
/// Useless, just to generate dto code
|
|
/// </summary>
|
|
[ProducesResponseType(typeof(AgendaDTO), 200)]
|
|
[HttpGet("AgendaDTO")]
|
|
public ObjectResult GetAgendaDTO()
|
|
{
|
|
return new ObjectResult("AgendaDTO") { StatusCode = 200 };
|
|
}
|
|
|
|
/// <summary>
|
|
/// Useless, just to generate dto code
|
|
/// </summary>
|
|
[ProducesResponseType(typeof(WeatherDTO), 200)]
|
|
[HttpGet("WeatherDTO")]
|
|
public ObjectResult GetWeatherDTO()
|
|
{
|
|
return new ObjectResult("WeatherDTO") { StatusCode = 200 };
|
|
}
|
|
}
|
|
}
|