-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add querying endpoints for filters #5
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,4 +2,4 @@ Flask==3.0.0 | |
| Flask-CORS==4.0.0 | ||
| Flask-SQLAlchemy==3.1.1 | ||
| python-dotenv==1.0.0 | ||
| SQLAlchemy==2.0.23 | ||
| SQLAlchemy==2.0.35 | ||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,6 @@ | ||||||||||
| from flask import Blueprint, request, jsonify | ||||||||||
| from database import db | ||||||||||
| from sqlalchemy import or_ | ||||||||||
| from models import StudySpot | ||||||||||
| from datetime import datetime | ||||||||||
| import logging | ||||||||||
|
|
@@ -59,6 +60,73 @@ def health_check(): | |||||||||
|
|
||||||||||
| TIME_PATTERN = re.compile(r'^([01]\d|2[0-3]):([0-5]\d)$') | ||||||||||
|
|
||||||||||
| @api_bp.route('/schema', methods=['GET']) | ||||||||||
| def get_schema(): | ||||||||||
| """Return database schema information.""" | ||||||||||
| try: | ||||||||||
|
Comment on lines
+63
to
+66
|
||||||||||
| # Get all tables | ||||||||||
| inspector = db.inspect(db.engine) | ||||||||||
| tables = inspector.get_table_names() | ||||||||||
|
||||||||||
|
|
||||||||||
| schema = {} | ||||||||||
| for table in tables: | ||||||||||
| columns = inspector.get_columns(table) | ||||||||||
| schema[table] = { | ||||||||||
| 'columns': [ | ||||||||||
| { | ||||||||||
| 'name': col['name'], | ||||||||||
| 'type': str(col['type']), | ||||||||||
| 'nullable': col['nullable'], | ||||||||||
| 'default': str(col['default']) if col['default'] else None | ||||||||||
|
||||||||||
| 'default': str(col['default']) if col['default'] else None | |
| 'default': str(col['default']) if col['default'] is not None else None |
Copilot
AI
Mar 2, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/study_spots/raw currently returns the same payload as the existing /study_spots endpoint (to_dict() for all rows), but adds another route that fetches the entire table without pagination. If this is meant for debugging/admin use, consider gating it (auth/env flag) or adding pagination/limits; otherwise it’s redundant and increases maintenance surface.
Outdated
Copilot
AI
Mar 2, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/study_spots/distinct/access_hours returns ['true','false'], which doesn’t represent distinct access_hours values and also encodes booleans as strings. If the intent is an “open now” filter, consider using a dedicated route/column name (e.g., open_now) and return JSON booleans (true/false) to avoid confusing API consumers.
| # For open now, return boolean options | |
| return jsonify(['true', 'false']), 200 | |
| # For open now, return boolean options as JSON booleans | |
| return jsonify([True, False]), 200 |
Copilot
AI
Mar 2, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For spot_type/tags, this endpoint loads all StudySpot rows into memory to compute distinct values. That won’t scale as the table grows; prefer doing this in the database (e.g., via JSON table-valued functions / json_each/jsonb_array_elements depending on the DB) or add a reasonable cap and/or caching strategy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused import:
or_is added but not referenced anywhere in this file. Please remove it to avoid lint issues and keep imports minimal.