Continuing with error refactoring.
This commit is contained in:
@@ -116,38 +116,40 @@ where
|
||||
}
|
||||
|
||||
fn decode(row: UserAppSecretRow) -> Result<UserAppSecret, DecodeError> {
|
||||
Ok(UserAppSecret {
|
||||
id: row.id,
|
||||
app_id: row.app_id,
|
||||
secret_hash: row.secret_hash,
|
||||
expires_at: row.expires_at,
|
||||
created_at: row.created_at,
|
||||
})
|
||||
Ok(UserAppSecret::new(
|
||||
row.id,
|
||||
row.app_id,
|
||||
row.secret_hash,
|
||||
row.expires_at,
|
||||
row.created_at,
|
||||
)?)
|
||||
}
|
||||
|
||||
fn encode(secret: UserAppSecret) -> UserAppSecretRow {
|
||||
UserAppSecretRow {
|
||||
id: secret.id,
|
||||
app_id: secret.app_id,
|
||||
secret_hash: secret.secret_hash,
|
||||
expires_at: secret.expires_at,
|
||||
created_at: secret.created_at,
|
||||
id: secret.id(),
|
||||
app_id: secret.app_id(),
|
||||
secret_hash: secret.secret_hash().clone(),
|
||||
expires_at: secret.expires_at(),
|
||||
created_at: secret.created_at(),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use chrono::Utc;
|
||||
use chrono::{Duration, Utc};
|
||||
|
||||
use super::*;
|
||||
|
||||
fn row() -> UserAppSecretRow {
|
||||
let created_at = Utc::now();
|
||||
|
||||
UserAppSecretRow {
|
||||
id: Uuid::new_v4(),
|
||||
app_id: Uuid::new_v4(),
|
||||
secret_hash: vec![0; 32],
|
||||
expires_at: Utc::now(),
|
||||
created_at: Utc::now(),
|
||||
expires_at: created_at + Duration::days(1),
|
||||
created_at,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user