Add a libraries command and scan subcommand
This commit is contained in:
parent
2eb4e391c2
commit
af1af8dce1
9 changed files with 182 additions and 1 deletions
83
src/models/library.rs
Normal file
83
src/models/library.rs
Normal file
|
@ -0,0 +1,83 @@
|
|||
use chrono::{DateTime, Utc};
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::types::LibraryResponseDto;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Library {
|
||||
pub id: Uuid,
|
||||
pub name: String,
|
||||
pub asset_count: i64,
|
||||
pub updated_at: DateTime<Utc>,
|
||||
pub refreshed_at: Option<DateTime<Utc>>,
|
||||
}
|
||||
|
||||
impl From<LibraryResponseDto> for Library {
|
||||
fn from(value: LibraryResponseDto) -> Self {
|
||||
Self {
|
||||
id: Uuid::parse_str(&value.id).expect("Unable to parse a library's UUID"),
|
||||
name: value.name,
|
||||
asset_count: value.asset_count,
|
||||
updated_at: value.updated_at,
|
||||
refreshed_at: value.refreshed_at,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
use std::str::FromStr;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn from_library_response_dto_success() {
|
||||
let dto = LibraryResponseDto {
|
||||
id: String::from("123e4567-e89b-12d3-a456-426655440000"),
|
||||
name: String::from("Christmas photos"),
|
||||
asset_count: 1246,
|
||||
exclusion_patterns: vec![],
|
||||
import_paths: vec![],
|
||||
owner_id: String::from("abc123"),
|
||||
updated_at: DateTime::<Utc>::from_str("2024-11-17T12:55:12Z").unwrap(),
|
||||
created_at: DateTime::<Utc>::from_str("2023-10-17T12:55:12Z").unwrap(),
|
||||
refreshed_at: Some(DateTime::<Utc>::from_str("2024-11-17T12:53:12Z").unwrap()),
|
||||
};
|
||||
|
||||
let library = Library::from(dto);
|
||||
|
||||
assert_eq!(
|
||||
library.id,
|
||||
Uuid::parse_str("123e4567-e89b-12d3-a456-426655440000").unwrap()
|
||||
);
|
||||
assert_eq!(library.name, "Christmas photos".to_string());
|
||||
assert_eq!(library.asset_count, 1246);
|
||||
assert_eq!(
|
||||
library.updated_at,
|
||||
DateTime::<Utc>::from_str("2024-11-17T12:55:12Z").unwrap()
|
||||
);
|
||||
assert_eq!(
|
||||
library.refreshed_at,
|
||||
Some(DateTime::<Utc>::from_str("2024-11-17T12:53:12Z").unwrap())
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn from_library_response_dto_invalid_uuid_panics() {
|
||||
let dto = LibraryResponseDto {
|
||||
id: String::from("invalid_uuid"),
|
||||
name: String::from("Christmas photos"),
|
||||
asset_count: 1246,
|
||||
exclusion_patterns: vec![],
|
||||
import_paths: vec![],
|
||||
owner_id: String::from("abc123"),
|
||||
updated_at: DateTime::<Utc>::from_str("2024-11-17T12:55:12Z").unwrap(),
|
||||
created_at: DateTime::<Utc>::from_str("2023-10-17T12:55:12Z").unwrap(),
|
||||
refreshed_at: Some(DateTime::<Utc>::from_str("2024-11-17T12:53:12Z").unwrap()),
|
||||
};
|
||||
|
||||
let _ = Library::from(dto);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue