Skip to content

Commit f5c459a

Browse files
authored
Merge pull request #231 from cuappdev/chimdi/api-refactoring
Minor API Refactoring
2 parents c0cc759 + e87b6e9 commit f5c459a

2 files changed

Lines changed: 15 additions & 9 deletions

File tree

schema.graphql

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ type CreateReport {
8585
report: Report
8686
}
8787

88-
scalar Date
89-
9088
scalar DateTime
9189

9290
enum DayOfWeekEnum {
@@ -319,7 +317,8 @@ type User {
319317
friendships: [Friendship]
320318
friends: [User]
321319
totalGymDays: Int!
322-
streakStart: Date
320+
streakStart: DateTime
321+
workoutHistory: [Workout]
323322
}
324323

325324
type Workout {

src/schema.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import os
44
from flask_jwt_extended import create_access_token, create_refresh_token, get_jwt_identity, get_jwt, jwt_required
55
from functools import wraps
6-
from datetime import datetime, timedelta, timezone
6+
from datetime import datetime, timedelta, time, timezone
77
from graphene_sqlalchemy import SQLAlchemyObjectType
88
from graphql import GraphQLError
99
from src.models.capacity import Capacity as CapacityModel
@@ -30,8 +30,10 @@
3030
import requests
3131
from firebase_admin import messaging
3232
import logging
33+
from zoneinfo import ZoneInfo
3334
from sqlalchemy import func, cast, Date
3435

36+
local_tz = ZoneInfo("America/New_York")
3537

3638
def resolve_enum_value(entry):
3739
"""Return the raw value for Enum objects while leaving plain strings untouched."""
@@ -67,7 +69,7 @@ def to_local_time(dt):
6769
return None
6870

6971
# Convert to local timezone (server-local)
70-
return dt_utc.astimezone()
72+
return dt_utc.astimezone(local_tz)
7173

7274

7375
def goal_at(goal_history, window_start_date):
@@ -264,9 +266,14 @@ class Meta:
264266
total_gym_days = graphene.Int(
265267
required=True, description="Get the total number of gym days (unique workout days) for user."
266268
)
267-
streak_start = graphene.Date(
268-
description="The start date of the most recent active streak, up until the current date."
269+
streak_start = graphene.DateTime(
270+
description="The start datetime of the most recent active streak (midnight of the day in local timezone), up until the current date."
269271
)
272+
workout_history = graphene.List(lambda: Workout)
273+
274+
def resolve_workout_history(self, info):
275+
query = Workout.get_query(info).filter(WorkoutModel.user_id == self.id).order_by(WorkoutModel.workout_time.desc())
276+
return query.all()
270277

271278
def resolve_total_gym_days(self, info):
272279
return (
@@ -432,8 +439,8 @@ def goal_for_window_start(ws_date):
432439
return None
433440

434441
last_streak_start_date = workout_dates[idx_last_streak_start]
435-
436-
return last_streak_start_date
442+
local_midnight = datetime.combine(last_streak_start_date, time.min, tzinfo=local_tz)
443+
return local_midnight
437444

438445
def resolve_max_streak(self, info):
439446
user = User.get_query(info).filter(UserModel.id == self.id).first()

0 commit comments

Comments
 (0)