Skip to content

Commit

Permalink
Merge pull request #32 from grant-baer/wiring_up_db_to_backend
Browse files Browse the repository at this point in the history
Wiring up db to backend
  • Loading branch information
gp-sb authored Nov 13, 2023
2 parents a511329 + 09e9237 commit 90e63d4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 15 deletions.
15 changes: 3 additions & 12 deletions Backend/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
from werkzeug.security import check_password_hash
import secrets # For generating a session key

from datetime import datetime
from datetime import datetime

from db_access import User
from db_access import User
from db_access import Image


Expand All @@ -26,21 +26,18 @@
@app.route("/store_image", methods=["POST"])
def store_image():
data = request.get_json()

# Validate required fields
required_fields = ["creator", "prompt", "url"]
for field in required_fields:
if field not in data:
return jsonify({"error": f"Missing field: {field}"}), 400

# Retrieve creator user by user
try:
creator = User.objects.get(username=data["creator"])
except DoesNotExist:
return jsonify({"error": "Creator user does not exist."}), 404
except Exception as e:
return jsonify({"error": str(e)}), 400

try:
image = Image(
creator=creator,
Expand All @@ -59,13 +56,7 @@ def store_image():
return jsonify({"error": str(e)}), 500
data = request.get_json()
text = data["text"]
# In the future, create obj that stores:
# - Timestamp
# - Prompt
# - Image URL (placeholder till we send prompt to Dalle)
# - Author
# - Votes
# For now, we'll just print it.

print(text)
return jsonify({"message": "Text logged successfully!"})

Expand Down
3 changes: 0 additions & 3 deletions Backend/db_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,12 @@
# MongoDB connection
connect(db="dbPicturePerfect", host="localhost", port=27017)


class User(Document):
username = StringField(required=True, unique=True)
email = StringField(required=True)
encrypted_password = StringField(
required=True
)


ranking = IntField()

meta = {"collection": "users"}
Expand Down

0 comments on commit 90e63d4

Please sign in to comment.