Skip to content

Commit

Permalink
dev: fix clippy warnings for: src/routes/settings.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
da2ce7 committed May 10, 2023
1 parent 7277e4e commit c20608f
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions src/routes/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@ use crate::models::response::OkResponse;
pub fn init(cfg: &mut web::ServiceConfig) {
cfg.service(
web::scope("/settings")
.service(
web::resource("")
.route(web::get().to(get_settings))
.route(web::post().to(update_settings_handler)),
)
.service(web::resource("/name").route(web::get().to(get_site_name)))
.service(web::resource("/public").route(web::get().to(get_public_settings))),
.service(web::resource("").route(web::get().to(get)).route(web::post().to(update)))
.service(web::resource("/name").route(web::get().to(site_name)))
.service(web::resource("/public").route(web::get().to(get_public))),
);
}

pub async fn get_settings(req: HttpRequest, app_data: WebAppData) -> ServiceResult<impl Responder> {
/// Get Settings
///
/// # Errors
///
/// This function will return an error if unable to get user from database.
pub async fn get(req: HttpRequest, app_data: WebAppData) -> ServiceResult<impl Responder> {
// check for user
let user = app_data.auth.get_user_compact_from_request(&req).await?;

Expand All @@ -32,13 +33,23 @@ pub async fn get_settings(req: HttpRequest, app_data: WebAppData) -> ServiceResu
Ok(HttpResponse::Ok().json(OkResponse { data: &*settings }))
}

pub async fn get_public_settings(app_data: WebAppData) -> ServiceResult<impl Responder> {
/// Get Public Settings
///
/// # Errors
///
/// This function should not return an error.
pub async fn get_public(app_data: WebAppData) -> ServiceResult<impl Responder> {
let public_settings = app_data.cfg.get_public().await;

Ok(HttpResponse::Ok().json(OkResponse { data: public_settings }))
}

pub async fn get_site_name(app_data: WebAppData) -> ServiceResult<impl Responder> {
/// Get Name of Website
///
/// # Errors
///
/// This function should not return an error.
pub async fn site_name(app_data: WebAppData) -> ServiceResult<impl Responder> {
let settings = app_data.cfg.settings.read().await;

Ok(HttpResponse::Ok().json(OkResponse {
Expand All @@ -55,7 +66,7 @@ pub async fn get_site_name(app_data: WebAppData) -> ServiceResult<impl Responder
/// - There is no logged-in user.
/// - The user is not an administrator.
/// - The settings could not be updated because they were loaded from env vars.
pub async fn update_settings_handler(
pub async fn update(
req: HttpRequest,
payload: web::Json<config::TorrustBackend>,
app_data: WebAppData,
Expand Down

0 comments on commit c20608f

Please sign in to comment.