Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions opengeodeweb_back_schemas.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,63 @@
"points"
],
"additionalProperties": false
},
"edged_curve": {
"$id": "opengeodeweb_back/create/edged_curve",
"route": "/edged_curve",
"methods": [
"POST"
],
"type": "object",
"properties": {
"name": {
"type": "string",
"minLength": 1
},
"points": {
"type": "array",
"items": {
"title": "EdgedCurvePoint",
"type": "object",
"properties": {
"x": {
"type": "number"
},
"y": {
"type": "number"
},
"z": {
"type": "number"
}
},
"required": [
"x",
"y",
"z"
],
"additionalProperties": false
},
"minItems": 2
},
"edges": {
"type": "array",
"items": {
"type": "array",
"items": {
"type": "integer"
},
"minItems": 2,
"maxItems": 2
},
"minItems": 1
}
},
"required": [
"name",
"points",
"edges"
],
"additionalProperties": false
}
},
"vertex_attribute_names": {
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,3 @@ werkzeug==3.1.2
# flask
# flask-cors

opengeodeweb-microservice==1.*,>=1.1.3
26 changes: 26 additions & 0 deletions src/opengeodeweb_back/routes/create/blueprint_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,29 @@ def point_set() -> flask.Response:
pointset
)
return flask.make_response(result, 200)


@routes.route(
Comment thread
MaxNumerique marked this conversation as resolved.
schemas_dict["edged_curve"]["route"],
methods=schemas_dict["edged_curve"]["methods"],
)
def edged_curve() -> flask.Response:
"""Endpoint to create an edged curve in 3D space."""
json_data = utils_functions.validate_request(
flask.request, schemas_dict["edged_curve"]
)
params = schemas.EdgedCurve.from_dict(json_data)

edged_curve_obj = GeodeEdgedCurve3D()
builder = edged_curve_obj.builder()
builder.set_name(params.name)
for point in params.points:
builder.create_point(opengeode.Point3D([point.x, point.y, point.z]))

for edge in params.edges:
builder.create_edge_with_vertices(edge[0], edge[1])

result = utils_functions.generate_native_viewable_and_light_viewable_from_object(
edged_curve_obj
)
return flask.make_response(result, 200)
1 change: 1 addition & 0 deletions src/opengeodeweb_back/routes/create/schemas/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from .point_set import *
from .edged_curve import *
38 changes: 38 additions & 0 deletions src/opengeodeweb_back/routes/create/schemas/edged_curve.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"route": "/edged_curve",
"methods": ["POST"],
"type": "object",
"properties": {
"name": {
"type": "string",
"minLength": 1
},
"points": {
"type": "array",
"items": {
"title": "EdgedCurvePoint",
"type": "object",
"properties": {
"x": { "type": "number" },
"y": { "type": "number" },
"z": { "type": "number" }
},
"required": ["x", "y", "z"],
"additionalProperties": false
},
"minItems": 2
},
"edges": {
"type": "array",
"items": {
"type": "array",
"items": { "type": "integer" },
"minItems": 2,
"maxItems": 2
},
"minItems": 1
}
},
"required": ["name", "points", "edges"],
"additionalProperties": false
}
23 changes: 23 additions & 0 deletions src/opengeodeweb_back/routes/create/schemas/edged_curve.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from dataclasses_json import DataClassJsonMixin
from dataclasses import dataclass
from typing import List


@dataclass
class EdgedCurvePoint(DataClassJsonMixin):
def __post_init__(self) -> None:
print(self, flush=True)

x: float
y: float
z: float


@dataclass
class EdgedCurve(DataClassJsonMixin):
def __post_init__(self) -> None:
print(self, flush=True)

edges: List[List[int]]
name: str
points: List[EdgedCurvePoint]
34 changes: 34 additions & 0 deletions tests/test_create_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ def point_data() -> test_utils.JsonData:
return {"name": "test_point", "points": [{"x": 1.0, "y": 2.0, "z": 3.0}]}


@pytest.fixture
def curve_data() -> test_utils.JsonData:
return {
"name": "test_curve",
"points": [{"x": 0.0, "y": 0.0, "z": 0.0}, {"x": 1.0, "y": 1.0, "z": 1.0}],
"edges": [[0, 1]],
}


def test_create_point(client: FlaskClient, point_data: test_utils.JsonData) -> None:
"""Test the creation of a point with valid data."""
route: str = "/opengeodeweb_back/create/point_set"
Expand Down Expand Up @@ -74,3 +83,28 @@ def test_create_point_with_invalid_data(client: FlaskClient) -> None:
invalid_data = {"name": "invalid_point", "points": [{"y": 2.0, "z": 3.0}]}
response = client.post(route, json=invalid_data)
assert response.status_code == 400


def test_create_curve(client: FlaskClient, curve_data: test_utils.JsonData) -> None:
"""Test the creation of a curve with valid data."""
route: str = "/opengeodeweb_back/create/edged_curve"

# Test with all required data
response = client.post(route, json=curve_data)
assert response.status_code == 200

# Verify response data
response_data = response.get_json()
assert "viewable_file" in response_data
assert "id" in response_data
assert "name" in response_data
assert "native_file" in response_data
assert "viewer_type" in response_data
assert "geode_object_type" in response_data

assert response_data["name"] == curve_data["name"]
assert response_data["viewer_type"] == "mesh"
assert response_data["geode_object_type"] == "EdgedCurve3D"

# Test with missing parameters
test_utils.test_route_wrong_params(client, route, lambda: copy.deepcopy(curve_data))
Loading