This commit is contained in:
2026-03-01 03:33:36 +01:00
parent 68f16055a8
commit e982ea372f
26 changed files with 496 additions and 550 deletions

View File

@@ -1,7 +1,7 @@
use crate::models::channel;
use crate::models::channel::ChannelType;
use sea_orm::Set;
use serde::Serialize;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
#[derive(Debug, Serialize)]
@@ -27,11 +27,11 @@ impl From<channel::Model> for ChannelResponse {
}
}
#[derive(Debug, Serialize)]
#[derive(Debug, Deserialize)]
pub struct CreateChannelRequest {
pub server_id: Option<Uuid>,
pub category_id: Option<Uuid>,
pub position: i32,
pub position: Option<i32>,
pub channel_type: ChannelType,
pub name: Option<String>,
}
@@ -41,10 +41,21 @@ impl From<CreateChannelRequest> for channel::ActiveModel {
Self {
server_id: Set(request.server_id),
category_id: Set(request.category_id),
position: Set(request.position),
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
}
}

View File

@@ -28,13 +28,19 @@ pub struct CreateMessageRequest {
pub content: String,
}
impl From<CreateMessageRequest> for message::ActiveModel {
fn from(request: CreateMessageRequest) -> Self {
Self {
channel_id: Set(request.channel_id),
user_id: Set(Uuid::new_v4()),
content: Set(request.content),
impl CreateMessageRequest {
pub fn into_active_model(self, author_id: Uuid) -> message::ActiveModel {
message::ActiveModel {
channel_id: Set(self.channel_id),
user_id: Set(author_id),
content: Set(self.content),
..Default::default()
}
}
pub fn apply_to(self, mut am: message::ActiveModel) -> message::ActiveModel {
am.channel_id = Set(self.channel_id);
am.content = Set(self.content);
am
}
}

View File

@@ -7,6 +7,7 @@ use uuid::Uuid;
pub struct UserResponse {
pub id: Uuid,
pub username: String,
pub pub_key: String,
}
impl From<user::Model> for UserResponse {
@@ -14,6 +15,7 @@ impl From<user::Model> for UserResponse {
Self {
id: model.id,
username: model.username,
pub_key: model.pub_key,
}
}
}
@@ -31,3 +33,10 @@ impl From<CreateUserRequest> for user::ActiveModel {
}
}
}
impl CreateUserRequest {
pub fn apply_to(self, mut am: user::ActiveModel) -> user::ActiveModel {
am.username = Set(self.username);
am
}
}