Skip to content

Commit

Permalink
Convert challenge names in response (#1621)
Browse files Browse the repository at this point in the history
  • Loading branch information
piazzatron committed Jul 6, 2021
1 parent 9ede487 commit 6cdf470
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions discovery-provider/src/api/v1/helpers.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import logging
from typing import Dict
from src import api_helpers
from src.utils.config import shared_config
from hashids import Hashids
from flask_restx import fields, reqparse
from datetime import datetime
from .models.common import full_response
from src.queries.get_challenges import ChallengeResponse
from src.models import ChallengeType

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -245,10 +247,18 @@ def extend_activity(item):
}
return None

challenge_type_map: Dict[ChallengeType, str] = {
ChallengeType.boolean: 'boolean',
ChallengeType.numeric: 'numeric',
ChallengeType.aggregate: 'aggregate',
ChallengeType.trending: 'trending'
}

def extend_challenge_response(challenge: ChallengeResponse):
user_id = encode_int_id(challenge["user_id"])
new_challenge = challenge.copy()
new_challenge["user_id"] = user_id
new_challenge["challenge_type"] = challenge_type_map[challenge["challenge_type"]]
return new_challenge

def abort_bad_path_param(param, namespace):
Expand Down

0 comments on commit 6cdf470

Please sign in to comment.