PATCH: Fix to Database Changes
This commit is contained in:
@@ -78,13 +78,15 @@ def signup():
|
|||||||
# Create new user once input is validated
|
# Create new user once input is validated
|
||||||
cursor.execute(
|
cursor.execute(
|
||||||
"""INSERT INTO users
|
"""INSERT INTO users
|
||||||
(username, password, email, num_followers, bio)
|
(username, password, email, num_followers, stream_key, is_partnered, bio)
|
||||||
VALUES (?, ?, ?, ?, ?)""",
|
VALUES (?, ?, ?, ?, ?, ?, ?)""",
|
||||||
(
|
(
|
||||||
username,
|
username,
|
||||||
generate_password_hash(password),
|
generate_password_hash(password),
|
||||||
email,
|
email,
|
||||||
0,
|
0,
|
||||||
|
'1',
|
||||||
|
0,
|
||||||
"This user does not have a Bio."
|
"This user does not have a Bio."
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
from flask import Blueprint, session
|
from flask import Blueprint, session, jsonify
|
||||||
from utils.stream_utils import streamer_data, streamer_id, streamer_live_status, streamer_most_recent_stream, streamer_stream, followed_live_streams
|
from utils.stream_utils import streamer_live_status, streamer_most_recent_stream, user_stream, followed_live_streams
|
||||||
from utils.user_utils import get_user_id
|
from utils.user_utils import get_user_id
|
||||||
from database.database import Database
|
from database.database import Database
|
||||||
stream_bp = Blueprint("stream", __name__)
|
stream_bp = Blueprint("stream", __name__)
|
||||||
|
|
||||||
|
|
||||||
@@ -24,7 +24,9 @@ def get_sample_streams() -> list[dict]:
|
|||||||
streams = cursor.execute("""SELECT * FROM streams
|
streams = cursor.execute("""SELECT * FROM streams
|
||||||
ORDER BY num_viewers DESC
|
ORDER BY num_viewers DESC
|
||||||
LIMIT 25; """).fetchall()
|
LIMIT 25; """).fetchall()
|
||||||
return streams
|
return jsonify({
|
||||||
|
"streams": streams
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
@stream_bp.route('/get_recommended_streams')
|
@stream_bp.route('/get_recommended_streams')
|
||||||
@@ -60,7 +62,7 @@ def get_categories() -> list[dict]:
|
|||||||
"""
|
"""
|
||||||
Returns a list of (sample) categories being watched right now
|
Returns a list of (sample) categories being watched right now
|
||||||
"""
|
"""
|
||||||
|
|
||||||
db = Database()
|
db = Database()
|
||||||
cursor = db.create_connection()
|
cursor = db.create_connection()
|
||||||
|
|
||||||
@@ -70,8 +72,7 @@ def get_categories() -> list[dict]:
|
|||||||
GROUP BY category_name
|
GROUP BY category_name
|
||||||
ORDER BY SUM(num_viewers) DESC
|
ORDER BY SUM(num_viewers) DESC
|
||||||
LIMIT 25; """).fetchall()
|
LIMIT 25; """).fetchall()
|
||||||
return categories
|
return jsonify({'categories': categories})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@stream_bp.route('/get_followed_categories')
|
@stream_bp.route('/get_followed_categories')
|
||||||
@@ -91,11 +92,8 @@ def get_streamer_data(streamer_username):
|
|||||||
"""
|
"""
|
||||||
Returns a given streamer's data
|
Returns a given streamer's data
|
||||||
"""
|
"""
|
||||||
streamers_id = streamer_id(streamer_username)
|
return
|
||||||
if not streamers_id:
|
|
||||||
return #whatever
|
|
||||||
streamers_data = streamer_data(streamers_id)
|
|
||||||
return streamers_data
|
|
||||||
|
|
||||||
@stream_bp.route('/streamer/<string:streamer_username>/status')
|
@stream_bp.route('/streamer/<string:streamer_username>/status')
|
||||||
def get_streamer_status(streamer_username):
|
def get_streamer_status(streamer_username):
|
||||||
@@ -105,7 +103,7 @@ def get_streamer_status(streamer_username):
|
|||||||
return {"status": "live", "streamId": 1}
|
return {"status": "live", "streamId": 1}
|
||||||
streamers_id = streamer_id(streamer_username)
|
streamers_id = streamer_id(streamer_username)
|
||||||
if not streamers_id:
|
if not streamers_id:
|
||||||
return #whatever
|
return # whatever
|
||||||
streamer_status = streamer_live_status(streamers_id)
|
streamer_status = streamer_live_status(streamers_id)
|
||||||
stream_id = streamer_most_recent_stream(streamers_id)
|
stream_id = streamer_most_recent_stream(streamers_id)
|
||||||
return {"live": streamer_status, "streamerId": streamers_id, "streamId": stream_id}
|
return {"live": streamer_status, "streamerId": streamers_id, "streamId": stream_id}
|
||||||
@@ -116,28 +114,24 @@ def get_stream(streamer_username):
|
|||||||
"""
|
"""
|
||||||
Returns a streamer's most recent stream data
|
Returns a streamer's most recent stream data
|
||||||
"""
|
"""
|
||||||
streamers_id = streamer_id(streamer_username)
|
return # Whatever
|
||||||
if not streamers_id:
|
|
||||||
return #whatever
|
|
||||||
most_recent_stream = streamer_most_recent_stream(streamers_id)
|
|
||||||
if most_recent_stream:
|
|
||||||
return most_recent_stream
|
|
||||||
|
|
||||||
return #Whatever
|
|
||||||
|
|
||||||
@stream_bp.route('/get_stream_data/<int:streamer_username>/<int:stream_id>', methods=['GET'])
|
@stream_bp.route('/get_stream_data/<int:streamer_username>/<int:stream_id>', methods=['GET'])
|
||||||
def get_specific_stream(streamer_username,stream_id):
|
def get_specific_stream(streamer_username, stream_id):
|
||||||
"""
|
"""
|
||||||
Returns a streamer's stream data given stream_id
|
Returns a streamer's stream data given stream_id
|
||||||
"""
|
"""
|
||||||
stream = streamer_stream(streamer_username, stream_id)
|
stream = user_stream(streamer_username, stream_id)
|
||||||
if stream:
|
if stream:
|
||||||
return stream
|
return stream
|
||||||
|
|
||||||
return #whatever
|
|
||||||
|
|
||||||
#@login_required
|
return # whatever
|
||||||
|
|
||||||
|
# @login_required
|
||||||
# need to add in a lock to this route for only logged in users since we will be taking from the session
|
# need to add in a lock to this route for only logged in users since we will be taking from the session
|
||||||
|
|
||||||
|
|
||||||
@stream_bp.route('/get_followed_streams', methods=['GET'])
|
@stream_bp.route('/get_followed_streams', methods=['GET'])
|
||||||
def get_followed_streamers():
|
def get_followed_streamers():
|
||||||
"""
|
"""
|
||||||
@@ -147,7 +141,7 @@ def get_followed_streamers():
|
|||||||
user_id = get_user_id(username)
|
user_id = get_user_id(username)
|
||||||
live_following_streams = followed_live_streams(user_id)
|
live_following_streams = followed_live_streams(user_id)
|
||||||
if not followed_live_streams:
|
if not followed_live_streams:
|
||||||
return #whatever
|
return # whatever
|
||||||
return live_following_streams
|
return live_following_streams
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
@@ -38,15 +38,14 @@ CREATE TABLE categories
|
|||||||
DROP TABLE IF EXISTS streams;
|
DROP TABLE IF EXISTS streams;
|
||||||
CREATE TABLE streams
|
CREATE TABLE streams
|
||||||
(
|
(
|
||||||
|
stream_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
user_id INTEGER NOT NULL,
|
user_id INTEGER NOT NULL,
|
||||||
stream_id INTEGER NOT NULL,
|
|
||||||
title TEXT NOT NULL,
|
title TEXT NOT NULL,
|
||||||
start_time DATETIME NOT NULL,
|
start_time DATETIME NOT NULL,
|
||||||
num_viewers INTEGER NOT NULL DEFAULT 0,
|
num_viewers INTEGER NOT NULL DEFAULT 0,
|
||||||
isLive BOOLEAN NOT NULL DEFAULT 0,
|
isLive BOOLEAN NOT NULL DEFAULT 0,
|
||||||
vod_id INTEGER,
|
vod_id INTEGER,
|
||||||
category_id NOT NULL,
|
category_id NOT NULL,
|
||||||
PRIMARY KEY (user_id, stream_id),
|
|
||||||
FOREIGN KEY (category_id) REFERENCES categories(category_id) ON DELETE CASCADE,
|
FOREIGN KEY (category_id) REFERENCES categories(category_id) ON DELETE CASCADE,
|
||||||
FOREIGN KEY (user_id) REFERENCES users(user_id) ON DELETE CASCADE
|
FOREIGN KEY (user_id) REFERENCES users(user_id) ON DELETE CASCADE
|
||||||
);
|
);
|
||||||
@@ -7,36 +7,28 @@ INSERT INTO categories (category_name) VALUES
|
|||||||
('Sports');
|
('Sports');
|
||||||
|
|
||||||
-- Sample data for users
|
-- Sample data for users
|
||||||
INSERT INTO users (username, password, email, num_followers, bio) VALUES
|
INSERT INTO users (username, password, email, num_followers, stream_key, is_partnered, bio) VALUES
|
||||||
('GamerDude', 'password123', 'gamerdude@example.com', 500, 'Streaming my gaming adventures!'),
|
('GamerDude', 'password123', 'gamerdude@example.com', 500, '1', 0, 'Streaming my gaming adventures!'),
|
||||||
('MusicLover', 'music4life', 'musiclover@example.com', 1200, 'I share my favorite tunes.'),
|
('MusicLover', 'music4life', 'musiclover@example.com', 1200, '1', 0, 'I share my favorite tunes.'),
|
||||||
('ArtFan', 'artistic123', 'artfan@example.com', 300, 'Exploring the world of art.'),
|
('ArtFan', 'artistic123', 'artfan@example.com', 300, '1', 0, 'Exploring the world of art.'),
|
||||||
('EduGuru', 'learn123', 'eduguru@example.com', 800, 'Teaching everything I know.'),
|
('EduGuru', 'learn123', 'eduguru@example.com', 800, '1', 0, 'Teaching everything I know.'),
|
||||||
('SportsStar', 'sports123', 'sportsstar@example.com', 2000, 'Join me for live sports updates!');
|
('SportsStar', 'sports123', 'sportsstar@example.com', 2000, '1', 0, 'Join me for live sports updates!');
|
||||||
|
|
||||||
-- Sample data for streamers
|
|
||||||
INSERT INTO streamers (user_id, streamer_id, since, stream_key, isPartnered) VALUES
|
|
||||||
(1, 101, '2023-01-01', '1234', 1),
|
|
||||||
(2, 102, '2022-05-15', '2345', 0),
|
|
||||||
(3, 103, '2023-03-20', '3456', 0),
|
|
||||||
(4, 104, '2021-11-05', '4567', 1),
|
|
||||||
(5, 105, '2020-07-18', '5678', 1);
|
|
||||||
|
|
||||||
-- Sample data for streams
|
-- Sample data for streams
|
||||||
INSERT INTO streams (streamer_id, stream_id, title, start_time, num_viewers, isLive, vod_id, category_id) VALUES
|
INSERT INTO streams (user_id, title, start_time, num_viewers, isLive, vod_id, category_id) VALUES
|
||||||
(101, 1001, 'Epic Gaming Session', '2025-01-25 18:00:00', 150, 1, NULL, 1),
|
(1, 'Epic Gaming Session', '2025-01-25 18:00:00', 150, 1, NULL, 1),
|
||||||
(102, 1002, 'Live Music Jam', '2025-01-25 20:00:00', 350, 1, NULL, 2),
|
(2, 'Live Music Jam', '2025-01-25 20:00:00', 350, 1, NULL, 2),
|
||||||
(103, 1003, 'Sketching Live', '2025-01-24 15:00:00', 80, 0, 201, 3),
|
(3, 'Sketching Live', '2025-01-24 15:00:00', 80, 0, 201, 3),
|
||||||
(104, 1004, 'Math Made Easy', '2025-01-23 10:00:00', 400, 0, 202, 4),
|
(4, 'Math Made Easy', '2025-01-23 10:00:00', 400, 0, 202, 4),
|
||||||
(105, 1005, 'Sports Highlights', '2025-01-25 12:00:00', 500, 1, NULL, 5);
|
(5, 'Sports Highlights', '2025-01-25 12:00:00', 500, 1, NULL, 5);
|
||||||
|
|
||||||
-- Sample data for follows
|
-- Sample data for follows
|
||||||
INSERT INTO follows (user_id, streamer_id, since) VALUES
|
INSERT INTO follows (user_id, followed_id, since) VALUES
|
||||||
(1, 102, '2024-12-01'),
|
(1, 2, '2024-12-01'),
|
||||||
(2, 101, '2024-11-15'),
|
(2, 3, '2024-11-15'),
|
||||||
(3, 103, '2024-10-20'),
|
(3, 4, '2024-10-20'),
|
||||||
(4, 104, '2024-09-12'),
|
(4, 5, '2024-09-12'),
|
||||||
(5, 105, '2024-08-30');
|
(5, 1, '2024-08-30');
|
||||||
|
|
||||||
-- Sample data for user_preferences
|
-- Sample data for user_preferences
|
||||||
INSERT INTO user_preferences (user_id, category_id, favourability) VALUES
|
INSERT INTO user_preferences (user_id, category_id, favourability) VALUES
|
||||||
@@ -47,9 +39,16 @@ INSERT INTO user_preferences (user_id, category_id, favourability) VALUES
|
|||||||
(5, 5, 10);
|
(5, 5, 10);
|
||||||
|
|
||||||
-- Sample data for subscribes
|
-- Sample data for subscribes
|
||||||
INSERT INTO subscribes (user_id, streamer_id, since, expires) VALUES
|
INSERT INTO subscribes (user_id, subscribed_id, since, expires) VALUES
|
||||||
(1, 101, '2024-12-01', '2025-01-01'),
|
(1, 101, '2024-12-01', '2025-01-01'),
|
||||||
(2, 102, '2024-11-15', '2025-02-15'),
|
(2, 102, '2024-11-15', '2025-02-15'),
|
||||||
(3, 103, '2024-10-20', '2025-01-20'),
|
(3, 103, '2024-10-20', '2025-01-20'),
|
||||||
(4, 104, '2024-09-12', '2025-01-12'),
|
(4, 104, '2024-09-12', '2025-01-12'),
|
||||||
(5, 105, '2024-08-30', '2025-02-28');
|
(5, 105, '2024-08-30', '2025-02-28');
|
||||||
|
|
||||||
|
SELECT * FROM users;
|
||||||
|
SELECT * FROM streams;
|
||||||
|
SELECT * FROM follows;
|
||||||
|
SELECT * FROM user_preferences;
|
||||||
|
SELECT * FROM subscribes;
|
||||||
|
SELECT * FROM categories;
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ CREATE TABLE follows
|
|||||||
user_id INTEGER NOT NULL,
|
user_id INTEGER NOT NULL,
|
||||||
followed_id INTEGER NOT NULL,
|
followed_id INTEGER NOT NULL,
|
||||||
since DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
since DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
PRIMARY KEY (user_id, streamer_id),
|
PRIMARY KEY (user_id, followed_id),
|
||||||
FOREIGN KEY (user_id) REFERENCES users(user_id) ON DELETE CASCADE,
|
FOREIGN KEY (user_id) REFERENCES users(user_id) ON DELETE CASCADE,
|
||||||
FOREIGN KEY (followed_id) REFERENCES users(user_id) ON DELETE CASCADE
|
FOREIGN KEY (followed_id) REFERENCES users(user_id) ON DELETE CASCADE
|
||||||
);
|
);
|
||||||
@@ -45,7 +45,7 @@ CREATE TABLE subscribes
|
|||||||
subscribed_id INTEGER NOT NULL,
|
subscribed_id INTEGER NOT NULL,
|
||||||
since DATETIME NOT NULL,
|
since DATETIME NOT NULL,
|
||||||
expires DATETIME NOT NULL,
|
expires DATETIME NOT NULL,
|
||||||
PRIMARY KEY (user_id,streamer_id),
|
PRIMARY KEY (user_id),
|
||||||
FOREIGN KEY(user_id) REFERENCES users(user_id) ON DELETE CASCADE,
|
FOREIGN KEY(user_id) REFERENCES users(user_id) ON DELETE CASCADE,
|
||||||
FOREIGN KEY(subscribed_id) REFERENCES users(user_id) ON DELETE CASCADE
|
FOREIGN KEY(subscribed_id) REFERENCES users(user_id) ON DELETE CASCADE
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ from database.database import Database
|
|||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
|
|
||||||
def user_live_status(user_id: int) -> bool:
|
def streamer_live_status(user_id: int) -> bool:
|
||||||
"""
|
"""
|
||||||
Returns whether the given streamer is live
|
Returns whether the given streamer is live
|
||||||
"""
|
"""
|
||||||
@@ -27,7 +27,7 @@ def followed_live_streams(user_id: int):
|
|||||||
|
|
||||||
return live_streams
|
return live_streams
|
||||||
|
|
||||||
def user_most_recent_stream(user_id: int):
|
def streamer_most_recent_stream(user_id: int):
|
||||||
"""
|
"""
|
||||||
Returns data of the most recent stream by a streamer
|
Returns data of the most recent stream by a streamer
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user