public async Task <IActionResult> Delete(string productId, string publishedOn)
        {
            var db = await _dbContextBuilder.Build();

            try
            {
                var checkForProduct = await db.LoadAsync <Product>(productId, publishedOn);

                if (checkForProduct == null)
                {
                    return(NotFound());
                }
                await db.DeleteAsync <Product>(productId, publishedOn,
                                               new DynamoDBOperationConfig { SkipVersionCheck = true });

                return(StatusCode(204));
            }
            catch (AmazonDynamoDBException addbe)
            {
                return(AmazonExceptionHandlers.HandleAmazonDynamoDBException(addbe));
            }
            catch (AmazonServiceException ase)
            {
                AmazonExceptionHandlers.HandleAmazonServiceExceptionException(ase);
            }
            catch (AmazonClientException ace)
            {
                AmazonExceptionHandlers.HandleAmazonClientExceptionException(ace);
            }
            return(StatusCode(500));
        }
        public async Task <IActionResult> Get(string productId, string publishedOn)
        {
            var db = await _dbContextBuilder.Build();

            try
            {
                var product = await db.LoadAsync <Product>(hashKey : productId, rangeKey : publishedOn);

                if (product == null)
                {
                    return(NotFound());
                }
                Console.WriteLine(product.ObjectPersistenceProductId);
                Console.WriteLine(product.PublishOn);
                return(Ok(product));
            }
            catch (AmazonDynamoDBException addbe)
            {
                return(AmazonExceptionHandlers.HandleAmazonDynamoDBException(addbe));
            }
            catch (AmazonServiceException ase)
            {
                AmazonExceptionHandlers.HandleAmazonServiceExceptionException(ase);
            }
            catch (AmazonClientException ace)
            {
                AmazonExceptionHandlers.HandleAmazonClientExceptionException(ace);
            }
            return(StatusCode(500));
        }
Beispiel #3
0
        public async Task <IActionResult> UpdateItem([FromBody] UpdateItemRequest request)
        {
            try
            {
                var res = await _dynamoClient.UpdateItemAsync(request);

                return(new JsonResult(res)
                {
                    StatusCode = 200
                });
            }
            catch (AmazonDynamoDBException addbe)
            {
                return(AmazonExceptionHandlers.HandleAmazonDynamoDBException(addbe));
            }
            catch (AmazonServiceException ase)
            {
                AmazonExceptionHandlers.HandleAmazonServiceExceptionException(ase);
            }
            catch (AmazonClientException ace)
            {
                AmazonExceptionHandlers.HandleAmazonClientExceptionException(ace);
            }
            return(StatusCode(500));
        }
        public async Task <IActionResult> Update([FromBody] Product product, string productId, string publishedOn)
        {
            var db = await _dbContextBuilder.Build();

            try
            {
                var checkForProduct = await db.LoadAsync <Product>(productId, publishedOn);

                if (checkForProduct == null)
                {
                    return(NotFound());
                }
                product.ObjectPersistenceProductId = productId;
                product.PublishOn = publishedOn;
                await db.SaveAsync <Product>(product,
                                             new DynamoDBOperationConfig { SkipVersionCheck = true, IgnoreNullValues = true });

                var updatedProduct = await db.LoadAsync <Product>(productId, publishedOn);

                return(Ok(updatedProduct));
            }
            catch (AmazonDynamoDBException addbe)
            {
                return(AmazonExceptionHandlers.HandleAmazonDynamoDBException(addbe));
            }
            catch (AmazonServiceException ase)
            {
                AmazonExceptionHandlers.HandleAmazonServiceExceptionException(ase);
            }
            catch (AmazonClientException ace)
            {
                AmazonExceptionHandlers.HandleAmazonClientExceptionException(ace);
            }
            return(StatusCode(500));
        }
Beispiel #5
0
        public async Task <IActionResult> GetTableStatus(string tableName)
        {
            Console.WriteLine("*** Retrieving table status information ***");
            Console.WriteLine($"Searching for table status: {tableName}");

            DescribeTableRequest req = new DescribeTableRequest();

            req.TableName = tableName;
            try
            {
                var res = await _dynamoClient.DescribeTableAsync(req);

                var description = res.Table.TableStatus;
                return(Ok(description));
            }
            catch (AmazonDynamoDBException addbe)
            {
                return(AmazonExceptionHandlers.HandleAmazonDynamoDBException(addbe));
            }
            catch (AmazonServiceException ase)
            {
                AmazonExceptionHandlers.HandleAmazonServiceExceptionException(ase);
            }
            catch (AmazonClientException ace)
            {
                AmazonExceptionHandlers.HandleAmazonClientExceptionException(ace);
            }
            return(StatusCode(500));
        }
