This commit is contained in:
2026-02-21 10:39:52 +01:00
parent f7c975a3f0
commit 66c1fe0025
38 changed files with 1543 additions and 616 deletions

View File

View File

@@ -0,0 +1,35 @@
use crate::models::category;
use sea_orm::Set;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
#[derive(Debug, Serialize)]
pub struct CategoryResponse {
pub id: Uuid,
pub name: String,
}
impl From<category::Model> for CategoryResponse {
fn from(model: category::Model) -> Self {
Self {
id: model.id,
name: model.name,
}
}
}
#[derive(Debug, Deserialize)]
pub struct CreateCategoryRequest {
pub server_id: Uuid,
pub name: String,
}
impl From<CreateCategoryRequest> for category::ActiveModel {
fn from(request: CreateCategoryRequest) -> Self {
Self {
server_id: Set(request.server_id),
name: Set(request.name),
..Default::default()
}
}
}

View File

@@ -0,0 +1,50 @@
use crate::models::channel;
use crate::models::channel::ChannelType;
use sea_orm::Set;
use serde::Serialize;
use uuid::Uuid;
#[derive(Debug, Serialize)]
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, Serialize)]
pub struct CreateChannelRequest {
pub server_id: Option<Uuid>,
pub category_id: Option<Uuid>,
pub position: 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),
channel_type: Set(request.channel_type),
name: Set(request.name),
..Default::default()
}
}
}

View File

@@ -0,0 +1,40 @@
use crate::models::message;
use sea_orm::Set;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
#[derive(Debug, Serialize)]
pub struct MessageResponse {
pub id: Uuid,
pub channel_id: Uuid,
pub author_id: Uuid,
pub content: String,
}
impl From<message::Model> for MessageResponse {
fn from(model: message::Model) -> Self {
Self {
id: model.id,
channel_id: model.channel_id,
author_id: model.user_id,
content: model.content,
}
}
}
#[derive(Debug, Deserialize)]
pub struct CreateMessageRequest {
pub channel_id: Uuid,
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),
..Default::default()
}
}
}

View File

@@ -0,0 +1,6 @@
pub mod auth;
pub mod category;
pub mod channel;
pub mod message;
pub mod server;
pub mod user;

View File

@@ -0,0 +1,52 @@
// On importe le modèle pour pouvoir mapper
use crate::models::server;
use sea_orm::Set;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
#[derive(Debug, Serialize)]
pub struct ServerResponse {
pub id: Uuid,
pub name: String,
pub created_at: String,
pub updated_at: String,
}
impl From<server::Model> for ServerResponse {
fn from(model: server::Model) -> Self {
Self {
id: model.id,
name: model.name,
created_at: model.created_at.to_rfc3339(),
updated_at: model.updated_at.to_rfc3339(),
}
}
}
#[derive(Debug, Deserialize)]
pub struct CreateServerRequest {
pub name: String,
pub password: Option<String>,
}
impl From<CreateServerRequest> for server::ActiveModel {
fn from(request: CreateServerRequest) -> Self {
Self {
name: Set(request.name),
password: Set(request.password),
..Default::default()
}
}
}
#[derive(Serialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum TreeItemType {
// todo : faire le CategoryResponse et ChannelResponse
}
#[derive(Serialize)]
#[serde(transparent)]
pub struct ServerTreeResponse {
items: Vec<TreeItemType>,
}

View File

@@ -0,0 +1,33 @@
use crate::models::user;
use sea_orm::Set;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
#[derive(Debug, Serialize)]
pub struct UserResponse {
pub id: Uuid,
pub username: String,
}
impl From<user::Model> for UserResponse {
fn from(model: user::Model) -> Self {
Self {
id: model.id,
username: model.username,
}
}
}
#[derive(Debug, Deserialize)]
pub struct CreateUserRequest {
pub username: String,
}
impl From<CreateUserRequest> for user::ActiveModel {
fn from(request: CreateUserRequest) -> Self {
Self {
username: Set(request.username),
..Default::default()
}
}
}

View File

@@ -0,0 +1 @@
pub mod dto;

1
src/interfaces/mod.rs Normal file
View File

@@ -0,0 +1 @@
pub mod http;