From 6477ddabcc28d4b99084b9fc1ba382c4908040db Mon Sep 17 00:00:00 2001 From: taco-paco Date: Thu, 12 Sep 2024 18:13:40 +0900 Subject: [PATCH] feat: item.id change to Uuid type --- crates/lambdas/src/compile.rs | 4 ++-- crates/types/src/item.rs | 13 ++++++++----- crates/worker/src/purgatory.rs | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/crates/lambdas/src/compile.rs b/crates/lambdas/src/compile.rs index 7b94dc4..f03e2fb 100644 --- a/crates/lambdas/src/compile.rs +++ b/crates/lambdas/src/compile.rs @@ -36,9 +36,9 @@ async fn compile( sqs_client: &aws_sdk_sqs::Client, queue_url: &str, ) -> Result<(), Error> { - let created_at = Utc::now().to_rfc3339(); + let created_at = Utc::now(); let item = Item { - id: request.id.to_string(), + id: request.id, status: Status::Pending, created_at }; diff --git a/crates/types/src/item.rs b/crates/types/src/item.rs index ef70eae..6005e98 100644 --- a/crates/types/src/item.rs +++ b/crates/types/src/item.rs @@ -4,6 +4,7 @@ use serde::{Deserialize, Serialize}; use std::collections::HashMap; use std::fmt; use std::fmt::Formatter; +use uuid::Uuid; pub type AttributeMap = HashMap; @@ -135,7 +136,7 @@ pub enum ItemError { } pub struct Item { - pub id: String, + pub id: Uuid, pub status: Status, pub created_at: DateTime, // TODO: type: Compiling/Verifying @@ -168,7 +169,7 @@ impl From for AttributeMap { let mut item_map = HashMap::from([ ( Item::id_attribute_name().into(), - AttributeValue::S(value.id), + AttributeValue::S(value.id.into()), ), ( Item::created_at_attribute_name().into(), @@ -186,8 +187,10 @@ impl TryFrom for Item { fn try_from(value: AttributeMap) -> Result { let id = value .get(Item::id_attribute_name()) - .ok_or(ItemError::FormatError)?; - let id = id.as_s().map_err(|_| ItemError::FormatError)?; + .ok_or(ItemError::FormatError)? + .as_s() + .map_err(|_| ItemError::FormatError)?; + let id = Uuid::parse_str(id.as_str()).map_err(|_| ItemError::FormatError)?; let status = (&value).try_into()?; let created_at = value @@ -197,7 +200,7 @@ impl TryFrom for Item { let created_at = DateTime::::parse_from_rfc3339(created_at.as_str())?; Ok(Item { - id: id.clone(), + id, status, created_at: created_at.into(), }) diff --git a/crates/worker/src/purgatory.rs b/crates/worker/src/purgatory.rs index 4606b11..47a5a3b 100644 --- a/crates/worker/src/purgatory.rs +++ b/crates/worker/src/purgatory.rs @@ -126,7 +126,7 @@ impl Inner { Inner::purge_item( &db_client, &s3_client, - &Uuid::parse_str(&item.id).unwrap(), + &item.id, &item.status, ) .await;