feat: Improve database/path route

This commit is contained in:
2024-06-11 10:59:15 +02:00
parent 9100a6e619
commit 9e77f4996e
6 changed files with 28 additions and 41 deletions

View File

@@ -8,23 +8,12 @@
</component>
<component name="ChangeListManager">
<list default="true" id="79f184c3-e88e-45be-9116-5fa813562754" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/.idea/.idea.REST API/.idea/dataSources.local.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.REST API/.idea/dataSources.local.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/.idea.REST API/.idea/dataSources/469f6bec-f113-4467-9d39-7ac38558045a.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.REST API/.idea/dataSources/469f6bec-f113-4467-9d39-7ac38558045a.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/.idea.REST API/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.REST API/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Console/Program.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Console/Program.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Console/bin/Debug/net8.0/Console" beforeDir="false" afterPath="$PROJECT_DIR$/Console/bin/Debug/net8.0/Console" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Console/Routes/RouteMap.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Console/Routes/RoutePath.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Console/bin/Debug/net8.0/Console.dll" beforeDir="false" afterPath="$PROJECT_DIR$/Console/bin/Debug/net8.0/Console.dll" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Console/bin/Debug/net8.0/Console.pdb" beforeDir="false" afterPath="$PROJECT_DIR$/Console/bin/Debug/net8.0/Console.pdb" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Console/bin/Debug/net8.0/LibParse.dll" beforeDir="false" afterPath="$PROJECT_DIR$/Console/bin/Debug/net8.0/LibParse.dll" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Console/bin/Debug/net8.0/LibParse.pdb" beforeDir="false" afterPath="$PROJECT_DIR$/Console/bin/Debug/net8.0/LibParse.pdb" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Console/bin/Debug/net8.0/LibServer.dll" beforeDir="false" afterPath="$PROJECT_DIR$/Console/bin/Debug/net8.0/LibServer.dll" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Console/bin/Debug/net8.0/LibServer.pdb" beforeDir="false" afterPath="$PROJECT_DIR$/Console/bin/Debug/net8.0/LibServer.pdb" afterDir="false" />
<change beforePath="$PROJECT_DIR$/LibParse/bin/Debug/net8.0/LibParse.dll" beforeDir="false" afterPath="$PROJECT_DIR$/LibParse/bin/Debug/net8.0/LibParse.dll" afterDir="false" />
<change beforePath="$PROJECT_DIR$/LibParse/bin/Debug/net8.0/LibParse.pdb" beforeDir="false" afterPath="$PROJECT_DIR$/LibParse/bin/Debug/net8.0/LibParse.pdb" afterDir="false" />
<change beforePath="$PROJECT_DIR$/LibServer/Http/Request.cs" beforeDir="false" afterPath="$PROJECT_DIR$/LibServer/Http/Request.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/LibServer/bin/Debug/net8.0/LibServer.dll" beforeDir="false" afterPath="$PROJECT_DIR$/LibServer/bin/Debug/net8.0/LibServer.dll" afterDir="false" />
<change beforePath="$PROJECT_DIR$/LibServer/bin/Debug/net8.0/LibServer.pdb" beforeDir="false" afterPath="$PROJECT_DIR$/LibServer/bin/Debug/net8.0/LibServer.pdb" afterDir="false" />
<change beforePath="$PROJECT_DIR$/REST API.sln.DotSettings.user" beforeDir="false" afterPath="$PROJECT_DIR$/REST API.sln.DotSettings.user" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../Web/src/components/mapCanvas.jsx" beforeDir="false" afterPath="$PROJECT_DIR$/../Web/src/components/mapCanvas.jsx" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -131,7 +120,7 @@
<workItem from="1717668473610" duration="971000" />
<workItem from="1717670832494" duration="901000" />
<workItem from="1717673464254" duration="1428000" />
<workItem from="1718093417281" duration="1709000" />
<workItem from="1718093417281" duration="2913000" />
</task>
<servers />
</component>

View File

@@ -19,7 +19,7 @@ internal static class Program {
{ "", new Root() },
{ "database", new RouteDatabase(cassandraSession) },
{ "database/metadata", new RouteMetadata(cassandraSession) },
{ "database/route", new RouteMap(cassandraSession) },
{ "database/path", new RoutePath(cassandraSession) },
{ "roomba/control", new RouteControl() }
};

View File

@@ -6,9 +6,9 @@ using Console.JsonClasses;
namespace Console.Routes;
public class RouteMap(ISession cassandraSession): IRoute {
public class RoutePath(ISession cassandraSession): IRoute {
/// <summary>
/// GET request for the database/mapped route, return a map based on given criteria.
/// GET request for the database/path route, return a path of a map based on given criteria.
/// </summary>
public HttpResponse Get(HttpRequest request) {
try {
@@ -27,7 +27,6 @@ public class RouteMap(ISession cassandraSession): IRoute {
if (selectStatement == null) throw new Exception("No valid search criteria given, give one of (id).");
// Execute the query and return all rows in an array
var rowSet = cassandraSession.Execute(selectStatement);
@@ -43,8 +42,8 @@ public class RouteMap(ISession cassandraSession): IRoute {
}
/// <summary>
/// POST request for the database route, insert a new map containing
/// object data into the database.
/// POST request for the database/path route, insert a new path containing
/// routing data into the database.
/// </summary>
public HttpResponse Post(HttpRequest request) {
try {
@@ -55,6 +54,22 @@ public class RouteMap(ISession cassandraSession): IRoute {
throw new Exception("objectData is null");
}
if (parsedBody?.id == null) {
throw new Exception("id is null");
}
var selectStatement =
parsedBody?.id != null ? cassandraSession.Prepare(@"SELECT * FROM Roommapper.Maps WHERE Id = ?;")
.Bind(Guid.Parse(parsedBody.id)) :
throw new Exception("No valid search criteria given, give one of (id).");
// Execute the query and return all rows in an array
var rowSet = cassandraSession.Execute(selectStatement);
if (rowSet.IsExhausted()) {
throw new Exception("No matching map found with the given criteria.");
}
// Prepare the insert statement, bind the values, and execute the query
// Using a prepare due to the potential of SQL injection when accepting
// any form of user data.

View File

@@ -33,28 +33,10 @@ export default class MapCanvas extends React.Component {
this.draw();
}
async getLinePoints() {
async getLinePoints(endpoint = '') {
try {
const { searchOption, inputValue } = this.state;
const url = `${API_ENDPOINT}/database?${searchOption}=${inputValue}`;
const data = await (await fetch(url)).json();
// Combine all found sets into a singular array.
const map = [];
if (!Array.isArray(data) || data.length < 1) return map;
data.forEach((set) => set.Objects.forEach((coord) => map.push(coord)));
return map;
} catch (ex) {
return;
// this.props.onError(ex);
}
}
async getRoutePoints() {
try {
const { searchOption, inputValue } = this.state;
const url = `${API_ENDPOINT}/database/route?id=${inputValue}`;
const url = `${API_ENDPOINT}/database/${endpoint}?${searchOption}=${inputValue}`;
const data = await (await fetch(url)).json();
// Combine all found sets into a singular array.
@@ -74,7 +56,8 @@ export default class MapCanvas extends React.Component {
const ctx = this.canvasRef.current.getContext('2d');
// Get the points to draw from the server
const points = await this.getLinePoints();
const route = await this.getRoutePoints();
const route = await this.getLinePoints("path");
// const route = await this.getRoutePoints();
// Set the font for the text we will draw on the canvas
ctx.font = "24px Comic Sans MS";