Skip to content

Commit b737e91

Browse files
committed
test
1 parent 97763eb commit b737e91

19 files changed

Lines changed: 48 additions & 809 deletions

src/opengeodeweb_back/routes/create/blueprint_create.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def create_point() -> flask.Response:
2929
"""Endpoint to create a single point in 3D space."""
3030
print(f"create_point : {flask.request=}", flush=True)
3131
utils_functions.validate_request(flask.request, create_point_json)
32-
params = CreatePoint.from_dict(flask.request.get_json())
32+
params = CreatePoint(**flask.request.get_json())
3333

3434
# Create the point
3535
class_ = geode_functions.geode_object_class("PointSet3D")
@@ -56,7 +56,7 @@ def create_aoi() -> flask.Response:
5656
"""Endpoint to create an Area of Interest (AOI) as an EdgedCurve3D."""
5757
print(f"create_aoi : {flask.request=}", flush=True)
5858
utils_functions.validate_request(flask.request, create_aoi_json)
59-
params = CreateAoi.from_dict(flask.request.get_json())
59+
params = CreateAoi(**flask.request.get_json())
6060

6161
# Create the edged curve
6262
class_ = geode_functions.geode_object_class("EdgedCurve3D")
@@ -68,7 +68,7 @@ def create_aoi() -> flask.Response:
6868
vertex_indices: list[int] = []
6969
for point in params.points:
7070
vertex_id = builder.create_point(
71-
opengeode.Point3D([point["x"], point["y"], params.z])
71+
opengeode.Point3D([point.x, point.y, params.z])
7272
)
7373
vertex_indices.append(vertex_id)
7474

Lines changed: 5 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,18 @@
1-
from typing import Any, Optional, List, TypeVar, Callable, Type, cast
2-
3-
4-
T = TypeVar("T")
5-
6-
7-
def from_float(x: Any) -> float:
8-
assert isinstance(x, (float, int)) and not isinstance(x, bool)
9-
return float(x)
10-
11-
12-
def to_float(x: Any) -> float:
13-
assert isinstance(x, (int, float))
14-
return x
15-
16-
17-
def from_str(x: Any) -> str:
18-
assert isinstance(x, str)
19-
return x
20-
21-
22-
def from_none(x: Any) -> Any:
23-
assert x is None
24-
return x
25-
26-
27-
def from_union(fs, x):
28-
for f in fs:
29-
try:
30-
return f(x)
31-
except:
32-
pass
33-
assert False
34-
35-
36-
def from_list(f: Callable[[Any], T], x: Any) -> List[T]:
37-
assert isinstance(x, list)
38-
return [f(y) for y in x]
39-
40-
41-
def to_class(c: Type[T], x: Any) -> dict:
42-
assert isinstance(x, c)
43-
return cast(Any, x).to_dict()
1+
from dataclasses import dataclass
2+
from typing import List, Optional
443

454

5+
@dataclass
466
class Point:
477
x: float
488
y: float
499

50-
def __init__(self, x: float, y: float) -> None:
51-
self.x = x
52-
self.y = y
53-
54-
@staticmethod
55-
def from_dict(obj: Any) -> "Point":
56-
assert isinstance(obj, dict)
57-
x = from_float(obj.get("x"))
58-
y = from_float(obj.get("y"))
59-
return Point(x, y)
60-
61-
def to_dict(self) -> dict:
62-
result: dict = {}
63-
result["x"] = to_float(self.x)
64-
result["y"] = to_float(self.y)
65-
return result
66-
6710

11+
@dataclass
6812
class CreateAoi:
69-
id: Optional[str]
7013
name: str
7114
"""Name of the AOI"""
7215

7316
points: List[Point]
7417
z: float
75-
76-
def __init__(
77-
self, id: Optional[str], name: str, points: List[Point], z: float
78-
) -> None:
79-
self.id = id
80-
self.name = name
81-
self.points = points
82-
self.z = z
83-
84-
@staticmethod
85-
def from_dict(obj: Any) -> "CreateAoi":
86-
assert isinstance(obj, dict)
87-
id = from_union([from_str, from_none], obj.get("id"))
88-
name = from_str(obj.get("name"))
89-
points = from_list(Point.from_dict, obj.get("points"))
90-
z = from_float(obj.get("z"))
91-
return CreateAoi(id, name, points, z)
92-
93-
def to_dict(self) -> dict:
94-
result: dict = {}
95-
if self.id is not None:
96-
result["id"] = from_union([from_str, from_none], self.id)
97-
result["name"] = from_str(self.name)
98-
result["points"] = from_list(lambda x: to_class(Point, x), self.points)
99-
result["z"] = to_float(self.z)
100-
return result
101-
102-
103-
def create_aoi_from_dict(s: Any) -> CreateAoi:
104-
return CreateAoi.from_dict(s)
105-
106-
107-
def create_aoi_to_dict(x: CreateAoi) -> Any:
108-
return to_class(CreateAoi, x)
18+
id: Optional[str] = None
Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,9 @@
1-
# type: ignore
2-
from typing import Any, TypeVar, Type, cast
3-
4-
5-
T = TypeVar("T")
6-
7-
8-
def from_str(x: Any) -> str:
9-
assert isinstance(x, str)
10-
return x
11-
12-
13-
def from_float(x: Any) -> float:
14-
assert isinstance(x, (float, int)) and not isinstance(x, bool)
15-
return float(x)
16-
17-
18-
def to_float(x: Any) -> float:
19-
assert isinstance(x, (int, float))
20-
return x
21-
22-
23-
def to_class(c: Type[T], x: Any) -> dict:
24-
assert isinstance(x, c)
25-
return cast(Any, x).to_dict()
1+
from dataclasses import dataclass
262

273

4+
@dataclass
285
class CreatePoint:
296
name: str
307
x: float
318
y: float
329
z: float
33-
34-
def __init__(self, name: str, x: float, y: float, z: float) -> None:
35-
self.name = name
36-
self.x = x
37-
self.y = y
38-
self.z = z
39-
40-
@staticmethod
41-
def from_dict(obj: Any) -> "CreatePoint":
42-
assert isinstance(obj, dict)
43-
name = from_str(obj.get("name"))
44-
x = from_float(obj.get("x"))
45-
y = from_float(obj.get("y"))
46-
z = from_float(obj.get("z"))
47-
return CreatePoint(name, x, y, z)
48-
49-
def to_dict(self) -> dict:
50-
result: dict = {}
51-
result["name"] = from_str(self.name)
52-
result["x"] = to_float(self.x)
53-
result["y"] = to_float(self.y)
54-
result["z"] = to_float(self.z)
55-
return result
56-
57-
58-
def create_point_from_dict(s: Any) -> CreatePoint:
59-
return CreatePoint.from_dict(s)
60-
61-
62-
def create_point_to_dict(x: CreatePoint) -> Any:
63-
return to_class(CreatePoint, x)
Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,6 @@
1-
# type: ignore
2-
from typing import Any, TypeVar, Type, cast
3-
4-
5-
T = TypeVar("T")
6-
7-
8-
def from_str(x: Any) -> str:
9-
assert isinstance(x, str)
10-
return x
11-
12-
13-
def to_class(c: Type[T], x: Any) -> dict:
14-
assert isinstance(x, c)
15-
return cast(Any, x).to_dict()
1+
from dataclasses import dataclass
162

173

4+
@dataclass
185
class MeshComponents:
196
id: str
20-
21-
def __init__(self, id: str) -> None:
22-
self.id = id
23-
24-
@staticmethod
25-
def from_dict(obj: Any) -> "MeshComponents":
26-
assert isinstance(obj, dict)
27-
id = from_str(obj.get("id"))
28-
return MeshComponents(id)
29-
30-
def to_dict(self) -> dict:
31-
result: dict = {}
32-
result["id"] = from_str(self.id)
33-
return result
34-
35-
36-
def mesh_components_from_dict(s: Any) -> MeshComponents:
37-
return MeshComponents.from_dict(s)
38-
39-
40-
def mesh_components_to_dict(x: MeshComponents) -> Any:
41-
return to_class(MeshComponents, x)
Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,6 @@
1-
# type: ignore
2-
from typing import Any, TypeVar, Type, cast
3-
4-
5-
T = TypeVar("T")
6-
7-
8-
def from_str(x: Any) -> str:
9-
assert isinstance(x, str)
10-
return x
11-
12-
13-
def to_class(c: Type[T], x: Any) -> dict:
14-
assert isinstance(x, c)
15-
return cast(Any, x).to_dict()
1+
from dataclasses import dataclass
162

173

4+
@dataclass
185
class VtmComponentIndices:
196
id: str
20-
21-
def __init__(self, id: str) -> None:
22-
self.id = id
23-
24-
@staticmethod
25-
def from_dict(obj: Any) -> "VtmComponentIndices":
26-
assert isinstance(obj, dict)
27-
id = from_str(obj.get("id"))
28-
return VtmComponentIndices(id)
29-
30-
def to_dict(self) -> dict:
31-
result: dict = {}
32-
result["id"] = from_str(self.id)
33-
return result
34-
35-
36-
def vtm_component_indices_from_dict(s: Any) -> VtmComponentIndices:
37-
return VtmComponentIndices.from_dict(s)
38-
39-
40-
def vtm_component_indices_to_dict(x: VtmComponentIndices) -> Any:
41-
return to_class(VtmComponentIndices, x)
Lines changed: 4 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,7 @@
1-
# type: ignore
2-
from typing import Optional, Any, TypeVar, Type, cast
3-
4-
5-
T = TypeVar("T")
6-
7-
8-
def from_none(x: Any) -> Any:
9-
assert x is None
10-
return x
11-
12-
13-
def from_str(x: Any) -> str:
14-
assert isinstance(x, str)
15-
return x
16-
17-
18-
def from_union(fs, x):
19-
for f in fs:
20-
try:
21-
return f(x)
22-
except:
23-
pass
24-
assert False
25-
26-
27-
def to_class(c: Type[T], x: Any) -> dict:
28-
assert isinstance(x, c)
29-
return cast(Any, x).to_dict()
1+
from dataclasses import dataclass
2+
from typing import Optional
303

314

5+
@dataclass
326
class AllowedFiles:
33-
supported_feature: Optional[str]
34-
35-
def __init__(self, supported_feature: Optional[str]) -> None:
36-
self.supported_feature = supported_feature
37-
38-
@staticmethod
39-
def from_dict(obj: Any) -> "AllowedFiles":
40-
assert isinstance(obj, dict)
41-
supported_feature = from_union(
42-
[from_none, from_str], obj.get("supported_feature")
43-
)
44-
return AllowedFiles(supported_feature)
45-
46-
def to_dict(self) -> dict:
47-
result: dict = {}
48-
result["supported_feature"] = from_union(
49-
[from_none, from_str], self.supported_feature
50-
)
51-
return result
52-
53-
54-
def allowed_files_from_dict(s: Any) -> AllowedFiles:
55-
return AllowedFiles.from_dict(s)
56-
57-
58-
def allowed_files_to_dict(x: AllowedFiles) -> Any:
59-
return to_class(AllowedFiles, x)
7+
supported_feature: Optional[str] = None

0 commit comments

Comments
 (0)