From fd75fd483f5a3bb8949a450f49d2eb30e2962cca Mon Sep 17 00:00:00 2001 From: Cameron Garnham Date: Wed, 26 Apr 2023 18:50:27 +0200 Subject: [PATCH] dev: fix clippy warnings for: src/routes/category.rs --- src/routes/category.rs | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/routes/category.rs b/src/routes/category.rs index 823c267e..855dfb38 100644 --- a/src/routes/category.rs +++ b/src/routes/category.rs @@ -9,14 +9,19 @@ pub fn init_routes(cfg: &mut web::ServiceConfig) { cfg.service( web::scope("/category").service( web::resource("") - .route(web::get().to(get_categories)) - .route(web::post().to(add_category)) - .route(web::delete().to(delete_category)), + .route(web::get().to(get)) + .route(web::post().to(add)) + .route(web::delete().to(delete)), ), ); } -pub async fn get_categories(app_data: WebAppData) -> ServiceResult { +/// Gets the Categories +/// +/// # Errors +/// +/// This function will return an error if there is a database error. +pub async fn get(app_data: WebAppData) -> ServiceResult { let categories = app_data.database.get_categories().await?; Ok(HttpResponse::Ok().json(OkResponse { data: categories })) @@ -28,7 +33,13 @@ pub struct Category { pub icon: Option, } -pub async fn add_category(req: HttpRequest, payload: web::Json, app_data: WebAppData) -> ServiceResult { +/// Adds a New Category +/// +/// # Errors +/// +/// This function will return an error if unable to get user. +/// This function will return an error if unable to insert into the database the new category. +pub async fn add(req: HttpRequest, payload: web::Json, app_data: WebAppData) -> ServiceResult { // check for user let user = app_data.auth.get_user_compact_from_request(&req).await?; @@ -44,11 +55,13 @@ pub async fn add_category(req: HttpRequest, payload: web::Json, app_da })) } -pub async fn delete_category( - req: HttpRequest, - payload: web::Json, - app_data: WebAppData, -) -> ServiceResult { +/// Deletes a Category +/// +/// # Errors +/// +/// This function will return an error if unable to get user. +/// This function will return an error if unable to delete the category from the database. +pub async fn delete(req: HttpRequest, payload: web::Json, app_data: WebAppData) -> ServiceResult { // code-review: why do we need to send the whole category object to delete it? // And we should use the ID instead of the name, because the name could change // or we could add support for multiple languages.