-
Notifications
You must be signed in to change notification settings - Fork 2
Tran/set up weekly challenges #225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| from datetime import datetime | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'datetime.datetime' imported but unused |
||
| from sqlalchemy import Column, Integer, String, Date, DateTime | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'sqlalchemy.DateTime' imported but unused |
||
| from src.database import Base | ||
|
|
||
| class WeeklyChallenge(Base): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Black would make changes. |
||
| """ | ||
| 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) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unexpected spaces around keyword / parameter equals |
||
| name = Column(String, nullable = False) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unexpected spaces around keyword / parameter equals |
||
| message = Column(String, nullable = False) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unexpected spaces around keyword / parameter equals |
||
| start_date = Column(Date, nullable = False) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unexpected spaces around keyword / parameter equals |
||
| end_date = Column (Date, nullable = False) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unexpected spaces around keyword / parameter equals |
||
|
|
||
|
|
||
| def serialize(self): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. too many blank lines (2) |
||
| """ | ||
| 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() | ||
| } | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. blank line at end of file |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -301,6 +302,15 @@ class Meta: | |
| exclude_fields = ("fcm_token",) | ||
|
|
||
|
|
||
|
|
||
| # MARK: - Weekly Challenge | ||
|
|
||
| class WeeklyChallenge(SQLAlchemyObjectType): | ||
| class Meta: | ||
| model = WeeklyChallengeModel | ||
|
|
||
|
|
||
|
|
||
| # MARK: - Query | ||
|
|
||
|
|
||
|
|
@@ -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() | ||
|
|
@@ -1000,6 +1031,33 @@ def mutate(self, info, reminder_id): | |
|
|
||
| return reminder | ||
|
|
||
| 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 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. block comment should start with '# ' |
||
| new_challenge = WeeklyChallengeModel( | ||
| name = name, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unexpected spaces around keyword / parameter equals |
||
| message = message, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unexpected spaces around keyword / parameter equals |
||
| start_date = start_date, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unexpected spaces around keyword / parameter equals |
||
| end_date = end_date, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unexpected spaces around keyword / parameter equals |
||
| ) | ||
|
|
||
| db_session.add(new_challenge) | ||
| db_session.commit() | ||
| return new_challenge | ||
|
|
||
|
|
||
| class AddFriend(graphene.Mutation): | ||
| class Arguments: | ||
| user_id = graphene.Int(required=True) | ||
|
|
@@ -1124,8 +1182,7 @@ class Mutation(graphene.ObjectType): | |
| add_friend = AddFriend.Field(description="Send a friend request to another user.") | ||
| accept_friend_request = AcceptFriendRequest.Field(description="Accept a friend request.") | ||
| remove_friend = RemoveFriend.Field(description="Remove a friendship.") | ||
| get_pending_friend_requests = GetPendingFriendRequests.Field( | ||
| description="Get all pending friend requests for a user.") | ||
|
|
||
| get_pending_friend_requests = GetPendingFriendRequests.Field(description="Get all pending friend requests for a user.") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. line too long (123 > 120 characters) |
||
| create_weekly_challenge = CreateWeeklyChallenge.Field(description="Creates a new weekly challenge.") | ||
|
|
||
| schema = graphene.Schema(query=Query, mutation=Mutation) | ||
Uh oh!
There was an error while loading. Please reload this page.