FEAT: Added feature to return streamers data given their username
This commit is contained in:
@@ -45,6 +45,16 @@ def get_recommended_streams() -> list[dict]:
|
|||||||
streams = get_streams_based_on_category(category)
|
streams = get_streams_based_on_category(category)
|
||||||
return streams
|
return streams
|
||||||
|
|
||||||
|
@stream_bp.route('/streams/<string:streamer_username>/data')
|
||||||
|
def get_stream(streamer_username):
|
||||||
|
"""
|
||||||
|
Returns a streamer's most recent stream data
|
||||||
|
"""
|
||||||
|
|
||||||
|
user_id = get_user_id(streamer_username)
|
||||||
|
|
||||||
|
return jsonify(get_most_recent_stream(user_id))
|
||||||
|
|
||||||
|
|
||||||
## Category Routes
|
## Category Routes
|
||||||
@stream_bp.route('/categories/popular/<int:no_categories>')
|
@stream_bp.route('/categories/popular/<int:no_categories>')
|
||||||
|
|||||||
Binary file not shown.
@@ -49,7 +49,7 @@ CREATE TABLE streams
|
|||||||
(
|
(
|
||||||
user_id INTEGER NOT NULL PRIMARY KEY,
|
user_id INTEGER NOT NULL PRIMARY KEY,
|
||||||
title TEXT NOT NULL,
|
title TEXT NOT NULL,
|
||||||
datetime DATETIME NOT NULL,
|
start_time DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
num_viewers INTEGER NOT NULL DEFAULT 0,
|
num_viewers INTEGER NOT NULL DEFAULT 0,
|
||||||
category_id INTEGER NOT NULL,
|
category_id INTEGER NOT NULL,
|
||||||
FOREIGN KEY (category_id) REFERENCES categories(category_id),
|
FOREIGN KEY (category_id) REFERENCES categories(category_id),
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ INSERT INTO categories (category_name) VALUES
|
|||||||
('Sports');
|
('Sports');
|
||||||
|
|
||||||
-- Sample Data for streams
|
-- Sample Data for streams
|
||||||
INSERT INTO streams (user_id, title, datetime, num_viewers, category_id) VALUES
|
INSERT INTO streams (user_id, title, start_time, num_viewers, category_id) VALUES
|
||||||
(1, 'Epic Gaming Session', '2025-01-25 18:00:00', 150, 1),
|
(1, 'Epic Gaming Session', '2025-01-25 18:00:00', 150, 1),
|
||||||
(2, 'Live Music Jam', '2025-01-25 20:00:00', 350, 2),
|
(2, 'Live Music Jam', '2025-01-25 20:00:00', 350, 2),
|
||||||
(3, 'Sketching Live', '2025-01-24 15:00:00', 80, 3),
|
(3, 'Sketching Live', '2025-01-24 15:00:00', 80, 3),
|
||||||
|
|||||||
@@ -34,6 +34,20 @@ def get_followed_live_streams(user_id: int) -> Optional[List[dict]]:
|
|||||||
""", (user_id,))
|
""", (user_id,))
|
||||||
return live_streams
|
return live_streams
|
||||||
|
|
||||||
|
def get_most_recent_stream(user_id: int) -> Optional[dict]:
|
||||||
|
"""
|
||||||
|
Returns data of the most recent stream by a streamer
|
||||||
|
"""
|
||||||
|
with Database() as db:
|
||||||
|
most_recent_stream = db.fetchone("""
|
||||||
|
SELECT s.user_id, u.username, s.title, s.start_time, s.num_viewers, c.category_name
|
||||||
|
FROM streams AS s
|
||||||
|
JOIN categories AS c ON s.category_id = c.category_id
|
||||||
|
JOIN users AS u ON s.user_id = u.user_id
|
||||||
|
WHERE u.user_id = ?
|
||||||
|
""", (user_id,))
|
||||||
|
return most_recent_stream
|
||||||
|
|
||||||
def get_vod(vod_id: int) -> dict:
|
def get_vod(vod_id: int) -> dict:
|
||||||
"""
|
"""
|
||||||
Returns data of a streamers vod
|
Returns data of a streamers vod
|
||||||
|
|||||||
Reference in New Issue
Block a user