Add get from configuration detail endpoint (mobile)
This commit is contained in:
parent
e3639589b0
commit
5fb5563730
@ -1,6 +1,5 @@
|
|||||||
using Manager.DTOs;
|
using Manager.DTOs;
|
||||||
using Manager.Helpers;
|
using Manager.Helpers;
|
||||||
using Manager.Interfaces.Models;
|
|
||||||
using Manager.Services;
|
using Manager.Services;
|
||||||
using ManagerService.Data;
|
using ManagerService.Data;
|
||||||
using ManagerService.Data.SubSection;
|
using ManagerService.Data.SubSection;
|
||||||
@ -16,7 +15,6 @@ using Newtonsoft.Json;
|
|||||||
using NSwag.Annotations;
|
using NSwag.Annotations;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
|
||||||
@ -128,6 +126,154 @@ namespace ManagerService.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get a list of all section from a specific configuration (mobile format)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">configuration id</param>
|
||||||
|
[AllowAnonymous]
|
||||||
|
[ProducesResponseType(typeof(List<object>), 200)]
|
||||||
|
[ProducesResponseType(typeof(string), 500)]
|
||||||
|
[ProducesResponseType(typeof(string), 400)]
|
||||||
|
[HttpGet("configuration/{id}/detail")]
|
||||||
|
public ObjectResult GetFromConfigurationDetail(string id)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (id == null)
|
||||||
|
throw new ArgumentNullException("Param is null");
|
||||||
|
|
||||||
|
Configuration configuration = _myInfoMateDbContext.Configurations.FirstOrDefault(c => c.Id == id);
|
||||||
|
|
||||||
|
if (configuration != null)
|
||||||
|
{
|
||||||
|
List<Section> sections = _myInfoMateDbContext.Sections.Where(s => s.ConfigurationId == id && !s.IsSubSection).ToList();
|
||||||
|
List<object> sectionsToReturn = new List<object>();
|
||||||
|
|
||||||
|
foreach (var section in sections)
|
||||||
|
{
|
||||||
|
var dto = SectionFactory.ToDTO(section);
|
||||||
|
|
||||||
|
switch (section.Type)
|
||||||
|
{
|
||||||
|
case SectionType.Map:
|
||||||
|
var geoPoints = _myInfoMateDbContext.GeoPoints.Where(gp => gp.SectionMapId == section.Id).ToList();
|
||||||
|
List<GeoPointDTO> geoPointDTOs = new List<GeoPointDTO>();
|
||||||
|
foreach (var geoPoint in geoPoints)
|
||||||
|
{
|
||||||
|
geoPointDTOs.Add(new GeoPointDTO() {
|
||||||
|
id = geoPoint.Id,
|
||||||
|
title = geoPoint.Title,
|
||||||
|
description = geoPoint.Description,
|
||||||
|
contents = geoPoint.Contents,
|
||||||
|
categorieId = geoPoint.CategorieId,
|
||||||
|
latitude = geoPoint.Latitude,
|
||||||
|
longitude = geoPoint.Longitude,
|
||||||
|
imageResourceId = geoPoint.ImageResourceId,
|
||||||
|
imageUrl = geoPoint.ImageUrl,
|
||||||
|
schedules = geoPoint.Schedules,
|
||||||
|
prices = geoPoint.Prices,
|
||||||
|
phone = geoPoint.Phone,
|
||||||
|
email = geoPoint.Email,
|
||||||
|
site = geoPoint.Site
|
||||||
|
});
|
||||||
|
}
|
||||||
|
(dto as MapDTO).points = geoPointDTOs;
|
||||||
|
break;
|
||||||
|
case SectionType.Quiz:
|
||||||
|
var quizQuestions = _myInfoMateDbContext.QuizQuestions.Where(qq => qq.SectionQuizId == section.Id).ToList();
|
||||||
|
List<QuestionDTO> questionDTOs = new List<QuestionDTO>();
|
||||||
|
foreach (var quizQuestion in quizQuestions)
|
||||||
|
{
|
||||||
|
questionDTOs.Add(new QuestionDTO()
|
||||||
|
{
|
||||||
|
id = quizQuestion.Id,
|
||||||
|
label = quizQuestion.Label,
|
||||||
|
responses = quizQuestion.Responses,
|
||||||
|
imageBackgroundResourceId = quizQuestion.ResourceId,
|
||||||
|
imageBackgroundResourceType = quizQuestion.Resource?.Type,
|
||||||
|
imageBackgroundResourceUrl = quizQuestion.Resource?.Url,
|
||||||
|
order = quizQuestion.Order,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
(dto as QuizDTO).questions = questionDTOs;
|
||||||
|
break;
|
||||||
|
case SectionType.Menu:
|
||||||
|
var subSections = _myInfoMateDbContext.Sections.Where(s => s.IsSubSection && s.ParentId == section.Id).ToList();
|
||||||
|
List<object> subSectionToReturn = new List<object>();
|
||||||
|
foreach (var subSection in subSections)
|
||||||
|
{
|
||||||
|
var subDTO = SectionFactory.ToDTO(subSection);
|
||||||
|
switch (subSection.Type)
|
||||||
|
{
|
||||||
|
case SectionType.Map:
|
||||||
|
var geoPointsSub = _myInfoMateDbContext.GeoPoints.Where(gp => gp.SectionMapId == subSection.Id).ToList();
|
||||||
|
List<GeoPointDTO> geoPointDTOsSub = new List<GeoPointDTO>();
|
||||||
|
foreach (var geoPointSub in geoPointsSub)
|
||||||
|
{
|
||||||
|
geoPointDTOsSub.Add(new GeoPointDTO()
|
||||||
|
{
|
||||||
|
id = geoPointSub.Id,
|
||||||
|
title = geoPointSub.Title,
|
||||||
|
description = geoPointSub.Description,
|
||||||
|
contents = geoPointSub.Contents,
|
||||||
|
categorieId = geoPointSub.CategorieId,
|
||||||
|
latitude = geoPointSub.Latitude,
|
||||||
|
longitude = geoPointSub.Longitude,
|
||||||
|
imageResourceId = geoPointSub.ImageResourceId,
|
||||||
|
imageUrl = geoPointSub.ImageUrl,
|
||||||
|
schedules = geoPointSub.Schedules,
|
||||||
|
prices = geoPointSub.Prices,
|
||||||
|
phone = geoPointSub.Phone,
|
||||||
|
email = geoPointSub.Email,
|
||||||
|
site = geoPointSub.Site
|
||||||
|
});
|
||||||
|
}
|
||||||
|
(subDTO as MapDTO).points = geoPointDTOsSub;
|
||||||
|
break;
|
||||||
|
case SectionType.Quiz:
|
||||||
|
var quizQuestionsSub = _myInfoMateDbContext.QuizQuestions.Where(qq => qq.SectionQuizId == subSection.Id).ToList();
|
||||||
|
List<QuestionDTO> questionDTOsSub = new List<QuestionDTO>();
|
||||||
|
foreach (var quizQuestionSub in quizQuestionsSub)
|
||||||
|
{
|
||||||
|
questionDTOsSub.Add(new QuestionDTO()
|
||||||
|
{
|
||||||
|
id = quizQuestionSub.Id,
|
||||||
|
label = quizQuestionSub.Label,
|
||||||
|
responses = quizQuestionSub.Responses,
|
||||||
|
imageBackgroundResourceId = quizQuestionSub.ResourceId,
|
||||||
|
imageBackgroundResourceType = quizQuestionSub.Resource?.Type,
|
||||||
|
imageBackgroundResourceUrl = quizQuestionSub.Resource?.Url,
|
||||||
|
order = quizQuestionSub.Order,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
(subDTO as QuizDTO).questions = questionDTOsSub;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
subSectionToReturn.Add(subDTO);
|
||||||
|
}
|
||||||
|
(dto as MenuDTO).sections = subSectionToReturn;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
sectionsToReturn.Add(dto);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new OkObjectResult(sectionsToReturn);
|
||||||
|
}
|
||||||
|
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>
|
/// <summary>
|
||||||
/// Delete all section from a specific configuration
|
/// Delete all section from a specific configuration
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -212,7 +358,6 @@ namespace ManagerService.Controllers
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//OldSection section = _sectionService.GetById(id);
|
|
||||||
Section section = _myInfoMateDbContext.Sections.FirstOrDefault(s => s.Id == id);
|
Section section = _myInfoMateDbContext.Sections.FirstOrDefault(s => s.Id == id);
|
||||||
|
|
||||||
if (section == null)
|
if (section == null)
|
||||||
@ -221,38 +366,6 @@ namespace ManagerService.Controllers
|
|||||||
var dto = SectionFactory.ToDTO(section);
|
var dto = SectionFactory.ToDTO(section);
|
||||||
|
|
||||||
return new OkObjectResult(dto);
|
return new OkObjectResult(dto);
|
||||||
/*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)
|
catch (KeyNotFoundException ex)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -6,6 +6,6 @@ namespace Manager.DTOs
|
|||||||
public class MenuDTO : SectionDTO
|
public class MenuDTO : SectionDTO
|
||||||
{
|
{
|
||||||
//public string Title { get; set; } // Dictionary<string, object> with all languages
|
//public string Title { get; set; } // Dictionary<string, object> with all languages
|
||||||
public List<SectionDTO> sections { get; set; }
|
public List<object> sections { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -39,7 +39,7 @@ namespace ManagerService.Data.SubSection
|
|||||||
latitude = Latitude,
|
latitude = Latitude,
|
||||||
longitude = Longitude,
|
longitude = Longitude,
|
||||||
meterZoneGPS = MeterZoneGPS,
|
meterZoneGPS = MeterZoneGPS,
|
||||||
sections = MenuSections.Select(s => s.ToDTO()).ToList()
|
//sections = MenuSections.Select(s => s.ToDTO()).ToList()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user