Init
This commit is contained in:
@@ -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 })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user