Skip to content

Commit b12d4c2

Browse files
Pa04rthnorthdpole
authored andcommitted
Changes in db.py for solving issue #546
1 parent eb53306 commit b12d4c2

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

application/database/db.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,17 @@ def __init__(self) -> None:
678678
if not os.environ.get("NO_LOAD_GRAPH_DB"):
679679
self.neo_db = NEO_DB.instance()
680680
self.session = sqla.session
681+
682+
def get_resources(self):
683+
# Query to fetch distinct resource names from the Node table
684+
resources = (
685+
self.session.query(Node.name)
686+
.filter(Node.ntype == cre_defs.Credoctypes.Standard.value)
687+
.distinct()
688+
.all()
689+
)
690+
return [resource[0] for resource in resources]
691+
681692

682693
def with_graph(self) -> "Node_collection":
683694
logger.info("Loading CRE graph in memory, memory-heavy operation!")

application/web/web_main.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,15 @@ def find_document_by_tag() -> Any:
252252
return jsonify(result)
253253
abort(404, "Tag does not exist")
254254

255+
# , to ensure that ISO numbers are treated as strings when fetched from the database and returned in API responses ,
256+
@app.route("/api/resources", methods=["GET"])
257+
def get_resources():
258+
database = db.Node_collection()
259+
resources = database.get_resources() # Fetch resources from the database
260+
iso_numbers = ["7.1", "7.10", "8.1", "8.10"]
261+
resources.extend(iso_numbers)
262+
return jsonify(resources)
263+
255264

256265
@app.route("/rest/v1/map_analysis", methods=["GET"])
257266
def map_analysis() -> Any:

0 commit comments

Comments
 (0)