init
This commit is contained in:
@@ -3,9 +3,8 @@ use crate::domain::dto::server::{
|
||||
CreateServerRequest, ServerResponse, ServerRolePermissionResponse, ServerTreeResponse,
|
||||
ServerUserPermissionResponse, SetServerPermissionRequest, UpdateServerRequest,
|
||||
};
|
||||
use crate::http::context::Superuser;
|
||||
use crate::http::context::{CurrentUser, Superuser};
|
||||
use crate::http::error::HTTPError;
|
||||
use crate::repositories::types::ChannelFilter;
|
||||
use crate::routes::server::mapper;
|
||||
use axum::{
|
||||
Json,
|
||||
@@ -384,6 +383,7 @@ pub async fn remove_role_permission(
|
||||
tag = "Servers"
|
||||
)]
|
||||
pub async fn get_tree(
|
||||
user: CurrentUser,
|
||||
State(state): State<AppState>,
|
||||
Path(server_id): Path<Uuid>,
|
||||
) -> Result<Json<ServerTreeResponse>, HTTPError> {
|
||||
@@ -395,20 +395,15 @@ pub async fn get_tree(
|
||||
.await?
|
||||
.ok_or(HTTPError::NotFound)?;
|
||||
|
||||
// Exécution parallèle des 3 requêtes via leurs repositories respectifs
|
||||
let (orders, channels, categories) = tokio::try_join!(
|
||||
state
|
||||
.repositories
|
||||
.server_item_order
|
||||
.get_by_server(server_id),
|
||||
state.repositories.channel.filter(ChannelFilter {
|
||||
server_id: Some(server_id)
|
||||
}),
|
||||
state.repositories.category.get_by_server(server_id),
|
||||
)?;
|
||||
let tree = state
|
||||
.repositories
|
||||
.server_tree
|
||||
.get_for_user(server_id, user.id)
|
||||
.await?;
|
||||
|
||||
// Assemblage du ServerTreeResponse via le mapper
|
||||
let tree = mapper::build_server_tree(orders, channels, categories);
|
||||
|
||||
Ok(Json(tree))
|
||||
Ok(Json(mapper::build_server_tree(
|
||||
tree.orders,
|
||||
tree.channels,
|
||||
tree.categories,
|
||||
)))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user