From 43cc4defbbe085c3cdb13e4b4a704d12738d2d7b Mon Sep 17 00:00:00 2001 From: phoenix Date: Thu, 5 Nov 2026 15:03:11 -0500 Subject: [PATCH] Adding features --- Cargo.toml | 16 ++++++++++++++++ src/access_level.rs | 16 +++++++++------- src/constants.rs | 12 ++++++++++++ src/ledger/mod.rs | 8 ++------ src/token.rs | 2 +- 5 files changed, 40 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index cf72992..1cf077d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,5 +15,21 @@ uuid = { version = "1.29.0", features = ["v4", "serde"] } josekit = { version = "0.10.3" } utoipa = { version = "6.0.0", features = ["uuid", "time"] } +[features] +default = ["full"] +full = ["access_level", "album", "constants", "coverart", "ledger", "login_result", "song", "token", "types", "user", "util"] +auth = ["constants", "login_result", "token", "user"] +access_level = ["constants"] +album = [] +constants = [] +coverart = ["constants", "types"] +ledger = ["constants", "song", "types", "user"] +login_result = ["constants", "token", "user"] +song = ["constants", "types"] +token = [] +types = [] +user = [] +util = [] + [dev-dependencies] tempfile = { version = "3.27.0" } diff --git a/src/access_level.rs b/src/access_level.rs index 35901f2..6ad2a8e 100644 --- a/src/access_level.rs +++ b/src/access_level.rs @@ -2,6 +2,8 @@ use std::default::Default; use serde::{Deserialize, Serialize}; +const DEFAULT_ACCESS_LEVEL: &str = super::constants::access_level::PUBLIC; + #[derive(Clone, Debug, Deserialize, Serialize, utoipa::ToSchema)] pub struct AccessLevel { pub id: uuid::Uuid, @@ -13,8 +15,8 @@ impl Default for AccessLevel { fn default() -> Self { AccessLevel { id: uuid::Uuid::nil(), - level: String::new(), - song_id: uuid::Uuid::new_v4(), + level: DEFAULT_ACCESS_LEVEL.to_string(), + song_id: uuid::Uuid::nil(), } } } @@ -22,16 +24,16 @@ impl Default for AccessLevel { pub fn default_level() -> AccessLevel { AccessLevel { id: uuid::Uuid::nil(), - level: String::from("Public"), - song_id: uuid::Uuid::new_v4(), + level: DEFAULT_ACCESS_LEVEL.to_string(), + song_id: uuid::Uuid::nil(), } } pub fn private_level() -> AccessLevel { AccessLevel { - id: uuid::Uuid::new_v4(), - level: String::from("Private"), - song_id: uuid::Uuid::new_v4(), + id: uuid::Uuid::nil(), + level: super::constants::access_level::PRIVATE.to_string(), + song_id: uuid::Uuid::nil(), } } diff --git a/src/constants.rs b/src/constants.rs index 4432a85..8fb3e8e 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -13,6 +13,18 @@ pub mod file_extensions { } } +pub mod song_event { + /// Song Event Type - Play + pub const SONG_EVENT_TYPE_PLAY: &str = "PLAY"; + /// Song Event Type - PAUSE + pub const SONG_EVENT_TYPE_PAUSE: &str = "PAUSE"; +} + +pub mod access_level { + pub const PUBLIC: &str = "PUBLIC"; + pub const PRIVATE: &str = "PRIVATE"; +} + pub mod error { pub const DIRECTORY_NOT_INITIALIZED: &str = "Directory has not been initialized"; pub const FILENAME_NOT_INITIALIZED: &str = "Filename has not bee initialized"; diff --git a/src/ledger/mod.rs b/src/ledger/mod.rs index 1d7b420..933f819 100644 --- a/src/ledger/mod.rs +++ b/src/ledger/mod.rs @@ -14,12 +14,8 @@ impl SongEvent { pub fn is_event_type_valid(&self) -> bool { matches!( self.event_type.as_str(), - SONG_EVENT_TYPE_PLAY | SONG_EVENT_TYPE_PAUSE + super::constants::song_event::SONG_EVENT_TYPE_PLAY + | super::constants::song_event::SONG_EVENT_TYPE_PAUSE ) } } - -/// Song Event Type - Play -pub const SONG_EVENT_TYPE_PLAY: &str = "PLAY"; -/// Song Event Type - PAUSE -pub const SONG_EVENT_TYPE_PAUSE: &str = "PAUSE"; diff --git a/src/token.rs b/src/token.rs index 3e013a5..79e8882 100644 --- a/src/token.rs +++ b/src/token.rs @@ -111,7 +111,7 @@ pub struct TokenResource { pub id: uuid::Uuid, } -pub const TOKEN_TYPE: &str = "JWT"; +const TOKEN_TYPE: &str = "JWT"; pub fn create_token( key: &String,