diff --git a/alembic/versions/553d2c1ee85a_create_challenge_table.py b/alembic/versions/553d2c1ee85a_create_challenge_table.py index 80ef56b..ecd1bbc 100644 --- a/alembic/versions/553d2c1ee85a_create_challenge_table.py +++ b/alembic/versions/553d2c1ee85a_create_challenge_table.py @@ -23,7 +23,8 @@ def upgrade() -> None: sa.Column("name", sa.String, nullable=False), sa.Column("type", sa.String, nullable=False), sa.Column("grade", sa.Integer, nullable=False), - sa.Column("score", sa.Float, nullable=False) + sa.Column("score", sa.Float, nullable=False), + sa.Column("goal", sa.Integer, nullable=False), ) op.create_table( diff --git a/app/models.py b/app/models.py index 2550cff..862d68a 100644 --- a/app/models.py +++ b/app/models.py @@ -202,6 +202,7 @@ class Challenge(Base): type = Column(String, nullable=False) grade = Column(Integer, nullable=False) score = Column(Float, nullable=False) + goal = Column(Integer, nullable=False) user_challenges = relationship( "User_Challenge", back_populates="challenge") diff --git a/app/routers/challenge.py b/app/routers/challenge.py index 93e56ad..b83b673 100644 --- a/app/routers/challenge.py +++ b/app/routers/challenge.py @@ -330,9 +330,7 @@ async def add_challenge_common( Returns: - dict: A dictionary containing details about the update status. """ - print("in add challenge common") user_id = current_user.user_id - print(user_id) challenges = db.query(models.Challenge).filter( models.Challenge.type == challenge_type).all() @@ -376,7 +374,7 @@ async def add_challenge_common( db.refresh(user_challenge) # If the progress is 1, and score is not added, update score in Redis - if progress == 1.0 and not user_challenge.score_added: + if user_challenge.progress == 1.0 and not user_challenge.score_added: # Use the score from the challenge await update_score_in_redis(user_id, challenge.score, r, db) user_challenge.score_added = True diff --git a/app/schemas.py b/app/schemas.py index 88be2a9..893469e 100644 --- a/app/schemas.py +++ b/app/schemas.py @@ -257,6 +257,9 @@ class TrackRoomOut(BaseModel): class Challenge(BaseModel): name: str type: str + goal: int + grade: int + score: int class UserChallengeOut(BaseModel): diff --git a/data/challenges.json b/data/challenges.json index aef68ef..3e7e099 100644 --- a/data/challenges.json +++ b/data/challenges.json @@ -2,120 +2,137 @@ { "id": 1, "type": "route_generation", - "name": "1 Route Generated", + "name": "Generate 1 Route", "score": 1, - "grade": 1 + "grade": 1, + "goal": 1 }, { "id": 2, "type": "route_generation", - "name": "5 Routes Generated", + "name": "Generate 5 Routes", "score": 3, - "grade": 2 + "grade": 2, + "goal": 5 }, { "id": 3, "type": "route_generation", - "name": "10 Routes Generated", + "name": "Generated 10 Routes", "score": 5, - "grade": 3 + "grade": 3, + "goal": 10 }, { "id": 4, "type": "favourited", - "name": "1 Favorited", + "name": "Favorite 1 Route", "score": 1, - "grade": 1 + "grade": 1, + "goal": 1 }, { "id": 5, "type": "favourited", - "name": "5 Favorited", + "name": "Favorite 5 Routes", "score": 3, - "grade": 2 + "grade": 2, + "goal": 5 }, { "id": 6, "type": "favourited", - "name": "10 Favorited", + "name": "Favorite 10 Routes", "score": 5, - "grade": 3 + "grade": 3, + "goal": 10 }, { "id": 7, "type": "shared", - "name": "1 Shared", + "name": "Shared 1 Route", "score": 1, - "grade": 1 + "grade": 1, + "goal": 1 }, { "id": 8, "type": "shared", - "name": "5 Shared", + "name": "Share 5 Routes", "score": 3, - "grade": 2 + "grade": 2, + "goal": 5 }, { "id": 9, "type": "shared", - "name": "10 Shared", + "name": "Share 10 Routes", "score": 5, - "grade": 3 + "grade": 3, + "goal": 10 }, { "id": 10, "type": "published", - "name": "1 Published", + "name": "Publish 1 Route", "score": 1, - "grade": 1 + "grade": 1, + "goal": 1 }, { "id": 11, "type": "published", - "name": "5 Published", + "name": "Publish 5 Routes", "score": 3, - "grade": 2 + "grade": 2, + "goal": 5 }, { "id": 12, "type": "published", - "name": "10 Published", + "name": "Publish 10 Routes", "score": 5, - "grade": 3 + "grade": 3, + "goal": 10 }, { "id": 13, "type": "read_tips", - "name": "1 Read", + "name": "Read 1 Tip", "score": 1, - "grade": 1 + "grade": 1, + "goal": 1 }, { "id": 14, "type": "read_tips", - "name": "5 Read", + "name": "Read 5 Tips", "score": 3, - "grade": 2 + "grade": 2, + "goal": 5 }, { "id": 15, "type": "read_tipes", - "name": "10 Read", + "name": "Read 10 Tips", "score": 5, - "grade": 3 + "grade": 3, + "goal": 10 }, { "id": 16, "type": "logged_in", - "name": "Logged In", + "name": "Daily Log In", "score": 1, - "grade": 1 + "grade": 1, + "goal": 1 }, { "id": 17, "type": "accessed_global_feed", - "name": "Accessed Global Feed", + "name": "Access Global Feed", "score": 1, - "grade": 1 + "grade": 1, + "goal": 1 } ]