Skip to content

Commit

Permalink
feat: [#615] New get categories service method
Browse files Browse the repository at this point in the history
  • Loading branch information
mario-nt committed Aug 3, 2024
1 parent fe11c2f commit 839a00d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/services/authorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub enum ACTION {
BanUser,
GetAboutPage,
GetLicensePage,
GetCategories,
GetTags,
}

Expand Down Expand Up @@ -180,6 +181,7 @@ impl CasbinConfiguration {
admin, BanUser
guest, GetAboutPage
guest, GetLicensePage
guest, GetCategories
guest, GetTags
",
),
Expand Down
17 changes: 17 additions & 0 deletions src/services/category.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,23 @@ impl Service {
},
}
}

/// Returns all the categories from the database
///
/// # Errors
///
/// It returns an error if:
///
/// * The user does not have the required permissions.
/// * There is a database error retrieving the categories.
pub async fn get_categories(&self) -> Result<Vec<Category>, ServiceError> {
self.authorization_service.authorize(ACTION::GetCategories, None).await?;

self.category_repository
.get_all()
.await
.map_err(|_| ServiceError::DatabaseError)
}
}

pub struct DbCategoryRepository {
Expand Down

0 comments on commit 839a00d

Please sign in to comment.