diff --git a/services/backup/src/database.rs b/services/backup/src/database.rs
--- a/services/backup/src/database.rs
+++ b/services/backup/src/database.rs
@@ -1,9 +1,20 @@
-use aws_sdk_dynamodb::{model::AttributeValue, Error as DynamoDBError};
+use aws_sdk_dynamodb::{
+ model::AttributeValue, output::GetItemOutput, Error as DynamoDBError,
+};
use chrono::{DateTime, Utc};
use std::{
+ collections::HashMap,
fmt::{Display, Formatter},
sync::Arc,
};
+use tracing::error;
+
+use crate::constants::{
+ BACKUP_TABLE_FIELD_ATTACHMENT_HOLDERS, BACKUP_TABLE_FIELD_BACKUP_ID,
+ BACKUP_TABLE_FIELD_COMPACTION_HOLDER, BACKUP_TABLE_FIELD_CREATED,
+ BACKUP_TABLE_FIELD_RECOVERY_DATA, BACKUP_TABLE_FIELD_USER_ID,
+ BACKUP_TABLE_INDEX_USERID_CREATED, BACKUP_TABLE_NAME,
+};
#[derive(Clone, Debug)]
pub struct BackupItem {
@@ -42,7 +53,46 @@
&self,
backup_item: BackupItem,
) -> Result<(), Error> {
- unimplemented!()
+ let item = HashMap::from([
+ (
+ BACKUP_TABLE_FIELD_USER_ID.to_string(),
+ AttributeValue::S(backup_item.user_id),
+ ),
+ (
+ BACKUP_TABLE_FIELD_CREATED.to_string(),
+ AttributeValue::S(backup_item.created.to_rfc3339()),
+ ),
+ (
+ BACKUP_TABLE_FIELD_BACKUP_ID.to_string(),
+ AttributeValue::S(backup_item.backup_id),
+ ),
+ (
+ BACKUP_TABLE_FIELD_RECOVERY_DATA.to_string(),
+ AttributeValue::S(backup_item.recovery_data),
+ ),
+ (
+ BACKUP_TABLE_FIELD_COMPACTION_HOLDER.to_string(),
+ AttributeValue::S(backup_item.compaction_holder),
+ ),
+ (
+ BACKUP_TABLE_FIELD_ATTACHMENT_HOLDERS.to_string(),
+ AttributeValue::S(backup_item.attachment_holders),
+ ),
+ ]);
+
+ self
+ .client
+ .put_item()
+ .table_name(BACKUP_TABLE_NAME)
+ .set_item(Some(item))
+ .send()
+ .await
+ .map_err(|e| {
+ error!("DynamoDB client failed to put backup item");
+ Error::AwsSdk(e.into())
+ })?;
+
+ Ok(())
}
pub async fn find_backup_item(
@@ -50,18 +100,88 @@
user_id: &str,
backup_id: &str,
) -> Result