Added ability to pick albums for motivation

+ clippy + fmt
This commit is contained in:
2023-09-16 10:18:47 -06:00
parent 295f2704bc
commit 8ec84ff946
3 changed files with 32 additions and 9 deletions
+17 -5
View File
@@ -1,6 +1,7 @@
use crate::album_manager::Album;
use crate::error::Error;
use j_db::database::Database;
use j_db::error::JDbError;
use j_db::model::JdbModel;
use rand::prelude::{IteratorRandom, SliceRandom};
use rand::thread_rng;
@@ -80,17 +81,28 @@ impl MotivationConfig {
db: &Database,
base_path: &Path,
border_color: &str,
album_name: Option<String>,
) -> Result<Motivation, Error> {
let motivation = Self::get_motivation_config(db)?;
let mut images = Vec::new();
for album in motivation.album {
let album = db.get::<Album>(album);
if let Some(album_name) = album_name {
let album = Album::find_album_by_name_or_alias(db, &album_name)?;
if let Ok(album) = album {
let mut album_images = album.images.clone();
images.append(&mut album_images);
if let Some(mut album) = album {
images.append(&mut album.images)
} else {
return Err(Error::from(JDbError::NotFound));
}
} else {
for album in motivation.album {
let album = db.get::<Album>(album);
if let Ok(album) = album {
let mut album_images = album.images.clone();
images.append(&mut album_images);
}
}
}