Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def initialize_firebase():
raise ValueError("GOOGLE_SERVICE_ACCOUNT_PATH environment variable not set.")
else:
firebase_app = firebase_admin.get_app()
logging.info("Firebase app created...")
logging.info("Firebase app created")
return firebase_app


Expand Down Expand Up @@ -197,7 +197,7 @@ def cleanup_expired_tokens():

# Update hourly average capacity every hour
@scheduler.task("cron", id="update_capacity", hour="*")
def scheduled_job():
def update_hourly_avg_capacity():
current_time = datetime.now()
current_day = current_time.strftime("%A").upper()
current_hour = current_time.hour
Expand Down
77 changes: 77 additions & 0 deletions migrations/versions/723cd68cf306_add_workout_reminders.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
"""add workout reminders

Revision ID: 723cd68cf306
Revises: 7a3c14648e56
Create Date: 2025-04-01 01:06:38.476352

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = '723cd68cf306'
down_revision = '7a3c14648e56'
branch_labels = None
depends_on = None

def upgrade():

op.execute("""
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1 FROM information_schema.tables WHERE table_name = 'workout_reminder'
) THEN
CREATE TABLE workout_reminder (
id SERIAL PRIMARY KEY,
user_id INTEGER NOT NULL REFERENCES users(id),
days_of_week dayofweekenum[] NOT NULL,
reminder_time TIME NOT NULL,
is_active BOOLEAN DEFAULT TRUE
);
END IF;
END
$$;
""")

op.execute("""
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1 FROM information_schema.columns
WHERE table_name = 'users' AND column_name = 'fcm_token'
) THEN
ALTER TABLE users ADD COLUMN fcm_token VARCHAR NOT NULL DEFAULT 'unset';
ALTER TABLE users ALTER COLUMN fcm_token DROP DEFAULT;
END IF;
END
$$;
""")


def downgrade():
op.execute("""
DO $$
BEGIN
IF EXISTS (
SELECT 1 FROM information_schema.tables WHERE table_name = 'workout_reminder'
) THEN
DROP TABLE workout_reminder;
END IF;
END
$$;
""")

op.execute("""
DO $$
BEGIN
IF EXISTS (
SELECT 1 FROM information_schema.columns
WHERE table_name = 'users' AND column_name = 'fcm_token'
) THEN
ALTER TABLE users DROP COLUMN fcm_token;
END IF;
END
$$;
""")
21 changes: 19 additions & 2 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ enum MuscleGroup {

type Mutation {
createGiveaway(name: String!): Giveaway
createUser(email: String!, encodedImage: String, name: String!, netId: String!): User
editUser(email: String, encodedImage: String, name: String, netId: String!): User
createUser(email: String!, encodedImage: String, fcmToken: String!, name: String!, netId: String!): User
editUser(email: String, encodedImage: String, fcmToken: String, name: String, netId: String!): User
enterGiveaway(giveawayId: Int!, userNetId: String!): GiveawayInstance
setWorkoutGoals(userId: Int!, workoutGoal: [String]!): User
logWorkout(facilityId: Int!, userId: Int!, workoutTime: DateTime!): Workout
Expand All @@ -214,6 +214,10 @@ type Mutation {
createCapacityReminder(capacityPercent: Int!, daysOfWeek: [String]!, fcmToken: String!, gyms: [String]!): CapacityReminder
toggleCapacityReminder(reminderId: Int!): CapacityReminder
deleteCapacityReminder(reminderId: Int!): CapacityReminder
createWorkoutReminder(daysOfWeek: [String]!, reminderTime: Time!, userId: Int!): WorkoutReminder
toggleWorkoutReminder(reminderId: Int!): WorkoutReminder
editWorkoutReminder(daysOfWeek: [String], reminderId: Int!, reminderTime: Time, userId: Int): WorkoutReminder
deleteWorkoutReminder(reminderId: Int!): WorkoutReminder
}

type OpenHours {
Expand Down Expand Up @@ -253,6 +257,7 @@ type Query {
getWorkoutGoals(id: Int!): [String]
getUserStreak(id: Int!): JSONString
getHourlyAverageCapacitiesByFacilityId(facilityId: Int): [HourlyAverageCapacity]
getWorkoutRemindersByUserId(userId: Int): [WorkoutReminder]
}

type RefreshAccessToken {
Expand All @@ -276,6 +281,8 @@ enum ReportType {
OTHER
}

scalar Time

type User {
id: ID!
email: String
Expand All @@ -285,7 +292,9 @@ type User {
maxStreak: Int
workoutGoal: [DayOfWeekGraphQLEnum]
encodedImage: String
fcmToken: String!
giveaways: [Giveaway]
workoutReminders: [WorkoutReminder]
}

type Workout {
Expand All @@ -294,3 +303,11 @@ type Workout {
userId: Int!
facilityId: Int!
}

type WorkoutReminder {
id: ID!
userId: Int!
daysOfWeek: [DayOfWeekGraphQLEnum]
reminderTime: String!
isActive: Boolean
}
6 changes: 4 additions & 2 deletions src/models/user.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from sqlalchemy import Column, Integer, String, ARRAY, Enum
from sqlalchemy.orm import backref, relationship
from sqlalchemy.orm import relationship
from src.database import Base
from src.models.enums import DayOfWeekEnum

Expand Down Expand Up @@ -30,4 +30,6 @@ class User(Base):
active_streak = Column(Integer, nullable=True)
max_streak = Column(Integer, nullable=True)
workout_goal = Column(ARRAY(Enum(DayOfWeekEnum)), nullable=True)
encoded_image = Column(String, nullable=True)
encoded_image = Column(String, nullable=True)
fcm_token = Column(String, nullable=False)
workout_reminders = relationship("WorkoutReminder")
24 changes: 24 additions & 0 deletions src/models/workout_reminder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from sqlalchemy import Column, Integer, ForeignKey, TIME, Boolean
from sqlalchemy.dialects.postgresql import ARRAY
from sqlalchemy import Enum as SQLAEnum
from src.models.enums import DayOfWeekEnum
from src.database import Base

class WorkoutReminder(Base):
"""
A workout reminder for an Uplift user.
Attributes:
- `id` The ID of the workout reminder.
- `user_id` The ID of the user who owns this reminder.
- `days_of_week` The days of the week when the reminder is active.
- `reminder_time` The time of day the reminder is scheduled for.
- `is_active` Whether the reminder is currently active (default is True).
"""

__tablename__ = "workout_reminder"

id = Column(Integer, primary_key=True)
user_id = Column(Integer, ForeignKey("users.id"), nullable=False)
days_of_week = Column(ARRAY(SQLAEnum(DayOfWeekEnum)), nullable=False)
reminder_time = Column(TIME, nullable=False)
is_active = Column(Boolean, default=True)
Loading