refactored nodes and implemented API function
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from quart import Blueprint, jsonify, request, abort
|
||||
from internal.db_wrappers import System, SystemDbController
|
||||
from internal.db_wrappers import SystemDbController
|
||||
from werkzeug.exceptions import HTTPException
|
||||
from internal.types import System
|
||||
|
||||
systems_bp = Blueprint('systems', __name__)
|
||||
db_h = SystemDbController()
|
||||
@@ -257,3 +258,29 @@ async def dismiss_client_from_system_route(system_id: str):
|
||||
except Exception as e:
|
||||
print(f"Error during system de-assignment: {e}")
|
||||
abort(500, f"Internal server error: {e}")
|
||||
|
||||
|
||||
@systems_bp.route('/search', methods=['GET'])
|
||||
async def search_systems_route():
|
||||
"""
|
||||
API endpoint to search for systems based on query parameters.
|
||||
Allows searching by 'name', 'frequency_khz', or any other field present in the System model.
|
||||
Example: /systems/search?name=MySystem&frequency_khz=1000
|
||||
"""
|
||||
print("\n--- Handling GET /systems/search ---")
|
||||
try:
|
||||
query_params = dict(request.args)
|
||||
|
||||
systems = await db_h.find_systems(query_params)
|
||||
|
||||
if systems:
|
||||
# If systems are found, return them as a list of dictionaries
|
||||
return jsonify([system.to_dict() for system in systems]), 200 # 200 OK
|
||||
else:
|
||||
# If no systems match the query, return 404 Not Found
|
||||
return jsonify({"message": "No systems found matching the criteria"}), 404
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception as e:
|
||||
print(f"Error searching systems: {e}")
|
||||
abort(500, f"Internal server error: {e}")
|
||||
|
||||
Reference in New Issue
Block a user