Beispiel #1
0
    def question_answer(self, request):
        """Exposes an API endpoint to insert a score for the current user.

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

        Returns:
            An instance of QuestionResponseMessage containing all the details of the question inserted,
            time, id, askerId, etc.
        """
        entity = Question.answer_from_message(request)
        if entity != None:
            return entity.to_message()
        return None
Beispiel #2
0
    def question_answer(self, request):
        """Exposes an API endpoint to insert a score for the current user.

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

        Returns:
            An instance of QuestionResponseMessage containing all the details of the question inserted,
            time, id, askerId, etc.
        """
        entity = Question.answer_from_message(request)
        if entity != None:
            return entity.to_message()
        return None
Beispiel #3
0
    def questions_list(self, request):
        """Exposes an API endpoint to query for questions for the current user.

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

        Returns:
            An instance of QuestionListResponse containing the questions 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.
        """
        if request.user_type == QuestionListRequest.User.ANY:
            query = Question.query_all()
        elif request.user_type == QuestionListRequest.User.CURRENT:
            query = Question.query_current_user()
        elif request.user_type == QuestionListRequest.User.SPECIFIC:
            query = Question.query_user_id(request.asker_id)
        #Default sorting is by asked date
        query = query.order(-Question.time_asked)
        items = [entity.to_message() for entity in query.fetch(request.limit)]
        return QuestionListResponse(questions=items)
Beispiel #4
0
    def questions_list(self, request):
        """Exposes an API endpoint to query for questions for the current user.

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

        Returns:
            An instance of QuestionListResponse containing the questions 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.
        """
        if request.user_type == QuestionListRequest.User.ANY:
            query = Question.query_all()
        elif request.user_type == QuestionListRequest.User.CURRENT:
            query = Question.query_current_user()
        elif request.user_type == QuestionListRequest.User.SPECIFIC:
            query = Question.query_user_id(request.asker_id)
        #Default sorting is by asked date
        query = query.order(-Question.time_asked)
        items = [entity.to_message() for entity in query.fetch(request.limit)]
        return QuestionListResponse(questions=items)