Skip to content

Commit c6eccaa

Browse files
author
Sophie Strausberg
committed
resolved merge conflicts
2 parents 75cf210 + f9a5859 commit c6eccaa

4 files changed

Lines changed: 47 additions & 9 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""Added fitness center to workout model
2+
3+
Revision ID: 0fde4435424e
4+
Revises: 6b01a81bb92b
5+
Create Date: 2025-03-06 20:50:25.488572
6+
7+
"""
8+
from alembic import op
9+
import sqlalchemy as sa
10+
11+
12+
# revision identifiers, used by Alembic.
13+
revision = '0fde4435424e'
14+
down_revision = '6b01a81bb92b'
15+
branch_labels = None
16+
depends_on = None
17+
18+
19+
def upgrade():
20+
# ### commands auto generated by Alembic - please adjust! ###
21+
op.add_column('workout', sa.Column('facility_id', sa.Integer(), nullable=False))
22+
op.create_foreign_key(None, 'workout', 'facility', ['facility_id'], ['id'])
23+
# ### end Alembic commands ###
24+
25+
26+
def downgrade():
27+
# ### commands auto generated by Alembic - please adjust! ###
28+
op.drop_constraint(None, 'workout', type_='foreignkey')
29+
op.drop_column('workout', 'facility_id')
30+
# ### end Alembic commands ###

schema.graphql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,14 @@ type Mutation {
177177
createUser(email: String!, name: String!, netId: String!): User
178178
enterGiveaway(giveawayId: Int!, userNetId: String!): GiveawayInstance
179179
setWorkoutGoals(userId: Int!, workoutGoal: [String]!): User
180+
<<<<<<< HEAD
180181
logWorkout(userId: Int!, workoutTime: DateTime!): Workout
181182
loginUser(netId: String!): LoginUser
182183
logoutUser: LogoutUser
183184
refreshAccessToken: RefreshAccessToken
185+
=======
186+
logWorkout(facilityId: Int!, userId: Int!, workoutTime: DateTime!): Workout
187+
>>>>>>> f9a58592618c0a8743aeeaadf2753e083905cb66
184188
createReport(createdAt: DateTime!, description: String!, gymId: Int!, issue: String!): CreateReport
185189
deleteUser(userId: Int!): User
186190
}
@@ -260,4 +264,5 @@ type Workout {
260264
id: ID!
261265
workoutTime: DateTime!
262266
userId: Int!
267+
facilityId: Int!
263268
}

src/models/workout.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ class Workout(Base):
1111
- `id` The ID of user.
1212
- `workout_time` The date and time of the workout.
1313
- `user_id` The ID of the user who completed the workout.
14+
- `facility_id` The ID of the facility visited
1415
"""
1516

1617
__tablename__ = "workout"
1718

1819
id = Column(Integer, primary_key=True)
1920
workout_time = Column(DateTime(), nullable=False) # should this be nullable?
2021
user_id = Column(Integer, ForeignKey("users.id"), nullable=False)
22+
facility_id = Column(Integer, ForeignKey("facility.id"), nullable=False)

src/schema.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -249,14 +249,10 @@ class Query(graphene.ObjectType):
249249
get_workouts_by_id = graphene.List(Workout, id=graphene.Int(), description="Get all of a user's workouts by ID.")
250250
activities = graphene.List(Activity)
251251
get_all_reports = graphene.List(Report, description="Get all reports.")
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-
)
252+
get_workout_goals = graphene.List(graphene.String, id=graphene.Int(required=True),
253+
description="Get the workout goals of a user by ID.")
254+
get_user_streak = graphene.Field(graphene.JSONString, id=graphene.Int(
255+
required=True), description="Get the current and max workout streak of a user.")
260256
get_hourly_average_capacities_by_facility_id = graphene.List(
261257
HourlyAverageCapacity, facility_id=graphene.Int(), description="Get all facility hourly average capacities."
262258
)
@@ -363,6 +359,7 @@ def resolve_get_user_streak(self, info, id):
363359

364360
return {"active_streak": active_streak, "max_streak": max_streak}
365361

362+
366363
def resolve_get_hourly_average_capacities_by_facility_id(self, info, facility_id):
367364
valid_facility_ids = [14492437, 8500985, 7169406, 10055021, 2323580, 16099753, 15446768, 12572681]
368365
if facility_id not in valid_facility_ids:
@@ -533,6 +530,7 @@ class logWorkout(graphene.Mutation):
533530
class Arguments:
534531
workout_time = graphene.DateTime(required=True)
535532
user_id = graphene.Int(required=True)
533+
facility_id = graphene.Int(required=True)
536534

537535
Output = Workout
538536

@@ -541,8 +539,11 @@ def mutate(self, info, workout_time, user_id):
541539
user = User.get_query(info).filter(UserModel.id == user_id).first()
542540
if not user:
543541
raise GraphQLError("User with given ID does not exist.")
542+
facility = Facility.get_query(info).filter(FacilityModel.id == facility_id).first()
543+
if not facility:
544+
raise GraphQLError("Facility with given ID does not exist.")
544545

545-
workout = WorkoutModel(workout_time=workout_time, user_id=user.id)
546+
workout = WorkoutModel(workout_time=workout_time, user_id=user.id, facility_id=facility.id)
546547

547548
db_session.add(workout)
548549
db_session.commit()

0 commit comments

Comments
 (0)