Skip to content
This repository has been archived by the owner on Dec 6, 2024. It is now read-only.

Commit

Permalink
feat: item.id change to Uuid type
Browse files Browse the repository at this point in the history
  • Loading branch information
taco-paco committed Sep 18, 2024
1 parent 54d9cae commit 6477dda
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions crates/lambdas/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down
13 changes: 8 additions & 5 deletions crates/types/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, AttributeValue>;

Expand Down Expand Up @@ -135,7 +136,7 @@ pub enum ItemError {
}

pub struct Item {
pub id: String,
pub id: Uuid,
pub status: Status,
pub created_at: DateTime<Utc>,
// TODO: type: Compiling/Verifying
Expand Down Expand Up @@ -168,7 +169,7 @@ impl From<Item> 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(),
Expand All @@ -186,8 +187,10 @@ impl TryFrom<AttributeMap> for Item {
fn try_from(value: AttributeMap) -> Result<Item, Self::Error> {
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
Expand All @@ -197,7 +200,7 @@ impl TryFrom<AttributeMap> for Item {
let created_at = DateTime::<FixedOffset>::parse_from_rfc3339(created_at.as_str())?;

Ok(Item {
id: id.clone(),
id,
status,
created_at: created_at.into(),
})
Expand Down
2 changes: 1 addition & 1 deletion crates/worker/src/purgatory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl Inner {
Inner::purge_item(
&db_client,
&s3_client,
&Uuid::parse_str(&item.id).unwrap(),
&item.id,
&item.status,
)
.await;
Expand Down

0 comments on commit 6477dda

Please sign in to comment.