-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/blueprint create #192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
50cf43d
Fix tests & other
SpliiT 7801d91
feat(NewBlueprint): New blueprint_create
SpliiT cb2c549
feat(NewBlueprint): New blueprint_create
SpliiT 65517a8
Apply prepare changes
SpliiT 1dece19
fix mypy & other comments
SpliiT 21f4cb2
fix mypy & other comments
SpliiT d2a53df
rm create_point from src/routes/schemas
SpliiT 9a1cade
feat(api): global error handling & direct response usage in create en…
SpliiT 0a6b95f
change typage
SpliiT ffa5114
rm type ignore
SpliiT ab3da30
change logic into class
SpliiT 6d1ac42
Merge branch 'next' into feat/blueprint_create
SpliiT de811b8
Apply prepare changes
SpliiT 9e8d185
fix versions
SpliiT ade9566
Merge branch 'next' into feat/blueprint_create
SpliiT f77e7f6
Apply prepare changes
SpliiT 764929b
wip
SpliiT 062067c
Merge branch 'feat/blueprint_create' of https://github.com/Geode-solu…
SpliiT 50e69f6
Merge branch 'next' of https://github.com/Geode-solutions/OpenGeodeWe…
SpliiT e3a9444
add data field
SpliiT bd5d69d
Apply prepare changes
SpliiT 0e82d14
rm ValueError
SpliiT 3501a37
Merge branch 'feat/blueprint_create' of https://github.com/Geode-solu…
SpliiT 518bc0b
Apply prepare changes
SpliiT 47d03bf
fix
BotellaA File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| # | ||
| # This file is autogenerated by pip-compile with Python 3.12 | ||
| # by the following command: | ||
| # | ||
| # pip-compile --cert=None --client-cert=None --index-url=None --pip-args=None requirements-internal.in | ||
| # | ||
| blinker==1.9.0 | ||
| # via | ||
| # flask | ||
| # opengeodeweb-microservice | ||
| click==8.3.0 | ||
| # via | ||
| # flask | ||
| # opengeodeweb-microservice | ||
| fastjsonschema==2.21.1 | ||
| # via opengeodeweb-microservice | ||
| flask==3.1.2 | ||
| # via | ||
| # flask-sqlalchemy | ||
| # opengeodeweb-microservice | ||
| flask-sqlalchemy==3.1.1 | ||
| # via opengeodeweb-microservice | ||
| greenlet==3.2.4 | ||
| # via | ||
| # opengeodeweb-microservice | ||
| # sqlalchemy | ||
| itsdangerous==2.2.0 | ||
| # via | ||
| # flask | ||
| # opengeodeweb-microservice | ||
| jinja2==3.1.6 | ||
| # via | ||
| # flask | ||
| # opengeodeweb-microservice | ||
| markupsafe==3.0.3 | ||
| # via | ||
| # flask | ||
| # jinja2 | ||
| # opengeodeweb-microservice | ||
| # werkzeug | ||
| opengeodeweb-microservice==1.0.3 | ||
| # via -r requirements-internal.in | ||
| sqlalchemy==2.0.43 | ||
| # via | ||
| # flask-sqlalchemy | ||
| # opengeodeweb-microservice | ||
| typing-extensions==4.15.0 | ||
| # via | ||
| # opengeodeweb-microservice | ||
| # sqlalchemy | ||
| werkzeug==3.1.3 | ||
| # via | ||
| # flask | ||
| # opengeodeweb-microservice |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
154 changes: 154 additions & 0 deletions
154
src/opengeodeweb_back/routes/create/blueprint_create.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,154 @@ | ||
| # Standard library imports | ||
| import json | ||
| import os | ||
| from typing import Dict, Any, List, TypedDict, cast | ||
|
|
||
| # Third party imports | ||
| import flask | ||
| import opengeode | ||
| import werkzeug | ||
|
|
||
| # Local application imports | ||
| from opengeodeweb_back import geode_functions, utils_functions | ||
| from opengeodeweb_microservice.database.data import Data | ||
| from opengeodeweb_microservice.database.connection import get_session | ||
| from opengeodeweb_back.utils_functions import save_all_viewables_and_return_info | ||
|
|
||
| routes = flask.Blueprint("create", __name__, url_prefix="/opengeodeweb_back/create") | ||
BotellaA marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| schemas = os.path.join(os.path.dirname(__file__), "schemas") | ||
|
|
||
| # --- Type definitions for request validation --- | ||
| class Point(TypedDict): | ||
BotellaA marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| x: float | ||
| y: float | ||
|
|
||
| class CreatePointRequest(TypedDict): | ||
| name: str | ||
| x: float | ||
| y: float | ||
| z: float | ||
|
|
||
| class CreateAOIRequest(TypedDict): | ||
| name: str | ||
| points: List[Point] | ||
| z: float | ||
|
|
||
| # Load schema for point creation | ||
| with open(os.path.join(schemas, "create_point.json"), "r") as file: | ||
| create_point_json = cast(Dict[str, Any], json.load(file)) | ||
|
|
||
| @routes.route( | ||
| create_point_json["route"], | ||
| methods=create_point_json["methods"] | ||
| ) | ||
| def create_point() -> flask.Response: | ||
| """Endpoint to create a single point in 3D space.""" | ||
| print(f"create_point : {flask.request=}", flush=True) | ||
| utils_functions.validate_request(flask.request, create_point_json) | ||
|
|
||
| try: | ||
| # Extract and validate data from request | ||
| request_data = cast(CreatePointRequest, flask.request.json) | ||
| name: str = request_data["name"] | ||
| x: float = request_data["x"] | ||
| y: float = request_data["y"] | ||
| z: float = request_data["z"] | ||
|
|
||
| # Create the point set | ||
| class_ = geode_functions.geode_object_class("PointSet3D") | ||
| point_set = class_.create() | ||
| builder = geode_functions.create_builder("PointSet3D", point_set) | ||
| builder.create_point(opengeode.Point3D([x, y, z])) # type: ignore | ||
| builder.set_name(name) | ||
|
|
||
| # Save and get info | ||
| result = save_all_viewables_and_return_info( | ||
| geode_object="PointSet3D", | ||
| data=point_set, | ||
| ) | ||
|
|
||
| # Vérifier que binary_light_viewable est présent | ||
| if "binary_light_viewable" not in result: | ||
| raise ValueError("binary_light_viewable is missing in the result") | ||
|
|
||
| # Prepare response | ||
| response: Dict[str, Any] = { | ||
| "viewable_file_name": result["viewable_file_name"], | ||
| "id": result["id"], | ||
| "name": name, | ||
| "native_file_name": result["native_file_name"], | ||
| "object_type": result["object_type"], | ||
| "geode_object": result["geode_object"], | ||
| "binary_light_viewable": result["binary_light_viewable"], | ||
| } | ||
|
|
||
| return flask.make_response(response, 200) | ||
|
|
||
| except Exception as e: | ||
| return flask.make_response({"error": str(e)}, 500) | ||
|
|
||
| # Load schema for AOI creation | ||
| with open(os.path.join(schemas, "create_aoi.json"), "r") as file: | ||
| create_aoi_json = cast(Dict[str, Any], json.load(file)) | ||
|
|
||
| @routes.route( | ||
| create_aoi_json["route"], | ||
| methods=create_aoi_json["methods"] | ||
| ) | ||
| def create_aoi() -> flask.Response: | ||
| """Endpoint to create an Area of Interest (AOI) as an EdgedCurve3D.""" | ||
| print(f"create_aoi : {flask.request=}", flush=True) | ||
| utils_functions.validate_request(flask.request, create_aoi_json) | ||
|
|
||
| try: | ||
BotellaA marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # Extract and validate data from request | ||
| request_data = cast(CreateAOIRequest, flask.request.json) | ||
| name: str = request_data["name"] | ||
| points: List[Point] = request_data["points"] | ||
| z: float = request_data["z"] | ||
|
|
||
| # Create the edged curve | ||
| class_ = geode_functions.geode_object_class("EdgedCurve3D") | ||
| edged_curve = class_.create() | ||
| builder = geode_functions.create_builder("EdgedCurve3D", edged_curve) | ||
| builder.set_name(name) | ||
|
|
||
| # Create vertices first | ||
| vertex_indices: List[int] = [] | ||
| for point in points: | ||
| vertex_id = builder.create_point(opengeode.Point3D([point["x"], point["y"], z])) # type: ignore | ||
| vertex_indices.append(vertex_id) | ||
|
|
||
| # Create edges between consecutive vertices and close the loop | ||
| num_vertices = len(vertex_indices) | ||
| for i in range(num_vertices): | ||
| next_i = (i + 1) % num_vertices | ||
| edge_id = builder.create_edge() | ||
| builder.set_edge_vertex(opengeode.EdgeVertex(edge_id, 0), vertex_indices[i]) # type: ignore | ||
| builder.set_edge_vertex(opengeode.EdgeVertex(edge_id, 1), vertex_indices[next_i]) # type: ignore | ||
|
|
||
| # Save and get info | ||
| result = save_all_viewables_and_return_info( | ||
| geode_object="EdgedCurve3D", | ||
| data=edged_curve, | ||
| ) | ||
|
|
||
| # Vérifier que binary_light_viewable est présent | ||
| if "binary_light_viewable" not in result: | ||
| raise ValueError("binary_light_viewable is missing in the result") | ||
|
|
||
| # Prepare response | ||
| response: Dict[str, Any] = { | ||
| "viewable_file_name": result["viewable_file_name"], | ||
| "id": result["id"], | ||
| "name": name, | ||
| "native_file_name": result["native_file_name"], | ||
| "object_type": result["object_type"], | ||
| "geode_object": result["geode_object"], | ||
| "binary_light_viewable": result["binary_light_viewable"], | ||
| } | ||
|
|
||
| return flask.make_response(response, 200) | ||
|
|
||
| except Exception as e: | ||
| return flask.make_response({"error": str(e)}, 500) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.