コード例 #1
0
ファイル: Function.cs プロジェクト: luisr200/PetzfinderApi
        /// <summary>
        /// A simple function that takes a string and does a ToUpper
        /// </summary>
        /// <param name="input"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public async Task <APIGatewayProxyResponse> FunctionHandler(APIGatewayProxyRequest request, ILambdaContext context)
        {
            if (request.HttpMethod == "OPTIONS")
            {
                return(new ApiGatewayResponse(200));
            }
            string tagId;

            request.PathParameters.TryGetValue("tagId", out tagId);
            TagService _service = new TagService();
            var        tag      = await _service.GetTagById(tagId);

            //var newTag = new Tags()
            //{
            //    TagId = "AYSBN",
            //    PetId = "555",
            //    Printed = "false",
            //    Name = "Negro"
            //};
            //await _service.UpdateTag(newTag);
            //var tags = await _service.GetAllTags();
            ApiGatewayResponse response = new ApiGatewayResponse()
            {
                StatusCode = 200,
                Body       = JsonConvert.SerializeObject(tag)
            };

            return(response);
        }
        public void Should_Create_NoContent_Response()
        {
            // Act
            var result = ApiGatewayResponse.NoContent();

            // Assert
            result.StatusCode.ShouldBe((int)HttpStatusCode.NoContent);
            result.Body.ShouldBeNull();
        }
        public void Should_Create_NotFound_Response(string message)
        {
            // Act
            var result = ApiGatewayResponse.NotFound(message);

            // Assert
            result.StatusCode.ShouldBe((int)HttpStatusCode.NotFound);
            result.Body.ShouldBe(message);
        }
        protected virtual async Task <APIGatewayProxyResponse> Subscribe()
        {
            Console.WriteLine("Subscriber Start");
            await Process();

            Console.WriteLine("Subscriber Done");

            return(ApiGatewayResponse.Ok(new { Message = "Subscription Successful" }));
        }
        public void Should_Create_Conflict_Response()
        {
            // Arrange
            const string message = "Test Conflict Response";

            // Act
            var result = ApiGatewayResponse.Conflict(message);

            // Assert
            result.StatusCode.ShouldBe((int)HttpStatusCode.Conflict);
            result.Body.ShouldBe(message);
        }
        public void Should_Create_OK_Response()
        {
            // Arrange
            var testObject = new TestObject {
                Foo = "Test"
            };

            // Act
            var result = ApiGatewayResponse.Ok(testObject);

            // Assert
            result.StatusCode.ShouldBe((int)HttpStatusCode.OK);
            result.Body.ShouldBe(JsonConvert.SerializeObject(testObject));
        }
        public void Should_Create_InternalServerError_Response()
        {
            // Arrange
            var exception = new Exception("Test Message");

            // Act
            var result = ApiGatewayResponse.InternalServerError(exception);

            // Assert
            result.StatusCode.ShouldBe((int)HttpStatusCode.InternalServerError);
            var message = (string)JsonConvert.DeserializeObject <dynamic>(result.Body).Message;

            message.ShouldBe(exception.Message);
        }
コード例 #8
0
        public async Task <APIGatewayProxyResponse> FunctionHandler(APIGatewayProxyRequest request, ILambdaContext context)
        {
            if (request.HttpMethod == "OPTIONS")
            {
                return(new ApiGatewayResponse());
            }
            string petId;

            request.PathParameters.TryGetValue("id", out petId);
            PetService _service = new PetService();
            var        tag      = await _service.GetPetById(petId);

            ApiGatewayResponse response = new ApiGatewayResponse()
            {
                StatusCode = 200,
                Body       = JsonConvert.SerializeObject(tag)
            };

            return(response);
        }
コード例 #9
0
        /// <summary>
        /// A simple function that takes a string and does a ToUpper
        /// </summary>
        /// <param name="input"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public async Task <APIGatewayProxyResponse> FunctionHandler(APIGatewayProxyRequest request, ILambdaContext context)
        {
            if (request.HttpMethod == "OPTIONS")
            {
                return(new ApiGatewayResponse(200));
            }
            string token        = request.Headers["Authorization"];
            var    accountEmail = DecodeJWT.GetAccountEmail(token);
            //LambdaLogger.Log("Context Identity: " + JsonConvert.SerializeObject(context));
            //LambdaLogger.Log("Request Context" + JsonConvert.SerializeObject(request.RequestContext.Authorizer.));
            UserService _service = new UserService();
            var         user     = await _service.GetUserByKey(accountEmail);

            ApiGatewayResponse response = new ApiGatewayResponse()
            {
                StatusCode = 200,
                Body       = JsonConvert.SerializeObject(user)
            };

            return(response);
        }