Beispiel #6
0
        public async Task <IActionResult> Delete(string tableName)
        {
            System.Console.WriteLine($"Deleting {tableName} table.");
            var req = new DeleteTableRequest();

            req.TableName = tableName;

            try
            {
                var res = await _dynamoClient.DeleteTableAsync(req);

                Console.WriteLine($"Deleted table: {req.TableName}");
                return(StatusCode(204));
            }
            catch (AmazonDynamoDBException addbe)
            {
                return(AmazonExceptionHandlers.HandleAmazonDynamoDBException(addbe));
            }
            catch (AmazonServiceException ase)
            {
                AmazonExceptionHandlers.HandleAmazonServiceExceptionException(ase);
            }
            catch (AmazonClientException ace)
            {
                AmazonExceptionHandlers.HandleAmazonClientExceptionException(ace);
            }
            return(StatusCode(500));
        }
Beispiel #7
0
        public async Task <IActionResult> Get(string tableName)
        {
            Console.WriteLine("*** Retrieving table information ***");
            Console.WriteLine($"Searching for table: {tableName}");

            DescribeTableRequest req = new DescribeTableRequest();

            req.TableName = tableName;
            try
            {
                var res = await _dynamoClient.DescribeTableAsync(req);

                var description = res.Table;
                Console.WriteLine($"Name: {description.TableName}");
                Console.WriteLine($"# of items: {description.ItemCount}");
                Console.WriteLine($"Provision Throughput (reads/sec): {description.ProvisionedThroughput.ReadCapacityUnits}");
                Console.WriteLine($"Provision Throughput (writes/sec): {description.ProvisionedThroughput.WriteCapacityUnits}");
                return(Ok(res.Table));
            }
            catch (AmazonDynamoDBException addbe)
            {
                return(AmazonExceptionHandlers.HandleAmazonDynamoDBException(addbe));
            }
            catch (AmazonServiceException ase)
            {
                AmazonExceptionHandlers.HandleAmazonServiceExceptionException(ase);
            }
            catch (AmazonClientException ace)
            {
                AmazonExceptionHandlers.HandleAmazonClientExceptionException(ace);
            }
            return(StatusCode(500));
        }
Beispiel #8
0
        public async Task <IActionResult> Create([FromBody] CreateTableRequest request)
        {
            Console.WriteLine("Request Info:");
            Console.WriteLine("\tTableName:");
            Console.WriteLine($"\t{request.TableName}");
            if (request.ProvisionedThroughput != null)
            {
                Console.WriteLine("\tReadCapacityUnits:");
                Console.WriteLine($"\t{request.ProvisionedThroughput.ReadCapacityUnits}");
                Console.WriteLine("\tWriteCapacityUnits:");
                Console.WriteLine($"\t{request.ProvisionedThroughput.WriteCapacityUnits}");
            }
            if (request.KeySchema != null)
            {
                System.Console.WriteLine("\tKeySchemas:");
                foreach (var k in request.KeySchema)
                {
                    Console.WriteLine("\tAttributeName");
                    Console.WriteLine($"\t{k.AttributeName}");
                    Console.WriteLine("\tKeyType");
                    Console.WriteLine($"\t{k.KeyType}");
                }
            }
            try
            {
                var res = await _dynamoClient.CreateTableAsync(request);

                Console.WriteLine("Created table");
                System.Console.WriteLine("\tTableName");
                System.Console.WriteLine($"\t{res.TableDescription.TableName}");
                System.Console.WriteLine("\tTableArn");
                System.Console.WriteLine($"\t{res.TableDescription.TableArn}");
                System.Console.WriteLine("\tTableId");
                System.Console.WriteLine($"\t{res.TableDescription.TableId}");
                System.Console.WriteLine("\tTableStatus");
                System.Console.WriteLine($"\t{res.TableDescription.TableStatus}");
                return(new JsonResult(
                           new
                {
                    message = $"Creating new table: {res.TableDescription.TableName}",
                    TableDescription = res.TableDescription
                })
                {
                    StatusCode = 202
                });
            }
            catch (AmazonDynamoDBException addbe)
            {
                return(AmazonExceptionHandlers.HandleAmazonDynamoDBException(addbe));
            }
            catch (AmazonServiceException ase)
            {
                AmazonExceptionHandlers.HandleAmazonServiceExceptionException(ase);
            }
            catch (AmazonClientException ace)
            {
                AmazonExceptionHandlers.HandleAmazonClientExceptionException(ace);
            }
            return(StatusCode(500));
        }
