created code for user routes and linked olds routes to reflect new ones

This commit is contained in:
JustIceO7
2025-01-24 05:11:03 +00:00
parent 52f977e885
commit ca2a7e9baf
5 changed files with 39 additions and 9 deletions

View File

@@ -22,7 +22,7 @@ const HomePage: React.FC = () => {
// ↓↓ runs twice when in development mode
useEffect(() => {
fetch("/api/get_loggedin_status")
fetch("/api/get_login_status")
.then((response) => response.json())
.then((data) => {
setLoggedInStatus(data);

View File

@@ -7,6 +7,9 @@ stripe.api_key = os.getenv("STRIPE_SECRET_KEY")
@stripe_bp.route('/create-checkout-session', methods=['POST'])
def create_checkout_session():
"""
Creates the stripe checkout session
"""
print("Creating checkout session")
try:
session = stripe.checkout.Session.create(
@@ -29,6 +32,9 @@ def create_checkout_session():
@stripe_bp.route('/session-status', methods=['GET']) # check for payment status
def session_status():
"""
Used to query payment status
"""
session = stripe.checkout.Session.retrieve(request.args.get('session_id'))
return jsonify(status=session.status, customer_email=session.customer_details.email)

View File

@@ -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():

Binary file not shown.

View File

@@ -94,7 +94,7 @@ CREATE TABLE subscribes
user_id INTEGER NOT NULL,
streamer_id INTEGER NOT NULL,
since DATETIME NOT NULL,
ends DATETIME NOT NULL,
expires DATETIME NOT NULL,
PRIMARY KEY (user_id,streamer_id),
FOREIGN KEY(user_id) REFERENCES users(user_id) ON DELETE CASCADE,
FOREIGN KEY(streamer_id) REFERENCES streamers(streamer_id) ON DELETE CASCADE