FEAT UPDATE: Updated Utils to use new database. Changed route arguments. Added unfollow feature
This commit is contained in:
@@ -4,7 +4,8 @@ from utils.stream_utils import (
|
||||
streamer_most_recent_stream,
|
||||
user_stream,
|
||||
followed_live_streams,
|
||||
followed_streamers
|
||||
followed_streamers,
|
||||
stream_tags
|
||||
)
|
||||
from utils.user_utils import get_user_id
|
||||
from blueprints.utils import login_required
|
||||
@@ -34,7 +35,8 @@ def get_sample_streams() -> list[dict]:
|
||||
|
||||
# shows default recommended streams for non-logged in users based on highest viewers
|
||||
streams = default_recommendations()
|
||||
|
||||
for stream in streams:
|
||||
stream['tags'] = stream_tags(stream["stream_id"])
|
||||
|
||||
return jsonify(streams)
|
||||
|
||||
@@ -48,6 +50,8 @@ def get_recommended_streams() -> list[dict]:
|
||||
user_id = session.get("username")
|
||||
category = user_recommendation_category(user_id)
|
||||
streams = recommendations_based_on_category(category)
|
||||
for stream in streams:
|
||||
stream['tags'] = stream_tags(stream["stream_id"])
|
||||
return jsonify(streams)
|
||||
|
||||
@stream_bp.route('/get_categories')
|
||||
@@ -120,12 +124,16 @@ def get_stream(streamer_username):
|
||||
return jsonify(streamer_most_recent_stream(user_id))
|
||||
|
||||
@login_required
|
||||
@stream_bp.route('/get_followed_categories')
|
||||
@stream_bp.route('/get_followed_category_streams')
|
||||
def get_following_categories_streams():
|
||||
"""
|
||||
Returns popular streams in categories which the user followed
|
||||
"""
|
||||
|
||||
streams = followed_categories_recommendations(get_user_id(session.get('username')))
|
||||
|
||||
for stream in streams:
|
||||
stream['tags'] = stream_tags(stream["stream_id"])
|
||||
return jsonify(streams)
|
||||
|
||||
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
from flask import Blueprint, jsonify, session
|
||||
from utils.user_utils import is_subscribed, is_following, subscription_expiration, verify_token, reset_password
|
||||
from utils.user_utils import is_subscribed, is_following, subscription_expiration, verify_token, reset_password, get_user_id, unfollow
|
||||
from blueprints.utils import login_required
|
||||
|
||||
user_bp = Blueprint("user", __name__)
|
||||
|
||||
|
||||
@user_bp.route('/is_subscribed/<int:user_id>/<int:subscribed_id>')
|
||||
def user_subscribed(user_id: int, subscribed_id: int):
|
||||
@login_required
|
||||
@user_bp.route('/is_subscribed/<int:subscribed_id>')
|
||||
def user_subscribed(subscribed_id: int):
|
||||
"""
|
||||
Checks to see if user is subscribed to another user
|
||||
"""
|
||||
user_id = session.get("user_id")
|
||||
if is_subscribed(user_id, subscribed_id):
|
||||
return jsonify({"subscribed": True})
|
||||
return jsonify({"subscribed": False})
|
||||
@@ -22,12 +24,27 @@ def user_following(user_id: int, subscribed_id: int):
|
||||
return jsonify({"following": True})
|
||||
return jsonify({"following": False})
|
||||
|
||||
@login_required
|
||||
@user_bp.route('/unfollow/<int:username>')
|
||||
def user_unfollow(followed_username):
|
||||
"""
|
||||
Unfollows a user
|
||||
"""
|
||||
user_id = session.get("user_id")
|
||||
followed_id = get_user_id(followed_username)
|
||||
response = unfollow(user_id, followed_id)
|
||||
|
||||
@user_bp.route('/subscription_remaining/<int:user_id>/<int:streamer_id>')
|
||||
def user_subscription_expiration(user_id: int, streamer_id: int):
|
||||
status = True if response else False
|
||||
return jsonify({"status": status})
|
||||
|
||||
@login_required
|
||||
@user_bp.route('/subscription_remaining/<int:streamer_id>')
|
||||
def user_subscription_expiration(streamer_id: int):
|
||||
"""
|
||||
Returns remaining time until subscription expiration
|
||||
"""
|
||||
|
||||
user_id = session.get("user_id")
|
||||
remaining_time = subscription_expiration(user_id, streamer_id)
|
||||
|
||||
return jsonify({"remaining_time": remaining_time})
|
||||
@@ -69,4 +86,4 @@ def user_reset_password(token, new_password):
|
||||
return "Success"
|
||||
else:
|
||||
return "Failure"
|
||||
return "Failure"
|
||||
return "Failure"
|
||||
Reference in New Issue
Block a user