This commit is contained in:
2026-01-04 12:38:41 +01:00
parent 96765342d1
commit 1a4b706702
14 changed files with 230 additions and 31 deletions

View File

@@ -2,7 +2,8 @@ use std::sync::Arc;
use sea_orm::{DbErr, EntityTrait, ActiveModelTrait, QueryFilter, ColumnTrait, QueryOrder};
use uuid::Uuid;
use crate::models::{category, channel, server};
use crate::repositories::RepositoryContext;
use super::RepositoryContext;
use super::types::{ServerExplorerItem, ServerTree};
#[derive(Clone)]
pub struct ServerRepository {
@@ -37,28 +38,9 @@ impl ServerRepository {
}
}
pub enum ServerExplorerItem {
Category(category::Model, Vec<channel::Model>),
Channel(channel::Model),
}
// Pour pouvoir trier facilement
impl ServerExplorerItem {
fn position(&self) -> i32 {
match self {
ServerExplorerItem::Category(cat, _) => cat.position,
ServerExplorerItem::Channel(chan) => chan.position,
}
}
}
pub struct ServerLayout {
pub items: Vec<ServerExplorerItem>,
}
// Helpers
impl ServerRepository {
pub async fn get_channels_tree(&self, server_id: Uuid) -> Result<ServerLayout, DbErr> {
pub async fn get_tree(&self, server_id: Uuid) -> Result<ServerTree, DbErr> {
// 1. Récupération des catégories avec leurs channels
let categories_with_channels = category::Entity::find()
.filter(category::Column::ServerId.eq(server_id))
@@ -108,6 +90,6 @@ impl ServerRepository {
}
});
Ok(ServerLayout { items })
Ok(ServerTree { items })
}
}