Beispiel #9
0
        public async Task <IActionResult> Update([FromBody] UpdateTableRequest request, string tableName)
        {
            request.TableName = tableName;
            Console.WriteLine("Request Info:");
            Console.WriteLine("\tTableName:");
            Console.WriteLine($"\t{request.TableName}");
            try
            {
                var res = await _dynamoClient.UpdateTableAsync(request);

                return(new JsonResult(
                           new
                {
                    message = $"Updated {res.TableDescription.TableName} table.",
                    TableDescription = res.TableDescription
                })
                {
                    StatusCode = 202
                });
            }
            catch (AmazonDynamoDBException addbe)
            {
                return(AmazonExceptionHandlers.HandleAmazonDynamoDBException(addbe));
            }
            catch (AmazonServiceException ase)
            {
                AmazonExceptionHandlers.HandleAmazonServiceExceptionException(ase);
            }
            catch (AmazonClientException ace)
            {
                AmazonExceptionHandlers.HandleAmazonClientExceptionException(ace);
            }
            return(StatusCode(500));
        }
Beispiel #10
0
        public async Task <IActionResult> Get(string productId, string publishedOn)
        {
            var table = await _dbTableBuilder.Build();

            try
            {
                var product = await table.GetItemAsync(hashKey : productId, rangeKey : publishedOn);

                if (product == null)
                {
                    return(NotFound());
                }
                Console.WriteLine(product["DocumentProductId"]);
                Console.WriteLine(product["PublishOn"]);
                return(Ok(product.ToJson()));
            }
            catch (AmazonDynamoDBException addbe)
            {
                return(AmazonExceptionHandlers.HandleAmazonDynamoDBException(addbe));
            }
            catch (AmazonServiceException ase)
            {
                AmazonExceptionHandlers.HandleAmazonServiceExceptionException(ase);
            }
            catch (AmazonClientException ace)
            {
                AmazonExceptionHandlers.HandleAmazonClientExceptionException(ace);
            }
            return(StatusCode(500));
        }
Beispiel #11
0
        public async Task <IActionResult> Delete(string productId, string publishedOn)
        {
            var table = await _dbTableBuilder.Build();

            try
            {
                var checkForProduct = await table.GetItemAsync(productId, publishedOn);

                if (checkForProduct == null)
                {
                    return(NotFound());
                }
                await table.DeleteItemAsync(productId, publishedOn);

                return(StatusCode(204));
            }
            catch (AmazonDynamoDBException addbe)
            {
                return(AmazonExceptionHandlers.HandleAmazonDynamoDBException(addbe));
            }
            catch (AmazonServiceException ase)
            {
                AmazonExceptionHandlers.HandleAmazonServiceExceptionException(ase);
            }
            catch (AmazonClientException ace)
            {
                AmazonExceptionHandlers.HandleAmazonClientExceptionException(ace);
            }
            return(StatusCode(500));
        }
Beispiel #12
0
        public async Task <IActionResult> Update([FromBody] Amazon.DynamoDBv2.DocumentModel.Document product, string productId, string publishedOn)
        {
            var table = await _dbTableBuilder.Build();

            try
            {
                var checkForProduct = await table.GetItemAsync(productId, publishedOn);

                if (checkForProduct == null)
                {
                    return(NotFound());
                }
                product["DocumentProductId"] = productId;
                product["PublishOn"]         = publishedOn;
                await table.UpdateItemAsync(product);

                var updatedProduct = await table.GetItemAsync(productId, publishedOn);

                return(Ok(updatedProduct.ToJson()));
            }
            catch (AmazonDynamoDBException addbe)
            {
                return(AmazonExceptionHandlers.HandleAmazonDynamoDBException(addbe));
            }
            catch (AmazonServiceException ase)
            {
                AmazonExceptionHandlers.HandleAmazonServiceExceptionException(ase);
            }
            catch (AmazonClientException ace)
            {
                AmazonExceptionHandlers.HandleAmazonClientExceptionException(ace);
            }
            return(StatusCode(500));
        }
