Moved albums to the database

+ Clippy + fmt
This commit is contained in:
2023-01-20 15:01:31 -07:00
parent 362977caa9
commit 8d35d350ad
5 changed files with 79 additions and 33 deletions
+41
View File
@@ -0,0 +1,41 @@
use crate::error::Error;
use j_db::database::Database;
use j_db::model::JdbModel;
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct AlbumConfig {
id: Option<u64>,
pub name: String,
pub album_id: String,
}
impl JdbModel for AlbumConfig {
fn id(&self) -> Option<u64> {
self.id
}
fn set_id(&mut self, id: u64) {
self.id = Some(id)
}
fn tree() -> String {
"Album".to_string()
}
}
impl AlbumConfig {
pub fn new(name: &str, album_id: &str) -> AlbumConfig {
Self {
id: None,
name: name.to_string(),
album_id: album_id.to_string(),
}
}
pub fn get_album_by_name(db: &Database, name: &str) -> Result<Option<AlbumConfig>, Error> {
Ok(db
.filter(|_, album_config: &AlbumConfig| album_config.name.eq_ignore_ascii_case(name))?
.next())
}
}
+1
View File
@@ -1,2 +1,3 @@
pub mod album;
pub mod insult_compliment;
pub mod random;