Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions requirements.txt
Comment thread
tnt07-t marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,4 @@ zipp==3.15.0
sentry-sdk==2.13.0
flask_jwt_extended==4.7.1
firebase-admin==6.4.0
dotenv
11 changes: 11 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ type CreateReport {
report: Report
}

scalar Date

scalar DateTime

enum DayOfWeekEnum {
Expand Down Expand Up @@ -275,6 +277,7 @@ type Query {
getUserFriends(userId: Int!): [User]
getCapacityReminderById(id: Int!): CapacityReminder
getAllCapacityReminders: [CapacityReminder]
getWeeklyChallengeByDate(date: Date!): WeeklyChallenge
}

type RefreshAccessToken {
Expand Down Expand Up @@ -318,6 +321,14 @@ type User {
friends: [User]
}

type WeeklyChallenge {
id: ID!
name: String!
message: String!
startDate: String!
endDate: String!
}

type Workout {
id: ID!
workoutTime: DateTime!
Expand Down
36 changes: 36 additions & 0 deletions src/models/weekly_challenge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from datetime import datetime
from sqlalchemy import Column, Integer, String, Date, DateTime
from src.database import Base

class WeeklyChallenge(Base):
"""
A weekly challenge.

Attributes:
- `id` The ID of weekly challenge.
- `name` The name of weekly challenge.
- `message` The challenge's message.
- `start_date` The start date of the weekly challenge.
- `end_date` The end date of the weekly challenge.
"""
__tablename__ = "weekly_challenge"

id = Column(Integer, primary_key = True, autoincrement = True)
name = Column(String, nullable = False)
message = Column(String, nullable = False)
start_date = Column(Date, nullable = False)
end_date = Column (Date, nullable = False)


def serialize(self):
"""
Serialize weekly challenge object
"""
return {
"id": self.id,
"name": self.name,
"message": self.message,
"start_date": self.start_date.isoformat(),
"end_date": self.end_date.isoformat()
}

60 changes: 60 additions & 0 deletions src/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from src.models.enums import DayOfWeekGraphQLEnum, CapacityReminderGymGraphQLEnum
from src.models.giveaway import Giveaway as GiveawayModel
from src.models.giveaway import GiveawayInstance as GiveawayInstanceModel
from src.models.weekly_challenge import WeeklyChallenge as WeeklyChallengeModel
from src.models.workout import Workout as WorkoutModel
from src.models.report import Report as ReportModel
from src.models.hourly_average_capacity import HourlyAverageCapacity as HourlyAverageCapacityModel
Expand Down Expand Up @@ -301,6 +302,15 @@ class Meta:
exclude_fields = ("fcm_token",)



# MARK: - Weekly Challenge

class WeeklyChallenge(SQLAlchemyObjectType):
class Meta:
model = WeeklyChallengeModel



# MARK: - Query


Expand Down Expand Up @@ -341,6 +351,27 @@ class Query(graphene.ObjectType):
description="Get all capacity reminders."
)

get_weekly_challenge_by_date = graphene.Field(
WeeklyChallenge,
date = graphene.Date(required = True),
description = "Get a weekly challenge by its Date."
)


def resolve_get_weekly_challenge_by_date(self, info, date):
# Query all weekly challenges where the date falls between start_date and end_date
challenge = (
WeeklyChallenge.get_query(info)
.filter(
WeeklyChallengeModel.start_date <= date,
WeeklyChallengeModel.end_date >= date
)
.first()
)
if not challenge:
raise GraphQLError("No weekly challenge found for the given date.")
return challenge

def resolve_get_all_gyms(self, info):
query = Gym.get_query(info)
return query.all()
Expand Down Expand Up @@ -1000,6 +1031,35 @@ def mutate(self, info, reminder_id):

return reminder


"""
Comment thread
tnt07-t marked this conversation as resolved.
Outdated
class CreateWeeklyChallenge(graphene.Mutation):
class Arguments:
name = graphene.String(required = True)
message = graphene.String(required = True)
start_date = graphene.Date(required = True)
end_date = graphene.Date(required = True)

Output = WeeklyChallenge

def mutate(self, info, name, message, start_date, end_date):
#Validate that end_date is after start_date
if end_date <= start_date:
raise GraphQLError("End date must be after start date")

#Create new weekly challenge
new_challenge = WeeklyChallengeModel(
name = name,
message = message,
start_date = start_date,
end_date = end_date,
)

db_session.add(new_challenge)
db_session.commit()
return new_challenge
"""

class AddFriend(graphene.Mutation):
class Arguments:
user_id = graphene.Int(required=True)
Expand Down
Loading