Skip to content
Snippets Groups Projects
Commit 15861cad authored by Detlef Runde's avatar Detlef Runde
Browse files

introduced some logic (check, if elements of Link (to and from) exist)

parent d628d8ae
No related branches found
No related tags found
1 merge request!2Use now API v1.0.0
......@@ -93,18 +93,24 @@ namespace Org.OpenAPITools.Controllers
string result = "ok";
string worldlinkinfo = "";
List<WorldLink> worldlinklistfrom = _trackableService.GetWorldLinkUUIDFrom(trackableUUID);
List<WorldLink> worldlinklistto = _trackableService.GetWorldLinkUUIDTo(trackableUUID);
foreach(WorldLink worldlink in worldlinklistfrom)
foreach (WorldLink worldlink in worldlinklistfrom)
{
worldlinkinfo += worldlink.UUID.ToString() + "; ";
worldlink.UUIDFrom = Guid.Empty;
worldlink.TypeFrom = ObjectType.NotIdentifiedEnum;
_trackableService.UpdateWorldLink(worldlink.UUID, worldlink);
}
List<WorldLink> worldlinklistto = _trackableService.GetWorldLinkUUIDTo(trackableUUID);
foreach (WorldLink worldlink in worldlinklistto)
{
{
worldlinkinfo += worldlink.UUID.ToString() + "; ";
worldlink.UUIDTo = Guid.Empty;
worldlink.TypeTo = ObjectType.NotIdentifiedEnum;
_trackableService.UpdateWorldLink(worldlink.UUID, worldlink);
}
if (worldlinkinfo.Length > 1)
{
result += ", but removed object is still referenced in " + worldlinkinfo;
result += ", removed object was referenced in " + worldlinkinfo + " and removed there as well";
}
return (answer.IsAcknowledged && answer.DeletedCount > 0) ? new ObjectResult(result) : StatusCode(404, "Not found, could not find UUID in database.");
}
......
......@@ -93,20 +93,26 @@ namespace Org.OpenAPITools.Controllers
string result = "ok";
string worldlinkinfo = "";
List<WorldLink> worldlinklistfrom = _worldAnchorService.GetWorldLinkUUIDFrom(worldAnchorUUID);
List<WorldLink> worldlinklistto = _worldAnchorService.GetWorldLinkUUIDTo(worldAnchorUUID);
foreach (WorldLink worldlink in worldlinklistfrom)
{
worldlinkinfo += worldlink.UUID.ToString() + "; ";
worldlink.UUIDFrom = Guid.Empty;
worldlink.TypeFrom = ObjectType.NotIdentifiedEnum;
_worldAnchorService.UpdateWorldLink(worldlink.UUID, worldlink);
}
List<WorldLink> worldlinklistto = _worldAnchorService.GetWorldLinkUUIDTo(worldAnchorUUID);
foreach (WorldLink worldlink in worldlinklistto)
{
worldlinkinfo += worldlink.UUID.ToString() + "; ";
worldlink.UUIDTo = Guid.Empty;
worldlink.TypeTo = ObjectType.NotIdentifiedEnum;
_worldAnchorService.UpdateWorldLink(worldlink.UUID, worldlink);
}
if (worldlinkinfo.Length > 1)
{
result += ", but removed object is still referenced in " + worldlinkinfo;
result += ", but removed object was referenced in " + worldlinkinfo + " and removed there as well";
}
return (answer.IsAcknowledged && answer.DeletedCount > 0) ? new ObjectResult(result) : StatusCode(404, "Not found, could not find UUID in database.");
return (answer.IsAcknowledged && answer.DeletedCount > 0) ? new ObjectResult(result) : StatusCode(404, "Not found, could not find UUID in database.");
}
/// <summary>
......
......@@ -107,6 +107,43 @@ namespace Org.OpenAPITools.Controllers
public override IActionResult GetWorldLinkById([FromRoute(Name = "worldLinkUUID")][Required] Guid worldLinkUUID)
{
WorldLink myworldlink = _worldLinkService.Get(worldLinkUUID);
if (null != myworldlink)
{
// check TypeFrom
if (myworldlink.TypeFrom == ObjectType.TrackableEnum)
{
if (null == _worldLinkService.GetTrackable(myworldlink.UUIDFrom))
{
myworldlink.TypeFrom = ObjectType.NotIdentifiedEnum;
myworldlink.UUIDFrom = Guid.Empty;
}
}
else if (myworldlink.TypeFrom == ObjectType.WorldAnchorEnum)
{
if (null == _worldLinkService.GetAnchor(myworldlink.UUIDFrom))
{
myworldlink.TypeFrom = ObjectType.NotIdentifiedEnum;
myworldlink.UUIDFrom = Guid.Empty;
}
}
// check TypeTo
if (myworldlink.TypeTo == ObjectType.TrackableEnum)
{
if (null == _worldLinkService.GetTrackable(myworldlink.UUIDTo))
{
myworldlink.TypeTo = ObjectType.NotIdentifiedEnum;
myworldlink.UUIDTo = Guid.Empty;
}
}
else if (myworldlink.TypeTo == ObjectType.WorldAnchorEnum)
{
if (null == _worldLinkService.GetAnchor(myworldlink.UUIDTo))
{
myworldlink.TypeTo = ObjectType.NotIdentifiedEnum;
myworldlink.UUIDTo = Guid.Empty;
}
}
}
return (null != myworldlink) ? new ObjectResult(myworldlink) : StatusCode(404, "Not found, could not find UUID in database.");
}
......@@ -125,6 +162,43 @@ namespace Org.OpenAPITools.Controllers
public override IActionResult GetWorldLinks()
{
List<WorldLink> worldlinklist = _worldLinkService.Get();
foreach (WorldLink myworldlink in worldlinklist)
{
// check TypeFrom
if (myworldlink.TypeFrom == ObjectType.TrackableEnum)
{
if (null == _worldLinkService.GetTrackable(myworldlink.UUIDFrom))
{
myworldlink.TypeFrom = ObjectType.NotIdentifiedEnum;
myworldlink.UUIDFrom = Guid.Empty;
}
}
else if (myworldlink.TypeFrom == ObjectType.WorldAnchorEnum)
{
if (null == _worldLinkService.GetAnchor(myworldlink.UUIDFrom))
{
myworldlink.TypeFrom = ObjectType.NotIdentifiedEnum;
myworldlink.UUIDFrom = Guid.Empty;
}
}
// check TypeTo
if (myworldlink.TypeTo == ObjectType.TrackableEnum)
{
if (null == _worldLinkService.GetTrackable(myworldlink.UUIDTo))
{
myworldlink.TypeTo = ObjectType.NotIdentifiedEnum;
myworldlink.UUIDTo = Guid.Empty;
}
}
else if (myworldlink.TypeTo == ObjectType.WorldAnchorEnum)
{
if (null == _worldLinkService.GetAnchor(myworldlink.UUIDTo))
{
myworldlink.TypeTo = ObjectType.NotIdentifiedEnum;
myworldlink.UUIDTo = Guid.Empty;
}
}
}
return new ObjectResult(worldlinklist);
}
}
......
......@@ -57,6 +57,9 @@ namespace Org.OpenAPITools.Services
public List<WorldLink> GetWorldLinkUUIDTo(Guid UUID) =>
_worldlinkcollection.Find<WorldLink>(worldlink => worldlink.UUIDTo == UUID).ToList();
public ReplaceOneResult UpdateWorldLink(Guid UUID, WorldLink worldlinkIn) =>
_worldlinkcollection.ReplaceOne(worldlink => worldlink.UUID == UUID, worldlinkIn);
}
}
......
......@@ -55,7 +55,9 @@ namespace Org.OpenAPITools.Services
public List<WorldLink> GetWorldLinkUUIDTo(Guid UUID) =>
_worldlinkcollection.Find<WorldLink>(worldlink => worldlink.UUIDTo == UUID).ToList();
}
public ReplaceOneResult UpdateWorldLink(Guid UUID, WorldLink worldlinkIn) =>
_worldlinkcollection.ReplaceOne(worldlink => worldlink.UUID == UUID, worldlinkIn);
}
}
......@@ -77,12 +77,12 @@ namespace Org.OpenAPITools
})
.AddNewtonsoftJson(opts =>
{
opts.SerializerSettings.ContractResolver = new DefaultContractResolver();
/* opts.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
opts.SerializerSettings.Converters.Add(new StringEnumConverter
{
NamingStrategy = new CamelCaseNamingStrategy()
});*/
opts.SerializerSettings.ContractResolver = new DefaultContractResolver();
/* opts.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
opts.SerializerSettings.Converters.Add(new StringEnumConverter
{
NamingStrategy = new CamelCaseNamingStrategy()
});*/
});
services
......@@ -109,9 +109,9 @@ namespace Org.OpenAPITools
c.CustomSchemaIds(type => type.FriendlyId(true));
c.IncludeXmlComments($"{AppContext.BaseDirectory}{Path.DirectorySeparatorChar}{Assembly.GetEntryAssembly().GetName().Name}.xml");
// Include DataAnnotation attributes on Controller Action parameters as OpenAPI validation rules (e.g required, pattern, ..)
// Use [ValidateModelState] on Actions to actually validate it in C# as well!
c.OperationFilter<GeneratePathParamsValidationFilter>();
// Include DataAnnotation attributes on Controller Action parameters as OpenAPI validation rules (e.g required, pattern, ..)
// Use [ValidateModelState] on Actions to actually validate it in C# as well!
c.OperationFilter<GeneratePathParamsValidationFilter>();
});
services
.AddSwaggerGenNewtonsoftSupport();
......@@ -142,14 +142,14 @@ namespace Org.OpenAPITools
})
.UseSwaggerUI(c =>
{
// set route prefix to openapi, e.g. http://localhost:8080/openapi/index.html
c.RoutePrefix = "openapi";
//TODO: Either use the SwaggerGen generated OpenAPI contract (generated from C# classes)
// set route prefix to openapi, e.g. http://localhost:8080/openapi/index.html
c.RoutePrefix = "openapi";
//TODO: Either use the SwaggerGen generated OpenAPI contract (generated from C# classes)
c.SwaggerEndpoint("/openapi/0.0.6/openapi.json", "World Storage API");
//TODO: Or alternatively use the original OpenAPI contract that's included in the static files
// c.SwaggerEndpoint("/openapi-original.json", "World Storage API Original");
});
//TODO: Or alternatively use the original OpenAPI contract that's included in the static files
//c.SwaggerEndpoint("/openapi-original.json", "World Storage API Original");
});
app.UseRouting();
app.UseEndpoints(endpoints =>
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment