Files
ox_speak_server_v2/src/interfaces/http/dto/channel.rs
2026-03-02 01:36:28 +01:00

63 lines
1.7 KiB
Rust

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<Uuid>,
pub category_id: Option<Uuid>,
pub position: i32,
pub channel_type: ChannelType,
pub name: Option<String>,
}
impl From<channel::Model> 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<Uuid>,
pub category_id: Option<Uuid>,
pub position: Option<i32>,
pub channel_type: ChannelType,
pub name: Option<String>,
}
impl From<CreateChannelRequest> 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
}
}