use crate::models::channel; use crate::models::channel::ChannelType; use sea_orm::Set; use serde::{Deserialize, Serialize}; use utoipa::ToSchema; use uuid::Uuid; #[derive(Debug, Serialize, ToSchema)] pub struct ChannelResponse { pub id: Uuid, pub server_id: Option, pub category_id: Option, pub position: i32, pub channel_type: ChannelType, pub name: Option, } impl From for ChannelResponse { fn from(model: channel::Model) -> Self { Self { id: model.id, server_id: model.server_id, category_id: model.category_id, position: model.position, channel_type: model.channel_type, name: model.name, } } } #[derive(Debug, Deserialize, ToSchema)] pub struct CreateChannelRequest { pub server_id: Option, pub category_id: Option, pub position: Option, pub channel_type: ChannelType, pub name: Option, } impl From for channel::ActiveModel { fn from(request: CreateChannelRequest) -> Self { Self { server_id: Set(request.server_id), category_id: Set(request.category_id), position: Set(request.position.unwrap_or(0)), channel_type: Set(request.channel_type), name: Set(request.name), ..Default::default() } } } impl CreateChannelRequest { pub fn apply_to(self, mut am: channel::ActiveModel) -> channel::ActiveModel { am.server_id = Set(self.server_id); am.category_id = Set(self.category_id); am.position = Set(self.position.unwrap_or(0)); am.channel_type = Set(self.channel_type); am.name = Set(self.name); am } }