Beispiel #13
0
        public async Task <IActionResult> Get(string tableName)
        {
            try
            {
                Dictionary <string, AttributeValue> queryInfo = new Dictionary <string, AttributeValue>();
                var queryString = HttpContext.Request.Query;
                foreach (var queryVariable in queryString)
                {
                    queryInfo.Add(queryVariable.Key, new AttributeValue(queryVariable.Value));
                }
                GetItemRequest request = new GetItemRequest(tableName, queryInfo);

                var res = await _dynamoClient.GetItemAsync(request);

                return(Ok(res.Item));
            }
            catch (AmazonDynamoDBException addbe)
            {
                return(AmazonExceptionHandlers.HandleAmazonDynamoDBException(addbe));
            }
            catch (AmazonServiceException ase)
            {
                AmazonExceptionHandlers.HandleAmazonServiceExceptionException(ase);
            }
            catch (AmazonClientException ace)
            {
                AmazonExceptionHandlers.HandleAmazonClientExceptionException(ace);
            }
            return(StatusCode(500));
        }
Beispiel #14
0
        public async Task <IActionResult> Create([FromBody] Amazon.DynamoDBv2.DocumentModel.Document product)
        {
            var table = await _dbTableBuilder.Build();

            try
            {
                Console.WriteLine(product["DocumentProductId"]);
                Console.WriteLine(product["PublishOn"]);

                await table.PutItemAsync(product);

                var productId = product["DocumentProductId"].AsString();
                return(new JsonResult(
                           new
                {
                    message = $"Created new product: {productId}",
                    product = product.ToJson()
                })
                {
                    StatusCode = 201
                });
            }
            catch (AmazonDynamoDBException addbe)
            {
                if (addbe.ErrorCode == "ConditionalCheckFailedException")
                {
                    return new JsonResult(
                        new
                    {
                        message = $"Product {product["DocumentProductId"]} already exists"
                    })
                           {
                               StatusCode = 409
                           }
                }
                ;
                return(AmazonExceptionHandlers.HandleAmazonDynamoDBException(addbe));
            }
            catch (AmazonServiceException ase)
            {
                AmazonExceptionHandlers.HandleAmazonServiceExceptionException(ase);
            }
            catch (AmazonClientException ace)
            {
                AmazonExceptionHandlers.HandleAmazonClientExceptionException(ace);
            }
            return(StatusCode(500));
        }
        public async Task <IActionResult> Create([FromBody] Product product)
        {
            var db = await _dbContextBuilder.Build();

            try
            {
                Console.WriteLine(product.ObjectPersistenceProductId);
                Console.WriteLine(product.PublishOn);
                await db.SaveAsync <Product>(product);

                return(new JsonResult(
                           new
                {
                    message = $"Created new product: {product.ObjectPersistenceProductId}",
                    product = product
                })
                {
                    StatusCode = 201
                });
            }
            catch (AmazonDynamoDBException addbe)
            {
                if (addbe.ErrorCode == "ConditionalCheckFailedException")
                {
                    return new JsonResult(
                        new
                    {
                        message = $"Product {product.ObjectPersistenceProductId} already exists"
                    })
                           {
                               StatusCode = 409
                           }
                }
                ;
                return(AmazonExceptionHandlers.HandleAmazonDynamoDBException(addbe));
            }
            catch (AmazonServiceException ase)
            {
                AmazonExceptionHandlers.HandleAmazonServiceExceptionException(ase);
            }
            catch (AmazonClientException ace)
            {
                AmazonExceptionHandlers.HandleAmazonClientExceptionException(ace);
            }
            return(StatusCode(500));
        }
Beispiel #16
0
        public async Task <IActionResult> Get([FromBody] GetItemRequest request)
        {
            try
            {
                var res = await _dynamoClient.GetItemAsync(request);

                return(Ok(res.Item));
            }
            catch (AmazonDynamoDBException addbe)
            {
                return(AmazonExceptionHandlers.HandleAmazonDynamoDBException(addbe));
            }
            catch (AmazonServiceException ase)
            {
                AmazonExceptionHandlers.HandleAmazonServiceExceptionException(ase);
            }
            catch (AmazonClientException ace)
            {
                AmazonExceptionHandlers.HandleAmazonClientExceptionException(ace);
            }
            return(StatusCode(500));
        }