Skip to content

Commit

Permalink
New Api Endpoints (#268)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas-Nan authored Jun 12, 2024
2 parents f7ede0c + e653ef4 commit 3ea4b87
Show file tree
Hide file tree
Showing 18 changed files with 343 additions and 42,331 deletions.
25 changes: 25 additions & 0 deletions backend/api-gateway/APIGateway.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.9.34728.123
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "APIGateway", "APIGateway.csproj", "{D414C91A-FF04-4628-9C8C-E3C945ABFE5A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D414C91A-FF04-4628-9C8C-E3C945ABFE5A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D414C91A-FF04-4628-9C8C-E3C945ABFE5A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D414C91A-FF04-4628-9C8C-E3C945ABFE5A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D414C91A-FF04-4628-9C8C-E3C945ABFE5A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {483A3EDE-B15B-4AC3-8290-49487CA19FB7}
EndGlobalSection
EndGlobal
101 changes: 99 additions & 2 deletions backend/api-gateway/Controllers/APIGatewayController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Text.Json;
using APIGateway.Models;
using System.ComponentModel.DataAnnotations;
using System.Data;

namespace BIE.Core.API.Controllers
{
Expand All @@ -21,6 +22,101 @@ public APIGatewayController(HttpClient httpClient, ILogger<APIGatewayController>
_logger = logger;
}

/// <summary>
/// Gets the list of available datasets with id, name and description
/// </summary>
/// <returns>Data for the specified dataset in the provided viewport bounds and zoom level.</returns>
[HttpGet("getDatasetList")]
[ProducesResponseType(typeof(DatasetListResponse), 200)]
[ProducesResponseType(400)]
public IActionResult GetDataSetList()
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}

var datasetInfoList = MockData.DataSetDescription;

return Ok(datasetInfoList);
}

/// <summary>
/// Gets the metadata for the given dataset. Contains things like icon, visualization types
/// </summary>
/// <returns>Data for the specified dataset in the provided viewport bounds and zoom level.</returns>
[HttpGet("getDatasetMetadata")]
[ProducesResponseType(typeof(DatasetListResponse), 200)]
[ProducesResponseType(400)]
[ProducesResponseType(500)]

public IActionResult GetDatasetMetadata([FromQuery, Required] string datasetID)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
return Ok(new DatasetMetadata { icon = "", type="marker" });
}

/// <summary>
/// Loads the location data for the given point or poylgon.
/// </summary>
/// <param name="request">Contains the current dataset id and the list of coordinates.
/// In case of a single point a list with a single element.</param>
/// <returns>Data for the specified point/polygon as a list of key/values.</returns>
[HttpPut("loadLocationData")]
[ProducesResponseType(typeof(LocationDataResponse), 200)]
[ProducesResponseType(400)]
[ProducesResponseType(500)]
public IActionResult LoadLocationData([FromBody, Required] LocationDataRequest request)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}

_logger.LogInformation($"Fetching data for DatasetID: {request.DatasetId}");

// Generate mock data for the current dataset
var currentDatasetData = GenerateMockData("charging_stations", 3);

// Generate mock data for general data from other datasets
var generalData = GenerateMockData("house_footprints", 3);

var extraRows = GenerateMockData("extra_dataset", 1);

var response = new LocationDataResponse
{
CurrentDatasetData = currentDatasetData,
GeneralData = generalData,
ExtraRows = extraRows
};

return Ok(response);
}

// Helper method to generate mock data
private List<DatasetItem> GenerateMockData(string mapId, int count)
{
var random = new Random();
var data = new List<DatasetItem>();

for (int i = 0; i < count; i++)
{
var item = new DatasetItem
{
Id = Guid.NewGuid().ToString(), // Generate a unique ID
Key = $"{mapId} Item {i + 1} (distance)",
Value = $"{random.Next(50, 1000)} m",
MapId = mapId
};
data.Add(item);
}

return data;
}

