Skip to content

Commit 618f857

Browse files
committed
refactor: [#801] more code cleanup
1 parent c6fa4b6 commit 618f857

File tree

3 files changed

+22
-26
lines changed

3 files changed

+22
-26
lines changed

src/services/authorization.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ impl Default for CasbinConfiguration {
249249
admin, GetCanonicalInfoHash
250250
admin, ChangePassword
251251
admin, BanUser
252-
admin, GenerateUserProfilesListing
252+
admin, GenerateUserProfileSpecification
253253
registered, GetAboutPage
254254
registered, GetLicensePage
255255
registered, GetCategories

src/services/user.rs

+19-19
Original file line numberDiff line numberDiff line change
@@ -366,34 +366,20 @@ impl ListingService {
366366
}
367367
}
368368

369-
/// Returns a list of all the user profiles matching the search criteria.
370-
///
371-
/// # Errors
372-
///
373-
/// Returns a `ServiceError::DatabaseError` if the database query fails.
374-
pub async fn generate_user_profile_listing(
375-
&self,
376-
listing: &ListingSpecification,
377-
maybe_user_id: Option<UserId>,
378-
) -> Result<UserProfilesResponse, ServiceError> {
379-
self.authorization_service
380-
.authorize(ACTION::GenerateUserProfilesListing, maybe_user_id)
381-
.await?;
382-
383-
let user_profiles_response = self.user_profile_repository.generate_listing(listing).await?;
384-
385-
Ok(user_profiles_response)
386-
}
387-
388369
/// It converts the user listing request into an internal listing specification.
389370
///
390371
/// # Errors
391372
///
392373
/// Returns a `ServiceError::InvalidUserListing` if there is an incorrect value in the url params for the listing request.
393374
pub async fn listing_specification_from_user_request(
394375
&self,
376+
maybe_user_id: Option<UserId>,
395377
request: &ListingRequest,
396378
) -> Result<ListingSpecification, ServiceError> {
379+
self.authorization_service
380+
.authorize(ACTION::GenerateUserProfilesListing, maybe_user_id)
381+
.await?;
382+
397383
let settings = self.configuration.settings.read().await;
398384
let default_user_profile_page_size = settings.api.default_user_profile_page_size;
399385
let max_user_profile_page_size = settings.api.max_user_profile_page_size;
@@ -447,6 +433,20 @@ impl ListingService {
447433
search: request.search.clone(),
448434
})
449435
}
436+
437+
/// Returns a list of all the user profiles matching the search criteria.
438+
///
439+
/// # Errors
440+
///
441+
/// Returns a `ServiceError::DatabaseError` if the database query fails.
442+
pub async fn generate_user_profile_listing(
443+
&self,
444+
listing: &ListingSpecification,
445+
) -> Result<UserProfilesResponse, ServiceError> {
446+
let user_profiles_response = self.user_profile_repository.generate_listing(listing).await?;
447+
448+
Ok(user_profiles_response)
449+
}
450450
}
451451

452452
#[cfg_attr(test, automock)]

src/web/api/server/v1/contexts/user/handlers.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -201,18 +201,14 @@ pub async fn get_user_profiles_handler(
201201
) -> Response {
202202
let listing = match app_data
203203
.listing_service
204-
.listing_specification_from_user_request(&criteria)
204+
.listing_specification_from_user_request(maybe_user_id, &criteria)
205205
.await
206206
{
207207
Ok(listing_value) => listing_value,
208208
Err(err) => return err.into_response(),
209209
};
210210

211-
match app_data
212-
.listing_service
213-
.generate_user_profile_listing(&listing, maybe_user_id)
214-
.await
215-
{
211+
match app_data.listing_service.generate_user_profile_listing(&listing).await {
216212
Ok(users) => Json(crate::web::api::server::v1::responses::OkResponseData { data: users }).into_response(),
217213
Err(error) => error.into_response(),
218214
}

0 commit comments

Comments
 (0)