created code for user routes and linked olds routes to reflect new ones
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
from flask import Blueprint
|
||||
from flask import Blueprint, jsonify, session
|
||||
from database.database import Database
|
||||
from datetime import datetime
|
||||
|
||||
user_bp = Blueprint("stream", __name__)
|
||||
user_bp = Blueprint("user", __name__)
|
||||
|
||||
@user_bp.route('/is_subscribed/<int:user_id>/<int:streamer_id>', methods=['GET'])
|
||||
def user_subscribed(user_id, streamer_id):
|
||||
@@ -10,29 +11,52 @@ def user_subscribed(user_id, streamer_id):
|
||||
"""
|
||||
db = Database()
|
||||
cursor = db.create_connection()
|
||||
return
|
||||
data = cursor.execute("SELECT * FROM subscribes WHERE user_id = ? AND streamer_id = ? AND expires > since", (user_id, streamer_id)).fetchone()
|
||||
if data:
|
||||
return jsonify({"subscribed": True})
|
||||
return jsonify({"subscribed": False})
|
||||
|
||||
@user_bp.route('/is_following/<int:user_id>/<int:streamer_id>', methods=['GET'])
|
||||
def user_following(user_id, streamer_id):
|
||||
"""
|
||||
Checks to see if user is following a streamer
|
||||
"""
|
||||
return
|
||||
db = Database()
|
||||
cursor = db.create_connection()
|
||||
data = cursor.execute("SELECT * FROM follows WHERE user_id = ? AND streamer_id = ?", (user_id, streamer_id)).fetchone()
|
||||
if data:
|
||||
return jsonify({"following": True})
|
||||
return jsonify({"following": False})
|
||||
|
||||
|
||||
@user_bp.route('/subscription_remaining/<int:user_id>/<int:streamer_id>', methods=['GET'])
|
||||
def user_subscription_expiration(user_id, streamer_id):
|
||||
"""
|
||||
Returns remaining time until subscription expiration
|
||||
"""
|
||||
return
|
||||
db = Database()
|
||||
cursor = db.create_connection()
|
||||
data = cursor.execute("SELECT expires from subscriptions WHERE user_id = ? AND streamer_id = ? AND expires > since", (user_id,streamer_id))
|
||||
if data:
|
||||
expiration_date = data[0]
|
||||
|
||||
ends_datetime = datetime.strptime(expiration_date, '%Y-%m-%d %H:%M:%S')
|
||||
|
||||
remaining_time = ends_datetime - datetime.now()
|
||||
|
||||
return jsonify({"remaining_time": remaining_time.seconds})
|
||||
|
||||
return jsonify({"remaining_time": 0})
|
||||
|
||||
@user_bp.route('/get_login_status')
|
||||
def get_login_status():
|
||||
logged_in = False
|
||||
"""
|
||||
Returns whether the user is logged in or not
|
||||
"""
|
||||
return {"logged_in": logged_in}
|
||||
username = session.get("username", None)
|
||||
if not username:
|
||||
return {"logged_in": True}
|
||||
return {"logged_in": False}
|
||||
|
||||
@user_bp.route('/authenticate_user')
|
||||
def authenticate_user():
|
||||
|
||||
Reference in New Issue
Block a user