Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions backend/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ REDIS_PASSWORD=<your_redis_password_here>
REDIS_URL=redis://:your_redis_password_here@localhost:6379/0

# Frontend URL
# Staging: http://localhost:3000
FRONTEND_URL=http://localhost:5173

# Backend Port
# Staging: 8000
PORT=5050
3 changes: 2 additions & 1 deletion backend/models/post.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ def to_dict(self):
"downvotes": self.downvotes,
"created_at": self.created_at.isoformat() if self.created_at else None,
"user_id": self.user_id,
"author": self.user.username if hasattr(self, 'user') and self.user else None
"author": self.user.username if hasattr(self, 'user') and self.user else None,
"comment_count": len(self.comments) if self.comments else 0
}

def __repr__(self):
Expand Down
49 changes: 49 additions & 0 deletions backend/routes/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,52 @@ def get_user_comments_count(username):
count = Comment.query.filter_by(user_id=user.id).count()
return jsonify({"count": count}), 200

# GET POSTS USER HAS VOTED ON
@user_bp.route('/users/<string:username>/voted-posts', methods=['GET'])
def get_user_voted_posts(username):
"""Get all posts that a user has voted on"""
user = User.query.filter_by(username=username).first()
if not user:
return jsonify({"msg": "User not found"}), 404

# Get all votes by this user with their associated posts
votes = Vote.query.filter_by(user_id=user.id).all()

# Get the posts and include user's vote type
posts_with_votes = []
for vote in votes:
post = BlogPost.query.get(vote.post_id)
if post:
post_dict = post.to_dict()
post_dict['user_vote'] = vote.vote_type
posts_with_votes.append(post_dict)

return jsonify(posts_with_votes), 200

# GET POSTS USER HAS COMMENTED ON
@user_bp.route('/users/<string:username>/commented-posts', methods=['GET'])
def get_user_commented_posts(username):
"""Get all posts that a user has commented on, with their comment preview"""
user = User.query.filter_by(username=username).first()
if not user:
return jsonify({"msg": "User not found"}), 404

# Get distinct posts user has commented on
# For each post, include user's most recent comment as a preview
comments = Comment.query.filter_by(user_id=user.id).order_by(Comment.created_at.desc()).all()

# Track unique posts and their most recent comment from this user
seen_posts = {}
for comment in comments:
if comment.post_id not in seen_posts:
post = BlogPost.query.get(comment.post_id)
if post:
post_dict = post.to_dict()
post_dict['user_comment'] = {
'content': comment.content,
'created_at': comment.created_at.isoformat() if comment.created_at else None
}
seen_posts[comment.post_id] = post_dict

return jsonify(list(seen_posts.values())), 200

4 changes: 4 additions & 0 deletions frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@

<!-- Bootstrap icons-->
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.5.0/font/bootstrap-icons.css" rel="stylesheet" />

<!-- Cloudflare Turnstile - preload for faster CAPTCHA rendering -->
<link rel="preconnect" href="https://challenges.cloudflare.com">
<script src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer></script>
</head>
<body>
<div id="root"></div>
Expand Down
Loading