コード例 #10
0
        public async Task <ApiGatewayResponse> FunctionHandler(APIGatewayProxyRequest request, ILambdaContext context)
        {
            List <InMemoryFile> fileList = new List <InMemoryFile>();

            var unprintedTags = await _tagService.GetUnprintedTags();

            Dictionary <Tags, InMemoryFile> filesDictionary = new Dictionary <Tags, InMemoryFile>();

            foreach (var val in unprintedTags)
            {
                var qrArray = QrCodeCreator.CreateQrArray($"https://petzfinder.net/tag/{val.TagId}");
                var file    = new InMemoryFile()
                {
                    Content  = qrArray,
                    FileName = $"{val.TagId}.png"
                };
                filesDictionary.Add(val, file);
            }
            var timeStamp = DateTime.Now.ToString("yyyy_MM_dd_mm");

            _AwsService.UploadZipFileToS3(ZipFile.GetZipArchive(filesDictionary.Values.ToList()), timeStamp);
            foreach (var tag in unprintedTags)
            {
                tag.Printed         = "true";
                tag.FileDestination = timeStamp.Replace("_mm_ss", "");
                await _tagService.UpdateTag(tag);
            }

            //_AwsService.UploadQRFileListToS3(filesDictionary);
            ApiGatewayResponse response = new ApiGatewayResponse()
            {
                StatusCode = 200
                             //Body = Base64UrlEncoder.Encode(ZipFile.GetZipArchive(filesDictionary.Values.ToList())),
                             //IsBase64Encoded = true
            };

            //var zip = ZipFile.GetZipArchive(filesDictionary.Values.ToList());
            return(response);
        }
コード例 #11
0
ファイル: Function.cs プロジェクト: luisr200/PetzfinderApi
        public async Task <ApiGatewayResponse> FunctionHandler(APIGatewayProxyRequest request, ILambdaContext context)
        {
            LambdaLogger.Log("CONTEXT: " + JsonConvert.SerializeObject(request));
            //byte[] data = Convert.FromBase64String(request.Body);
            //string decodedString = Encoding.UTF8.GetString(data);
            var pet = JsonConvert.DeserializeObject <Pet>(request.Body);

            if (string.IsNullOrEmpty(pet.Id))
            {
                pet.Id = AlphanumericFactory.RandomString(5);
            }
            PetService _service = new PetService();
            await _service.PutPet(pet);

            ApiGatewayResponse response = new ApiGatewayResponse()
            {
                StatusCode = 200,
                Body       = JsonConvert.SerializeObject(pet)
            };

            return(response);
        }
コード例 #12
0
ファイル: Function.cs プロジェクト: luisr200/PetzfinderApi
        public async Task <ApiGatewayResponse> FunctionHandler(APIGatewayProxyRequest request, ILambdaContext context)
        {
            string token = request.Headers["Authorization"];

            LambdaLogger.Log("CONTEXT: " + JsonConvert.SerializeObject(request));
            LambdaLogger.Log("BODY: " + JsonConvert.SerializeObject(request.Body));
            var accountEmail = DecodeJWT.GetAccountEmail(token);
            //byte[] data = Convert.FromBase64String(request.Body);
            //string decodedString = Encoding.UTF8.GetString(data);
            var user = JsonConvert.DeserializeObject <User>(request.Body);

            user.Email = accountEmail;
            UserService _service = new UserService();
            await _service.PutUser(user);

            ApiGatewayResponse response = new ApiGatewayResponse()
            {
                StatusCode = 200
            };

            return(response);
        }
コード例 #13
0
        /// <summary>
        /// A simple function that takes a string and does a ToUpper
        /// </summary>
        /// <param name="input"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public async Task <APIGatewayProxyResponse> FunctionHandler(APIGatewayProxyRequest request, ILambdaContext context)
        {
            if (request.HttpMethod == "OPTIONS")
            {
                return(new ApiGatewayResponse(200));
            }
            LambdaLogger.Log("CONTEXT: " + JsonConvert.SerializeObject(request));
            string token = request.Headers["Authorization"];

            LambdaLogger.Log("Token: " + token);
            var accountEmail = DecodeJWT.GetAccountEmail(token);

            LambdaLogger.Log("Serial: " + DecodeJWT.GetAccountEmail(token));
            PetService _service = new PetService();
            var        pets     = await _service.GetAllUserPets(accountEmail);

            ApiGatewayResponse response = new ApiGatewayResponse()
            {
                StatusCode = 200,
                Body       = JsonConvert.SerializeObject(pets)
            };

            return(response);
        }