diff --git a/inventory/__init__.py b/inventory/__init__.py index 91a4ea7..dd5fa9d 100644 --- a/inventory/__init__.py +++ b/inventory/__init__.py @@ -3,6 +3,7 @@ from flask_sqlalchemy import SQLAlchemy import logging import os + db = SQLAlchemy() logger = logging.getLogger('sqlalchemy.engine') @@ -25,6 +26,8 @@ def create_app(): # db.create_all() from .routes import main + from .routes.photos import photo_bp app.register_blueprint(main) + app.register_blueprint(photo_bp) return app diff --git a/inventory/routes/photos.py b/inventory/routes/photos.py index 915d27a..3297620 100644 --- a/inventory/routes/photos.py +++ b/inventory/routes/photos.py @@ -1,7 +1,7 @@ import os import datetime -from flask import Blueprint, current_app, request, jsonify +from flask import Blueprint, current_app, request, jsonify, send_from_directory from .helpers import generate_hashed_filename, get_photo_attachable_class_by_name from .. import db @@ -58,3 +58,18 @@ def upload_photo(): db.session.commit() return jsonify({"success": True, "id": photo.id}), 201 + +@photo_bp.route("/api/photos/", methods=["GET"]) +def get_photo(photo_id: int): + photo = db.session.get(Photo, photo_id) + if not photo: + return jsonify({"success": False, "error": f"No photo found with ID {photo_id}"}), 404 + + return jsonify({ + "success": True, + "id": photo.id, + "filename": photo.filename, + "caption": photo.caption, + "timestamp": photo.timestamp.isoformat() if photo.timestamp else None, + "url": f"/static/{photo.filename}" + })