Skip to content

Commit ddcfe92

Browse files
authored
Merge pull request #241 from Geode-solutions/feat/edges-creation
Feat/edges creation
2 parents d398bab + 5e7bcb7 commit ddcfe92

7 files changed

Lines changed: 179 additions & 1 deletion

File tree

opengeodeweb_back_schemas.json

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,63 @@
4343
"points"
4444
],
4545
"additionalProperties": false
46+
},
47+
"edged_curve": {
48+
"$id": "opengeodeweb_back/create/edged_curve",
49+
"route": "/edged_curve",
50+
"methods": [
51+
"POST"
52+
],
53+
"type": "object",
54+
"properties": {
55+
"name": {
56+
"type": "string",
57+
"minLength": 1
58+
},
59+
"points": {
60+
"type": "array",
61+
"items": {
62+
"title": "EdgedCurvePoint",
63+
"type": "object",
64+
"properties": {
65+
"x": {
66+
"type": "number"
67+
},
68+
"y": {
69+
"type": "number"
70+
},
71+
"z": {
72+
"type": "number"
73+
}
74+
},
75+
"required": [
76+
"x",
77+
"y",
78+
"z"
79+
],
80+
"additionalProperties": false
81+
},
82+
"minItems": 2
83+
},
84+
"edges": {
85+
"type": "array",
86+
"items": {
87+
"type": "array",
88+
"items": {
89+
"type": "integer"
90+
},
91+
"minItems": 2,
92+
"maxItems": 2
93+
},
94+
"minItems": 1
95+
}
96+
},
97+
"required": [
98+
"name",
99+
"points",
100+
"edges"
101+
],
102+
"additionalProperties": false
46103
}
47104
},
48105
"vertex_attribute_names": {

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,3 @@ werkzeug==3.1.2
6060
# flask
6161
# flask-cors
6262

63-
opengeodeweb-microservice==1.*,>=1.1.3

src/opengeodeweb_back/routes/create/blueprint_create.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,29 @@ def point_set() -> flask.Response:
3636
pointset
3737
)
3838
return flask.make_response(result, 200)
39+
40+
41+
@routes.route(
42+
schemas_dict["edged_curve"]["route"],
43+
methods=schemas_dict["edged_curve"]["methods"],
44+
)
45+
def edged_curve() -> flask.Response:
46+
"""Endpoint to create an edged curve in 3D space."""
47+
json_data = utils_functions.validate_request(
48+
flask.request, schemas_dict["edged_curve"]
49+
)
50+
params = schemas.EdgedCurve.from_dict(json_data)
51+
52+
edged_curve_obj = GeodeEdgedCurve3D()
53+
builder = edged_curve_obj.builder()
54+
builder.set_name(params.name)
55+
for point in params.points:
56+
builder.create_point(opengeode.Point3D([point.x, point.y, point.z]))
57+
58+
for edge in params.edges:
59+
builder.create_edge_with_vertices(edge[0], edge[1])
60+
61+
result = utils_functions.generate_native_viewable_and_light_viewable_from_object(
62+
edged_curve_obj
63+
)
64+
return flask.make_response(result, 200)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
from .point_set import *
2+
from .edged_curve import *
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"route": "/edged_curve",
3+
"methods": ["POST"],
4+
"type": "object",
5+
"properties": {
6+
"name": {
7+
"type": "string",
8+
"minLength": 1
9+
},
10+
"points": {
11+
"type": "array",
12+
"items": {
13+
"title": "EdgedCurvePoint",
14+
"type": "object",
15+
"properties": {
16+
"x": { "type": "number" },
17+
"y": { "type": "number" },
18+
"z": { "type": "number" }
19+
},
20+
"required": ["x", "y", "z"],
21+
"additionalProperties": false
22+
},
23+
"minItems": 2
24+
},
25+
"edges": {
26+
"type": "array",
27+
"items": {
28+
"type": "array",
29+
"items": { "type": "integer" },
30+
"minItems": 2,
31+
"maxItems": 2
32+
},
33+
"minItems": 1
34+
}
35+
},
36+
"required": ["name", "points", "edges"],
37+
"additionalProperties": false
38+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from dataclasses_json import DataClassJsonMixin
2+
from dataclasses import dataclass
3+
from typing import List
4+
5+
6+
@dataclass
7+
class EdgedCurvePoint(DataClassJsonMixin):
8+
def __post_init__(self) -> None:
9+
print(self, flush=True)
10+
11+
x: float
12+
y: float
13+
z: float
14+
15+
16+
@dataclass
17+
class EdgedCurve(DataClassJsonMixin):
18+
def __post_init__(self) -> None:
19+
print(self, flush=True)
20+
21+
edges: List[List[int]]
22+
name: str
23+
points: List[EdgedCurvePoint]

tests/test_create_routes.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ def point_data() -> test_utils.JsonData:
1414
return {"name": "test_point", "points": [{"x": 1.0, "y": 2.0, "z": 3.0}]}
1515

1616

17+
@pytest.fixture
18+
def curve_data() -> test_utils.JsonData:
19+
return {
20+
"name": "test_curve",
21+
"points": [{"x": 0.0, "y": 0.0, "z": 0.0}, {"x": 1.0, "y": 1.0, "z": 1.0}],
22+
"edges": [[0, 1]],
23+
}
24+
25+
1726
def test_create_point(client: FlaskClient, point_data: test_utils.JsonData) -> None:
1827
"""Test the creation of a point with valid data."""
1928
route: str = "/opengeodeweb_back/create/point_set"
@@ -74,3 +83,28 @@ def test_create_point_with_invalid_data(client: FlaskClient) -> None:
7483
invalid_data = {"name": "invalid_point", "points": [{"y": 2.0, "z": 3.0}]}
7584
response = client.post(route, json=invalid_data)
7685
assert response.status_code == 400
86+
87+
88+
def test_create_curve(client: FlaskClient, curve_data: test_utils.JsonData) -> None:
89+
"""Test the creation of a curve with valid data."""
90+
route: str = "/opengeodeweb_back/create/edged_curve"
91+
92+
# Test with all required data
93+
response = client.post(route, json=curve_data)
94+
assert response.status_code == 200
95+
96+
# Verify response data
97+
response_data = response.get_json()
98+
assert "viewable_file" in response_data
99+
assert "id" in response_data
100+
assert "name" in response_data
101+
assert "native_file" in response_data
102+
assert "viewer_type" in response_data
103+
assert "geode_object_type" in response_data
104+
105+
assert response_data["name"] == curve_data["name"]
106+
assert response_data["viewer_type"] == "mesh"
107+
assert response_data["geode_object_type"] == "EdgedCurve3D"
108+
109+
# Test with missing parameters
110+
test_utils.test_route_wrong_params(client, route, lambda: copy.deepcopy(curve_data))

0 commit comments

Comments
 (0)