Skip to content

Commit

Permalink
refactor: rename get folder stats to get music folder stats
Browse files Browse the repository at this point in the history
  • Loading branch information
vnghia committed Apr 14, 2024
1 parent 3cb9a77 commit c96791c
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 27 deletions.
8 changes: 4 additions & 4 deletions frontend/src/components/folder/list.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use dioxus::prelude::*;
use nghe_types::music_folder::get_folder_stats::{
GetFolderStatsParams, SubsonicGetFolderStatsBody,
use nghe_types::music_folder::get_music_folder_stats::{
GetMusicFolderStatsParams, SubsonicGetMusicFolderStatsBody,
};
use readable::byte::*;
use readable::num::*;
Expand All @@ -20,9 +20,9 @@ pub fn Folders() -> Element {
let get_folder_stats_fut = use_resource(move || async move {
Ok(common_state()
.ok_or_else(|| anyhow::anyhow!("common state is none"))?
.send_with_common::<_, SubsonicGetFolderStatsBody>(
.send_with_common::<_, SubsonicGetMusicFolderStatsBody>(
"/rest/getFolderStats",
GetFolderStatsParams {},
GetMusicFolderStatsParams {},
)
.await?
.root
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ use crate::models::*;
use crate::open_subsonic::id3::*;
use crate::{Database, DatabasePool};

add_common_validate!(GetFolderStatsParams, admin);
add_axum_response!(GetFolderStatsBody);
add_common_validate!(GetMusicFolderStatsParams, admin);
add_axum_response!(GetMusicFolderStatsBody);

#[add_convert_types(into = nghe_types::music_folder::get_folder_stats::FolderStats)]
#[add_convert_types(into = nghe_types::music_folder::get_music_folder_stats::MusicFolderStat)]
#[derive(Debug, Queryable)]
#[diesel(table_name = music_folders)]
#[diesel(check_for_backend(diesel::pg::Pg))]
#[cfg_attr(test, derive(PartialEq, Eq))]
struct FolderStats {
struct MusicFolderStat {
#[diesel(embed)]
music_folder: music_folders::MusicFolder,
artist_count: i64,
Expand All @@ -29,7 +29,7 @@ struct FolderStats {
total_size: i64,
}

async fn get_folder_stats(pool: &DatabasePool) -> Result<Vec<FolderStats>> {
async fn get_music_folder_stats(pool: &DatabasePool) -> Result<Vec<MusicFolderStat>> {
let songs_total_size = diesel::alias!(songs as songs_total_size);

get_basic_artist_id3_db()
Expand All @@ -52,21 +52,21 @@ async fn get_folder_stats(pool: &DatabasePool) -> Result<Vec<FolderStats>> {
.single_value()
.assume_not_null(),
))
.get_results::<FolderStats>(&mut pool.get().await?)
.get_results::<MusicFolderStat>(&mut pool.get().await?)
.await
.map_err(anyhow::Error::from)
}

pub async fn get_folder_stats_handler(
pub async fn get_music_folder_stats_handler(
State(database): State<Database>,
_: GetFolderStatsRequest,
) -> GetFolderStatsJsonResponse {
_: GetMusicFolderStatsRequest,
) -> GetMusicFolderStatsJsonResponse {
Ok(axum::Json(
GetFolderStatsBody {
folder_stats: get_folder_stats(&database.pool)
GetMusicFolderStatsBody {
folder_stats: get_music_folder_stats(&database.pool)
.await?
.into_iter()
.map(FolderStats::into)
.map(MusicFolderStat::into)
.collect(),
}
.into(),
Expand Down Expand Up @@ -117,7 +117,7 @@ mod tests {
});
infra.scan(.., None).await;

let folder_stats = get_folder_stats(infra.pool())
let folder_stats = get_music_folder_stats(infra.pool())
.await
.unwrap()
.into_iter()
Expand All @@ -138,7 +138,7 @@ mod tests {
let song_count = song_fs_infos.len() as _;
let total_size = song_fs_infos.iter().fold(0_u32, |aac, s| aac + s.file_size) as _;

FolderStats {
MusicFolderStat {
music_folder,
artist_count,
album_count,
Expand Down
12 changes: 9 additions & 3 deletions src/open_subsonic/music_folder/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
mod get_folder_stats;
mod get_music_folder_stats;

use axum::routing::get;
use axum::Router;

pub fn router() -> Router<crate::Database> {
Router::new()
.route("/rest/getFolderStats", get(get_folder_stats::get_folder_stats_handler))
.route("/rest/getFolderStats.view", get(get_folder_stats::get_folder_stats_handler))
.route(
"/rest/getMusicFolderStats",
get(get_music_folder_stats::get_music_folder_stats_handler),
)
.route(
"/rest/getMusicFolderStats.view",
get(get_music_folder_stats::get_music_folder_stats_handler),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ use nghe_proc_macros::{
use super::MusicFolderPath;

#[add_common_convert]
pub struct GetFolderStatsParams {}
pub struct GetMusicFolderStatsParams {}

#[add_types_derive]
#[derive(Debug)]
pub struct FolderStats {
pub struct MusicFolderStat {
pub music_folder: MusicFolderPath,
pub artist_count: u32,
pub album_count: u32,
Expand All @@ -20,8 +20,8 @@ pub struct FolderStats {

#[add_subsonic_response]
#[derive(Debug)]
pub struct GetFolderStatsBody {
pub folder_stats: Vec<FolderStats>,
pub struct GetMusicFolderStatsBody {
pub folder_stats: Vec<MusicFolderStat>,
}

add_request_types_test!(GetFolderStatsParams);
add_request_types_test!(GetMusicFolderStatsParams);
2 changes: 1 addition & 1 deletion types/src/music_folder/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub mod get_folder_stats;
pub mod get_music_folder_stats;

use nghe_proc_macros::add_types_derive;
use uuid::Uuid;
Expand Down

0 comments on commit c96791c

Please sign in to comment.