From 451994b755eecfcbb462c86a7ce72feff916ad33 Mon Sep 17 00:00:00 2001 From: EvanLin3141 Date: Sat, 1 Mar 2025 23:18:26 +0000 Subject: [PATCH] FIX: Followed Categories --- frontend/src/pages/FollowedCategories.tsx | 4 +-- web_server/blueprints/streams.py | 12 +++++++ web_server/database/testing_data.sql | 42 +++++++++++------------ web_server/utils/recommendation_utils.py | 14 ++++++++ 4 files changed, 49 insertions(+), 23 deletions(-) diff --git a/frontend/src/pages/FollowedCategories.tsx b/frontend/src/pages/FollowedCategories.tsx index d870236..430a84e 100644 --- a/frontend/src/pages/FollowedCategories.tsx +++ b/frontend/src/pages/FollowedCategories.tsx @@ -32,7 +32,7 @@ const FollowedCategories: React.FC = ({ extraClasses = "" const fetchFollowedCategories = async () => { try { - const response = await fetch("/api/categories/following"); + const response = await fetch("/api/categories/your_categories"); if (!response.ok) throw new Error("Failed to fetch followed categories"); const data = await response.json(); setFollowedCategories(data); @@ -52,7 +52,7 @@ const FollowedCategories: React.FC = ({ extraClasses = "" className={`top-0 left-0 w-screen h-screen overflow-x-hidden flex flex-col bg-[var(--sideBar-bg)] text-[var(--sideBar-text)] text-center overflow-y-auto scrollbar-hide transition-all duration-500 ease-in-out ${extraClasses}`} > {/* Followed Categories */} -
+
{followedCategories.map((category) => { return (
/status') def user_live_status(username): diff --git a/web_server/database/testing_data.sql b/web_server/database/testing_data.sql index cfcbcb4..8cef0a2 100644 --- a/web_server/database/testing_data.sql +++ b/web_server/database/testing_data.sql @@ -107,28 +107,28 @@ INSERT INTO streams (user_id, title, start_time, category_id) VALUES (3, 'Sketching Live', '2025-01-24 15:00:00', 3), (4, 'Math Made Easy', '2025-01-23 10:00:00', 4), (5, 'Sports Highlights', '2025-02-15 23:00:00', 5), -(6, 'Genshin1', '2025-02-17 18:00:00', 22), -(7, 'Genshin2', '2025-02-18 19:00:00', 22), -(8, 'Genshin3', '2025-02-19 20:00:00', 22), -(9, 'Genshin4', '2025-02-20 14:00:00', 22), -(10, 'Genshin5', '2025-02-21 09:00:00', 22), -(11, 'Genshin6', '2025-02-22 11:00:00', 22), -(12, 'Genshin7', '2025-02-23 21:00:00', 22), -(13, 'Genshin8', '2025-02-24 16:00:00', 22), -(14, 'Genshin9', '2025-02-25 22:00:00', 22), -(15, 'Genshin10', '2025-02-26 18:30:00', 22), -(16, 'Genshin11', '2025-02-27 17:00:00', 22), -(17, 'Genshin12', '2025-02-28 15:00:00', 22), -(18, 'Genshin13', '2025-03-01 10:00:00', 22), -(19, 'Genshin14', '2025-03-02 20:00:00', 22), -(20, 'Genshin15', '2025-03-03 13:00:00', 22), -(21, 'Genshin16', '2025-03-04 09:00:00', 22), +(6, 'Genshin1', '2025-02-17 18:00:00', 6), +(7, 'Genshin2', '2025-02-18 19:00:00', 7), +(8, 'Genshin3', '2025-02-19 20:00:00', 8), +(9, 'Genshin4', '2025-02-20 14:00:00', 9), +(10, 'Genshin5', '2025-02-21 09:00:00', 10), +(11, 'Genshin6', '2025-02-22 11:00:00', 11), +(12, 'Genshin7', '2025-02-23 21:00:00', 12), +(13, 'Genshin8', '2025-02-24 16:00:00', 13), +(14, 'Genshin9', '2025-02-25 22:00:00', 14), +(15, 'Genshin10', '2025-02-26 18:30:00', 15), +(16, 'Genshin11', '2025-02-27 17:00:00', 16), +(17, 'Genshin12', '2025-02-28 15:00:00', 17), +(18, 'Genshin13', '2025-03-01 10:00:00', 18), +(19, 'Genshin14', '2025-03-02 20:00:00', 19), +(20, 'Genshin15', '2025-03-03 13:00:00', 20), +(21, 'Genshin16', '2025-03-04 09:00:00', 21), (22, 'Genshin17', '2025-03-05 12:00:00', 22), -(23, 'Genshin18', '2025-03-06 14:00:00', 22), -(24, 'Genshin19', '2025-03-07 16:00:00', 22), -(25, 'Genshin20', '2025-03-08 19:00:00', 22), -(26, 'Genshin21', '2025-03-09 21:00:00', 22), -(27, 'Genshin22', '2025-03-10 17:00:00', 11); +(23, 'Genshin18', '2025-03-06 14:00:00', 23), +(24, 'Genshin19', '2025-03-07 16:00:00', 24), +(25, 'Genshin20', '2025-03-08 19:00:00', 25), +(26, 'Genshin21', '2025-03-09 21:00:00', 26), +(27, 'Genshin22', '2025-03-10 17:00:00', 27); -- Sample Data for vods INSERT INTO vods (user_id, title, datetime, category_id, length, views) VALUES diff --git a/web_server/utils/recommendation_utils.py b/web_server/utils/recommendation_utils.py index dbecaa6..a20a3f1 100644 --- a/web_server/utils/recommendation_utils.py +++ b/web_server/utils/recommendation_utils.py @@ -33,6 +33,20 @@ def get_followed_categories_recommendations(user_id: int, no_streams: int = 4) - """, (user_id, no_streams)) return streams +def get_followed_your_categories(user_id: int) -> Optional[List[dict]]: + """ + Returns all user followed categories + """ + with Database() as db: + categories = db.fetchall(""" + SELECT categories.category_name + FROM categories + JOIN followed_categories + ON categories.category_id = followed_categories.category_id + WHERE followed_categories.user_id = ?; + """, (user_id,)) + return categories + def get_streams_based_on_category(category_id: int, no_streams: int = 4, offset: int = 0) -> Optional[List[dict]]: """