Init
This commit is contained in:
@@ -33,3 +33,15 @@ impl From<CreateCategoryRequest> for category::ActiveModel {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl CreateCategoryRequest {
|
||||
pub fn apply_to(self, mut am: category::ActiveModel) -> category::ActiveModel {
|
||||
am.name = Set(self.name);
|
||||
am
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct ListCategoryQuery {
|
||||
pub server_id: Uuid,
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
// On importe le modèle pour pouvoir mapper
|
||||
use crate::interfaces::http::dto::category::CategoryResponse;
|
||||
use crate::interfaces::http::dto::channel::ChannelResponse;
|
||||
use crate::models::server;
|
||||
use crate::repositories::types::{ServerExplorerItem, ServerTree};
|
||||
use sea_orm::Set;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
@@ -39,10 +41,23 @@ impl From<CreateServerRequest> for server::ActiveModel {
|
||||
}
|
||||
}
|
||||
|
||||
impl CreateServerRequest {
|
||||
pub fn apply_to(self, mut am: server::ActiveModel) -> server::ActiveModel {
|
||||
am.name = Set(self.name);
|
||||
am.password = Set(self.password);
|
||||
am
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[serde(tag = "type", rename_all = "snake_case")]
|
||||
pub enum TreeItemType {
|
||||
// todo : faire le CategoryResponse et ChannelResponse
|
||||
Category {
|
||||
#[serde(flatten)]
|
||||
category: CategoryResponse,
|
||||
channels: Vec<ChannelResponse>,
|
||||
},
|
||||
Channel(ChannelResponse),
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
@@ -50,3 +65,23 @@ pub enum TreeItemType {
|
||||
pub struct ServerTreeResponse {
|
||||
items: Vec<TreeItemType>,
|
||||
}
|
||||
|
||||
impl From<ServerTree> for ServerTreeResponse {
|
||||
fn from(layout: ServerTree) -> Self {
|
||||
Self {
|
||||
items: layout
|
||||
.items
|
||||
.into_iter()
|
||||
.map(|item| match item {
|
||||
ServerExplorerItem::Category(cat, chans) => TreeItemType::Category {
|
||||
category: CategoryResponse::from(cat),
|
||||
channels: chans.into_iter().map(ChannelResponse::from).collect(),
|
||||
},
|
||||
ServerExplorerItem::Channel(chan) => {
|
||||
TreeItemType::Channel(ChannelResponse::from(chan))
|
||||
}
|
||||
})
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user