Skip to content

Commit

Permalink
utoipa more endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
agersant committed Jan 15, 2025
1 parent 32e0b8d commit e170f9d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 11 deletions.
42 changes: 36 additions & 6 deletions src/server/axum/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,10 @@ pub fn router() -> OpenApiRouter<App> {
.routes(routes!(get_initial_setup))
.routes(routes!(post_auth))
// Configuration
.route("/settings", get(get_settings))
.route("/settings", put(put_settings))
.route("/mount_dirs", get(get_mount_dirs))
.route("/mount_dirs", put(put_mount_dirs))
.route("/trigger_index", post(post_trigger_index))
.route("/index_status", get(get_index_status))
.routes(routes!(get_settings, put_settings))
.routes(routes!(get_mount_dirs, put_mount_dirs))
.routes(routes!(post_trigger_index))
.routes(routes!(get_index_status))
// User management
.route("/user", post(post_user))
.route("/user/{name}", delete(delete_user))
Expand Down Expand Up @@ -113,6 +111,13 @@ async fn get_initial_setup(
Ok(Json(initial_setup))
}

#[utoipa::path(
get,
path = "/settings",
responses(
(status = 200, body = dto::Settings),
),
)]
async fn get_settings(
_admin_rights: AdminRights,
State(config_manager): State<config::Manager>,
Expand All @@ -133,6 +138,11 @@ async fn get_settings(
Ok(Json(settings))
}

#[utoipa::path(
put,
path = "/settings",
request_body = dto::NewSettings,
)]
async fn put_settings(
_admin_rights: AdminRights,
State(config_manager): State<config::Manager>,
Expand All @@ -158,6 +168,13 @@ async fn put_settings(
Ok(())
}

#[utoipa::path(
get,
path = "/mount_dirs",
responses(
(status = 200, body = Vec<dto::MountDir>),
),
)]
async fn get_mount_dirs(
_admin_rights: AdminRights,
State(config_manager): State<config::Manager>,
Expand All @@ -167,6 +184,11 @@ async fn get_mount_dirs(
Ok(Json(mount_dirs))
}

#[utoipa::path(
put,
path = "/mount_dirs",
request_body = Vec<dto::MountDir>,
)]
async fn put_mount_dirs(
_admin_rights: AdminRights,
State(config_manager): State<config::Manager>,
Expand Down Expand Up @@ -264,6 +286,7 @@ async fn delete_user(
Ok(())
}

#[utoipa::path(post, path = "/trigger_index")]
async fn post_trigger_index(
_admin_rights: AdminRights,
State(scanner): State<scanner::Scanner>,
Expand All @@ -272,6 +295,13 @@ async fn post_trigger_index(
Ok(())
}

#[utoipa::path(
get,
path = "/index_status",
responses(
(status = 200, body = dto::IndexStatus),
)
)]
async fn get_index_status(
_admin_rights: AdminRights,
State(scanner): State<scanner::Scanner>,
Expand Down
11 changes: 6 additions & 5 deletions src/server/dto/v8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,9 @@ pub struct UserUpdate {
pub new_is_admin: Option<bool>,
}

#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize)]
#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize, ToSchema)]
pub struct MountDir {
#[schema(value_type = String)]
pub source: PathBuf,
pub name: String,
}
Expand All @@ -158,19 +159,19 @@ impl From<config::MountDir> for MountDir {
}
}

#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, ToSchema)]
pub struct NewSettings {
pub album_art_pattern: Option<String>,
pub ddns_update_url: Option<String>,
}

#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, ToSchema)]
pub struct Settings {
pub album_art_pattern: String,
pub ddns_update_url: String,
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, ToSchema)]
pub enum IndexState {
OutOfDate,
InProgress,
Expand All @@ -188,7 +189,7 @@ impl From<scanner::State> for IndexState {
}
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, ToSchema)]
pub struct IndexStatus {
state: IndexState,
last_start_time: Option<u64>,
Expand Down

0 comments on commit e170f9d

Please sign in to comment.