Update save geometry + other, id null etc (thx claude)
This commit is contained in:
parent
f17d72b34e
commit
bde1666b42
@ -163,9 +163,9 @@ namespace ManagerService.Controllers
|
|||||||
State = eventAgendaDTO.address.state,
|
State = eventAgendaDTO.address.state,
|
||||||
PostCode = eventAgendaDTO.address.postCode,
|
PostCode = eventAgendaDTO.address.postCode,
|
||||||
Country = eventAgendaDTO.address.country,
|
Country = eventAgendaDTO.address.country,
|
||||||
Geometry = eventAgendaDTO.address.geometry?.FromDto(),
|
Geometry = eventAgendaDTO.address.geometry,
|
||||||
PolyColor = eventAgendaDTO.address.polyColor,
|
PolyColor = eventAgendaDTO.address.polyColor,
|
||||||
Zoom = eventAgendaDTO.address.zoom
|
Zoom = eventAgendaDTO.address.zoom.GetValueOrDefault()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -451,7 +451,7 @@ namespace ManagerService.Controllers
|
|||||||
existingGuidedPath.IsLinear = guidedPathDTO.isLinear;
|
existingGuidedPath.IsLinear = guidedPathDTO.isLinear;
|
||||||
existingGuidedPath.RequireSuccessToAdvance = guidedPathDTO.requireSuccessToAdvance;
|
existingGuidedPath.RequireSuccessToAdvance = guidedPathDTO.requireSuccessToAdvance;
|
||||||
existingGuidedPath.HideNextStepsUntilComplete = guidedPathDTO.hideNextStepsUntilComplete;
|
existingGuidedPath.HideNextStepsUntilComplete = guidedPathDTO.hideNextStepsUntilComplete;
|
||||||
existingGuidedPath.Order = guidedPathDTO.order;
|
existingGuidedPath.Order = guidedPathDTO.order.GetValueOrDefault();
|
||||||
|
|
||||||
// Sync steps
|
// Sync steps
|
||||||
var dtoStepIds = (guidedPathDTO.steps ?? new List<GuidedStepDTO>())
|
var dtoStepIds = (guidedPathDTO.steps ?? new List<GuidedStepDTO>())
|
||||||
@ -643,7 +643,7 @@ namespace ManagerService.Controllers
|
|||||||
throw new KeyNotFoundException("GuidedStep does not exist");
|
throw new KeyNotFoundException("GuidedStep does not exist");
|
||||||
|
|
||||||
existingGuidedStep.GuidedPathId = guidedStepDTO.guidedPathId;
|
existingGuidedStep.GuidedPathId = guidedStepDTO.guidedPathId;
|
||||||
existingGuidedStep.Order = guidedStepDTO.order;
|
existingGuidedStep.Order = guidedStepDTO.order.GetValueOrDefault();
|
||||||
existingGuidedStep.Title = guidedStepDTO.title;
|
existingGuidedStep.Title = guidedStepDTO.title;
|
||||||
existingGuidedStep.Description = guidedStepDTO.description;
|
existingGuidedStep.Description = guidedStepDTO.description;
|
||||||
if (guidedStepDTO.geometry != null)
|
if (guidedStepDTO.geometry != null)
|
||||||
@ -666,7 +666,7 @@ namespace ManagerService.Controllers
|
|||||||
|
|
||||||
_myInfoMateDbContext.SaveChanges();
|
_myInfoMateDbContext.SaveChanges();
|
||||||
|
|
||||||
return new OkObjectResult(existingGuidedStep);
|
return new OkObjectResult(existingGuidedStep.ToDTO());
|
||||||
}
|
}
|
||||||
catch (ArgumentNullException ex)
|
catch (ArgumentNullException ex)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -6,7 +6,7 @@ namespace ManagerService.DTOs
|
|||||||
{
|
{
|
||||||
public class EventAgendaDTO
|
public class EventAgendaDTO
|
||||||
{
|
{
|
||||||
public int id { get; set; }
|
public int? id { get; set; }
|
||||||
|
|
||||||
public List<TranslationDTO> label { get; set; }
|
public List<TranslationDTO> label { get; set; }
|
||||||
|
|
||||||
@ -58,6 +58,6 @@ namespace ManagerService.DTOs
|
|||||||
|
|
||||||
public string polyColor { get; set; } // color of the polyline or polygon
|
public string polyColor { get; set; } // color of the polyline or polygon
|
||||||
|
|
||||||
public int zoom { get; set; }
|
public int? zoom { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,7 +14,7 @@ namespace ManagerService.DTOs
|
|||||||
public bool isLinear { get; set; }
|
public bool isLinear { get; set; }
|
||||||
public bool requireSuccessToAdvance { get; set; }
|
public bool requireSuccessToAdvance { get; set; }
|
||||||
public bool hideNextStepsUntilComplete { get; set; }
|
public bool hideNextStepsUntilComplete { get; set; }
|
||||||
public int order { get; set; }
|
public int? order { get; set; }
|
||||||
public List<GuidedStepDTO> steps { get; set; }
|
public List<GuidedStepDTO> steps { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,7 +8,7 @@ namespace ManagerService.DTOs
|
|||||||
{
|
{
|
||||||
public string id { get; set; }
|
public string id { get; set; }
|
||||||
public string guidedPathId { get; set; }
|
public string guidedPathId { get; set; }
|
||||||
public int order { get; set; }
|
public int? order { get; set; }
|
||||||
public List<TranslationDTO> title { get; set; }
|
public List<TranslationDTO> title { get; set; }
|
||||||
public List<TranslationDTO> description { get; set; }
|
public List<TranslationDTO> description { get; set; }
|
||||||
public GeometryDTO geometry { get; set; }
|
public GeometryDTO geometry { get; set; }
|
||||||
|
|||||||
@ -6,6 +6,6 @@ namespace ManagerService.DTOs
|
|||||||
public class OrderedTranslationAndResourceDTO
|
public class OrderedTranslationAndResourceDTO
|
||||||
{
|
{
|
||||||
public List<TranslationAndResourceDTO> translationAndResourceDTOs { get; set; }
|
public List<TranslationAndResourceDTO> translationAndResourceDTOs { get; set; }
|
||||||
public int order { get; set; }
|
public int? order { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,7 +5,7 @@ namespace Manager.DTOs
|
|||||||
{
|
{
|
||||||
public class MapDTO : SectionDTO
|
public class MapDTO : SectionDTO
|
||||||
{
|
{
|
||||||
public int zoom { get; set; } // Default = 18
|
public int? zoom { get; set; } // Default = 18
|
||||||
public MapTypeApp? mapType { get; set; } // Default = Hybrid for Google
|
public MapTypeApp? mapType { get; set; } // Default = Hybrid for Google
|
||||||
public MapTypeMapBox? mapTypeMapbox { get; set; } // Default = standard for MapBox
|
public MapTypeMapBox? mapTypeMapbox { get; set; } // Default = standard for MapBox
|
||||||
public MapProvider? mapProvider { get; set; } // Default = Google
|
public MapProvider? mapProvider { get; set; } // Default = Google
|
||||||
@ -41,7 +41,7 @@ namespace Manager.DTOs
|
|||||||
|
|
||||||
public class CategorieDTO
|
public class CategorieDTO
|
||||||
{
|
{
|
||||||
public int id { get; set; }
|
public int? id { get; set; }
|
||||||
public List<TranslationDTO> label { get; set; }
|
public List<TranslationDTO> label { get; set; }
|
||||||
public string icon { get; set; } // icon material
|
public string icon { get; set; } // icon material
|
||||||
public ResourceDTO resourceDTO { get; set; } // Icon
|
public ResourceDTO resourceDTO { get; set; } // Icon
|
||||||
|
|||||||
@ -28,7 +28,7 @@ namespace Manager.DTOs
|
|||||||
{
|
{
|
||||||
public List<TranslationAndResourceDTO> label { get; set; }
|
public List<TranslationAndResourceDTO> label { get; set; }
|
||||||
public bool isGood { get; set; }
|
public bool isGood { get; set; }
|
||||||
public int order { get; set; } // Order to show
|
public int? order { get; set; } // Order to show
|
||||||
}
|
}
|
||||||
|
|
||||||
/*public class LevelDTO
|
/*public class LevelDTO
|
||||||
|
|||||||
@ -13,7 +13,7 @@ namespace Manager.DTOs
|
|||||||
{
|
{
|
||||||
public List<TranslationDTO> title { get; set; }
|
public List<TranslationDTO> title { get; set; }
|
||||||
public List<TranslationDTO> description { get; set; }
|
public List<TranslationDTO> description { get; set; }
|
||||||
public int order { get; set; } // Order to show
|
public int? order { get; set; } // Order to show
|
||||||
public string resourceId { get; set; }
|
public string resourceId { get; set; }
|
||||||
public ResourceDTO resource { get; set; }
|
public ResourceDTO resource { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
@ -46,7 +46,7 @@ namespace ManagerService.Data.SubSection
|
|||||||
{
|
{
|
||||||
return new Categorie()
|
return new Categorie()
|
||||||
{
|
{
|
||||||
Id = categorieDTO.id,
|
Id = categorieDTO.id.GetValueOrDefault(),
|
||||||
// TODO
|
// TODO
|
||||||
/*Label = categorieDTO.label,
|
/*Label = categorieDTO.label,
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -48,7 +48,7 @@ namespace ManagerService.Data.SubSection
|
|||||||
{
|
{
|
||||||
Title = contentDTO.title,
|
Title = contentDTO.title,
|
||||||
Description = contentDTO.description,
|
Description = contentDTO.description,
|
||||||
Order = contentDTO.order,
|
Order = contentDTO.order.GetValueOrDefault(),
|
||||||
ResourceId = contentDTO.resourceId
|
ResourceId = contentDTO.resourceId
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,5 @@
|
|||||||
using Manager.DTOs;
|
using Manager.DTOs;
|
||||||
using ManagerService.DTOs;
|
using ManagerService.DTOs;
|
||||||
using ManagerService.Helpers;
|
|
||||||
using NetTopologySuite.Geometries;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
@ -80,11 +78,7 @@ namespace ManagerService.Data.SubSection
|
|||||||
state = Address.State,
|
state = Address.State,
|
||||||
postCode = Address.PostCode,
|
postCode = Address.PostCode,
|
||||||
country = Address.Country,
|
country = Address.Country,
|
||||||
geometry = Address.Geometry != null ? new GeometryDTO
|
geometry = Address.Geometry,
|
||||||
{
|
|
||||||
type = Address.Geometry.GeometryType,
|
|
||||||
coordinates = Address.Geometry.Coordinates,
|
|
||||||
} : null,
|
|
||||||
polyColor = Address.PolyColor,
|
polyColor = Address.PolyColor,
|
||||||
zoom = Address.Zoom
|
zoom = Address.Zoom
|
||||||
} : null,
|
} : null,
|
||||||
@ -114,9 +108,9 @@ namespace ManagerService.Data.SubSection
|
|||||||
State = dto.address.state,
|
State = dto.address.state,
|
||||||
PostCode = dto.address.postCode,
|
PostCode = dto.address.postCode,
|
||||||
Country = dto.address.country,
|
Country = dto.address.country,
|
||||||
Geometry = dto.address.geometry != null ? dto.address.geometry.FromDto() : null,
|
Geometry = dto.address.geometry,
|
||||||
PolyColor = dto.address.polyColor,
|
PolyColor = dto.address.polyColor,
|
||||||
Zoom = dto.address.zoom
|
Zoom = dto.address.zoom.GetValueOrDefault()
|
||||||
} : null;
|
} : null;
|
||||||
Phone = dto.phone;
|
Phone = dto.phone;
|
||||||
Email = dto.email;
|
Email = dto.email;
|
||||||
@ -124,6 +118,35 @@ namespace ManagerService.Data.SubSection
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void UpdateFromDTO(EventAgendaDTO dto)
|
||||||
|
{
|
||||||
|
Label = dto.label;
|
||||||
|
Description = dto.description;
|
||||||
|
Type = dto.type;
|
||||||
|
DateAdded = dto.dateAdded;
|
||||||
|
DateFrom = dto.dateFrom;
|
||||||
|
DateTo = dto.dateTo;
|
||||||
|
Website = dto.website;
|
||||||
|
ResourceId = dto.resourceId;
|
||||||
|
Address = dto.address != null ? new EventAddress
|
||||||
|
{
|
||||||
|
Address = dto.address.address,
|
||||||
|
StreetNumber = dto.address.streetNumber,
|
||||||
|
StreetName = dto.address.streetName,
|
||||||
|
City = dto.address.city,
|
||||||
|
State = dto.address.state,
|
||||||
|
PostCode = dto.address.postCode,
|
||||||
|
Country = dto.address.country,
|
||||||
|
Geometry = dto.address.geometry,
|
||||||
|
PolyColor = dto.address.polyColor,
|
||||||
|
Zoom = dto.address.zoom.GetValueOrDefault()
|
||||||
|
} : null;
|
||||||
|
Phone = dto.phone;
|
||||||
|
Email = dto.email;
|
||||||
|
SectionAgendaId = dto.sectionAgendaId;
|
||||||
|
SectionEventId = dto.sectionEventId;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
public class EventAddress
|
public class EventAddress
|
||||||
{
|
{
|
||||||
@ -141,7 +164,7 @@ namespace ManagerService.Data.SubSection
|
|||||||
|
|
||||||
public string Country { get; set; }
|
public string Country { get; set; }
|
||||||
|
|
||||||
public Geometry Geometry { get; set; }
|
public GeometryDTO Geometry { get; set; }
|
||||||
|
|
||||||
public string PolyColor { get; set; } // color of the polyline or polygon
|
public string PolyColor { get; set; } // color of the polyline or polygon
|
||||||
|
|
||||||
|
|||||||
@ -75,7 +75,7 @@ namespace ManagerService.Data.SubSection
|
|||||||
IsLinear = dto.isLinear;
|
IsLinear = dto.isLinear;
|
||||||
RequireSuccessToAdvance = dto.requireSuccessToAdvance;
|
RequireSuccessToAdvance = dto.requireSuccessToAdvance;
|
||||||
HideNextStepsUntilComplete = dto.hideNextStepsUntilComplete;
|
HideNextStepsUntilComplete = dto.hideNextStepsUntilComplete;
|
||||||
Order = dto.order;
|
Order = dto.order.GetValueOrDefault();
|
||||||
//Steps = dto.Steps?.Select(s => s.FromDTO()).ToList() ?? new List<GuidedStep>() // Other method
|
//Steps = dto.Steps?.Select(s => s.FromDTO()).ToList() ?? new List<GuidedStep>() // Other method
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -95,7 +95,7 @@ namespace ManagerService.Data.SubSection
|
|||||||
IsStepLocked = dto.isStepLocked;
|
IsStepLocked = dto.isStepLocked;
|
||||||
TimerSeconds = dto.timerSeconds;
|
TimerSeconds = dto.timerSeconds;
|
||||||
TimerExpiredMessage = dto.timerExpiredMessage ?? new List<TranslationDTO>();
|
TimerExpiredMessage = dto.timerExpiredMessage ?? new List<TranslationDTO>();
|
||||||
Order = dto.order;
|
Order = dto.order.GetValueOrDefault();
|
||||||
QuizQuestions = dto.quizQuestions;
|
QuizQuestions = dto.quizQuestions;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -37,7 +37,7 @@ namespace ManagerService.Data.SubSection
|
|||||||
return new OrderedTranslationAndResource()
|
return new OrderedTranslationAndResource()
|
||||||
{
|
{
|
||||||
TranslationAndResources = orderedTranslationAndResourceDTO.translationAndResourceDTOs.Select(tar => new TranslationAndResource().FromDTO(tar)).ToList(),
|
TranslationAndResources = orderedTranslationAndResourceDTO.translationAndResourceDTOs.Select(tar => new TranslationAndResource().FromDTO(tar)).ToList(),
|
||||||
Order = orderedTranslationAndResourceDTO.order
|
Order = orderedTranslationAndResourceDTO.order.GetValueOrDefault()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,10 +1,11 @@
|
|||||||
using Manager.DTOs;
|
using Manager.DTOs;
|
||||||
using NetTopologySuite;
|
using NetTopologySuite;
|
||||||
using NetTopologySuite.Geometries;
|
using NetTopologySuite.Geometries;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace ManagerService.Helpers
|
namespace ManagerService.Helpers
|
||||||
{
|
{
|
||||||
@ -54,24 +55,36 @@ namespace ManagerService.Helpers
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static T DeserializeCoordinates<T>(object coordinates)
|
||||||
|
{
|
||||||
|
if (coordinates is JsonElement jsonElement)
|
||||||
|
return jsonElement.Deserialize<T>();
|
||||||
|
|
||||||
|
// Newtonsoft JToken (JArray etc.) — convert via JSON string
|
||||||
|
var json = JsonConvert.SerializeObject(coordinates);
|
||||||
|
return System.Text.Json.JsonSerializer.Deserialize<T>(json);
|
||||||
|
}
|
||||||
|
|
||||||
private static Point CreatePoint(GeometryDTO dto, GeometryFactory factory)
|
private static Point CreatePoint(GeometryDTO dto, GeometryFactory factory)
|
||||||
{
|
{
|
||||||
var coords = ((JsonElement)dto.coordinates).Deserialize<List<double>>();
|
var coords = DeserializeCoordinates<List<double>>(dto.coordinates);
|
||||||
var point = factory.CreatePoint(new Coordinate(coords[0], coords[1]));
|
return factory.CreatePoint(new CoordinateZ(coords[0], coords[1], 0.0));
|
||||||
return point;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static LineString CreateLineString(GeometryDTO dto, GeometryFactory factory)
|
private static LineString CreateLineString(GeometryDTO dto, GeometryFactory factory)
|
||||||
{
|
{
|
||||||
var coords = ((JsonElement)dto.coordinates).Deserialize<List<List<double>>>();
|
var coords = DeserializeCoordinates<List<List<double>>>(dto.coordinates);
|
||||||
var coordinates = coords.Select(c => new Coordinate(c[0], c[1])).ToArray();
|
var coordinates = coords.Select(c => new CoordinateZ(c[0], c[1], 0.0)).ToArray();
|
||||||
return factory.CreateLineString(coordinates);
|
return factory.CreateLineString(coordinates);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Polygon CreatePolygon(GeometryDTO dto, GeometryFactory factory)
|
private static Polygon CreatePolygon(GeometryDTO dto, GeometryFactory factory)
|
||||||
{
|
{
|
||||||
var rings = ((JsonElement)dto.coordinates).Deserialize<List<List<List<double>>>>();
|
var rings = DeserializeCoordinates<List<List<List<double>>>>(dto.coordinates);
|
||||||
var exterior = rings.First().Select(c => new Coordinate(c[0], c[1])).ToArray();
|
var exterior = rings.First().Select(c => new CoordinateZ(c[0], c[1], 0.0)).ToArray();
|
||||||
|
// NTS requires closed rings
|
||||||
|
if (exterior.Length > 0 && !exterior.First().Equals2D(exterior.Last()))
|
||||||
|
exterior = exterior.Append(exterior.First()).ToArray();
|
||||||
return factory.CreatePolygon(exterior);
|
return factory.CreatePolygon(exterior);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -163,7 +163,7 @@ namespace ManagerService.Services
|
|||||||
Longitude = dto.longitude,
|
Longitude = dto.longitude,
|
||||||
MeterZoneGPS = dto.meterZoneGPS,
|
MeterZoneGPS = dto.meterZoneGPS,
|
||||||
Type = dto.type,
|
Type = dto.type,
|
||||||
MapZoom = mapDTO.zoom,
|
MapZoom = mapDTO.zoom ?? 18,
|
||||||
MapMapType = mapDTO.mapType,
|
MapMapType = mapDTO.mapType,
|
||||||
MapTypeMapbox = mapDTO.mapTypeMapbox,
|
MapTypeMapbox = mapDTO.mapTypeMapbox,
|
||||||
MapMapProvider = mapDTO.mapProvider,
|
MapMapProvider = mapDTO.mapProvider,
|
||||||
|
|||||||
@ -191,7 +191,7 @@ namespace ManagerService
|
|||||||
app.UseCors(
|
app.UseCors(
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
options => options
|
options => options
|
||||||
.SetIsOriginAllowed(origin => string.IsNullOrEmpty(origin) || origin == "http://localhost:62080")
|
.SetIsOriginAllowed(origin => string.IsNullOrEmpty(origin) || origin == "http://localhost:64402")
|
||||||
.AllowAnyMethod()
|
.AllowAnyMethod()
|
||||||
.AllowAnyHeader()
|
.AllowAnyHeader()
|
||||||
.AllowCredentials()
|
.AllowCredentials()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user