utoipa more endpoints
This commit is contained in:
parent
364710ef79
commit
1c3ba3d709
2 changed files with 42 additions and 11 deletions
|
@ -30,12 +30,10 @@ pub fn router() -> OpenApiRouter<App> {
|
||||||
.routes(routes!(get_initial_setup))
|
.routes(routes!(get_initial_setup))
|
||||||
.routes(routes!(post_auth))
|
.routes(routes!(post_auth))
|
||||||
// Configuration
|
// Configuration
|
||||||
.route("/settings", get(get_settings))
|
.routes(routes!(get_settings, put_settings))
|
||||||
.route("/settings", put(put_settings))
|
.routes(routes!(get_mount_dirs, put_mount_dirs))
|
||||||
.route("/mount_dirs", get(get_mount_dirs))
|
.routes(routes!(post_trigger_index))
|
||||||
.route("/mount_dirs", put(put_mount_dirs))
|
.routes(routes!(get_index_status))
|
||||||
.route("/trigger_index", post(post_trigger_index))
|
|
||||||
.route("/index_status", get(get_index_status))
|
|
||||||
// User management
|
// User management
|
||||||
.route("/user", post(post_user))
|
.route("/user", post(post_user))
|
||||||
.route("/user/{name}", delete(delete_user))
|
.route("/user/{name}", delete(delete_user))
|
||||||
|
@ -113,6 +111,13 @@ async fn get_initial_setup(
|
||||||
Ok(Json(initial_setup))
|
Ok(Json(initial_setup))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[utoipa::path(
|
||||||
|
get,
|
||||||
|
path = "/settings",
|
||||||
|
responses(
|
||||||
|
(status = 200, body = dto::Settings),
|
||||||
|
),
|
||||||
|
)]
|
||||||
async fn get_settings(
|
async fn get_settings(
|
||||||
_admin_rights: AdminRights,
|
_admin_rights: AdminRights,
|
||||||
State(config_manager): State<config::Manager>,
|
State(config_manager): State<config::Manager>,
|
||||||
|
@ -133,6 +138,11 @@ async fn get_settings(
|
||||||
Ok(Json(settings))
|
Ok(Json(settings))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[utoipa::path(
|
||||||
|
put,
|
||||||
|
path = "/settings",
|
||||||
|
request_body = dto::NewSettings,
|
||||||
|
)]
|
||||||
async fn put_settings(
|
async fn put_settings(
|
||||||
_admin_rights: AdminRights,
|
_admin_rights: AdminRights,
|
||||||
State(config_manager): State<config::Manager>,
|
State(config_manager): State<config::Manager>,
|
||||||
|
@ -158,6 +168,13 @@ async fn put_settings(
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[utoipa::path(
|
||||||
|
get,
|
||||||
|
path = "/mount_dirs",
|
||||||
|
responses(
|
||||||
|
(status = 200, body = Vec<dto::MountDir>),
|
||||||
|
),
|
||||||
|
)]
|
||||||
async fn get_mount_dirs(
|
async fn get_mount_dirs(
|
||||||
_admin_rights: AdminRights,
|
_admin_rights: AdminRights,
|
||||||
State(config_manager): State<config::Manager>,
|
State(config_manager): State<config::Manager>,
|
||||||
|
@ -167,6 +184,11 @@ async fn get_mount_dirs(
|
||||||
Ok(Json(mount_dirs))
|
Ok(Json(mount_dirs))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[utoipa::path(
|
||||||
|
put,
|
||||||
|
path = "/mount_dirs",
|
||||||
|
request_body = Vec<dto::MountDir>,
|
||||||
|
)]
|
||||||
async fn put_mount_dirs(
|
async fn put_mount_dirs(
|
||||||
_admin_rights: AdminRights,
|
_admin_rights: AdminRights,
|
||||||
State(config_manager): State<config::Manager>,
|
State(config_manager): State<config::Manager>,
|
||||||
|
@ -264,6 +286,7 @@ async fn delete_user(
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[utoipa::path(post, path = "/trigger_index")]
|
||||||
async fn post_trigger_index(
|
async fn post_trigger_index(
|
||||||
_admin_rights: AdminRights,
|
_admin_rights: AdminRights,
|
||||||
State(scanner): State<scanner::Scanner>,
|
State(scanner): State<scanner::Scanner>,
|
||||||
|
@ -272,6 +295,13 @@ async fn post_trigger_index(
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[utoipa::path(
|
||||||
|
get,
|
||||||
|
path = "/index_status",
|
||||||
|
responses(
|
||||||
|
(status = 200, body = dto::IndexStatus),
|
||||||
|
)
|
||||||
|
)]
|
||||||
async fn get_index_status(
|
async fn get_index_status(
|
||||||
_admin_rights: AdminRights,
|
_admin_rights: AdminRights,
|
||||||
State(scanner): State<scanner::Scanner>,
|
State(scanner): State<scanner::Scanner>,
|
||||||
|
|
|
@ -134,8 +134,9 @@ pub struct UserUpdate {
|
||||||
pub new_is_admin: Option<bool>,
|
pub new_is_admin: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize)]
|
#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize, ToSchema)]
|
||||||
pub struct MountDir {
|
pub struct MountDir {
|
||||||
|
#[schema(value_type = String)]
|
||||||
pub source: PathBuf,
|
pub source: PathBuf,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
}
|
}
|
||||||
|
@ -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 struct NewSettings {
|
||||||
pub album_art_pattern: Option<String>,
|
pub album_art_pattern: Option<String>,
|
||||||
pub ddns_update_url: 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 struct Settings {
|
||||||
pub album_art_pattern: String,
|
pub album_art_pattern: String,
|
||||||
pub ddns_update_url: String,
|
pub ddns_update_url: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, ToSchema)]
|
||||||
pub enum IndexState {
|
pub enum IndexState {
|
||||||
OutOfDate,
|
OutOfDate,
|
||||||
InProgress,
|
InProgress,
|
||||||
|
@ -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 {
|
pub struct IndexStatus {
|
||||||
state: IndexState,
|
state: IndexState,
|
||||||
last_start_time: Option<u64>,
|
last_start_time: Option<u64>,
|
||||||
|
|
Loading…
Add table
Reference in a new issue