Skip to content

Commit

Permalink
Extract Playlist to its own file
Browse files Browse the repository at this point in the history
  • Loading branch information
martpie committed Oct 27, 2024
1 parent 92b231b commit f9bd273
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
5 changes: 4 additions & 1 deletion src-tauri/src/libs/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
pub mod error;
pub mod events;
pub mod file_associations;
pub mod track;
pub mod utils;

// DB Structs
pub mod playlist;
pub mod track;
21 changes: 21 additions & 0 deletions src-tauri/src/libs/playlist.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use std::path::PathBuf;

use bonsaidb::core::schema::Collection;
use serde::{Deserialize, Serialize};
use ts_rs::TS;

/** ----------------------------------------------------------------------------
* Playlist
* represent a playlist, that has a name and a list of tracks
* -------------------------------------------------------------------------- */

#[derive(Debug, Clone, Serialize, Deserialize, Collection, TS)]
#[collection(name = "playlists", primary_key = String)]
#[ts(export, export_to = "../../src/generated/typings/index.ts")]
pub struct Playlist {
#[natural_id]
pub _id: String,
pub name: String,
pub tracks: Vec<String>, // vector of IDs
pub import_path: Option<PathBuf>, // the path of the file on disk (not set for playlists created in app)
}
17 changes: 1 addition & 16 deletions src-tauri/src/plugins/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use ts_rs::TS;

use crate::libs::error::{AnyResult, MuseeksError};
use crate::libs::events::IPCEvent;
use crate::libs::playlist::Playlist;
use crate::libs::track::{get_track_from_file, get_track_id_for_path, Track};
use crate::libs::utils::{scan_dirs, TimeLogger};

Expand Down Expand Up @@ -270,22 +271,6 @@ impl DB {
}
}

/** ----------------------------------------------------------------------------
* Playlist
* represent a playlist, that has a name and a list of tracks
* -------------------------------------------------------------------------- */

#[derive(Debug, Clone, Serialize, Deserialize, Collection, TS)]
#[collection(name = "playlists", primary_key = String)]
#[ts(export, export_to = "../../src/generated/typings/index.ts")]
pub struct Playlist {
#[natural_id]
pub _id: String,
pub name: String,
pub tracks: Vec<String>, // vector of IDs
pub import_path: Option<PathBuf>, // the path of the file on disk (not set for playlists created in app)
}

/**
* Scan progress
*/
Expand Down

0 comments on commit f9bd273

Please sign in to comment.