UPDATE/REFACTOR: Change how followed content is obtained for Sidebar
This commit is contained in:
@@ -132,14 +132,15 @@ def user_unfollow(target_user_id: int):
|
||||
|
||||
@login_required
|
||||
@user_bp.route('/user/following')
|
||||
def user_followed_streamers():
|
||||
def user_followed_content():
|
||||
"""
|
||||
Queries DB to get a list of followed streamers
|
||||
Queries DB to get a dict of followed users and categories
|
||||
"""
|
||||
user_id = session.get('user_id')
|
||||
|
||||
live_following_streams = get_followed_streamers(user_id)
|
||||
return live_following_streams
|
||||
streams = get_followed_streamers(user_id)
|
||||
categories = get_followed_categories(user_id)
|
||||
return jsonify({"streams": streams, "categories": categories})
|
||||
|
||||
@login_required
|
||||
@user_bp.route('/user/category/follow/<string:category_name>')
|
||||
|
||||
@@ -216,6 +216,16 @@ def get_email(user_id: int) -> Optional[str]:
|
||||
def get_followed_streamers(user_id: int) -> Optional[List[dict]]:
|
||||
"""
|
||||
Returns a list of streamers who the user follows
|
||||
|
||||
Returns:
|
||||
List of dictionaries with the following structure:
|
||||
[
|
||||
{
|
||||
"user_id": int,
|
||||
"username": str
|
||||
},
|
||||
...
|
||||
]
|
||||
"""
|
||||
with Database() as db:
|
||||
followed_streamers = db.fetchall("""
|
||||
@@ -225,6 +235,28 @@ def get_followed_streamers(user_id: int) -> Optional[List[dict]]:
|
||||
""", (user_id,))
|
||||
return followed_streamers
|
||||
|
||||
def get_followed_categories(user_id: int) -> Optional[List[dict]]:
|
||||
"""
|
||||
Returns a list of categories that the user follows
|
||||
|
||||
Returns:
|
||||
List of dictionaries with the following structure:
|
||||
[
|
||||
{
|
||||
"category_id": int,
|
||||
"category_name": str
|
||||
},
|
||||
...
|
||||
]
|
||||
"""
|
||||
with Database() as db:
|
||||
followed_categories = db.fetchall("""
|
||||
SELECT category_id, category_name
|
||||
FROM categories
|
||||
WHERE category_id IN (SELECT category_id FROM followed_categories WHERE user_id = ?);
|
||||
""", (user_id,))
|
||||
return followed_categories
|
||||
|
||||
def get_user(user_id: int) -> Optional[dict]:
|
||||
"""
|
||||
Returns information about a user from user_id
|
||||
|
||||
Reference in New Issue
Block a user