示例#1
0
        /// <summary>
        /// Get list of questions from API Gateway
        /// </summary>
        /// <param name="request"></param>
        /// <returns>The list of questions</returns>
        public APIGatewayProxyResponse GetQuestions(APIGatewayProxyRequest request, ILambdaContext context)
        {
            Log(context, "Get all questions request\n");

            var questions = QuestionsDb.GetQuestions();
            var body      = JsonConvert.SerializeObject(questions);

            return(CreateAPIGatewayProxyResponse(body));
        }
示例#2
0
        /// <summary>
        /// Get question from API Gateway
        /// </summary>
        /// <param name="request">with question Id</param>
        /// <returns>Question</returns>
        public APIGatewayProxyResponse GetQuestion(APIGatewayProxyRequest request, ILambdaContext context)
        {
            Log(context, "Get question request\n");

            request.QueryStringParameters.TryGetValue("Id", out string questionId);

            if (string.IsNullOrEmpty(questionId))
            {
                var badQuestionIdResponse = new APIGatewayProxyResponse
                {
                    StatusCode = (int)HttpStatusCode.InternalServerError,
                    Body       = "Unknown question Id.",
                    Headers    = new Dictionary <string, string> {
                        {
                            "Content-Type", "application/json"
                        }
                    }
                };

                return(badQuestionIdResponse);
            }

            var questionIdValue = int.Parse(questionId);

            var question = QuestionsDb.GetQuestions().OfType <Question>().SingleOrDefault(q => q.Id == questionIdValue);

            if (question == null)
            {
                const string questionNotFoundText = "Question not found.";

                return(CreateAPIGatewayProxyResponse(ToJson(questionNotFoundText), HttpStatusCode.NotFound));
            }

            var body = ToJson(question);

            return(CreateAPIGatewayProxyResponse(body));
        }