Example #1
0
 def get_user_scores(self,request):
     """Gets all User's scores"""
     user = User.query(User.name == request.user_name).get()
     if not user:
         raise endpoints.NotFoundException(
                 'A User with that name does not exist!')
     scores = Score.query(ndb.OR(Score.winner == user.key,
                                 Score.loser == user.key))
     return ScoreForms(items=[score.to_form() for score in scores])
    def scores_insert(self, request):
        """Exposes an API endpoint to insert a score for the current user.

        Args:
            request: An instance of ScoreRequestMessage parsed from the API
                request.

        Returns:
            An instance of ScoreResponseMessage containing the score inserted,
            the time the score was inserted and the ID of the score.
        """
        entity = Score.put_from_message(request)
        return entity.to_message()
    def scores_list(self, request):
        """Exposes an API endpoint to query for scores for the current user.

        Args:
            request: An instance of ScoresListRequest parsed from the API
                request.

        Returns:
            An instance of ScoresListResponse containing the scores for the
            current user returned in the query. If the API request specifies an
            order of WHEN (the default), the results are ordered by time from
            most recent to least recent. If the API request specifies an order
            of TEXT, the results are ordered by the string value of the scores.
        """
        query = Score.query_current_user()
        if request.order == ScoresListRequest.Order.TEXT:
            query = query.order(Score.outcome)
        elif request.order == ScoresListRequest.Order.WHEN:
            query = query.order(-Score.played)
        items = [entity.to_message() for entity in query.fetch(request.limit)]
        #my_message = MyResponseMessage(name='jason')
        return ScoresListResponse(items=items)