diff --git a/services/backup/docker-server/contents/server/src/DatabaseManager.h b/services/backup/docker-server/contents/server/src/DatabaseManager.h --- a/services/backup/docker-server/contents/server/src/DatabaseManager.h +++ b/services/backup/docker-server/contents/server/src/DatabaseManager.h @@ -32,7 +32,7 @@ template std::shared_ptr innerFindItem(Aws::DynamoDB::Model::GetItemRequest &request); - void innerRemoveItem(const Item &item, const std::string &key); + void innerRemoveItem(const Item &item); public: static DatabaseManager &getInstance(); diff --git a/services/backup/docker-server/contents/server/src/DatabaseManager.cpp b/services/backup/docker-server/contents/server/src/DatabaseManager.cpp --- a/services/backup/docker-server/contents/server/src/DatabaseManager.cpp +++ b/services/backup/docker-server/contents/server/src/DatabaseManager.cpp @@ -28,14 +28,19 @@ } } -void DatabaseManager::innerRemoveItem( - const Item &item, - const std::string &key) { +void DatabaseManager::innerRemoveItem(const Item &item) { Aws::DynamoDB::Model::DeleteItemRequest request; request.SetTableName(item.getTableName()); + PrimaryKey pk = item.getPrimaryKey(); + PrimaryKeyValue primaryKeyValue = item.getPrimaryKeyValue(); request.AddKey( - item.getPrimaryKey().partitionKey, - Aws::DynamoDB::Model::AttributeValue(key)); + pk.partitionKey, + Aws::DynamoDB::Model::AttributeValue(primaryKeyValue.partitionKey)); + if (pk.sortKey != nullptr && primaryKeyValue.sortKey != nullptr) { + request.AddKey( + *pk.sortKey, + Aws::DynamoDB::Model::AttributeValue(*primaryKeyValue.sortKey)); + } const Aws::DynamoDB::Model::DeleteItemOutcome &outcome = getDynamoDBClient()->DeleteItem(request); @@ -100,20 +105,7 @@ } void DatabaseManager::removeBackupItem(std::shared_ptr item) { - Aws::DynamoDB::Model::DeleteItemRequest request; - request.SetTableName(item->getTableName()); - request.AddKey( - BackupItem::FIELD_USER_ID, - Aws::DynamoDB::Model::AttributeValue(item->getUserID())); - request.AddKey( - BackupItem::FIELD_BACKUP_ID, - Aws::DynamoDB::Model::AttributeValue(item->getBackupID())); - - const Aws::DynamoDB::Model::DeleteItemOutcome &outcome = - comm::network::getDynamoDBClient()->DeleteItem(request); - if (!outcome.IsSuccess()) { - throw std::runtime_error(outcome.GetError().GetMessage()); - } + this->innerRemoveItem(*item); } void DatabaseManager::putLogItem(const LogItem &item) { @@ -167,20 +159,7 @@ } void DatabaseManager::removeLogItem(std::shared_ptr item) { - Aws::DynamoDB::Model::DeleteItemRequest request; - request.SetTableName(item->getTableName()); - request.AddKey( - LogItem::FIELD_BACKUP_ID, - Aws::DynamoDB::Model::AttributeValue(item->getBackupID())); - request.AddKey( - LogItem::FIELD_LOG_ID, - Aws::DynamoDB::Model::AttributeValue(item->getLogID())); - - const Aws::DynamoDB::Model::DeleteItemOutcome &outcome = - getDynamoDBClient()->DeleteItem(request); - if (!outcome.IsSuccess()) { - throw std::runtime_error(outcome.GetError().GetMessage()); - } + this->innerRemoveItem(*item); } } // namespace database