fix puzzle + added order in back

This commit is contained in:
Thomas Fransolet 2025-05-27 14:44:33 +02:00
parent 79d1bc3db5
commit 75a6b0c323
4 changed files with 29 additions and 20 deletions

View File

@ -633,10 +633,10 @@ namespace ManagerService.Controllers
{ {
foreach (var puzzleMessageDebut in puzzle.PuzzleMessageDebut) foreach (var puzzleMessageDebut in puzzle.PuzzleMessageDebut)
{ {
if (puzzleMessageDebut.ResourceId == id) if (puzzleMessageDebut.resourceId == id)
{ {
puzzleMessageDebut.ResourceId = null; puzzleMessageDebut.resourceId = null;
puzzleMessageDebut.Resource = null; puzzleMessageDebut.resource = null;
_myInfoMateDbContext.Entry(puzzle).Property(p => p.PuzzleMessageDebut).IsModified = true; _myInfoMateDbContext.Entry(puzzle).Property(p => p.PuzzleMessageDebut).IsModified = true;
} }
} }
@ -645,10 +645,10 @@ namespace ManagerService.Controllers
{ {
foreach (var puzzleMessageFin in puzzle.PuzzleMessageFin) foreach (var puzzleMessageFin in puzzle.PuzzleMessageFin)
{ {
if (puzzleMessageFin.ResourceId == id) if (puzzleMessageFin.resourceId == id)
{ {
puzzleMessageFin.ResourceId = null; puzzleMessageFin.resourceId = null;
puzzleMessageFin.Resource = null; puzzleMessageFin.resource = null;
_myInfoMateDbContext.Entry(puzzle).Property(p => p.PuzzleMessageFin).IsModified = true; _myInfoMateDbContext.Entry(puzzle).Property(p => p.PuzzleMessageFin).IsModified = true;
} }
} }

View File

@ -146,7 +146,7 @@ namespace ManagerService.Controllers
if (configuration != null) if (configuration != null)
{ {
List<Section> sections = _myInfoMateDbContext.Sections.Where(s => s.ConfigurationId == id && !s.IsSubSection).ToList(); List<Section> sections = _myInfoMateDbContext.Sections.Where(s => s.ConfigurationId == id && !s.IsSubSection).OrderBy(s => s.Order).ToList();
List<object> sectionsToReturn = new List<object>(); List<object> sectionsToReturn = new List<object>();
foreach (var section in sections) foreach (var section in sections)
@ -155,8 +155,12 @@ namespace ManagerService.Controllers
switch (section.Type) switch (section.Type)
{ {
case SectionType.Puzzle:
Resource resource = _myInfoMateDbContext.Resources.FirstOrDefault(r => r.Id == (dto as PuzzleDTO).puzzleImageId);
(dto as PuzzleDTO).puzzleImage = resource.ToDTO();
break;
case SectionType.Map: case SectionType.Map:
var geoPoints = _myInfoMateDbContext.GeoPoints.Where(gp => gp.SectionMapId == section.Id).ToList(); var geoPoints = _myInfoMateDbContext.GeoPoints.Where(gp => gp.SectionMapId == section.Id)/*.OrderBy(gp => gp.or)*/.ToList();
List<GeoPointDTO> geoPointDTOs = new List<GeoPointDTO>(); List<GeoPointDTO> geoPointDTOs = new List<GeoPointDTO>();
foreach (var geoPoint in geoPoints) foreach (var geoPoint in geoPoints)
{ {
@ -180,7 +184,7 @@ namespace ManagerService.Controllers
(dto as MapDTO).points = geoPointDTOs; (dto as MapDTO).points = geoPointDTOs;
break; break;
case SectionType.Quiz: case SectionType.Quiz:
var quizQuestions = _myInfoMateDbContext.QuizQuestions.Where(qq => qq.SectionQuizId == section.Id).ToList(); var quizQuestions = _myInfoMateDbContext.QuizQuestions.Where(qq => qq.SectionQuizId == section.Id).OrderBy(q => q.Order).ToList();
List<QuestionDTO> questionDTOs = new List<QuestionDTO>(); List<QuestionDTO> questionDTOs = new List<QuestionDTO>();
foreach (var quizQuestion in quizQuestions) foreach (var quizQuestion in quizQuestions)
{ {
@ -198,13 +202,17 @@ namespace ManagerService.Controllers
(dto as QuizDTO).questions = questionDTOs; (dto as QuizDTO).questions = questionDTOs;
break; break;
case SectionType.Menu: case SectionType.Menu:
var subSections = _myInfoMateDbContext.Sections.Where(s => s.IsSubSection && s.ParentId == section.Id).ToList(); var subSections = _myInfoMateDbContext.Sections.Where(s => s.IsSubSection && s.ParentId == section.Id).OrderBy(s => s.Order).ToList();
List<object> subSectionToReturn = new List<object>(); List<object> subSectionToReturn = new List<object>();
foreach (var subSection in subSections) foreach (var subSection in subSections)
{ {
var subDTO = SectionFactory.ToDTO(subSection); var subDTO = SectionFactory.ToDTO(subSection);
switch (subSection.Type) switch (subSection.Type)
{ {
case SectionType.Puzzle:
Resource resourceSub = _myInfoMateDbContext.Resources.FirstOrDefault(r => r.Id == (subDTO as PuzzleDTO).puzzleImageId);
(subDTO as PuzzleDTO).puzzleImage = resourceSub?.ToDTO();
break;
case SectionType.Map: case SectionType.Map:
var geoPointsSub = _myInfoMateDbContext.GeoPoints.Where(gp => gp.SectionMapId == subSection.Id).ToList(); var geoPointsSub = _myInfoMateDbContext.GeoPoints.Where(gp => gp.SectionMapId == subSection.Id).ToList();
List<GeoPointDTO> geoPointDTOsSub = new List<GeoPointDTO>(); List<GeoPointDTO> geoPointDTOsSub = new List<GeoPointDTO>();
@ -231,7 +239,7 @@ namespace ManagerService.Controllers
(subDTO as MapDTO).points = geoPointDTOsSub; (subDTO as MapDTO).points = geoPointDTOsSub;
break; break;
case SectionType.Quiz: case SectionType.Quiz:
var quizQuestionsSub = _myInfoMateDbContext.QuizQuestions.Where(qq => qq.SectionQuizId == subSection.Id).ToList(); var quizQuestionsSub = _myInfoMateDbContext.QuizQuestions.Where(qq => qq.SectionQuizId == subSection.Id).OrderBy(q => q.Order).ToList();
List<QuestionDTO> questionDTOsSub = new List<QuestionDTO>(); List<QuestionDTO> questionDTOsSub = new List<QuestionDTO>();
foreach (var quizQuestionSub in quizQuestionsSub) foreach (var quizQuestionSub in quizQuestionsSub)
{ {
@ -321,7 +329,7 @@ namespace ManagerService.Controllers
if (id == null) if (id == null)
throw new ArgumentNullException("Param is null"); throw new ArgumentNullException("Param is null");
List<Section> sections = _myInfoMateDbContext.Sections.Where(s => s.ParentId == id && s.IsSubSection).ToList(); List<Section> sections = _myInfoMateDbContext.Sections.Where(s => s.ParentId == id && s.IsSubSection).OrderBy(s=> s.Order).ToList();
//List<OldSection> sections = _sectionService.GetAllSubSection(id); //List<OldSection> sections = _sectionService.GetAllSubSection(id);
List<object> sectionsToReturn = new List<object>(); List<object> sectionsToReturn = new List<object>();

View File

@ -16,11 +16,11 @@ namespace ManagerService.Data.SubSection
{ {
[Required] [Required]
[Column(TypeName = "jsonb")] [Column(TypeName = "jsonb")]
public List<TranslationAndResource> PuzzleMessageDebut { get; set; } public List<TranslationAndResourceDTO> PuzzleMessageDebut { get; set; }
[Required] [Required]
[Column(TypeName = "jsonb")] [Column(TypeName = "jsonb")]
public List<TranslationAndResource> PuzzleMessageFin { get; set; } public List<TranslationAndResourceDTO> PuzzleMessageFin { get; set; }
public string PuzzleImageId { get; set; } // But only image is possible public string PuzzleImageId { get; set; } // But only image is possible
public Resource PuzzleImage { get; set; } // But only image is possible public Resource PuzzleImage { get; set; } // But only image is possible
@ -54,8 +54,8 @@ namespace ManagerService.Data.SubSection
latitude = Latitude, latitude = Latitude,
longitude = Longitude, longitude = Longitude,
meterZoneGPS = MeterZoneGPS, meterZoneGPS = MeterZoneGPS,
messageDebut = PuzzleMessageDebut.Select(md => md.ToDTO()).ToList(), messageDebut = PuzzleMessageDebut,
messageFin = PuzzleMessageFin.Select(mf => mf.ToDTO()).ToList(), messageFin = PuzzleMessageFin,
puzzleImage = PuzzleImage.ToDTO(), puzzleImage = PuzzleImage.ToDTO(),
puzzleImageId = PuzzleImageId, puzzleImageId = PuzzleImageId,
rows = PuzzleRows, rows = PuzzleRows,

View File

@ -207,8 +207,8 @@ namespace ManagerService.Services
Longitude = dto.longitude, Longitude = dto.longitude,
MeterZoneGPS = dto.meterZoneGPS, MeterZoneGPS = dto.meterZoneGPS,
Type = dto.type, Type = dto.type,
PuzzleMessageDebut = puzzleDTO.messageDebut.Select(md => new TranslationAndResource().FromDTO(md)).ToList(), PuzzleMessageDebut = puzzleDTO.messageDebut,
PuzzleMessageFin = puzzleDTO.messageFin.Select(mf => new TranslationAndResource().FromDTO(mf)).ToList(), PuzzleMessageFin = puzzleDTO.messageFin,
PuzzleImageId = puzzleDTO.puzzleImageId, PuzzleImageId = puzzleDTO.puzzleImageId,
PuzzleRows = puzzleDTO.rows, PuzzleRows = puzzleDTO.rows,
PuzzleCols = puzzleDTO.cols PuzzleCols = puzzleDTO.cols
@ -482,8 +482,9 @@ namespace ManagerService.Services
longitude = puzzle.Longitude, longitude = puzzle.Longitude,
meterZoneGPS = puzzle.MeterZoneGPS, meterZoneGPS = puzzle.MeterZoneGPS,
type = puzzle.Type, type = puzzle.Type,
messageDebut = puzzle.PuzzleMessageDebut.Select(md => md.ToDTO()).ToList(), messageDebut = puzzle.PuzzleMessageDebut,
messageFin = puzzle.PuzzleMessageFin.Select(mf => mf.ToDTO()).ToList(), messageFin = puzzle.PuzzleMessageFin,
puzzleImage = puzzle.PuzzleImage?.ToDTO(),
puzzleImageId = puzzle.PuzzleImageId, puzzleImageId = puzzle.PuzzleImageId,
rows = puzzle.PuzzleRows, rows = puzzle.PuzzleRows,
cols = puzzle.PuzzleCols cols = puzzle.PuzzleCols