PATCH: Fixed a load of broken user routes
This commit is contained in:
@@ -52,23 +52,28 @@ def user_following(user_id: int, followed_id: int):
|
||||
|
||||
@login_required
|
||||
@user_bp.route('/user/follow/<string:username>')
|
||||
def follow(username):
|
||||
def follow_user(username):
|
||||
"""
|
||||
Follows a user
|
||||
"""
|
||||
user_id = session.get("user_id")
|
||||
following_id = get_user_id(username)
|
||||
follow(user_id, following_id)
|
||||
if follow(user_id, following_id):
|
||||
return jsonify({"success": True,
|
||||
"already_following": False})
|
||||
return jsonify({"success": True,
|
||||
"already_following": True})
|
||||
|
||||
@login_required
|
||||
@user_bp.route('/user/unfollow/<string:username>')
|
||||
def user_unfollow(followed_username):
|
||||
def unfollow_user(username):
|
||||
"""
|
||||
Unfollows a user
|
||||
"""
|
||||
user_id = session.get("user_id")
|
||||
followed_id = get_user_id(followed_username)
|
||||
followed_id = get_user_id(username)
|
||||
unfollow(user_id, followed_id)
|
||||
return jsonify({"success": True})
|
||||
|
||||
@login_required
|
||||
@user_bp.route('/user/following')
|
||||
@@ -88,7 +93,10 @@ def get_login_status():
|
||||
Returns whether the user is logged in or not
|
||||
"""
|
||||
username = session.get("username")
|
||||
return jsonify({'status': username is not None, 'username': username})
|
||||
user_id = session.get("user_id")
|
||||
return jsonify({'status': username is not None,
|
||||
'username': username,
|
||||
'user_id': user_id})
|
||||
|
||||
@user_bp.route('/user/forgot_password/<string:email>', methods=['GET','POST'])
|
||||
def user_forgot_password(email):
|
||||
|
||||
Binary file not shown.
@@ -124,9 +124,7 @@ LIMIT 10;
|
||||
INSERT INTO follows (user_id, followed_id, since) VALUES
|
||||
(7, 1, '2024-08-30'),
|
||||
(7, 2, '2024-08-30'),
|
||||
(7, 3, '2024-08-30'),
|
||||
(7, 4, '2024-08-30'),
|
||||
(7, 5, '2024-08-30');
|
||||
(7, 3, '2024-08-30');
|
||||
|
||||
INSERT INTO followed_categories (user_id, category_id) VALUES
|
||||
(7, 1),
|
||||
@@ -134,5 +132,5 @@ INSERT INTO followed_categories (user_id, category_id) VALUES
|
||||
(7, 3);
|
||||
|
||||
INSERT INTO subscribes (user_id, subscribed_id, since, expires) VALUES
|
||||
(7, 1, '2024-08-30', '2025-02-28'),
|
||||
(7, 1, '2024-08-30', '2025-02-28 12:00:00'),
|
||||
(7, 2, '2024-08-30', '2025-02-15');
|
||||
@@ -27,3 +27,4 @@ gevent-websocket
|
||||
flask-oauthlib==0.9.6
|
||||
celery==5.2.3
|
||||
redis==5.2.1
|
||||
python-dateutil
|
||||
@@ -4,6 +4,7 @@ from datetime import datetime
|
||||
from itsdangerous import URLSafeTimedSerializer
|
||||
from os import getenv
|
||||
from werkzeug.security import generate_password_hash, check_password_hash
|
||||
from dateutil import parser
|
||||
from dotenv import load_dotenv
|
||||
load_dotenv()
|
||||
|
||||
@@ -91,29 +92,28 @@ def follow(user_id: int, following_id: int):
|
||||
"""
|
||||
Follows following_id user from user_id user
|
||||
"""
|
||||
with Database() as db:
|
||||
data = db.execute("""
|
||||
SELECT * FROM follows
|
||||
WHERE user_id = ?
|
||||
AND followed_id = ?
|
||||
""", (user_id, following_id))
|
||||
|
||||
if not data:
|
||||
if not is_following(user_id, following_id):
|
||||
with Database() as db:
|
||||
db.execute("""
|
||||
INSERT INTO follows (user_id, followed_id)
|
||||
VALUES(?,?)
|
||||
VALUES(?,?);
|
||||
""", (user_id, following_id))
|
||||
return True
|
||||
return False
|
||||
|
||||
def unfollow(user_id: int, followed_id: int):
|
||||
"""
|
||||
Unfollows follow_id user from user_id user
|
||||
"""
|
||||
with Database() as db:
|
||||
db.execute("""
|
||||
DELETE FROM follows
|
||||
WHERE user_id = ?
|
||||
AND followed_id = ?
|
||||
""", (user_id, followed_id))
|
||||
if is_following(user_id, followed_id):
|
||||
with Database() as db:
|
||||
db.execute("""
|
||||
DELETE FROM follows
|
||||
WHERE user_id = ?
|
||||
AND followed_id = ?
|
||||
""", (user_id, followed_id))
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def subscription_expiration(user_id: int, subscribed_id: int) -> int:
|
||||
@@ -131,7 +131,7 @@ def subscription_expiration(user_id: int, subscribed_id: int) -> int:
|
||||
|
||||
if data:
|
||||
expiration_date = data["expires"]
|
||||
remaining_time = (expiration_date - datetime.now()).seconds
|
||||
remaining_time = (parser.parse(expiration_date) - datetime.now()).seconds
|
||||
return remaining_time
|
||||
|
||||
return 0
|
||||
|
||||
Reference in New Issue
Block a user