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,
|
||||
PostCode = eventAgendaDTO.address.postCode,
|
||||
Country = eventAgendaDTO.address.country,
|
||||
Geometry = eventAgendaDTO.address.geometry?.FromDto(),
|
||||
Geometry = eventAgendaDTO.address.geometry,
|
||||
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.RequireSuccessToAdvance = guidedPathDTO.requireSuccessToAdvance;
|
||||
existingGuidedPath.HideNextStepsUntilComplete = guidedPathDTO.hideNextStepsUntilComplete;
|
||||
existingGuidedPath.Order = guidedPathDTO.order;
|
||||
existingGuidedPath.Order = guidedPathDTO.order.GetValueOrDefault();
|
||||
|
||||
// Sync steps
|
||||
var dtoStepIds = (guidedPathDTO.steps ?? new List<GuidedStepDTO>())
|
||||
@ -643,7 +643,7 @@ namespace ManagerService.Controllers
|
||||
throw new KeyNotFoundException("GuidedStep does not exist");
|
||||
|
||||
existingGuidedStep.GuidedPathId = guidedStepDTO.guidedPathId;
|
||||
existingGuidedStep.Order = guidedStepDTO.order;
|
||||
existingGuidedStep.Order = guidedStepDTO.order.GetValueOrDefault();
|
||||
existingGuidedStep.Title = guidedStepDTO.title;
|
||||
existingGuidedStep.Description = guidedStepDTO.description;
|
||||
if (guidedStepDTO.geometry != null)
|
||||
@ -666,7 +666,7 @@ namespace ManagerService.Controllers
|
||||
|
||||
_myInfoMateDbContext.SaveChanges();
|
||||
|
||||
return new OkObjectResult(existingGuidedStep);
|
||||
return new OkObjectResult(existingGuidedStep.ToDTO());
|
||||
}
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
|
||||
@ -6,7 +6,7 @@ namespace ManagerService.DTOs
|
||||
{
|
||||
public class EventAgendaDTO
|
||||
{
|
||||
public int id { get; set; }
|
||||
public int? id { 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 int zoom { get; set; }
|
||||
public int? zoom { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@ -14,7 +14,7 @@ namespace ManagerService.DTOs
|
||||
public bool isLinear { get; set; }
|
||||
public bool requireSuccessToAdvance { get; set; }
|
||||
public bool hideNextStepsUntilComplete { get; set; }
|
||||
public int order { get; set; }
|
||||
public int? order { get; set; }
|
||||
public List<GuidedStepDTO> steps { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,7 +8,7 @@ namespace ManagerService.DTOs
|
||||
{
|
||||
public string id { 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> description { get; set; }
|
||||
public GeometryDTO geometry { get; set; }
|
||||
|
||||
@ -6,6 +6,6 @@ namespace ManagerService.DTOs
|
||||
public class OrderedTranslationAndResourceDTO
|
||||
{
|
||||
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 int zoom { get; set; } // Default = 18
|
||||
public int? zoom { get; set; } // Default = 18
|
||||
public MapTypeApp? mapType { get; set; } // Default = Hybrid for Google
|
||||
public MapTypeMapBox? mapTypeMapbox { get; set; } // Default = standard for MapBox
|
||||
public MapProvider? mapProvider { get; set; } // Default = Google
|
||||
@ -41,7 +41,7 @@ namespace Manager.DTOs
|
||||
|
||||
public class CategorieDTO
|
||||
{
|
||||
public int id { get; set; }
|
||||
public int? id { get; set; }
|
||||
public List<TranslationDTO> label { get; set; }
|
||||
public string icon { get; set; } // icon material
|
||||
public ResourceDTO resourceDTO { get; set; } // Icon
|
||||
|
||||
@ -28,7 +28,7 @@ namespace Manager.DTOs
|
||||
{
|
||||
public List<TranslationAndResourceDTO> label { 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
|
||||
|
||||
@ -13,7 +13,7 @@ namespace Manager.DTOs
|
||||
{
|
||||
public List<TranslationDTO> title { 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 ResourceDTO resource { get; set; }
|
||||
}
|
||||
|
||||
@ -46,7 +46,7 @@ namespace ManagerService.Data.SubSection
|
||||
{
|
||||
return new Categorie()
|
||||
{
|
||||
Id = categorieDTO.id,
|
||||
Id = categorieDTO.id.GetValueOrDefault(),
|
||||
// TODO
|
||||
/*Label = categorieDTO.label,
|
||||
*/
|
||||
|
||||
@ -48,7 +48,7 @@ namespace ManagerService.Data.SubSection
|
||||
{
|
||||
Title = contentDTO.title,
|
||||
Description = contentDTO.description,
|
||||
Order = contentDTO.order,
|
||||
Order = contentDTO.order.GetValueOrDefault(),
|
||||
ResourceId = contentDTO.resourceId
|
||||
};
|
||||
}
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
using Manager.DTOs;
|
||||
using ManagerService.DTOs;
|
||||
using ManagerService.Helpers;
|
||||
using NetTopologySuite.Geometries;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
@ -80,11 +78,7 @@ namespace ManagerService.Data.SubSection
|
||||
state = Address.State,
|
||||
postCode = Address.PostCode,
|
||||
country = Address.Country,
|
||||
geometry = Address.Geometry != null ? new GeometryDTO
|
||||
{
|
||||
type = Address.Geometry.GeometryType,
|
||||
coordinates = Address.Geometry.Coordinates,
|
||||
} : null,
|
||||
geometry = Address.Geometry,
|
||||
polyColor = Address.PolyColor,
|
||||
zoom = Address.Zoom
|
||||
} : null,
|
||||
@ -114,9 +108,9 @@ namespace ManagerService.Data.SubSection
|
||||
State = dto.address.state,
|
||||
PostCode = dto.address.postCode,
|
||||
Country = dto.address.country,
|
||||
Geometry = dto.address.geometry != null ? dto.address.geometry.FromDto() : null,
|
||||
Geometry = dto.address.geometry,
|
||||
PolyColor = dto.address.polyColor,
|
||||
Zoom = dto.address.zoom
|
||||
Zoom = dto.address.zoom.GetValueOrDefault()
|
||||
} : null;
|
||||
Phone = dto.phone;
|
||||
Email = dto.email;
|
||||
@ -124,6 +118,35 @@ namespace ManagerService.Data.SubSection
|
||||
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
|
||||
{
|
||||
@ -141,7 +164,7 @@ namespace ManagerService.Data.SubSection
|
||||
|
||||
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
|
||||
|
||||
|
||||
@ -75,7 +75,7 @@ namespace ManagerService.Data.SubSection
|
||||
IsLinear = dto.isLinear;
|
||||
RequireSuccessToAdvance = dto.requireSuccessToAdvance;
|
||||
HideNextStepsUntilComplete = dto.hideNextStepsUntilComplete;
|
||||
Order = dto.order;
|
||||
Order = dto.order.GetValueOrDefault();
|
||||
//Steps = dto.Steps?.Select(s => s.FromDTO()).ToList() ?? new List<GuidedStep>() // Other method
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -95,7 +95,7 @@ namespace ManagerService.Data.SubSection
|
||||
IsStepLocked = dto.isStepLocked;
|
||||
TimerSeconds = dto.timerSeconds;
|
||||
TimerExpiredMessage = dto.timerExpiredMessage ?? new List<TranslationDTO>();
|
||||
Order = dto.order;
|
||||
Order = dto.order.GetValueOrDefault();
|
||||
QuizQuestions = dto.quizQuestions;
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -37,7 +37,7 @@ namespace ManagerService.Data.SubSection
|
||||
return new OrderedTranslationAndResource()
|
||||
{
|
||||
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 NetTopologySuite;
|
||||
using NetTopologySuite.Geometries;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using System;
|
||||
|
||||
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)
|
||||
{
|
||||
var coords = ((JsonElement)dto.coordinates).Deserialize<List<double>>();
|
||||
var point = factory.CreatePoint(new Coordinate(coords[0], coords[1]));
|
||||
return point;
|
||||
var coords = DeserializeCoordinates<List<double>>(dto.coordinates);
|
||||
return factory.CreatePoint(new CoordinateZ(coords[0], coords[1], 0.0));
|
||||
}
|
||||
|
||||
private static LineString CreateLineString(GeometryDTO dto, GeometryFactory factory)
|
||||
{
|
||||
var coords = ((JsonElement)dto.coordinates).Deserialize<List<List<double>>>();
|
||||
var coordinates = coords.Select(c => new Coordinate(c[0], c[1])).ToArray();
|
||||
var coords = DeserializeCoordinates<List<List<double>>>(dto.coordinates);
|
||||
var coordinates = coords.Select(c => new CoordinateZ(c[0], c[1], 0.0)).ToArray();
|
||||
return factory.CreateLineString(coordinates);
|
||||
}
|
||||
|
||||
private static Polygon CreatePolygon(GeometryDTO dto, GeometryFactory factory)
|
||||
{
|
||||
var rings = ((JsonElement)dto.coordinates).Deserialize<List<List<List<double>>>>();
|
||||
var exterior = rings.First().Select(c => new Coordinate(c[0], c[1])).ToArray();
|
||||
var rings = DeserializeCoordinates<List<List<List<double>>>>(dto.coordinates);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -163,7 +163,7 @@ namespace ManagerService.Services
|
||||
Longitude = dto.longitude,
|
||||
MeterZoneGPS = dto.meterZoneGPS,
|
||||
Type = dto.type,
|
||||
MapZoom = mapDTO.zoom,
|
||||
MapZoom = mapDTO.zoom ?? 18,
|
||||
MapMapType = mapDTO.mapType,
|
||||
MapTypeMapbox = mapDTO.mapTypeMapbox,
|
||||
MapMapProvider = mapDTO.mapProvider,
|
||||
|
||||
@ -191,7 +191,7 @@ namespace ManagerService
|
||||
app.UseCors(
|
||||
#if DEBUG
|
||||
options => options
|
||||
.SetIsOriginAllowed(origin => string.IsNullOrEmpty(origin) || origin == "http://localhost:62080")
|
||||
.SetIsOriginAllowed(origin => string.IsNullOrEmpty(origin) || origin == "http://localhost:64402")
|
||||
.AllowAnyMethod()
|
||||
.AllowAnyHeader()
|
||||
.AllowCredentials()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user