/// <summary>
/// Gets the dataset viewport data based on the provided parameters.
/// </summary>
Expand Down Expand Up @@ -57,7 +153,8 @@ public async Task<IActionResult> GetDatasetViewportData(
}
else if (datasetID == "house_footprints")
{
targetUrl = $"http://api-composer:80/api/v1.0/Dataset/2/data?ZoomLevel={zoomLevel}&BottomLat={BottomLat}&BottomLong={BottomLong}&TopLat={TopLat}&TopLong={TopLong}";
return Ok(MockData.MockHouseFootprints);
//targetUrl = $"http://api-composer:80/api/v1.0/Dataset/2/data?ZoomLevel={zoomLevel}&BottomLat={BottomLat}&BottomLong={BottomLong}&TopLat={TopLat}&TopLong={TopLong}";
}
else
{
Expand All @@ -71,7 +168,7 @@ public async Task<IActionResult> GetDatasetViewportData(
response.EnsureSuccessStatusCode(); // Throw if not a success code.
var content = await response.Content.ReadAsStringAsync();
var geoJsonResponse = JsonSerializer.Deserialize<GeoJsonResponse>(content);

return Ok(geoJsonResponse);
}
catch (HttpRequestException ex)
Expand Down
17 changes: 17 additions & 0 deletions backend/api-gateway/Models/DatasetListResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace APIGateway.Models
{
public class DatasetListResponse
{
public List<DatasetBasicData> basicInfoList { get; set; }

}

public class DatasetBasicData
{
public string datasetId { get; set; }
public string name { get; set; }
public string description { get; set; }
public string icon { get; set; }

}
}
8 changes: 8 additions & 0 deletions backend/api-gateway/Models/DatasetMetadata.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace APIGateway.Models
{
public class DatasetMetadata
{
public string icon { get; set; }
public string type { get; set; }
}
}
1 change: 1 addition & 0 deletions backend/api-gateway/Models/GeoJsonResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace APIGateway.Models
{

public class GeoJsonResponse
{
public string type { get; set; }
Expand Down
32 changes: 32 additions & 0 deletions backend/api-gateway/Models/LocationData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
namespace APIGateway.Models
{
public class LocationDataRequest
{
public string DatasetId { get; set; }
public List<Coordinate> Location { get; set; }
}

public class Coordinate
{
public double Latitude { get; set; }
public double Longitude { get; set; }
}

public class LocationDataResponse
{
public List<DatasetItem> CurrentDatasetData { get; set; }
public List<DatasetItem> GeneralData { get; set; }
public object ExtraRows { get; internal set; }
}

public class DatasetItem
{
public string Id { get; set; }

public string Key { get; set; }
public string Value { get; set; }
public string MapId { get; set; } // Optional -> for "open in map" functionality
}


}
31 changes: 31 additions & 0 deletions backend/api-gateway/Models/MockData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
namespace APIGateway.Models
{
public static class MockData
{
public static readonly string MockHouseFootprints = "{\r\n \"type\": \"FeatureCollection\",\r\n \"features\": [\r\n {\r\n \"id\": \"0\",\r\n \"type\": \"Feature\",\r\n \"properties\": {\r\n \"ags\": 9571224\r\n },\r\n \"geometry\": {\r\n \"type\": \"Polygon\",\r\n \"coordinates\": [\r\n [\r\n [\r\n 603185.06,\r\n 5426501.29\r\n ],\r\n [\r\n 603188.02,\r\n 5426502.03\r\n ],\r\n [\r\n 603187.78,\r\n 5426503.2\r\n ],\r\n [\r\n 603190.18,\r\n 5426503.72\r\n ],\r\n [\r\n 603193.28,\r\n 5426490.21\r\n ],\r\n [\r\n 603188.14,\r\n 5426488.96\r\n ],\r\n [\r\n 603185.06,\r\n 5426501.29\r\n ]\r\n ]\r\n ]\r\n }\r\n },\r\n {\r\n \"id\": \"1\",\r\n \"type\": \"Feature\",\r\n \"properties\": {\r\n \"ags\": 9571224\r\n },\r\n \"geometry\": {\r\n \"type\": \"Polygon\",\r\n \"coordinates\": [\r\n [\r\n [\r\n 602871.72,\r\n 5426708.37\r\n ],\r\n [\r\n 602891.49,\r\n 5426719.73\r\n ],\r\n [\r\n 602894.74,\r\n 5426714.03\r\n ],\r\n [\r\n 602875.03,\r\n 5426702.7\r\n ],\r\n [\r\n 602871.72,\r\n 5426708.37\r\n ]\r\n ]\r\n ]\r\n }\r\n },\r\n {\r\n \"id\": \"2\",\r\n \"type\": \"Feature\",\r\n \"properties\": {\r\n \"ags\": 9571224\r\n },\r\n \"geometry\": {\r\n \"type\": \"Polygon\",\r\n \"coordinates\": [\r\n [\r\n [\r\n 603194.51,\r\n 5426496.8\r\n ],\r\n [\r\n 603203.35,\r\n 5426499.28\r\n ],\r\n [\r\n 603205.01,\r\n 5426493.25\r\n ],\r\n [\r\n 603196.13,\r\n 5426490.74\r\n ],\r\n [\r\n 603194.51,\r\n 5426496.8\r\n ]\r\n ]\r\n ]\r\n }\r\n },\r\n {\r\n \"id\": \"3\",\r\n \"type\": \"Feature\",\r\n \"properties\": {\r\n \"ags\": 9571224\r\n },\r\n \"geometry\": {\r\n \"type\": \"Polygon\",\r\n \"coordinates\": [\r\n [\r\n [\r\n 603170.79,\r\n 5426480.85\r\n ],\r\n [\r\n 603177.67,\r\n 5426482.3\r\n ],\r\n [\r\n 603176.79,\r\n 5426486.22\r\n ],\r\n [\r\n 603188.14,\r\n 5426488.96\r\n ],\r\n [\r\n 603193.28,\r\n 5426490.21\r\n ],\r\n [\r\n 603195.55,\r\n 5426480.31\r\n ],\r\n [\r\n 603179.11,\r\n 5426476.51\r\n ],\r\n [\r\n 603179.56,\r\n 5426474.57\r\n ],\r\n [\r\n 603172.59,\r\n 5426472.89\r\n ],\r\n [\r\n 603170.79,\r\n 5426480.85\r\n ]\r\n ]\r\n ]\r\n }\r\n },\r\n {\r\n \"id\": \"4\",\r\n \"type\": \"Feature\",\r\n \"properties\": {\r\n \"ags\": 9571224\r\n },\r\n \"geometry\": {\r\n \"type\": \"Polygon\",\r\n \"coordinates\": [\r\n [\r\n [\r\n 603195.71,\r\n 5426529.57\r\n ],\r\n [\r\n 603197.59,\r\n 5426541.28\r\n ],\r\n [\r\n 603203.53,\r\n 5426540.35\r\n ],\r\n [\r\n 603201.65,\r\n 5426528.63\r\n ],\r\n [\r\n 603200.54,\r\n 5426528.04\r\n ],\r\n [\r\n 603196.61,\r\n 5426528.65\r\n ],\r\n [\r\n 603195.71,\r\n 5426529.57\r\n ]\r\n ]\r\n ]\r\n }\r\n },\r\n {\r\n \"id\": \"5\",\r\n \"type\": \"Feature\",\r\n \"properties\": {\r\n \"ags\": 9571224\r\n },\r\n \"geometry\": {\r\n \"type\": \"Polygon\",\r\n \"coordinates\": [\r\n [\r\n [\r\n 603158.42,\r\n 5426494.45\r\n ],\r\n [\r\n 603168.37,\r\n 5426496.39\r\n ],\r\n [\r\n 603170.41,\r\n 5426484.82\r\n ],\r\n [\r\n 603160.45,\r\n 5426482.86\r\n ],\r\n [\r\n 603158.42,\r\n 5426494.45\r\n ]\r\n ]\r\n ]\r\n }\r\n },\r\n {\r\n \"id\": \"6\",\r\n \"type\": \"Feature\",\r\n \"properties\": {\r\n \"ags\": 9571224\r\n },\r\n \"geometry\": {\r\n \"type\": \"Polygon\",\r\n \"coordinates\": [\r\n [\r\n [\r\n 603192.21,\r\n 5426473.14\r\n ],\r\n [\r\n 603197.55,\r\n 5426475.39\r\n ],\r\n [\r\n 603201.94,\r\n 5426464.4\r\n ],\r\n [\r\n 603196.7,\r\n 5426462.41\r\n ],\r\n [\r\n 603192.21,\r\n 5426473.14\r\n ]\r\n ]\r\n ]\r\n }\r\n },\r\n {\r\n \"id\": \"7\",\r\n \"type\": \"Feature\",\r\n \"properties\": {\r\n \"ags\": 9571224\r\n },\r\n \"geometry\": {\r\n \"type\": \"Polygon\",\r\n \"coordinates\": [\r\n [\r\n [\r\n 603165.26,\r\n 5426534.1\r\n ],\r\n [\r\n 603173.59,\r\n 5426541.31\r\n ],\r\n [\r\n 603179.5,\r\n 5426533.53\r\n ],\r\n [\r\n 603185.85,\r\n 5426525.18\r\n ],\r\n [\r\n 603188.33,\r\n 5426527.02\r\n ],\r\n [\r\n 603191.12,\r\n 5426523.34\r\n ],\r\n [\r\n 603188.6,\r\n 5426521.55\r\n ],\r\n [\r\n 603179.71,\r\n 5426514.92\r\n ],\r\n [\r\n 603165.26,\r\n 5426534.1\r\n ]\r\n ]\r\n ]\r\n }\r\n },\r\n {\r\n \"id\": \"8\",\r\n \"type\": \"Feature\",\r\n \"properties\": {\r\n \"ags\": 9571224\r\n },\r\n \"geometry\": {\r\n \"type\": \"Polygon\",\r\n \"coordinates\": [\r\n [\r\n [\r\n 603207.73,\r\n 5426536.57\r\n ],\r\n [\r\n 603211.75,\r\n 5426538.14\r\n ],\r\n [\r\n 603213.5,\r\n 5426534.23\r\n ],\r\n [\r\n 603208.64,\r\n 5426532.38\r\n ],\r\n [\r\n 603207.98,\r\n 5426535.35\r\n ],\r\n [\r\n 603207.73,\r\n 5426536.57\r\n ]\r\n ]\r\n ]\r\n }\r\n },\r\n {\r\n \"id\": \"9\",\r\n \"type\": \"Feature\",\r\n \"properties\": {\r\n \"ags\": 9571224\r\n },\r\n \"geometry\": {\r\n \"type\": \"Polygon\",\r\n \"coordinates\": [\r\n [\r\n [\r\n 603230.32,\r\n 5426487.01\r\n ],\r\n [\r\n 603232.98,\r\n 5426488.17\r\n ],\r\n [\r\n 603232.52,\r\n 5426489.2\r\n ],\r\n [\r\n 603235.48,\r\n 5426490.48\r\n ],\r\n [\r\n 603235.95,\r\n 5426489.45\r\n ],\r\n [\r\n 603242.24,\r\n 5426492.21\r\n ],\r\n [\r\n 603246.43,\r\n 5426482.6\r\n ],\r\n [\r\n 603240.48,\r\n 5426480.0\r\n ],\r\n [\r\n 603241.48,\r\n 5426477.73\r\n ],\r\n [\r\n 603235.99,\r\n 5426475.32\r\n ],\r\n [\r\n 603234.99,\r\n 5426477.6\r\n ],\r\n [\r\n 603234.53,\r\n 5426477.39\r\n ],\r\n [\r\n 603230.32,\r\n 5426487.01\r\n ]\r\n ]\r\n ]\r\n }\r\n }\r\n ],\r\n \"crs\": {\r\n \"type\": \"name\",\r\n \"properties\": {\r\n \"name\": \"urn:ogc:def:crs:EPSG::25832\"\r\n }\r\n }\r\n}\r\n";
public static readonly DatasetListResponse DataSetDescription = new DatasetListResponse
{
basicInfoList = [
new () {
datasetId = "empty_map",
name = "Empty Map",
description = "An empty, default map of Germany, with no data loaded.",
icon = "",
},
new ()
{
datasetId = "charging_stations",
name = "Charging stations",
description = "Locations of all charging stations in Germany.",
icon = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"32\" height=\"32\" fill=\"#000000\" viewBox=\"0 0 256 256\"><path d=\"M134.62,123.51a8,8,0,0,1,.81,7.46l-16,40A8,8,0,0,1,104.57,165l11.61-29H96a8,8,0,0,1-7.43-11l16-40A8,8,0,1,1,119.43,91l-11.61,29H128A8,8,0,0,1,134.62,123.51ZM248,86.63V168a24,24,0,0,1-48,0V128a8,8,0,0,0-8-8H176v88h16a8,8,0,0,1,0,16H32a8,8,0,0,1,0-16H48V56A24,24,0,0,1,72,32h80a24,24,0,0,1,24,24v48h16a24,24,0,0,1,24,24v40a8,8,0,0,0,16,0V86.63A8,8,0,0,0,229.66,81L210.34,61.66a8,8,0,0,1,11.32-11.32L241,69.66A23.85,23.85,0,0,1,248,86.63ZM160,208V56a8,8,0,0,0-8-8H72a8,8,0,0,0-8,8V208Z\"></path></svg>",
},
new()
{
datasetId = "house_footprints",
name = "House Footprints",
description = "Footprints for the houses.",
icon = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"32\" height=\"32\" fill=\"#000000\" viewBox=\"0 0 256 256\"><path d=\"M232,56H72V40a8,8,0,0,0-8-8H48A32,32,0,0,0,16,64V176a32,32,0,0,0,32,32H232a8,8,0,0,0,8-8V64A8,8,0,0,0,232,56ZM32,64A16,16,0,0,1,48,48h8v96H48a31.82,31.82,0,0,0-16,4.29ZM224,192H48a16,16,0,0,1,0-32H64a8,8,0,0,0,8-8V72H224ZM104,136a8,8,0,0,0,0,16h16v8a8,8,0,0,0,16,0v-8h24v8a8,8,0,0,0,16,0v-8h16a8,8,0,0,0,0-16H176V120h16a8,8,0,0,0,0-16H176V96a8,8,0,0,0-16,0v8H136V96a8,8,0,0,0-16,0v8H104a8,8,0,0,0,0,16h16v16Zm32-16h24v16H136Z\"></path></svg>"
}]
};
}
}
Loading

0 comments on commit 3ea4b87

Please sign in to comment.