Skip to content

Commit 60d0989

Browse files
author
Sophie Strausberg
committed
reformat
1 parent 9253679 commit 60d0989

4 files changed

Lines changed: 22 additions & 18 deletions

File tree

app_factory.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ def create_app(run_migrations=False):
6262

6363
jwt = JWTManager(app)
6464

65-
6665
@jwt.token_in_blocklist_loader
6766
def check_if_token_revoked(jwt_header, jwt_payload: dict) -> bool:
6867
jti = jwt_payload["jti"]

dump.rdb

-203 Bytes
Binary file not shown.

src/models/token_blacklist.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1-
from sqlalchemy import Column, Float, String, Integer, DateTime
2-
from sqlalchemy.orm import relationship
1+
from sqlalchemy import Column, String, Integer, DateTime
32
from src.database import Base
43

54

65
class TokenBlocklist(Base):
6+
"""
7+
Represents a JWT token that has been revoked (blacklisted).
8+
9+
Attributes:
10+
- `id` The primary key of the token record.
11+
- `jti` The unique identifier (JWT ID) of the token. Indexed for fast lookup.
12+
- `expires_at` The DateTime when the token expires.
13+
"""
14+
715
__tablename__ = "token_blacklist"
816

917
id = Column(Integer, primary_key=True)

src/schema.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
import graphene
22
import os
3-
from flask_jwt_extended import (
4-
create_access_token,
5-
create_refresh_token,
6-
verify_jwt_in_request,
7-
get_jwt_identity,
8-
get_jwt,
9-
jwt_required,
10-
)
3+
from flask_jwt_extended import create_access_token, create_refresh_token, get_jwt_identity, get_jwt, jwt_required
114
from functools import wraps
125
from datetime import datetime, timedelta, timezone
136
from graphene_sqlalchemy import SQLAlchemyObjectType
@@ -30,7 +23,6 @@
3023
from src.models.report import Report as ReportModel
3124
from src.models.hourly_average_capacity import HourlyAverageCapacity as HourlyAverageCapacityModel
3225
from src.database import db_session
33-
from flask import current_app
3426

3527

3628
# MARK: - Gym
@@ -257,8 +249,14 @@ class Query(graphene.ObjectType):
257249
get_workouts_by_id = graphene.List(Workout, id=graphene.Int(), description="Get all of a user's workouts by ID.")
258250
activities = graphene.List(Activity)
259251
get_all_reports = graphene.List(Report, description="Get all reports.")
260-
get_workout_goals = graphene.List(graphene.String, id=graphene.Int(required=True), description="Get the workout goals of a user by ID.")
261-
get_user_streak = graphene.Field(graphene.JSONString, id=graphene.Int(required=True), description="Get the current and max workout streak of a user.")
252+
get_workout_goals = graphene.List(
253+
graphene.String, id=graphene.Int(required=True), description="Get the workout goals of a user by ID."
254+
)
255+
get_user_streak = graphene.Field(
256+
graphene.JSONString,
257+
id=graphene.Int(required=True),
258+
description="Get the current and max workout streak of a user.",
259+
)
262260
get_hourly_average_capacities_by_facility_id = graphene.List(
263261
HourlyAverageCapacity, facility_id=graphene.Int(), description="Get all facility hourly average capacities."
264262
)
@@ -316,15 +314,15 @@ def resolve_get_weekly_workout_days(self, info, id):
316314
def resolve_get_all_reports(self, info):
317315
query = ReportModel.query.all()
318316
return query
319-
317+
320318
@jwt_required()
321319
def resolve_get_workout_goals(self, info, id):
322320
user = User.get_query(info).filter(UserModel.id == id).first()
323321
if not user:
324322
raise GraphQLError("User with the given ID does not exist.")
325323

326324
return [day.value for day in user.workout_goal] if user.workout_goal else []
327-
325+
328326
@jwt_required()
329327
def resolve_get_user_streak(self, info, id):
330328
user = User.get_query(info).filter(UserModel.id == id).first()
@@ -364,7 +362,7 @@ def resolve_get_user_streak(self, info, id):
364362
max_streak = max(max_streak, streak)
365363

366364
return {"active_streak": active_streak, "max_streak": max_streak}
367-
365+
368366
def resolve_get_hourly_average_capacities_by_facility_id(self, info, facility_id):
369367
valid_facility_ids = [14492437, 8500985, 7169406, 10055021, 2323580, 16099753, 15446768, 12572681]
370368
if facility_id not in valid_facility_ids:
@@ -409,7 +407,6 @@ def mutate(self, info):
409407
return RefreshAccessToken(new_access_token=new_access_token)
410408

411409

412-
# WHAT happens if a user tries to access this route if they are not logged in?
413410
class LogoutUser(graphene.Mutation):
414411
success = graphene.Boolean()
415412

0 commit comments

Comments
 (0)