Add photo retrieval endpoint and improve photo upload response
This commit is contained in:
parent
3e0faae851
commit
ca3417c269
2 changed files with 19 additions and 1 deletions
|
|
@ -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/<int:photo_id>", 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}"
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue