Skip to content

Commit

Permalink
dev: fix clippy warnings for: src/routes/category.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
da2ce7 committed May 10, 2023
1 parent 21493b0 commit fd75fd4
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions src/routes/category.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<impl Responder> {
/// Gets the Categories
///
/// # Errors
///
/// This function will return an error if there is a database error.
pub async fn get(app_data: WebAppData) -> ServiceResult<impl Responder> {
let categories = app_data.database.get_categories().await?;

Ok(HttpResponse::Ok().json(OkResponse { data: categories }))
Expand All @@ -28,7 +33,13 @@ pub struct Category {
pub icon: Option<String>,
}

pub async fn add_category(req: HttpRequest, payload: web::Json<Category>, app_data: WebAppData) -> ServiceResult<impl Responder> {
/// 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<Category>, app_data: WebAppData) -> ServiceResult<impl Responder> {
// check for user
let user = app_data.auth.get_user_compact_from_request(&req).await?;

Expand All @@ -44,11 +55,13 @@ pub async fn add_category(req: HttpRequest, payload: web::Json<Category>, app_da
}))
}

pub async fn delete_category(
req: HttpRequest,
payload: web::Json<Category>,
app_data: WebAppData,
) -> ServiceResult<impl Responder> {
/// 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<Category>, app_data: WebAppData) -> ServiceResult<impl Responder> {
// 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.
Expand Down

0 comments on commit fd75fd4

Please sign in to comment.