init
This commit is contained in:
@@ -1,2 +1,3 @@
|
|||||||
/target
|
/target
|
||||||
/.idea
|
/.idea
|
||||||
|
*.db
|
||||||
+1
-1
@@ -25,7 +25,7 @@ uuid = { version = "1.23.1", features = ["v4", "v7", "fast-rng", "serde"] }
|
|||||||
tracing = "0.1.44"
|
tracing = "0.1.44"
|
||||||
tracing-subscriber = { version = "0.3", features = ["env-filter", "fmt", "time"] }
|
tracing-subscriber = { version = "0.3", features = ["env-filter", "fmt", "time"] }
|
||||||
thiserror = "2"
|
thiserror = "2"
|
||||||
utoipa = { version = "5", features = ["uuid"] }
|
utoipa = { version = "5", features = ["uuid", "chrono"] }
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
bitflags = "2.11.1"
|
bitflags = "2.11.1"
|
||||||
argon2 = { version = "0.6.0-rc.8", features = ["password-hash"] }
|
argon2 = { version = "0.6.0-rc.8", features = ["password-hash"] }
|
||||||
|
|||||||
+13
-1
@@ -3,12 +3,14 @@ pub mod state;
|
|||||||
use crate::config::AppConfig;
|
use crate::config::AppConfig;
|
||||||
use crate::database::Database;
|
use crate::database::Database;
|
||||||
use crate::http::server::HttpServer;
|
use crate::http::server::HttpServer;
|
||||||
|
use crate::metrics::{reporter, AppMetrics};
|
||||||
use crate::repositories::Repositories;
|
use crate::repositories::Repositories;
|
||||||
use crate::udp::server::UdpServer;
|
use crate::udp::server::UdpServer;
|
||||||
use event_bus::EventBus;
|
use event_bus::EventBus;
|
||||||
use migration::{Migrator, MigratorTrait};
|
use migration::{Migrator, MigratorTrait};
|
||||||
pub use state::AppState;
|
pub use state::AppState;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use std::time::Duration;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
pub struct App {
|
pub struct App {
|
||||||
@@ -58,12 +60,15 @@ impl App {
|
|||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let metrics = AppMetrics::new();
|
||||||
|
|
||||||
let state = AppState {
|
let state = AppState {
|
||||||
db,
|
db,
|
||||||
config: Arc::new(config),
|
config: Arc::new(config),
|
||||||
repositories,
|
repositories,
|
||||||
init_token,
|
init_token,
|
||||||
default_server: Arc::new(default_server),
|
default_server: Arc::new(default_server),
|
||||||
|
metrics,
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(Self { state })
|
Ok(Self { state })
|
||||||
@@ -78,7 +83,14 @@ impl App {
|
|||||||
let (http_server, http_shutdown_tx) = HttpServer::new(&config.network, self.state.clone());
|
let (http_server, http_shutdown_tx) = HttpServer::new(&config.network, self.state.clone());
|
||||||
|
|
||||||
// Initialize UDP service
|
// Initialize UDP service
|
||||||
let (udp_server, udp_shutdown_tx) = UdpServer::new(&config.network);
|
let udp_metrics = Arc::clone(&self.state.metrics.udp);
|
||||||
|
let (udp_server, udp_shutdown_tx) = UdpServer::new(&config.network, udp_metrics);
|
||||||
|
|
||||||
|
// Lance le reporter central de métriques toutes les 30 secondes
|
||||||
|
reporter::spawn_reporter(
|
||||||
|
Arc::new(self.state.metrics.clone()),
|
||||||
|
Duration::from_secs(30),
|
||||||
|
);
|
||||||
|
|
||||||
// On lance les serveurs dans des tâches séparées
|
// On lance les serveurs dans des tâches séparées
|
||||||
let mut http_handle = tokio::spawn(http_server.run());
|
let mut http_handle = tokio::spawn(http_server.run());
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use crate::config::AppConfig;
|
use crate::config::AppConfig;
|
||||||
|
use crate::metrics::AppMetrics;
|
||||||
use crate::models::server;
|
use crate::models::server;
|
||||||
use crate::repositories::Repositories;
|
use crate::repositories::Repositories;
|
||||||
use sea_orm::DatabaseConnection;
|
use sea_orm::DatabaseConnection;
|
||||||
@@ -11,6 +12,7 @@ pub struct AppState {
|
|||||||
pub repositories: Repositories,
|
pub repositories: Repositories,
|
||||||
pub init_token: Option<uuid::Uuid>,
|
pub init_token: Option<uuid::Uuid>,
|
||||||
pub default_server: Arc<server::Model>,
|
pub default_server: Arc<server::Model>,
|
||||||
|
pub metrics: AppMetrics,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AppState {}
|
impl AppState {}
|
||||||
|
|||||||
@@ -66,3 +66,42 @@ where
|
|||||||
context.user.clone().ok_or(HTTPError::Unauthorized)
|
context.user.clone().ok_or(HTTPError::Unauthorized)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Représente un utilisateur avec les privilèges d'administrateur.
|
||||||
|
///
|
||||||
|
/// **Usage :**
|
||||||
|
/// ```rust
|
||||||
|
/// pub async fn suppression_globale(admin: Superuser) {
|
||||||
|
/// // Ici, nous sommes certains que admin.is_superuser est true.
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct Superuser(pub user::Model);
|
||||||
|
|
||||||
|
impl Deref for Superuser {
|
||||||
|
type Target = user::Model;
|
||||||
|
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<S> FromRequestParts<S> for Superuser
|
||||||
|
where
|
||||||
|
S: Send + Sync,
|
||||||
|
{
|
||||||
|
type Rejection = HTTPError;
|
||||||
|
|
||||||
|
async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {
|
||||||
|
// On récupère d'abord l'utilisateur authentifié normalement
|
||||||
|
let current_user = CurrentUser::from_request_parts(parts, state).await?;
|
||||||
|
|
||||||
|
// On vérifie le flag superuser
|
||||||
|
if current_user.is_superuser {
|
||||||
|
Ok(Superuser(current_user.0))
|
||||||
|
} else {
|
||||||
|
// L'utilisateur est authentifié mais n'a pas les droits
|
||||||
|
Err(HTTPError::Forbidden)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ use std::sync::atomic::{AtomicU64, Ordering};
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
|
use crate::metrics::{Metrics, MetricsSnapshot};
|
||||||
|
|
||||||
// ── Compteurs ────────────────────────────────────────────────────────────────
|
// ── Compteurs ────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
/// Compteurs atomiques du serveur HTTP.
|
/// Compteurs atomiques du serveur HTTP.
|
||||||
@@ -99,6 +101,14 @@ impl HttpMetrics {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Metrics for HttpMetrics {
|
||||||
|
type Snapshot = HttpMetricsSnapshot;
|
||||||
|
|
||||||
|
fn snapshot(&self) -> HttpMetricsSnapshot {
|
||||||
|
self.snapshot()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ── Snapshot ─────────────────────────────────────────────────────────────────
|
// ── Snapshot ─────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
/// Lecture cohérente des compteurs à un instant T.
|
/// Lecture cohérente des compteurs à un instant T.
|
||||||
@@ -148,6 +158,12 @@ impl HttpMetricsSnapshot {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl MetricsSnapshot for HttpMetricsSnapshot {
|
||||||
|
fn taken_at(&self) -> Instant {
|
||||||
|
self.taken_at
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ── Taux ─────────────────────────────────────────────────────────────────────
|
// ── Taux ─────────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
/// Taux moyens par seconde calculés entre deux snapshots.
|
/// Taux moyens par seconde calculés entre deux snapshots.
|
||||||
|
|||||||
+3
-8
@@ -6,7 +6,6 @@
|
|||||||
|
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
|
||||||
|
|
||||||
use axum::middleware as axum_middleware;
|
use axum::middleware as axum_middleware;
|
||||||
use axum::Router;
|
use axum::Router;
|
||||||
@@ -16,12 +15,11 @@ use tower_http::catch_panic::CatchPanicLayer;
|
|||||||
use tower_http::cors::CorsLayer;
|
use tower_http::cors::CorsLayer;
|
||||||
use tower_http::trace::TraceLayer;
|
use tower_http::trace::TraceLayer;
|
||||||
|
|
||||||
use crate::config::{AppConfig, NetworkConfig};
|
use crate::config::NetworkConfig;
|
||||||
use crate::core::AppState;
|
use crate::core::AppState;
|
||||||
use crate::http::OxRouter;
|
|
||||||
use crate::routes;
|
use crate::routes;
|
||||||
|
|
||||||
use super::metrics::{self, HttpMetrics};
|
use super::metrics::HttpMetrics;
|
||||||
use super::middleware::context_middleware;
|
use super::middleware::context_middleware;
|
||||||
|
|
||||||
// ── Erreurs ───────────────────────────────────────────────────────────────────
|
// ── Erreurs ───────────────────────────────────────────────────────────────────
|
||||||
@@ -82,7 +80,7 @@ impl HttpServer {
|
|||||||
app_state: AppState,
|
app_state: AppState,
|
||||||
) -> (Self, broadcast::Sender<()>) {
|
) -> (Self, broadcast::Sender<()>) {
|
||||||
let bind_addr = SocketAddr::new(network_config.host.into(), network_config.tcp_port);
|
let bind_addr = SocketAddr::new(network_config.host.into(), network_config.tcp_port);
|
||||||
let metrics = HttpMetrics::new();
|
let metrics = Arc::clone(&app_state.metrics.http);
|
||||||
let (shutdown_tx, shutdown_rx) = broadcast::channel(1);
|
let (shutdown_tx, shutdown_rx) = broadcast::channel(1);
|
||||||
|
|
||||||
(
|
(
|
||||||
@@ -106,9 +104,6 @@ impl HttpServer {
|
|||||||
/// La future se résout lorsqu'un signal de shutdown est reçu ou qu'une
|
/// La future se résout lorsqu'un signal de shutdown est reçu ou qu'une
|
||||||
/// erreur I/O fatale survient.
|
/// erreur I/O fatale survient.
|
||||||
pub async fn run(mut self) -> Result<(), HttpServerError> {
|
pub async fn run(mut self) -> Result<(), HttpServerError> {
|
||||||
// Lance le reporter de métriques toutes les 30 secondes
|
|
||||||
metrics::spawn_reporter(self.metrics.clone(), Duration::from_secs(30));
|
|
||||||
|
|
||||||
let metrics = self.metrics.clone();
|
let metrics = self.metrics.clone();
|
||||||
let app_state = self.app_state.clone();
|
let app_state = self.app_state.clone();
|
||||||
|
|
||||||
|
|||||||
@@ -10,3 +10,4 @@ pub mod routes;
|
|||||||
pub mod udp;
|
pub mod udp;
|
||||||
|
|
||||||
pub mod auth;
|
pub mod auth;
|
||||||
|
pub mod metrics;
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
//! Traits communs pour l'uniformisation des métriques.
|
||||||
|
|
||||||
|
use std::sync::Arc;
|
||||||
|
use std::time::Instant;
|
||||||
|
|
||||||
|
use crate::http::metrics::HttpMetrics;
|
||||||
|
use crate::udp::metrics::UdpMetrics;
|
||||||
|
|
||||||
|
/// Contrat minimal pour un jeu de compteurs métriques.
|
||||||
|
pub trait Metrics {
|
||||||
|
type Snapshot: MetricsSnapshot;
|
||||||
|
|
||||||
|
/// Prend un instantané cohérent des compteurs à l'instant T.
|
||||||
|
fn snapshot(&self) -> Self::Snapshot;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Contrat minimal pour un snapshot de métriques.
|
||||||
|
pub trait MetricsSnapshot: Clone {
|
||||||
|
/// Instant auquel le snapshot a été pris.
|
||||||
|
fn taken_at(&self) -> Instant;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── AppMetrics ────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
/// Regroupe toutes les métriques de l'application.
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct AppMetrics {
|
||||||
|
pub http: Arc<HttpMetrics>,
|
||||||
|
pub udp: Arc<UdpMetrics>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AppMetrics {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
http: HttpMetrics::new(),
|
||||||
|
udp: UdpMetrics::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub mod reporter;
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
//! Reporter central — orchestre le snapshot et le logging de toutes les métriques.
|
||||||
|
|
||||||
|
use std::sync::Arc;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use crate::metrics::AppMetrics;
|
||||||
|
|
||||||
|
/// Lance une tâche tokio unique qui reporte toutes les métriques à intervalle régulier.
|
||||||
|
pub fn spawn_reporter(metrics: Arc<AppMetrics>, interval: Duration) {
|
||||||
|
let metrics_http = Arc::clone(&metrics.http);
|
||||||
|
let metrics_udp = Arc::clone(&metrics.udp);
|
||||||
|
|
||||||
|
tokio::spawn(async move {
|
||||||
|
let mut ticker = tokio::time::interval(interval);
|
||||||
|
ticker.tick().await;
|
||||||
|
|
||||||
|
let mut prev_http = metrics_http.snapshot();
|
||||||
|
let mut prev_udp = metrics_udp.snapshot();
|
||||||
|
|
||||||
|
loop {
|
||||||
|
ticker.tick().await;
|
||||||
|
|
||||||
|
let current_http = metrics_http.snapshot();
|
||||||
|
let current_udp = metrics_udp.snapshot();
|
||||||
|
|
||||||
|
let http_rates = current_http.rates_since(&prev_http);
|
||||||
|
let udp_rates = current_udp.rates_since(&prev_udp);
|
||||||
|
|
||||||
|
tracing::info!(
|
||||||
|
// ── HTTP ──
|
||||||
|
http_requests_total = current_http.requests_total,
|
||||||
|
http_responses_2xx = current_http.responses_2xx,
|
||||||
|
http_responses_4xx = current_http.responses_4xx,
|
||||||
|
http_responses_5xx = current_http.responses_5xx,
|
||||||
|
http_req_per_sec = format_args!("{:.2}", http_rates.requests_per_sec),
|
||||||
|
http_avg_latency_ms = format_args!("{:.1}", http_rates.avg_latency_ms),
|
||||||
|
// ── UDP ──
|
||||||
|
udp_pkts_rx = current_udp.packets_received,
|
||||||
|
udp_pkts_tx = current_udp.packets_sent,
|
||||||
|
udp_pkts_dropped = current_udp.packets_dropped,
|
||||||
|
udp_pkts_rx_s = format_args!("{:.1}", udp_rates.packets_received_per_sec),
|
||||||
|
udp_pkts_tx_s = format_args!("{:.1}", udp_rates.packets_sent_per_sec),
|
||||||
|
"App metrics"
|
||||||
|
);
|
||||||
|
|
||||||
|
prev_http = current_http;
|
||||||
|
prev_udp = current_udp;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
use crate::models::category;
|
use crate::models::category;
|
||||||
use crate::repositories::{AnyResult, RepositoryContext};
|
use crate::repositories::{AnyResult, RepositoryContext};
|
||||||
use sea_orm::{ActiveModelTrait, ColumnTrait, EntityTrait, QueryFilter};
|
use sea_orm::{ActiveModelTrait, EntityTrait};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct CategoryRepository {
|
pub struct CategoryRepository {
|
||||||
@@ -9,7 +10,7 @@ pub struct CategoryRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl CategoryRepository {
|
impl CategoryRepository {
|
||||||
pub async fn get_by_id(&self, id: uuid::Uuid) -> AnyResult<Option<category::Model>> {
|
pub async fn get_by_id(&self, id: Uuid) -> AnyResult<Option<category::Model>> {
|
||||||
Ok(category::Entity::find_by_id(id)
|
Ok(category::Entity::find_by_id(id)
|
||||||
.one(&self.context.db)
|
.one(&self.context.db)
|
||||||
.await?)
|
.await?)
|
||||||
@@ -19,18 +20,11 @@ impl CategoryRepository {
|
|||||||
Ok(category::Entity::find().all(&self.context.db).await?)
|
Ok(category::Entity::find().all(&self.context.db).await?)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_by_server_id(&self, server_id: uuid::Uuid) -> AnyResult<Vec<category::Model>> {
|
|
||||||
Ok(category::Entity::find()
|
|
||||||
.filter(category::Column::ServerId.eq(server_id))
|
|
||||||
.all(&self.context.db)
|
|
||||||
.await?)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn update(&self, active: category::ActiveModel) -> AnyResult<category::Model> {
|
pub async fn update(&self, active: category::ActiveModel) -> AnyResult<category::Model> {
|
||||||
let category = active.update(&self.context.db).await?;
|
let category = active.update(&self.context.db).await?;
|
||||||
self.context
|
self.context
|
||||||
.events
|
.events
|
||||||
.emit("Category_updated", category.clone());
|
.emit("category_updated", category.clone());
|
||||||
Ok(category)
|
Ok(category)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,15 +32,15 @@ impl CategoryRepository {
|
|||||||
let category = active.insert(&self.context.db).await?;
|
let category = active.insert(&self.context.db).await?;
|
||||||
self.context
|
self.context
|
||||||
.events
|
.events
|
||||||
.emit("Category_created", category.clone());
|
.emit("category_created", category.clone());
|
||||||
Ok(category)
|
Ok(category)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn delete(&self, id: uuid::Uuid) -> AnyResult<()> {
|
pub async fn delete(&self, id: Uuid) -> AnyResult<bool> {
|
||||||
category::Entity::delete_by_id(id)
|
let res = category::Entity::delete_by_id(id)
|
||||||
.exec(&self.context.db)
|
.exec(&self.context.db)
|
||||||
.await?;
|
.await?;
|
||||||
self.context.events.emit("Category_deleted", id);
|
self.context.events.emit("category_deleted", id);
|
||||||
Ok(())
|
Ok(res.rows_affected > 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,10 @@ impl ChannelRepository {
|
|||||||
.await?)
|
.await?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn get_all(&self) -> AnyResult<Vec<channel::Model>> {
|
||||||
|
Ok(channel::Entity::find().all(&self.context.db).await?)
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn update(&self, active: channel::ActiveModel) -> AnyResult<channel::Model> {
|
pub async fn update(&self, active: channel::ActiveModel) -> AnyResult<channel::Model> {
|
||||||
let channel = active.update(&self.context.db).await?;
|
let channel = active.update(&self.context.db).await?;
|
||||||
self.context.events.emit("channel_updated", channel.clone());
|
self.context.events.emit("channel_updated", channel.clone());
|
||||||
@@ -27,11 +31,11 @@ impl ChannelRepository {
|
|||||||
Ok(channel)
|
Ok(channel)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn delete(&self, id: uuid::Uuid) -> AnyResult<()> {
|
pub async fn delete(&self, id: uuid::Uuid) -> AnyResult<bool> {
|
||||||
channel::Entity::delete_by_id(id)
|
let res = channel::Entity::delete_by_id(id)
|
||||||
.exec(&self.context.db)
|
.exec(&self.context.db)
|
||||||
.await?;
|
.await?;
|
||||||
self.context.events.emit("channel_deleted", id);
|
self.context.events.emit("channel_deleted", id);
|
||||||
Ok(())
|
Ok(res.rows_affected > 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,10 @@ impl GroupRepository {
|
|||||||
.await?)
|
.await?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn get_all(&self) -> AnyResult<Vec<group::Model>> {
|
||||||
|
Ok(group::Entity::find().all(&self.context.db).await?)
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn get_by_id(&self, id: Uuid) -> AnyResult<Option<group::Model>> {
|
pub async fn get_by_id(&self, id: Uuid) -> AnyResult<Option<group::Model>> {
|
||||||
Ok(group::Entity::find_by_id(id).one(&self.context.db).await?)
|
Ok(group::Entity::find_by_id(id).one(&self.context.db).await?)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,10 @@ pub struct MessageRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl MessageRepository {
|
impl MessageRepository {
|
||||||
|
pub async fn get_all(&self) -> AnyResult<Vec<message::Model>> {
|
||||||
|
Ok(message::Entity::find().all(&self.context.db).await?)
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn get_by_id(&self, id: uuid::Uuid) -> AnyResult<Option<message::Model>> {
|
pub async fn get_by_id(&self, id: uuid::Uuid) -> AnyResult<Option<message::Model>> {
|
||||||
Ok(message::Entity::find_by_id(id)
|
Ok(message::Entity::find_by_id(id)
|
||||||
.one(&self.context.db)
|
.one(&self.context.db)
|
||||||
@@ -27,11 +31,14 @@ impl MessageRepository {
|
|||||||
Ok(message)
|
Ok(message)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn delete(&self, id: uuid::Uuid) -> AnyResult<()> {
|
pub async fn delete(&self, id: uuid::Uuid) -> AnyResult<bool> {
|
||||||
message::Entity::delete_by_id(id)
|
let result = message::Entity::delete_by_id(id)
|
||||||
.exec(&self.context.db)
|
.exec(&self.context.db)
|
||||||
.await?;
|
.await?;
|
||||||
self.context.events.emit("message_deleted", id);
|
let deleted = result.rows_affected > 0;
|
||||||
Ok(())
|
if deleted {
|
||||||
|
self.context.events.emit("message_deleted", id);
|
||||||
|
}
|
||||||
|
Ok(deleted)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ impl ServerRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn add_user(&self, server_id: Uuid, user_id: Uuid) -> AnyResult<bool> {
|
pub async fn add_user(&self, server_id: Uuid, user_id: Uuid) -> AnyResult<bool> {
|
||||||
let res = server_user::ActiveModel {
|
server_user::ActiveModel {
|
||||||
server_id: Set(server_id),
|
server_id: Set(server_id),
|
||||||
user_id: Set(user_id),
|
user_id: Set(user_id),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
|||||||
@@ -73,12 +73,15 @@ impl UserRepository {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn delete(&self, id: uuid::Uuid) -> AnyResult<()> {
|
pub async fn delete(&self, id: uuid::Uuid) -> AnyResult<bool> {
|
||||||
user::Entity::delete_by_id(id)
|
let result = user::Entity::delete_by_id(id)
|
||||||
.exec(&self.context.db)
|
.exec(&self.context.db)
|
||||||
.await?;
|
.await?;
|
||||||
self.context.events.emit("user_deleted", id);
|
let deleted = result.rows_affected > 0;
|
||||||
Ok(())
|
if deleted {
|
||||||
|
self.context.events.emit("user_deleted", id);
|
||||||
|
}
|
||||||
|
Ok(deleted)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn username_exists(&self, username: &str) -> AnyResult<bool> {
|
pub async fn username_exists(&self, username: &str) -> AnyResult<bool> {
|
||||||
|
|||||||
@@ -48,8 +48,8 @@ pub async fn login_user_pw(
|
|||||||
)
|
)
|
||||||
)]
|
)]
|
||||||
pub async fn check(
|
pub async fn check(
|
||||||
State(state): State<AppState>,
|
State(_state): State<AppState>,
|
||||||
user: CurrentUser,
|
_user: CurrentUser,
|
||||||
) -> Result<Json<CheckResponse>, HTTPError> {
|
) -> Result<Json<CheckResponse>, HTTPError> {
|
||||||
Ok(Json(CheckResponse {
|
Ok(Json(CheckResponse {
|
||||||
authenticated: true,
|
authenticated: true,
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
pub struct Category {}
|
// Ce fichier est conservé pour structure mais n'est plus utilisé.
|
||||||
|
// Les modèles de domaine sont directement gérés par SeaORM dans src/models.
|
||||||
|
|||||||
@@ -1,10 +1,30 @@
|
|||||||
|
use chrono::{DateTime, Utc};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use utoipa::ToSchema;
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
||||||
pub struct CreateCategoryRequest {}
|
pub struct CreateCategoryRequest {
|
||||||
|
pub server_id: Uuid,
|
||||||
|
#[schema(example = "Discussion")]
|
||||||
|
pub name: String,
|
||||||
|
#[serde(default)]
|
||||||
|
pub position: i32,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
||||||
pub struct UpdateCategoryRequest {}
|
pub struct UpdateCategoryRequest {
|
||||||
|
#[schema(example = "Discussion (Maj)")]
|
||||||
|
pub name: String,
|
||||||
|
pub position: i32,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
||||||
pub struct CategoryResponse {}
|
pub struct CategoryResponse {
|
||||||
|
pub id: Uuid,
|
||||||
|
pub server_id: Uuid,
|
||||||
|
pub name: String,
|
||||||
|
pub position: i32,
|
||||||
|
pub created_at: DateTime<Utc>,
|
||||||
|
pub updated_at: DateTime<Utc>,
|
||||||
|
}
|
||||||
|
|||||||
+147
-12
@@ -1,22 +1,157 @@
|
|||||||
use axum::http::StatusCode;
|
use crate::core::state::AppState;
|
||||||
use axum::response::IntoResponse;
|
use crate::http::context::Superuser;
|
||||||
|
use crate::http::error::HTTPError;
|
||||||
|
use crate::routes::category::dto::{
|
||||||
|
CategoryResponse, CreateCategoryRequest, UpdateCategoryRequest,
|
||||||
|
};
|
||||||
|
use crate::routes::category::mapper;
|
||||||
|
use axum::{
|
||||||
|
extract::{Path, State},
|
||||||
|
http::StatusCode,
|
||||||
|
Json,
|
||||||
|
};
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
pub async fn get_all() -> impl IntoResponse {
|
/// Liste toutes les catégories
|
||||||
StatusCode::NOT_IMPLEMENTED
|
#[utoipa::path(
|
||||||
|
get,
|
||||||
|
path = "/categories",
|
||||||
|
responses(
|
||||||
|
(status = 200, description = "Liste des catégories récupérée avec succès", body = [CategoryResponse]),
|
||||||
|
(status = 500, description = "Erreur interne du serveur")
|
||||||
|
),
|
||||||
|
tag = "Categories"
|
||||||
|
)]
|
||||||
|
pub async fn get_all(
|
||||||
|
State(state): State<AppState>,
|
||||||
|
) -> Result<Json<Vec<CategoryResponse>>, HTTPError> {
|
||||||
|
let categories = state.repositories.category.get_all().await?;
|
||||||
|
Ok(Json(
|
||||||
|
categories
|
||||||
|
.into_iter()
|
||||||
|
.map(mapper::category_model_to_category_response)
|
||||||
|
.collect(),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_by_id() -> impl IntoResponse {
|
/// Récupère une catégorie par son ID
|
||||||
StatusCode::NOT_IMPLEMENTED
|
#[utoipa::path(
|
||||||
|
get,
|
||||||
|
path = "/categories/{id}",
|
||||||
|
responses(
|
||||||
|
(status = 200, description = "Catégorie trouvée", body = CategoryResponse),
|
||||||
|
(status = 404, description = "Catégorie non trouvée"),
|
||||||
|
(status = 500, description = "Erreur interne du serveur")
|
||||||
|
),
|
||||||
|
params(
|
||||||
|
("id" = Uuid, Path, description = "ID de la catégorie")
|
||||||
|
),
|
||||||
|
tag = "Categories"
|
||||||
|
)]
|
||||||
|
pub async fn get_by_id(
|
||||||
|
State(state): State<AppState>,
|
||||||
|
Path(id): Path<Uuid>,
|
||||||
|
) -> Result<Json<CategoryResponse>, HTTPError> {
|
||||||
|
let category = state
|
||||||
|
.repositories
|
||||||
|
.category
|
||||||
|
.get_by_id(id)
|
||||||
|
.await?
|
||||||
|
.ok_or(HTTPError::NotFound)?;
|
||||||
|
|
||||||
|
Ok(Json(mapper::category_model_to_category_response(category)))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn create() -> impl IntoResponse {
|
/// Crée une nouvelle catégorie
|
||||||
StatusCode::NOT_IMPLEMENTED
|
#[utoipa::path(
|
||||||
|
post,
|
||||||
|
path = "/categories",
|
||||||
|
request_body = CreateCategoryRequest,
|
||||||
|
responses(
|
||||||
|
(status = 201, description = "Catégorie créée avec succès", body = CategoryResponse),
|
||||||
|
(status = 404, description = "Serveur non trouvé"),
|
||||||
|
(status = 500, description = "Erreur interne du serveur")
|
||||||
|
),
|
||||||
|
tag = "Categories"
|
||||||
|
)]
|
||||||
|
pub async fn create(
|
||||||
|
_admin: Superuser,
|
||||||
|
State(state): State<AppState>,
|
||||||
|
Json(payload): Json<CreateCategoryRequest>,
|
||||||
|
) -> Result<(StatusCode, Json<CategoryResponse>), HTTPError> {
|
||||||
|
// Vérifier que le serveur existe
|
||||||
|
state
|
||||||
|
.repositories
|
||||||
|
.server
|
||||||
|
.get_by_id(payload.server_id)
|
||||||
|
.await?
|
||||||
|
.ok_or(HTTPError::BadRequest("Server not found".to_string()))?;
|
||||||
|
|
||||||
|
let active_model = mapper::create_request_to_am(payload);
|
||||||
|
let category = state.repositories.category.create(active_model).await?;
|
||||||
|
Ok((
|
||||||
|
StatusCode::CREATED,
|
||||||
|
Json(mapper::category_model_to_category_response(category)),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn update() -> impl IntoResponse {
|
/// Met à jour une catégorie existante
|
||||||
StatusCode::NOT_IMPLEMENTED
|
#[utoipa::path(
|
||||||
|
put,
|
||||||
|
path = "/categories/{id}",
|
||||||
|
request_body = UpdateCategoryRequest,
|
||||||
|
responses(
|
||||||
|
(status = 200, description = "Catégorie mise à jour avec succès", body = CategoryResponse),
|
||||||
|
(status = 404, description = "Catégorie non trouvée"),
|
||||||
|
(status = 500, description = "Erreur interne du serveur")
|
||||||
|
),
|
||||||
|
params(
|
||||||
|
("id" = Uuid, Path, description = "ID de la catégorie")
|
||||||
|
),
|
||||||
|
tag = "Categories"
|
||||||
|
)]
|
||||||
|
pub async fn update(
|
||||||
|
_admin: Superuser,
|
||||||
|
State(state): State<AppState>,
|
||||||
|
Path(id): Path<Uuid>,
|
||||||
|
Json(payload): Json<UpdateCategoryRequest>,
|
||||||
|
) -> Result<Json<CategoryResponse>, HTTPError> {
|
||||||
|
// Vérifier l'existence
|
||||||
|
let category = state
|
||||||
|
.repositories
|
||||||
|
.category
|
||||||
|
.get_by_id(id)
|
||||||
|
.await?
|
||||||
|
.ok_or(HTTPError::NotFound)?;
|
||||||
|
|
||||||
|
let active_model = mapper::update_request_to_am(category.id, category.server_id, payload);
|
||||||
|
let category = state.repositories.category.update(active_model).await?;
|
||||||
|
|
||||||
|
Ok(Json(mapper::category_model_to_category_response(category)))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn delete() -> impl IntoResponse {
|
/// Supprime une catégorie
|
||||||
StatusCode::NOT_IMPLEMENTED
|
#[utoipa::path(
|
||||||
|
delete,
|
||||||
|
path = "/categories/{id}",
|
||||||
|
responses(
|
||||||
|
(status = 204, description = "Catégorie supprimée avec succès"),
|
||||||
|
(status = 404, description = "Catégorie non trouvée"),
|
||||||
|
(status = 500, description = "Erreur interne du serveur")
|
||||||
|
),
|
||||||
|
params(
|
||||||
|
("id" = Uuid, Path, description = "ID de la catégorie")
|
||||||
|
),
|
||||||
|
tag = "Categories"
|
||||||
|
)]
|
||||||
|
pub async fn delete(
|
||||||
|
_admin: Superuser,
|
||||||
|
State(state): State<AppState>,
|
||||||
|
Path(id): Path<Uuid>,
|
||||||
|
) -> Result<StatusCode, HTTPError> {
|
||||||
|
if state.repositories.category.delete(id).await? {
|
||||||
|
Ok(StatusCode::NO_CONTENT)
|
||||||
|
} else {
|
||||||
|
Err(HTTPError::NotFound)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,41 @@
|
|||||||
use super::{domain::Category, dto::CategoryResponse};
|
use crate::models::category;
|
||||||
|
use crate::routes::category::dto::{
|
||||||
|
CategoryResponse, CreateCategoryRequest, UpdateCategoryRequest,
|
||||||
|
};
|
||||||
|
use sea_orm::Set;
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
pub fn to_response(_item: Category) -> CategoryResponse {
|
pub fn category_model_to_category_response(model: category::Model) -> CategoryResponse {
|
||||||
todo!()
|
CategoryResponse {
|
||||||
|
id: model.id,
|
||||||
|
server_id: model.server_id,
|
||||||
|
name: model.name,
|
||||||
|
position: model.position,
|
||||||
|
created_at: model.created_at,
|
||||||
|
updated_at: model.updated_at,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn create_request_to_am(req: CreateCategoryRequest) -> category::ActiveModel {
|
||||||
|
category::ActiveModel {
|
||||||
|
id: Set(Uuid::new_v4()),
|
||||||
|
server_id: Set(req.server_id),
|
||||||
|
name: Set(req.name),
|
||||||
|
position: Set(req.position),
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn update_request_to_am(
|
||||||
|
id: Uuid,
|
||||||
|
server_id: Uuid,
|
||||||
|
req: UpdateCategoryRequest,
|
||||||
|
) -> category::ActiveModel {
|
||||||
|
category::ActiveModel {
|
||||||
|
id: Set(id),
|
||||||
|
server_id: Set(server_id),
|
||||||
|
name: Set(req.name),
|
||||||
|
position: Set(req.position),
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
use axum::{Router, routing::get};
|
use crate::core::state::AppState;
|
||||||
|
use axum::{routing::get, Router};
|
||||||
|
|
||||||
use super::handlers;
|
use super::handlers;
|
||||||
|
|
||||||
pub fn router() -> Router {
|
pub fn router() -> Router<AppState> {
|
||||||
Router::new()
|
Router::new()
|
||||||
.route("/categorys", get(handlers::get_all).post(handlers::create))
|
.route("/categories", get(handlers::get_all).post(handlers::create))
|
||||||
.route(
|
.route(
|
||||||
"/categorys/:id",
|
"/categories/:id",
|
||||||
get(handlers::get_by_id)
|
get(handlers::get_by_id)
|
||||||
.put(handlers::update)
|
.put(handlers::update)
|
||||||
.delete(handlers::delete),
|
.delete(handlers::delete),
|
||||||
|
|||||||
@@ -1,21 +1,2 @@
|
|||||||
use super::domain::Category;
|
// Ce fichier est conservé pour structure mais n'est plus utilisé.
|
||||||
|
// La logique a été déplacée directement dans les handlers.
|
||||||
pub async fn find_all() -> Vec<Category> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn find_by_id(_id: u64) -> Option<Category> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn create(_item: Category) -> Category {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn update(_id: u64, _item: Category) -> Option<Category> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn delete(_id: u64) -> bool {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
pub struct Channel {}
|
// Ce fichier est conservé pour structure mais n'est plus utilisé.
|
||||||
|
// Les modèles de domaine sont directement gérés par SeaORM dans src/models.
|
||||||
|
|||||||
@@ -1,10 +1,40 @@
|
|||||||
|
use crate::models::channel::ChannelType;
|
||||||
|
use chrono::{DateTime, Utc};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use utoipa::ToSchema;
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
||||||
pub struct CreateChannelRequest {}
|
pub struct CreateChannelRequest {
|
||||||
|
pub server_id: Option<Uuid>,
|
||||||
|
pub category_id: Option<Uuid>,
|
||||||
|
#[serde(default)]
|
||||||
|
pub position: i32,
|
||||||
|
pub channel_type: ChannelType,
|
||||||
|
#[schema(example = "général")]
|
||||||
|
pub name: Option<String>,
|
||||||
|
pub default_permissions: Option<u64>,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
||||||
pub struct UpdateChannelRequest {}
|
pub struct UpdateChannelRequest {
|
||||||
|
pub server_id: Option<Uuid>,
|
||||||
|
pub category_id: Option<Uuid>,
|
||||||
|
pub position: i32,
|
||||||
|
pub channel_type: ChannelType,
|
||||||
|
pub name: Option<String>,
|
||||||
|
pub default_permissions: Option<u64>,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
||||||
pub struct ChannelResponse {}
|
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>,
|
||||||
|
pub created_at: DateTime<Utc>,
|
||||||
|
pub updated_at: DateTime<Utc>,
|
||||||
|
pub default_permissions: Option<u64>,
|
||||||
|
}
|
||||||
|
|||||||
+178
-12
@@ -1,22 +1,188 @@
|
|||||||
use axum::http::StatusCode;
|
use crate::core::state::AppState;
|
||||||
use axum::response::IntoResponse;
|
use crate::http::context::Superuser;
|
||||||
|
use crate::http::error::HTTPError;
|
||||||
|
use crate::routes::channel::dto::{ChannelResponse, CreateChannelRequest, UpdateChannelRequest};
|
||||||
|
use crate::routes::channel::mapper;
|
||||||
|
use axum::{
|
||||||
|
extract::{Path, State},
|
||||||
|
http::StatusCode,
|
||||||
|
Json,
|
||||||
|
};
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
pub async fn get_all() -> impl IntoResponse {
|
/// Liste tous les channels
|
||||||
StatusCode::NOT_IMPLEMENTED
|
#[utoipa::path(
|
||||||
|
get,
|
||||||
|
path = "/channels",
|
||||||
|
responses(
|
||||||
|
(status = 200, description = "Liste des channels récupérée avec succès", body = [ChannelResponse]),
|
||||||
|
(status = 500, description = "Erreur interne du serveur")
|
||||||
|
),
|
||||||
|
tag = "Channels"
|
||||||
|
)]
|
||||||
|
pub async fn get_all(
|
||||||
|
State(state): State<AppState>,
|
||||||
|
) -> Result<Json<Vec<ChannelResponse>>, HTTPError> {
|
||||||
|
let channels = state.repositories.channel.get_all().await?;
|
||||||
|
Ok(Json(
|
||||||
|
channels
|
||||||
|
.into_iter()
|
||||||
|
.map(mapper::channel_model_to_channel_response)
|
||||||
|
.collect(),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_by_id() -> impl IntoResponse {
|
/// Récupère un channel par son ID
|
||||||
StatusCode::NOT_IMPLEMENTED
|
#[utoipa::path(
|
||||||
|
get,
|
||||||
|
path = "/channels/{id}",
|
||||||
|
responses(
|
||||||
|
(status = 200, description = "Channel trouvé", body = ChannelResponse),
|
||||||
|
(status = 404, description = "Channel non trouvé"),
|
||||||
|
(status = 500, description = "Erreur interne du serveur")
|
||||||
|
),
|
||||||
|
params(
|
||||||
|
("id" = Uuid, Path, description = "ID du channel")
|
||||||
|
),
|
||||||
|
tag = "Channels"
|
||||||
|
)]
|
||||||
|
pub async fn get_by_id(
|
||||||
|
State(state): State<AppState>,
|
||||||
|
Path(id): Path<Uuid>,
|
||||||
|
) -> Result<Json<ChannelResponse>, HTTPError> {
|
||||||
|
let channel = state
|
||||||
|
.repositories
|
||||||
|
.channel
|
||||||
|
.get_by_id(id)
|
||||||
|
.await?
|
||||||
|
.ok_or(HTTPError::NotFound)?;
|
||||||
|
|
||||||
|
Ok(Json(mapper::channel_model_to_channel_response(channel)))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn create() -> impl IntoResponse {
|
/// Crée un nouveau channel
|
||||||
StatusCode::NOT_IMPLEMENTED
|
#[utoipa::path(
|
||||||
|
post,
|
||||||
|
path = "/channels",
|
||||||
|
request_body = CreateChannelRequest,
|
||||||
|
responses(
|
||||||
|
(status = 201, description = "Channel créé avec succès", body = ChannelResponse),
|
||||||
|
(status = 400, description = "Données invalides (Serveur ou Catégorie non trouvée)"),
|
||||||
|
(status = 500, description = "Erreur interne du serveur")
|
||||||
|
),
|
||||||
|
tag = "Channels"
|
||||||
|
)]
|
||||||
|
pub async fn create(
|
||||||
|
_admin: Superuser,
|
||||||
|
State(state): State<AppState>,
|
||||||
|
Json(payload): Json<CreateChannelRequest>,
|
||||||
|
) -> Result<(StatusCode, Json<ChannelResponse>), HTTPError> {
|
||||||
|
// Vérifier que le serveur existe si fourni
|
||||||
|
if let Some(server_id) = payload.server_id {
|
||||||
|
state
|
||||||
|
.repositories
|
||||||
|
.server
|
||||||
|
.get_by_id(server_id)
|
||||||
|
.await?
|
||||||
|
.ok_or(HTTPError::BadRequest("Server not found".to_string()))?;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vérifier que la catégorie existe si fournie
|
||||||
|
if let Some(category_id) = payload.category_id {
|
||||||
|
state
|
||||||
|
.repositories
|
||||||
|
.category
|
||||||
|
.get_by_id(category_id)
|
||||||
|
.await?
|
||||||
|
.ok_or(HTTPError::BadRequest("Category not found".to_string()))?;
|
||||||
|
}
|
||||||
|
|
||||||
|
let active_model = mapper::create_request_to_am(payload);
|
||||||
|
let channel = state.repositories.channel.create(active_model).await?;
|
||||||
|
Ok((
|
||||||
|
StatusCode::CREATED,
|
||||||
|
Json(mapper::channel_model_to_channel_response(channel)),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn update() -> impl IntoResponse {
|
/// Met à jour un channel existant
|
||||||
StatusCode::NOT_IMPLEMENTED
|
#[utoipa::path(
|
||||||
|
put,
|
||||||
|
path = "/channels/{id}",
|
||||||
|
request_body = UpdateChannelRequest,
|
||||||
|
responses(
|
||||||
|
(status = 200, description = "Channel mis à jour avec succès", body = ChannelResponse),
|
||||||
|
(status = 404, description = "Channel non trouvé"),
|
||||||
|
(status = 400, description = "Données invalides (Serveur ou Catégorie non trouvée)"),
|
||||||
|
(status = 500, description = "Erreur interne du serveur")
|
||||||
|
),
|
||||||
|
params(
|
||||||
|
("id" = Uuid, Path, description = "ID du channel")
|
||||||
|
),
|
||||||
|
tag = "Channels"
|
||||||
|
)]
|
||||||
|
pub async fn update(
|
||||||
|
_admin: Superuser,
|
||||||
|
State(state): State<AppState>,
|
||||||
|
Path(id): Path<Uuid>,
|
||||||
|
Json(payload): Json<UpdateChannelRequest>,
|
||||||
|
) -> Result<Json<ChannelResponse>, HTTPError> {
|
||||||
|
// Vérifier l'existence
|
||||||
|
state
|
||||||
|
.repositories
|
||||||
|
.channel
|
||||||
|
.get_by_id(id)
|
||||||
|
.await?
|
||||||
|
.ok_or(HTTPError::NotFound)?;
|
||||||
|
|
||||||
|
// Vérifier que le serveur existe si fourni
|
||||||
|
if let Some(server_id) = payload.server_id {
|
||||||
|
state
|
||||||
|
.repositories
|
||||||
|
.server
|
||||||
|
.get_by_id(server_id)
|
||||||
|
.await?
|
||||||
|
.ok_or(HTTPError::BadRequest("Server not found".to_string()))?;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vérifier que la catégorie existe si fournie
|
||||||
|
if let Some(category_id) = payload.category_id {
|
||||||
|
state
|
||||||
|
.repositories
|
||||||
|
.category
|
||||||
|
.get_by_id(category_id)
|
||||||
|
.await?
|
||||||
|
.ok_or(HTTPError::BadRequest("Category not found".to_string()))?;
|
||||||
|
}
|
||||||
|
|
||||||
|
let active_model = mapper::update_request_to_am(id, payload);
|
||||||
|
let channel = state.repositories.channel.update(active_model).await?;
|
||||||
|
|
||||||
|
Ok(Json(mapper::channel_model_to_channel_response(channel)))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn delete() -> impl IntoResponse {
|
/// Supprime un channel
|
||||||
StatusCode::NOT_IMPLEMENTED
|
#[utoipa::path(
|
||||||
|
delete,
|
||||||
|
path = "/channels/{id}",
|
||||||
|
responses(
|
||||||
|
(status = 204, description = "Channel supprimé avec succès"),
|
||||||
|
(status = 404, description = "Channel non trouvé"),
|
||||||
|
(status = 500, description = "Erreur interne du serveur")
|
||||||
|
),
|
||||||
|
params(
|
||||||
|
("id" = Uuid, Path, description = "ID du channel")
|
||||||
|
),
|
||||||
|
tag = "Channels"
|
||||||
|
)]
|
||||||
|
pub async fn delete(
|
||||||
|
_admin: Superuser,
|
||||||
|
State(state): State<AppState>,
|
||||||
|
Path(id): Path<Uuid>,
|
||||||
|
) -> Result<StatusCode, HTTPError> {
|
||||||
|
if state.repositories.channel.delete(id).await? {
|
||||||
|
Ok(StatusCode::NO_CONTENT)
|
||||||
|
} else {
|
||||||
|
Err(HTTPError::NotFound)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,44 @@
|
|||||||
use super::{domain::Channel, dto::ChannelResponse};
|
use crate::models::channel;
|
||||||
|
use crate::routes::channel::dto::{ChannelResponse, CreateChannelRequest, UpdateChannelRequest};
|
||||||
|
use sea_orm::Set;
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
pub fn to_response(_item: Channel) -> ChannelResponse {
|
pub fn channel_model_to_channel_response(model: channel::Model) -> ChannelResponse {
|
||||||
todo!()
|
ChannelResponse {
|
||||||
|
id: model.id,
|
||||||
|
server_id: model.server_id,
|
||||||
|
category_id: model.category_id,
|
||||||
|
position: model.position,
|
||||||
|
channel_type: model.channel_type,
|
||||||
|
name: model.name,
|
||||||
|
created_at: model.created_at,
|
||||||
|
updated_at: model.updated_at,
|
||||||
|
default_permissions: model.default_permissions,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn create_request_to_am(req: CreateChannelRequest) -> channel::ActiveModel {
|
||||||
|
channel::ActiveModel {
|
||||||
|
id: Set(Uuid::new_v4()),
|
||||||
|
server_id: Set(req.server_id),
|
||||||
|
category_id: Set(req.category_id),
|
||||||
|
position: Set(req.position),
|
||||||
|
channel_type: Set(req.channel_type),
|
||||||
|
name: Set(req.name),
|
||||||
|
default_permissions: Set(req.default_permissions),
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn update_request_to_am(id: Uuid, req: UpdateChannelRequest) -> channel::ActiveModel {
|
||||||
|
channel::ActiveModel {
|
||||||
|
id: Set(id),
|
||||||
|
server_id: Set(req.server_id),
|
||||||
|
category_id: Set(req.category_id),
|
||||||
|
position: Set(req.position),
|
||||||
|
channel_type: Set(req.channel_type),
|
||||||
|
name: Set(req.name),
|
||||||
|
default_permissions: Set(req.default_permissions),
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
use axum::{Router, routing::get};
|
|
||||||
|
|
||||||
use super::handlers;
|
use super::handlers;
|
||||||
|
use crate::core::state::AppState;
|
||||||
|
use axum::{routing::get, Router};
|
||||||
|
|
||||||
pub fn router() -> Router {
|
pub fn router() -> Router<AppState> {
|
||||||
Router::new()
|
Router::new()
|
||||||
.route("/channels", get(handlers::get_all).post(handlers::create))
|
.route("/channels", get(handlers::get_all).post(handlers::create))
|
||||||
.route(
|
.route(
|
||||||
|
|||||||
@@ -1,21 +1,2 @@
|
|||||||
use super::domain::Channel;
|
// Ce fichier est conservé pour structure mais n'est plus utilisé.
|
||||||
|
// La logique a été déplacée directement dans les handlers.
|
||||||
pub async fn find_all() -> Vec<Channel> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn find_by_id(_id: u64) -> Option<Channel> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn create(_item: Channel) -> Channel {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn update(_id: u64, _item: Channel) -> Option<Channel> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn delete(_id: u64) -> bool {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
pub struct Group {}
|
// Ce fichier est conservé pour structure mais n'est plus utilisé.
|
||||||
|
// Les modèles de domaine sont directement gérés par SeaORM dans src/models.
|
||||||
|
|||||||
+34
-6
@@ -1,10 +1,38 @@
|
|||||||
|
use chrono::{DateTime, Utc};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use utoipa::ToSchema;
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
||||||
pub struct CreateGroupRequest {}
|
pub struct CreateGroupRequest {
|
||||||
|
pub server_id: Uuid,
|
||||||
|
#[schema(example = "Modérateurs")]
|
||||||
|
pub name: String,
|
||||||
|
#[serde(default)]
|
||||||
|
pub is_default: bool,
|
||||||
|
pub server_permissions: i64,
|
||||||
|
pub channel_permissions: i64,
|
||||||
|
pub voice_permissions: i64,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
||||||
pub struct UpdateGroupRequest {}
|
pub struct UpdateGroupRequest {
|
||||||
|
#[schema(example = "Modérateurs (MAJ)")]
|
||||||
|
pub name: String,
|
||||||
|
pub is_default: bool,
|
||||||
|
pub server_permissions: i64,
|
||||||
|
pub channel_permissions: i64,
|
||||||
|
pub voice_permissions: i64,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
||||||
pub struct GroupResponse {}
|
pub struct GroupResponse {
|
||||||
|
pub id: Uuid,
|
||||||
|
pub server_id: Uuid,
|
||||||
|
pub name: String,
|
||||||
|
pub is_default: bool,
|
||||||
|
pub created_at: DateTime<Utc>,
|
||||||
|
pub server_permissions: i64,
|
||||||
|
pub channel_permissions: i64,
|
||||||
|
pub voice_permissions: i64,
|
||||||
|
}
|
||||||
|
|||||||
+143
-12
@@ -1,22 +1,153 @@
|
|||||||
use axum::http::StatusCode;
|
use crate::core::state::AppState;
|
||||||
use axum::response::IntoResponse;
|
use crate::http::context::Superuser;
|
||||||
|
use crate::http::error::HTTPError;
|
||||||
|
use crate::routes::group::dto::{CreateGroupRequest, GroupResponse, UpdateGroupRequest};
|
||||||
|
use crate::routes::group::mapper;
|
||||||
|
use axum::{
|
||||||
|
Json,
|
||||||
|
extract::{Path, State},
|
||||||
|
http::StatusCode,
|
||||||
|
};
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
pub async fn get_all() -> impl IntoResponse {
|
/// Liste tous les groupes
|
||||||
StatusCode::NOT_IMPLEMENTED
|
#[utoipa::path(
|
||||||
|
get,
|
||||||
|
path = "/groups",
|
||||||
|
responses(
|
||||||
|
(status = 200, description = "Liste des groupes récupérée avec succès", body = [GroupResponse]),
|
||||||
|
(status = 500, description = "Erreur interne du serveur")
|
||||||
|
),
|
||||||
|
tag = "Groups"
|
||||||
|
)]
|
||||||
|
pub async fn get_all(State(state): State<AppState>) -> Result<Json<Vec<GroupResponse>>, HTTPError> {
|
||||||
|
let groups = state.repositories.group.get_all().await?;
|
||||||
|
Ok(Json(
|
||||||
|
groups
|
||||||
|
.into_iter()
|
||||||
|
.map(mapper::group_model_to_group_response)
|
||||||
|
.collect(),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_by_id() -> impl IntoResponse {
|
/// Récupère un groupe par son ID
|
||||||
StatusCode::NOT_IMPLEMENTED
|
#[utoipa::path(
|
||||||
|
get,
|
||||||
|
path = "/groups/{id}",
|
||||||
|
responses(
|
||||||
|
(status = 200, description = "Groupe trouvé", body = GroupResponse),
|
||||||
|
(status = 404, description = "Groupe non trouvé"),
|
||||||
|
(status = 500, description = "Erreur interne du serveur")
|
||||||
|
),
|
||||||
|
params(
|
||||||
|
("id" = Uuid, Path, description = "ID du groupe")
|
||||||
|
),
|
||||||
|
tag = "Groups"
|
||||||
|
)]
|
||||||
|
pub async fn get_by_id(
|
||||||
|
State(state): State<AppState>,
|
||||||
|
Path(id): Path<Uuid>,
|
||||||
|
) -> Result<Json<GroupResponse>, HTTPError> {
|
||||||
|
let group = state
|
||||||
|
.repositories
|
||||||
|
.group
|
||||||
|
.get_by_id(id)
|
||||||
|
.await?
|
||||||
|
.ok_or(HTTPError::NotFound)?;
|
||||||
|
|
||||||
|
Ok(Json(mapper::group_model_to_group_response(group)))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn create() -> impl IntoResponse {
|
/// Crée un nouveau groupe
|
||||||
StatusCode::NOT_IMPLEMENTED
|
#[utoipa::path(
|
||||||
|
post,
|
||||||
|
path = "/groups",
|
||||||
|
request_body = CreateGroupRequest,
|
||||||
|
responses(
|
||||||
|
(status = 201, description = "Groupe créé avec succès", body = GroupResponse),
|
||||||
|
(status = 404, description = "Serveur non trouvé"),
|
||||||
|
(status = 500, description = "Erreur interne du serveur")
|
||||||
|
),
|
||||||
|
tag = "Groups"
|
||||||
|
)]
|
||||||
|
pub async fn create(
|
||||||
|
_admin: Superuser,
|
||||||
|
State(state): State<AppState>,
|
||||||
|
Json(payload): Json<CreateGroupRequest>,
|
||||||
|
) -> Result<(StatusCode, Json<GroupResponse>), HTTPError> {
|
||||||
|
// Vérifier que le serveur existe
|
||||||
|
state
|
||||||
|
.repositories
|
||||||
|
.server
|
||||||
|
.get_by_id(payload.server_id)
|
||||||
|
.await?
|
||||||
|
.ok_or(HTTPError::BadRequest("Server not found".to_string()))?;
|
||||||
|
|
||||||
|
let active_model = mapper::create_request_to_am(payload);
|
||||||
|
let group = state.repositories.group.create(active_model).await?;
|
||||||
|
Ok((
|
||||||
|
StatusCode::CREATED,
|
||||||
|
Json(mapper::group_model_to_group_response(group)),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn update() -> impl IntoResponse {
|
/// Met à jour un groupe existant
|
||||||
StatusCode::NOT_IMPLEMENTED
|
#[utoipa::path(
|
||||||
|
put,
|
||||||
|
path = "/groups/{id}",
|
||||||
|
request_body = UpdateGroupRequest,
|
||||||
|
responses(
|
||||||
|
(status = 200, description = "Groupe mis à jour avec succès", body = GroupResponse),
|
||||||
|
(status = 404, description = "Groupe non trouvé"),
|
||||||
|
(status = 500, description = "Erreur interne du serveur")
|
||||||
|
),
|
||||||
|
params(
|
||||||
|
("id" = Uuid, Path, description = "ID du groupe")
|
||||||
|
),
|
||||||
|
tag = "Groups"
|
||||||
|
)]
|
||||||
|
pub async fn update(
|
||||||
|
_admin: Superuser,
|
||||||
|
State(state): State<AppState>,
|
||||||
|
Path(id): Path<Uuid>,
|
||||||
|
Json(payload): Json<UpdateGroupRequest>,
|
||||||
|
) -> Result<Json<GroupResponse>, HTTPError> {
|
||||||
|
// Vérifier l'existence
|
||||||
|
let group = state
|
||||||
|
.repositories
|
||||||
|
.group
|
||||||
|
.get_by_id(id)
|
||||||
|
.await?
|
||||||
|
.ok_or(HTTPError::NotFound)?;
|
||||||
|
|
||||||
|
let active_model = mapper::update_request_to_am(group.id, group.server_id, payload);
|
||||||
|
let group = state.repositories.group.update(active_model).await?;
|
||||||
|
|
||||||
|
Ok(Json(mapper::group_model_to_group_response(group)))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn delete() -> impl IntoResponse {
|
/// Supprime un groupe
|
||||||
StatusCode::NOT_IMPLEMENTED
|
#[utoipa::path(
|
||||||
|
delete,
|
||||||
|
path = "/groups/{id}",
|
||||||
|
responses(
|
||||||
|
(status = 204, description = "Groupe supprimé avec succès"),
|
||||||
|
(status = 404, description = "Groupe non trouvé"),
|
||||||
|
(status = 500, description = "Erreur interne du serveur")
|
||||||
|
),
|
||||||
|
params(
|
||||||
|
("id" = Uuid, Path, description = "ID du groupe")
|
||||||
|
),
|
||||||
|
tag = "Groups"
|
||||||
|
)]
|
||||||
|
pub async fn delete(
|
||||||
|
_admin: Superuser,
|
||||||
|
State(state): State<AppState>,
|
||||||
|
Path(id): Path<Uuid>,
|
||||||
|
) -> Result<StatusCode, HTTPError> {
|
||||||
|
if state.repositories.group.delete(id).await? {
|
||||||
|
Ok(StatusCode::NO_CONTENT)
|
||||||
|
} else {
|
||||||
|
Err(HTTPError::NotFound)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,47 @@
|
|||||||
use super::{domain::Group, dto::GroupResponse};
|
use crate::models::group;
|
||||||
|
use crate::routes::group::dto::{CreateGroupRequest, GroupResponse, UpdateGroupRequest};
|
||||||
|
use sea_orm::Set;
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
pub fn to_response(_item: Group) -> GroupResponse {
|
pub fn group_model_to_group_response(model: group::Model) -> GroupResponse {
|
||||||
todo!()
|
GroupResponse {
|
||||||
|
id: model.id,
|
||||||
|
server_id: model.server_id,
|
||||||
|
name: model.name,
|
||||||
|
is_default: model.is_default,
|
||||||
|
created_at: model.created_at,
|
||||||
|
server_permissions: model.server_permissions,
|
||||||
|
channel_permissions: model.channel_permissions,
|
||||||
|
voice_permissions: model.voice_permissions,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn create_request_to_am(req: CreateGroupRequest) -> group::ActiveModel {
|
||||||
|
group::ActiveModel {
|
||||||
|
id: Set(Uuid::new_v4()),
|
||||||
|
server_id: Set(req.server_id),
|
||||||
|
name: Set(req.name),
|
||||||
|
is_default: Set(req.is_default),
|
||||||
|
server_permissions: Set(req.server_permissions),
|
||||||
|
channel_permissions: Set(req.channel_permissions),
|
||||||
|
voice_permissions: Set(req.voice_permissions),
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn update_request_to_am(
|
||||||
|
id: Uuid,
|
||||||
|
server_id: Uuid,
|
||||||
|
req: UpdateGroupRequest,
|
||||||
|
) -> group::ActiveModel {
|
||||||
|
group::ActiveModel {
|
||||||
|
id: Set(id),
|
||||||
|
server_id: Set(server_id),
|
||||||
|
name: Set(req.name),
|
||||||
|
is_default: Set(req.is_default),
|
||||||
|
server_permissions: Set(req.server_permissions),
|
||||||
|
channel_permissions: Set(req.channel_permissions),
|
||||||
|
voice_permissions: Set(req.voice_permissions),
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
use axum::{Router, routing::get};
|
use crate::core::state::AppState;
|
||||||
|
use axum::{routing::get, Router};
|
||||||
|
|
||||||
use super::handlers;
|
use super::handlers;
|
||||||
|
|
||||||
pub fn router() -> Router {
|
pub fn router() -> Router<AppState> {
|
||||||
Router::new()
|
Router::new()
|
||||||
.route("/groups", get(handlers::get_all).post(handlers::create))
|
.route("/groups", get(handlers::get_all).post(handlers::create))
|
||||||
.route(
|
.route(
|
||||||
|
|||||||
@@ -1,21 +1,2 @@
|
|||||||
use super::domain::Group;
|
// Ce fichier est conservé pour structure mais n'est plus utilisé.
|
||||||
|
// La logique a été déplacée directement dans les handlers.
|
||||||
pub async fn find_all() -> Vec<Group> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn find_by_id(_id: u64) -> Option<Group> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn create(_item: Group) -> Group {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn update(_id: u64, _item: Group) -> Option<Group> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn delete(_id: u64) -> bool {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
pub struct Message {}
|
// Domain model for Message - currently unused in favor of models::message
|
||||||
|
|||||||
@@ -1,10 +1,27 @@
|
|||||||
|
use chrono::{DateTime, Utc};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use utoipa::ToSchema;
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
||||||
pub struct CreateMessageRequest {}
|
pub struct MessageResponse {
|
||||||
|
pub id: Uuid,
|
||||||
|
pub channel_id: Uuid,
|
||||||
|
pub user_id: Uuid,
|
||||||
|
pub content: String,
|
||||||
|
pub created_at: DateTime<Utc>,
|
||||||
|
pub updated_at: Option<DateTime<Utc>>,
|
||||||
|
pub reply_to_id: Option<Uuid>,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
||||||
pub struct UpdateMessageRequest {}
|
pub struct CreateMessageRequest {
|
||||||
|
pub channel_id: Uuid,
|
||||||
|
pub content: String,
|
||||||
|
pub reply_to_id: Option<Uuid>,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
||||||
pub struct MessageResponse {}
|
pub struct UpdateMessageRequest {
|
||||||
|
pub content: String,
|
||||||
|
}
|
||||||
|
|||||||
+177
-12
@@ -1,22 +1,187 @@
|
|||||||
use axum::http::StatusCode;
|
use crate::core::state::AppState;
|
||||||
use axum::response::IntoResponse;
|
use crate::http::context::CurrentUser;
|
||||||
|
use crate::http::error::HTTPError;
|
||||||
|
use crate::routes::message::dto::{CreateMessageRequest, MessageResponse, UpdateMessageRequest};
|
||||||
|
use crate::routes::message::mapper;
|
||||||
|
use axum::{
|
||||||
|
extract::{Path, State},
|
||||||
|
http::StatusCode,
|
||||||
|
Json,
|
||||||
|
};
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
pub async fn get_all() -> impl IntoResponse {
|
/// Liste tous les messages
|
||||||
StatusCode::NOT_IMPLEMENTED
|
#[utoipa::path(
|
||||||
|
get,
|
||||||
|
path = "/messages",
|
||||||
|
responses(
|
||||||
|
(status = 200, description = "Liste des messages récupérée avec succès", body = [MessageResponse]),
|
||||||
|
(status = 500, description = "Erreur interne du serveur")
|
||||||
|
),
|
||||||
|
tag = "Messages"
|
||||||
|
)]
|
||||||
|
pub async fn get_all(
|
||||||
|
State(state): State<AppState>,
|
||||||
|
) -> Result<Json<Vec<MessageResponse>>, HTTPError> {
|
||||||
|
let messages = state.repositories.message.get_all().await?;
|
||||||
|
Ok(Json(
|
||||||
|
messages
|
||||||
|
.into_iter()
|
||||||
|
.map(mapper::message_model_to_message_response)
|
||||||
|
.collect(),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_by_id() -> impl IntoResponse {
|
/// Récupère un message par son ID
|
||||||
StatusCode::NOT_IMPLEMENTED
|
#[utoipa::path(
|
||||||
|
get,
|
||||||
|
path = "/messages/{id}",
|
||||||
|
responses(
|
||||||
|
(status = 200, description = "Message trouvé", body = MessageResponse),
|
||||||
|
(status = 404, description = "Message non trouvé"),
|
||||||
|
(status = 500, description = "Erreur interne du serveur")
|
||||||
|
),
|
||||||
|
params(
|
||||||
|
("id" = Uuid, Path, description = "ID du message")
|
||||||
|
),
|
||||||
|
tag = "Messages"
|
||||||
|
)]
|
||||||
|
pub async fn get_by_id(
|
||||||
|
State(state): State<AppState>,
|
||||||
|
Path(id): Path<Uuid>,
|
||||||
|
) -> Result<Json<MessageResponse>, HTTPError> {
|
||||||
|
let message = state
|
||||||
|
.repositories
|
||||||
|
.message
|
||||||
|
.get_by_id(id)
|
||||||
|
.await?
|
||||||
|
.ok_or(HTTPError::NotFound)?;
|
||||||
|
|
||||||
|
Ok(Json(mapper::message_model_to_message_response(message)))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn create() -> impl IntoResponse {
|
/// Crée un nouveau message
|
||||||
StatusCode::NOT_IMPLEMENTED
|
#[utoipa::path(
|
||||||
|
post,
|
||||||
|
path = "/messages",
|
||||||
|
request_body = CreateMessageRequest,
|
||||||
|
responses(
|
||||||
|
(status = 201, description = "Message créé avec succès", body = MessageResponse),
|
||||||
|
(status = 400, description = "Données invalides (canal non trouvé)"),
|
||||||
|
(status = 500, description = "Erreur interne du serveur")
|
||||||
|
),
|
||||||
|
tag = "Messages"
|
||||||
|
)]
|
||||||
|
pub async fn create(
|
||||||
|
user: CurrentUser,
|
||||||
|
State(state): State<AppState>,
|
||||||
|
Json(payload): Json<CreateMessageRequest>,
|
||||||
|
) -> Result<(StatusCode, Json<MessageResponse>), HTTPError> {
|
||||||
|
// Vérifier que le canal existe
|
||||||
|
state
|
||||||
|
.repositories
|
||||||
|
.channel
|
||||||
|
.get_by_id(payload.channel_id)
|
||||||
|
.await?
|
||||||
|
.ok_or(HTTPError::BadRequest("Channel not found".to_string()))?;
|
||||||
|
|
||||||
|
// Optionnel: vérifier reply_to_id
|
||||||
|
if let Some(reply_id) = payload.reply_to_id {
|
||||||
|
state
|
||||||
|
.repositories
|
||||||
|
.message
|
||||||
|
.get_by_id(reply_id)
|
||||||
|
.await?
|
||||||
|
.ok_or(HTTPError::BadRequest(
|
||||||
|
"Parent message not found".to_string(),
|
||||||
|
))?;
|
||||||
|
}
|
||||||
|
|
||||||
|
let active_model = mapper::create_request_to_am(user.id, payload);
|
||||||
|
let message = state.repositories.message.create(active_model).await?;
|
||||||
|
Ok((
|
||||||
|
StatusCode::CREATED,
|
||||||
|
Json(mapper::message_model_to_message_response(message)),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn update() -> impl IntoResponse {
|
/// Met à jour un message existant
|
||||||
StatusCode::NOT_IMPLEMENTED
|
#[utoipa::path(
|
||||||
|
put,
|
||||||
|
path = "/messages/{id}",
|
||||||
|
request_body = UpdateMessageRequest,
|
||||||
|
responses(
|
||||||
|
(status = 200, description = "Message mis à jour avec succès", body = MessageResponse),
|
||||||
|
(status = 403, description = "Interdit (pas l'auteur)"),
|
||||||
|
(status = 404, description = "Message non trouvé"),
|
||||||
|
(status = 500, description = "Erreur interne du serveur")
|
||||||
|
),
|
||||||
|
params(
|
||||||
|
("id" = Uuid, Path, description = "ID du message")
|
||||||
|
),
|
||||||
|
tag = "Messages"
|
||||||
|
)]
|
||||||
|
pub async fn update(
|
||||||
|
user: CurrentUser,
|
||||||
|
State(state): State<AppState>,
|
||||||
|
Path(id): Path<Uuid>,
|
||||||
|
Json(payload): Json<UpdateMessageRequest>,
|
||||||
|
) -> Result<Json<MessageResponse>, HTTPError> {
|
||||||
|
// Vérifier l'existence
|
||||||
|
let message = state
|
||||||
|
.repositories
|
||||||
|
.message
|
||||||
|
.get_by_id(id)
|
||||||
|
.await?
|
||||||
|
.ok_or(HTTPError::NotFound)?;
|
||||||
|
|
||||||
|
// Vérifier que l'utilisateur est l'auteur
|
||||||
|
if message.user_id != user.id && !user.is_superuser {
|
||||||
|
return Err(HTTPError::Forbidden);
|
||||||
|
}
|
||||||
|
|
||||||
|
let active_model = mapper::update_request_to_am(message, payload);
|
||||||
|
let message = state.repositories.message.update(active_model).await?;
|
||||||
|
|
||||||
|
Ok(Json(mapper::message_model_to_message_response(message)))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn delete() -> impl IntoResponse {
|
/// Supprime un message
|
||||||
StatusCode::NOT_IMPLEMENTED
|
#[utoipa::path(
|
||||||
|
delete,
|
||||||
|
path = "/messages/{id}",
|
||||||
|
responses(
|
||||||
|
(status = 204, description = "Message supprimé avec succès"),
|
||||||
|
(status = 403, description = "Interdit (pas l'auteur ou admin)"),
|
||||||
|
(status = 404, description = "Message non trouvé"),
|
||||||
|
(status = 500, description = "Erreur interne du serveur")
|
||||||
|
),
|
||||||
|
params(
|
||||||
|
("id" = Uuid, Path, description = "ID du message")
|
||||||
|
),
|
||||||
|
tag = "Messages"
|
||||||
|
)]
|
||||||
|
pub async fn delete(
|
||||||
|
user: CurrentUser,
|
||||||
|
State(state): State<AppState>,
|
||||||
|
Path(id): Path<Uuid>,
|
||||||
|
) -> Result<StatusCode, HTTPError> {
|
||||||
|
// Vérifier l'existence pour l'autorisation
|
||||||
|
let message = state
|
||||||
|
.repositories
|
||||||
|
.message
|
||||||
|
.get_by_id(id)
|
||||||
|
.await?
|
||||||
|
.ok_or(HTTPError::NotFound)?;
|
||||||
|
|
||||||
|
// Autoriser si auteur ou superuser
|
||||||
|
if message.user_id != user.id && !user.is_superuser {
|
||||||
|
return Err(HTTPError::Forbidden);
|
||||||
|
}
|
||||||
|
|
||||||
|
if state.repositories.message.delete(id).await? {
|
||||||
|
Ok(StatusCode::NO_CONTENT)
|
||||||
|
} else {
|
||||||
|
Err(HTTPError::NotFound)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,44 @@
|
|||||||
use super::{domain::Message, dto::MessageResponse};
|
use crate::models::message;
|
||||||
|
use crate::routes::message::dto::{CreateMessageRequest, MessageResponse, UpdateMessageRequest};
|
||||||
|
use chrono::Utc;
|
||||||
|
use sea_orm::Set;
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
pub fn to_response(_item: Message) -> MessageResponse {
|
pub fn message_model_to_message_response(model: message::Model) -> MessageResponse {
|
||||||
todo!()
|
MessageResponse {
|
||||||
|
id: model.id,
|
||||||
|
channel_id: model.channel_id,
|
||||||
|
user_id: model.user_id,
|
||||||
|
content: model.content,
|
||||||
|
created_at: model.created_at,
|
||||||
|
updated_at: model.updated_at,
|
||||||
|
reply_to_id: model.reply_to_id,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn create_request_to_am(user_id: Uuid, payload: CreateMessageRequest) -> message::ActiveModel {
|
||||||
|
message::ActiveModel {
|
||||||
|
id: Set(Uuid::now_v7()),
|
||||||
|
channel_id: Set(payload.channel_id),
|
||||||
|
user_id: Set(user_id),
|
||||||
|
content: Set(payload.content),
|
||||||
|
created_at: Set(Utc::now()),
|
||||||
|
updated_at: Set(None),
|
||||||
|
reply_to_id: Set(payload.reply_to_id),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn update_request_to_am(
|
||||||
|
model: message::Model,
|
||||||
|
payload: UpdateMessageRequest,
|
||||||
|
) -> message::ActiveModel {
|
||||||
|
message::ActiveModel {
|
||||||
|
id: Set(model.id),
|
||||||
|
channel_id: Set(model.channel_id),
|
||||||
|
user_id: Set(model.user_id),
|
||||||
|
content: Set(payload.content),
|
||||||
|
created_at: Set(model.created_at),
|
||||||
|
updated_at: Set(Some(Utc::now())),
|
||||||
|
reply_to_id: Set(model.reply_to_id),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
use axum::{Router, routing::get};
|
|
||||||
|
|
||||||
use super::handlers;
|
use super::handlers;
|
||||||
|
use crate::core::state::AppState;
|
||||||
|
use axum::{routing::get, Router};
|
||||||
|
|
||||||
pub fn router() -> Router {
|
pub fn router() -> Router<AppState> {
|
||||||
Router::new()
|
Router::new()
|
||||||
.route("/messages", get(handlers::get_all).post(handlers::create))
|
.route("/messages", get(handlers::get_all).post(handlers::create))
|
||||||
.route(
|
.route(
|
||||||
|
|||||||
@@ -1,21 +1 @@
|
|||||||
use super::domain::Message;
|
// Service layer for Message - currently unused in the simplified architecture
|
||||||
|
|
||||||
pub async fn find_all() -> Vec<Message> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn find_by_id(_id: u64) -> Option<Message> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn create(_item: Message) -> Message {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn update(_id: u64, _item: Message) -> Option<Message> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn delete(_id: u64) -> bool {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|||||||
+8
-7
@@ -12,12 +12,13 @@ pub mod server;
|
|||||||
pub mod user;
|
pub mod user;
|
||||||
|
|
||||||
pub fn router() -> OxRouter {
|
pub fn router() -> OxRouter {
|
||||||
Router::new().merge(auth::routes::router())
|
Router::new()
|
||||||
// .merge(user::routes::router())
|
.merge(auth::routes::router())
|
||||||
// .merge(server::routes::router())
|
.merge(server::routes::router())
|
||||||
// .merge(channel::routes::router())
|
.merge(category::routes::router())
|
||||||
// .merge(message::routes::router())
|
.merge(channel::routes::router())
|
||||||
// .merge(group::routes::router())
|
.merge(group::routes::router())
|
||||||
// .merge(category::routes::router())
|
.merge(message::routes::router())
|
||||||
|
.merge(user::routes::router())
|
||||||
// .merge(attachment::routes::router())
|
// .merge(attachment::routes::router())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,35 @@
|
|||||||
|
use chrono::{DateTime, Utc};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use utoipa::ToSchema;
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
||||||
pub struct CreateServerRequest {}
|
pub struct CreateServerRequest {
|
||||||
|
#[schema(example = "Mon Super Serveur")]
|
||||||
|
pub name: String,
|
||||||
|
pub password: Option<String>,
|
||||||
|
#[serde(default)]
|
||||||
|
pub is_default: bool,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
||||||
pub struct UpdateServerRequest {}
|
pub struct UpdateServerRequest {
|
||||||
|
pub name: String,
|
||||||
|
pub password: Option<String>,
|
||||||
|
pub is_default: bool,
|
||||||
|
pub default_server_permissions: i64,
|
||||||
|
pub default_channel_permissions: i64,
|
||||||
|
pub default_voice_permissions: i64,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
||||||
pub struct ServerResponse {}
|
pub struct ServerResponse {
|
||||||
|
pub id: Uuid,
|
||||||
|
pub name: String,
|
||||||
|
pub is_default: bool,
|
||||||
|
pub created_at: DateTime<Utc>,
|
||||||
|
pub updated_at: DateTime<Utc>,
|
||||||
|
pub default_server_permissions: i64,
|
||||||
|
pub default_channel_permissions: i64,
|
||||||
|
pub default_voice_permissions: i64,
|
||||||
|
}
|
||||||
|
|||||||
+136
-12
@@ -1,22 +1,146 @@
|
|||||||
use axum::http::StatusCode;
|
use crate::core::state::AppState;
|
||||||
use axum::response::IntoResponse;
|
use crate::http::context::Superuser;
|
||||||
|
use crate::http::error::HTTPError;
|
||||||
|
use crate::routes::server::dto::{CreateServerRequest, ServerResponse, UpdateServerRequest};
|
||||||
|
use crate::routes::server::mapper;
|
||||||
|
use axum::{
|
||||||
|
extract::{Path, State},
|
||||||
|
http::StatusCode,
|
||||||
|
Json,
|
||||||
|
};
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
pub async fn get_all() -> impl IntoResponse {
|
/// Liste tous les serveurs
|
||||||
StatusCode::NOT_IMPLEMENTED
|
#[utoipa::path(
|
||||||
|
get,
|
||||||
|
path = "/servers",
|
||||||
|
responses(
|
||||||
|
(status = 200, description = "Liste des serveurs récupérée avec succès", body = [ServerResponse]),
|
||||||
|
(status = 500, description = "Erreur interne du serveur")
|
||||||
|
),
|
||||||
|
tag = "Servers"
|
||||||
|
)]
|
||||||
|
pub async fn get_all(
|
||||||
|
State(state): State<AppState>,
|
||||||
|
) -> Result<Json<Vec<ServerResponse>>, HTTPError> {
|
||||||
|
let servers = state.repositories.server.get_all().await?;
|
||||||
|
Ok(Json(
|
||||||
|
servers
|
||||||
|
.into_iter()
|
||||||
|
.map(mapper::server_model_to_server_response)
|
||||||
|
.collect(),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_by_id() -> impl IntoResponse {
|
/// Récupère un serveur par son ID
|
||||||
StatusCode::NOT_IMPLEMENTED
|
#[utoipa::path(
|
||||||
|
get,
|
||||||
|
path = "/servers/{id}",
|
||||||
|
responses(
|
||||||
|
(status = 200, description = "Serveur trouvé", body = ServerResponse),
|
||||||
|
(status = 404, description = "Serveur non trouvé"),
|
||||||
|
(status = 500, description = "Erreur interne du serveur")
|
||||||
|
),
|
||||||
|
params(
|
||||||
|
("id" = Uuid, Path, description = "ID du serveur")
|
||||||
|
),
|
||||||
|
tag = "Servers"
|
||||||
|
)]
|
||||||
|
pub async fn get_by_id(
|
||||||
|
State(state): State<AppState>,
|
||||||
|
Path(id): Path<Uuid>,
|
||||||
|
) -> Result<Json<ServerResponse>, HTTPError> {
|
||||||
|
let server = state
|
||||||
|
.repositories
|
||||||
|
.server
|
||||||
|
.get_by_id(id)
|
||||||
|
.await?
|
||||||
|
.ok_or(HTTPError::NotFound)?;
|
||||||
|
|
||||||
|
Ok(Json(mapper::server_model_to_server_response(server)))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn create() -> impl IntoResponse {
|
/// Crée un nouveau serveur
|
||||||
StatusCode::NOT_IMPLEMENTED
|
#[utoipa::path(
|
||||||
|
post,
|
||||||
|
path = "/servers",
|
||||||
|
request_body = CreateServerRequest,
|
||||||
|
responses(
|
||||||
|
(status = 201, description = "Serveur créé avec succès", body = ServerResponse),
|
||||||
|
(status = 500, description = "Erreur interne du serveur")
|
||||||
|
),
|
||||||
|
tag = "Servers"
|
||||||
|
)]
|
||||||
|
pub async fn create(
|
||||||
|
_admin: Superuser,
|
||||||
|
State(state): State<AppState>,
|
||||||
|
Json(payload): Json<CreateServerRequest>,
|
||||||
|
) -> Result<(StatusCode, Json<ServerResponse>), HTTPError> {
|
||||||
|
let active_model = mapper::create_request_to_am(payload);
|
||||||
|
let server = state.repositories.server.create(active_model).await?;
|
||||||
|
Ok((
|
||||||
|
StatusCode::CREATED,
|
||||||
|
Json(mapper::server_model_to_server_response(server)),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn update() -> impl IntoResponse {
|
/// Met à jour un serveur existant
|
||||||
StatusCode::NOT_IMPLEMENTED
|
#[utoipa::path(
|
||||||
|
put,
|
||||||
|
path = "/servers/{id}",
|
||||||
|
request_body = UpdateServerRequest,
|
||||||
|
responses(
|
||||||
|
(status = 200, description = "Serveur mis à jour avec succès", body = ServerResponse),
|
||||||
|
(status = 404, description = "Serveur non trouvé"),
|
||||||
|
(status = 500, description = "Erreur interne du serveur")
|
||||||
|
),
|
||||||
|
params(
|
||||||
|
("id" = Uuid, Path, description = "ID du serveur")
|
||||||
|
),
|
||||||
|
tag = "Servers"
|
||||||
|
)]
|
||||||
|
pub async fn update(
|
||||||
|
_admin: Superuser,
|
||||||
|
State(state): State<AppState>,
|
||||||
|
Path(id): Path<Uuid>,
|
||||||
|
Json(payload): Json<UpdateServerRequest>,
|
||||||
|
) -> Result<Json<ServerResponse>, HTTPError> {
|
||||||
|
// Vérifier l'existence
|
||||||
|
let server = state
|
||||||
|
.repositories
|
||||||
|
.server
|
||||||
|
.get_by_id(id)
|
||||||
|
.await?
|
||||||
|
.ok_or(HTTPError::NotFound)?;
|
||||||
|
|
||||||
|
let active_model = mapper::update_request_to_am(server.id, payload);
|
||||||
|
let server = state.repositories.server.update(active_model).await?;
|
||||||
|
|
||||||
|
Ok(Json(mapper::server_model_to_server_response(server)))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn delete() -> impl IntoResponse {
|
/// Supprime un serveur
|
||||||
StatusCode::NOT_IMPLEMENTED
|
#[utoipa::path(
|
||||||
|
delete,
|
||||||
|
path = "/servers/{id}",
|
||||||
|
responses(
|
||||||
|
(status = 204, description = "Serveur supprimé avec succès"),
|
||||||
|
(status = 404, description = "Serveur non trouvé"),
|
||||||
|
(status = 500, description = "Erreur interne du serveur")
|
||||||
|
),
|
||||||
|
params(
|
||||||
|
("id" = Uuid, Path, description = "ID du serveur")
|
||||||
|
),
|
||||||
|
tag = "Servers"
|
||||||
|
)]
|
||||||
|
pub async fn delete(
|
||||||
|
_admin: Superuser,
|
||||||
|
State(state): State<AppState>,
|
||||||
|
Path(id): Path<Uuid>,
|
||||||
|
) -> Result<StatusCode, HTTPError> {
|
||||||
|
if state.repositories.server.delete(id).await? {
|
||||||
|
Ok(StatusCode::NO_CONTENT)
|
||||||
|
} else {
|
||||||
|
Err(HTTPError::NotFound)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,40 @@
|
|||||||
use super::{domain::Server, dto::ServerResponse};
|
use crate::models::server;
|
||||||
|
use crate::routes::server::dto::{CreateServerRequest, ServerResponse, UpdateServerRequest};
|
||||||
|
use sea_orm::Set;
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
pub fn to_response(_item: Server) -> ServerResponse {
|
pub fn server_model_to_server_response(model: server::Model) -> ServerResponse {
|
||||||
todo!()
|
ServerResponse {
|
||||||
|
id: model.id,
|
||||||
|
name: model.name,
|
||||||
|
is_default: model.is_default,
|
||||||
|
created_at: model.created_at,
|
||||||
|
updated_at: model.updated_at,
|
||||||
|
default_server_permissions: model.default_server_permissions,
|
||||||
|
default_channel_permissions: model.default_channel_permissions,
|
||||||
|
default_voice_permissions: model.default_voice_permissions,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn create_request_to_am(req: CreateServerRequest) -> server::ActiveModel {
|
||||||
|
server::ActiveModel {
|
||||||
|
id: Set(Uuid::new_v4()),
|
||||||
|
name: Set(req.name),
|
||||||
|
password: Set(req.password),
|
||||||
|
is_default: Set(req.is_default),
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn update_request_to_am(id: Uuid, req: UpdateServerRequest) -> server::ActiveModel {
|
||||||
|
server::ActiveModel {
|
||||||
|
id: Set(id),
|
||||||
|
name: Set(req.name),
|
||||||
|
password: Set(req.password),
|
||||||
|
is_default: Set(req.is_default),
|
||||||
|
default_server_permissions: Set(req.default_server_permissions),
|
||||||
|
default_channel_permissions: Set(req.default_channel_permissions),
|
||||||
|
default_voice_permissions: Set(req.default_voice_permissions),
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
use axum::{Router, routing::get};
|
|
||||||
|
|
||||||
use super::handlers;
|
use super::handlers;
|
||||||
|
use crate::core::state::AppState;
|
||||||
|
use axum::{routing::get, Router};
|
||||||
|
|
||||||
pub fn router() -> Router {
|
pub fn router() -> Router<AppState> {
|
||||||
Router::new()
|
Router::new()
|
||||||
.route("/servers", get(handlers::get_all).post(handlers::create))
|
.route("/servers", get(handlers::get_all).post(handlers::create))
|
||||||
.route(
|
.route(
|
||||||
|
|||||||
@@ -1,21 +1,2 @@
|
|||||||
use super::domain::Server;
|
// Ce fichier est conservé pour structure mais n'est plus utilisé.
|
||||||
|
// La logique a été déplacée directement dans les handlers.
|
||||||
pub async fn find_all() -> Vec<Server> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn find_by_id(_id: u64) -> Option<Server> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn create(_item: Server) -> Server {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn update(_id: u64, _item: Server) -> Option<Server> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn delete(_id: u64) -> bool {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
pub struct User {}
|
// Ce fichier est conservé pour la structure.
|
||||||
|
|||||||
+25
-6
@@ -1,10 +1,29 @@
|
|||||||
|
use chrono::{DateTime, Utc};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use utoipa::ToSchema;
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
||||||
pub struct CreateUserRequest {}
|
pub struct CreateUserRequest {
|
||||||
|
pub username: String,
|
||||||
|
pub password: String,
|
||||||
|
pub pub_key: String,
|
||||||
|
pub is_superuser: bool,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
||||||
pub struct UpdateUserRequest {}
|
pub struct UpdateUserRequest {
|
||||||
|
pub username: String,
|
||||||
|
pub pub_key: String,
|
||||||
|
pub is_superuser: bool,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
||||||
pub struct UserResponse {}
|
pub struct UserResponse {
|
||||||
|
pub id: Uuid,
|
||||||
|
pub username: String,
|
||||||
|
pub pub_key: String,
|
||||||
|
pub is_superuser: bool,
|
||||||
|
pub created_at: DateTime<Utc>,
|
||||||
|
pub updated_at: DateTime<Utc>,
|
||||||
|
}
|
||||||
|
|||||||
+172
-12
@@ -1,22 +1,182 @@
|
|||||||
use axum::http::StatusCode;
|
use crate::core::state::AppState;
|
||||||
use axum::response::IntoResponse;
|
use crate::http::context::Superuser;
|
||||||
|
use crate::http::error::HTTPError;
|
||||||
|
use crate::routes::user::dto::{CreateUserRequest, UpdateUserRequest, UserResponse};
|
||||||
|
use crate::routes::user::mapper;
|
||||||
|
use axum::{
|
||||||
|
Json,
|
||||||
|
extract::{Path, State},
|
||||||
|
http::StatusCode,
|
||||||
|
};
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
pub async fn get_all() -> impl IntoResponse {
|
/// Liste tous les utilisateurs
|
||||||
StatusCode::NOT_IMPLEMENTED
|
#[utoipa::path(
|
||||||
|
get,
|
||||||
|
path = "/users",
|
||||||
|
responses(
|
||||||
|
(status = 200, description = "Liste des utilisateurs récupérée avec succès", body = [UserResponse]),
|
||||||
|
(status = 401, description = "Non autorisé"),
|
||||||
|
(status = 403, description = "Interdit"),
|
||||||
|
(status = 500, description = "Erreur interne du serveur")
|
||||||
|
),
|
||||||
|
tag = "Users"
|
||||||
|
)]
|
||||||
|
pub async fn get_all(
|
||||||
|
_admin: Superuser,
|
||||||
|
State(state): State<AppState>,
|
||||||
|
) -> Result<Json<Vec<UserResponse>>, HTTPError> {
|
||||||
|
let users = state.repositories.user.get_all().await?;
|
||||||
|
Ok(Json(
|
||||||
|
users
|
||||||
|
.into_iter()
|
||||||
|
.map(mapper::user_model_to_user_response)
|
||||||
|
.collect(),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_by_id() -> impl IntoResponse {
|
/// Récupère un utilisateur par son ID
|
||||||
StatusCode::NOT_IMPLEMENTED
|
#[utoipa::path(
|
||||||
|
get,
|
||||||
|
path = "/users/{id}",
|
||||||
|
responses(
|
||||||
|
(status = 200, description = "Utilisateur trouvé", body = UserResponse),
|
||||||
|
(status = 401, description = "Non autorisé"),
|
||||||
|
(status = 403, description = "Interdit"),
|
||||||
|
(status = 404, description = "Utilisateur non trouvé"),
|
||||||
|
(status = 500, description = "Erreur interne du serveur")
|
||||||
|
),
|
||||||
|
params(
|
||||||
|
("id" = Uuid, Path, description = "ID de l'utilisateur")
|
||||||
|
),
|
||||||
|
tag = "Users"
|
||||||
|
)]
|
||||||
|
pub async fn get_by_id(
|
||||||
|
_admin: Superuser,
|
||||||
|
State(state): State<AppState>,
|
||||||
|
Path(id): Path<Uuid>,
|
||||||
|
) -> Result<Json<UserResponse>, HTTPError> {
|
||||||
|
let user = state
|
||||||
|
.repositories
|
||||||
|
.user
|
||||||
|
.get_by_id(id)
|
||||||
|
.await?
|
||||||
|
.ok_or(HTTPError::NotFound)?;
|
||||||
|
|
||||||
|
Ok(Json(mapper::user_model_to_user_response(user)))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn create() -> impl IntoResponse {
|
/// Crée un nouvel utilisateur
|
||||||
StatusCode::NOT_IMPLEMENTED
|
#[utoipa::path(
|
||||||
|
post,
|
||||||
|
path = "/users",
|
||||||
|
request_body = CreateUserRequest,
|
||||||
|
responses(
|
||||||
|
(status = 201, description = "Utilisateur créé avec succès", body = UserResponse),
|
||||||
|
(status = 400, description = "Requête invalide"),
|
||||||
|
(status = 401, description = "Non autorisé"),
|
||||||
|
(status = 403, description = "Interdit"),
|
||||||
|
(status = 500, description = "Erreur interne du serveur")
|
||||||
|
),
|
||||||
|
tag = "Users"
|
||||||
|
)]
|
||||||
|
pub async fn create(
|
||||||
|
_admin: Superuser,
|
||||||
|
State(state): State<AppState>,
|
||||||
|
Json(payload): Json<CreateUserRequest>,
|
||||||
|
) -> Result<(StatusCode, Json<UserResponse>), HTTPError> {
|
||||||
|
// Vérifier si le nom d'utilisateur existe déjà
|
||||||
|
if state
|
||||||
|
.repositories
|
||||||
|
.user
|
||||||
|
.username_exists(&payload.username)
|
||||||
|
.await?
|
||||||
|
{
|
||||||
|
return Err(HTTPError::BadRequest("Username already exists".to_string()));
|
||||||
|
}
|
||||||
|
|
||||||
|
let active_model = mapper::create_request_to_am(payload)
|
||||||
|
.map_err(|e| HTTPError::InternalServerError(e.to_string()))?;
|
||||||
|
|
||||||
|
let user = state.repositories.user.create(active_model).await?;
|
||||||
|
Ok((
|
||||||
|
StatusCode::CREATED,
|
||||||
|
Json(mapper::user_model_to_user_response(user)),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn update() -> impl IntoResponse {
|
/// Met à jour un utilisateur existant
|
||||||
StatusCode::NOT_IMPLEMENTED
|
#[utoipa::path(
|
||||||
|
put,
|
||||||
|
path = "/users/{id}",
|
||||||
|
request_body = UpdateUserRequest,
|
||||||
|
responses(
|
||||||
|
(status = 200, description = "Utilisateur mis à jour avec succès", body = UserResponse),
|
||||||
|
(status = 401, description = "Non autorisé"),
|
||||||
|
(status = 403, description = "Interdit"),
|
||||||
|
(status = 404, description = "Utilisateur non trouvé"),
|
||||||
|
(status = 500, description = "Erreur interne du serveur")
|
||||||
|
),
|
||||||
|
params(
|
||||||
|
("id" = Uuid, Path, description = "ID de l'utilisateur")
|
||||||
|
),
|
||||||
|
tag = "Users"
|
||||||
|
)]
|
||||||
|
pub async fn update(
|
||||||
|
_admin: Superuser,
|
||||||
|
State(state): State<AppState>,
|
||||||
|
Path(id): Path<Uuid>,
|
||||||
|
Json(payload): Json<UpdateUserRequest>,
|
||||||
|
) -> Result<Json<UserResponse>, HTTPError> {
|
||||||
|
// Vérifier l'existence
|
||||||
|
let user = state
|
||||||
|
.repositories
|
||||||
|
.user
|
||||||
|
.get_by_id(id)
|
||||||
|
.await?
|
||||||
|
.ok_or(HTTPError::NotFound)?;
|
||||||
|
|
||||||
|
// On pourrait aussi vérifier si le nouveau username existe déjà s'il a changé
|
||||||
|
if payload.username != user.username
|
||||||
|
&& state
|
||||||
|
.repositories
|
||||||
|
.user
|
||||||
|
.username_exists(&payload.username)
|
||||||
|
.await?
|
||||||
|
{
|
||||||
|
return Err(HTTPError::BadRequest("Username already exists".to_string()));
|
||||||
|
}
|
||||||
|
|
||||||
|
let active_model = mapper::update_request_to_am(user.id, payload);
|
||||||
|
let user = state.repositories.user.update(active_model).await?;
|
||||||
|
|
||||||
|
Ok(Json(mapper::user_model_to_user_response(user)))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn delete() -> impl IntoResponse {
|
/// Supprime un utilisateur
|
||||||
StatusCode::NOT_IMPLEMENTED
|
#[utoipa::path(
|
||||||
|
delete,
|
||||||
|
path = "/users/{id}",
|
||||||
|
responses(
|
||||||
|
(status = 204, description = "Utilisateur supprimé avec succès"),
|
||||||
|
(status = 401, description = "Non autorisé"),
|
||||||
|
(status = 403, description = "Interdit"),
|
||||||
|
(status = 404, description = "Utilisateur non trouvé"),
|
||||||
|
(status = 500, description = "Erreur interne du serveur")
|
||||||
|
),
|
||||||
|
params(
|
||||||
|
("id" = Uuid, Path, description = "ID de l'utilisateur")
|
||||||
|
),
|
||||||
|
tag = "Users"
|
||||||
|
)]
|
||||||
|
pub async fn delete(
|
||||||
|
_admin: Superuser,
|
||||||
|
State(state): State<AppState>,
|
||||||
|
Path(id): Path<Uuid>,
|
||||||
|
) -> Result<StatusCode, HTTPError> {
|
||||||
|
if state.repositories.user.delete(id).await? {
|
||||||
|
Ok(StatusCode::NO_CONTENT)
|
||||||
|
} else {
|
||||||
|
Err(HTTPError::NotFound)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,41 @@
|
|||||||
use super::{domain::User, dto::UserResponse};
|
use crate::auth::password::hash_password;
|
||||||
|
use crate::models::user;
|
||||||
|
use crate::routes::user::dto::{CreateUserRequest, UpdateUserRequest, UserResponse};
|
||||||
|
use anyhow::Result as AnyResult;
|
||||||
|
use sea_orm::{NotSet, Set};
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
pub fn to_response(_user: User) -> UserResponse {
|
pub fn user_model_to_user_response(model: user::Model) -> UserResponse {
|
||||||
todo!()
|
UserResponse {
|
||||||
|
id: model.id,
|
||||||
|
username: model.username,
|
||||||
|
pub_key: model.pub_key,
|
||||||
|
is_superuser: model.is_superuser,
|
||||||
|
created_at: model.created_at,
|
||||||
|
updated_at: model.updated_at,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn create_request_to_am(payload: CreateUserRequest) -> AnyResult<user::ActiveModel> {
|
||||||
|
Ok(user::ActiveModel {
|
||||||
|
id: Set(Uuid::new_v4()),
|
||||||
|
username: Set(payload.username),
|
||||||
|
password: Set(hash_password(&payload.password)?),
|
||||||
|
pub_key: Set(payload.pub_key),
|
||||||
|
is_superuser: Set(payload.is_superuser),
|
||||||
|
created_at: Set(chrono::Utc::now()),
|
||||||
|
updated_at: Set(chrono::Utc::now()),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn update_request_to_am(id: Uuid, payload: UpdateUserRequest) -> user::ActiveModel {
|
||||||
|
user::ActiveModel {
|
||||||
|
id: Set(id),
|
||||||
|
username: Set(payload.username),
|
||||||
|
password: NotSet, // On ne change pas le password via PUT général
|
||||||
|
pub_key: Set(payload.pub_key),
|
||||||
|
is_superuser: Set(payload.is_superuser),
|
||||||
|
updated_at: Set(chrono::Utc::now()),
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
|
use crate::core::state::AppState;
|
||||||
use axum::{routing::get, Router};
|
use axum::{routing::get, Router};
|
||||||
|
|
||||||
use super::handlers;
|
use super::handlers;
|
||||||
|
|
||||||
pub fn router() -> Router {
|
pub fn router() -> Router<AppState> {
|
||||||
Router::new()
|
Router::new()
|
||||||
.route("/users", get(handlers::get_all).post(handlers::create))
|
.route("/users", get(handlers::get_all).post(handlers::create))
|
||||||
.route(
|
.route(
|
||||||
|
|||||||
@@ -1,21 +1 @@
|
|||||||
use super::domain::User;
|
// Ce fichier est conservé pour la structure mais la logique est directement dans les handlers.
|
||||||
|
|
||||||
pub async fn find_all() -> Vec<User> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn find_by_id(_id: u64) -> Option<User> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn create(_user: User) -> User {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn update(_id: u64, _user: User) -> Option<User> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn delete(_id: u64) -> bool {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|||||||
+26
-12
@@ -27,6 +27,8 @@ use std::sync::atomic::{AtomicU64, Ordering};
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
|
use crate::metrics::{Metrics, MetricsSnapshot};
|
||||||
|
|
||||||
// ── Compteurs ────────────────────────────────────────────────────────────────
|
// ── Compteurs ────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
/// Compteurs atomiques du serveur UDP.
|
/// Compteurs atomiques du serveur UDP.
|
||||||
@@ -94,6 +96,7 @@ impl UdpMetrics {
|
|||||||
/// Prend un instantané cohérent de tous les compteurs.
|
/// Prend un instantané cohérent de tous les compteurs.
|
||||||
pub fn snapshot(&self) -> UdpMetricsSnapshot {
|
pub fn snapshot(&self) -> UdpMetricsSnapshot {
|
||||||
UdpMetricsSnapshot {
|
UdpMetricsSnapshot {
|
||||||
|
taken_at: Instant::now(),
|
||||||
packets_received: self.packets_received.load(Ordering::Relaxed),
|
packets_received: self.packets_received.load(Ordering::Relaxed),
|
||||||
bytes_received: self.bytes_received.load(Ordering::Relaxed),
|
bytes_received: self.bytes_received.load(Ordering::Relaxed),
|
||||||
packets_sent: self.packets_sent.load(Ordering::Relaxed),
|
packets_sent: self.packets_sent.load(Ordering::Relaxed),
|
||||||
@@ -105,14 +108,23 @@ impl UdpMetrics {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Metrics for UdpMetrics {
|
||||||
|
type Snapshot = UdpMetricsSnapshot;
|
||||||
|
|
||||||
|
fn snapshot(&self) -> UdpMetricsSnapshot {
|
||||||
|
self.snapshot()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ── Snapshot ─────────────────────────────────────────────────────────────────
|
// ── Snapshot ─────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
/// Lecture cohérente de l'ensemble des compteurs à un instant T.
|
/// Lecture cohérente de l'ensemble des compteurs à un instant T.
|
||||||
///
|
///
|
||||||
/// Permet de calculer des deltas et des taux entre deux points dans le temps
|
/// Permet de calculer des deltas et des taux entre deux points dans le temps
|
||||||
/// sans bloquer la boucle de routage.
|
/// sans bloquer la boucle de routage.
|
||||||
#[derive(Debug, Clone, Copy, Default)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub struct UdpMetricsSnapshot {
|
pub struct UdpMetricsSnapshot {
|
||||||
|
pub taken_at: Instant,
|
||||||
pub packets_received: u64,
|
pub packets_received: u64,
|
||||||
pub bytes_received: u64,
|
pub bytes_received: u64,
|
||||||
pub packets_sent: u64,
|
pub packets_sent: u64,
|
||||||
@@ -124,11 +136,12 @@ pub struct UdpMetricsSnapshot {
|
|||||||
|
|
||||||
impl UdpMetricsSnapshot {
|
impl UdpMetricsSnapshot {
|
||||||
/// Calcule les taux moyens par seconde depuis un snapshot précédent.
|
/// Calcule les taux moyens par seconde depuis un snapshot précédent.
|
||||||
///
|
pub fn rates_since(&self, previous: &Self) -> UdpRates {
|
||||||
/// `elapsed` est la durée réelle écoulée entre les deux snapshots.
|
let secs = self
|
||||||
pub fn rates_since(&self, previous: &Self, elapsed: Duration) -> UdpRates {
|
.taken_at
|
||||||
// On évite la division par zéro si l'interval est infinitésimal.
|
.duration_since(previous.taken_at)
|
||||||
let secs = elapsed.as_secs_f64().max(f64::EPSILON);
|
.as_secs_f64()
|
||||||
|
.max(f64::EPSILON);
|
||||||
|
|
||||||
UdpRates {
|
UdpRates {
|
||||||
packets_received_per_sec: self
|
packets_received_per_sec: self
|
||||||
@@ -151,6 +164,12 @@ impl UdpMetricsSnapshot {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl MetricsSnapshot for UdpMetricsSnapshot {
|
||||||
|
fn taken_at(&self) -> Instant {
|
||||||
|
self.taken_at
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ── Taux ─────────────────────────────────────────────────────────────────────
|
// ── Taux ─────────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
/// Taux moyens par seconde calculés entre deux [`UdpMetricsSnapshot`].
|
/// Taux moyens par seconde calculés entre deux [`UdpMetricsSnapshot`].
|
||||||
@@ -194,15 +213,12 @@ pub fn spawn_reporter(metrics: Arc<UdpMetrics>, interval: Duration) {
|
|||||||
ticker.tick().await;
|
ticker.tick().await;
|
||||||
|
|
||||||
let mut prev_snapshot = metrics.snapshot();
|
let mut prev_snapshot = metrics.snapshot();
|
||||||
let mut prev_instant = Instant::now();
|
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
ticker.tick().await;
|
ticker.tick().await;
|
||||||
|
|
||||||
let now = Instant::now();
|
|
||||||
let current = metrics.snapshot();
|
let current = metrics.snapshot();
|
||||||
let elapsed = now.duration_since(prev_instant);
|
let rates = current.rates_since(&prev_snapshot);
|
||||||
let rates = current.rates_since(&prev_snapshot, elapsed);
|
|
||||||
|
|
||||||
tracing::info!(
|
tracing::info!(
|
||||||
// ── Cumulatifs ──
|
// ── Cumulatifs ──
|
||||||
@@ -219,12 +235,10 @@ pub fn spawn_reporter(metrics: Arc<UdpMetrics>, interval: Duration) {
|
|||||||
pkts_tx_s = format!("{:.1}", rates.packets_sent_per_sec),
|
pkts_tx_s = format!("{:.1}", rates.packets_sent_per_sec),
|
||||||
bytes_tx_s = format!("{:.0}", rates.bytes_sent_per_sec),
|
bytes_tx_s = format!("{:.0}", rates.bytes_sent_per_sec),
|
||||||
pkts_dropped_s = format!("{:.1}", rates.packets_dropped_per_sec),
|
pkts_dropped_s = format!("{:.1}", rates.packets_dropped_per_sec),
|
||||||
interval_ms = elapsed.as_millis(),
|
|
||||||
"UDP metrics"
|
"UDP metrics"
|
||||||
);
|
);
|
||||||
|
|
||||||
prev_snapshot = current;
|
prev_snapshot = current;
|
||||||
prev_instant = now;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-2
@@ -69,9 +69,8 @@ impl UdpServer {
|
|||||||
///
|
///
|
||||||
/// Retourne le serveur et un [`broadcast::Sender`] pour déclencher le
|
/// Retourne le serveur et un [`broadcast::Sender`] pour déclencher le
|
||||||
/// shutdown gracieux.
|
/// shutdown gracieux.
|
||||||
pub fn new(network: &NetworkConfig) -> (Self, broadcast::Sender<()>) {
|
pub fn new(network: &NetworkConfig, metrics: Arc<UdpMetrics>) -> (Self, broadcast::Sender<()>) {
|
||||||
let bind_addr = SocketAddr::new(network.host.into(), network.udp_port);
|
let bind_addr = SocketAddr::new(network.host.into(), network.udp_port);
|
||||||
let metrics = UdpMetrics::new();
|
|
||||||
let (shutdown_tx, shutdown_rx) = broadcast::channel(1);
|
let (shutdown_tx, shutdown_rx) = broadcast::channel(1);
|
||||||
(
|
(
|
||||||
Self {
|
Self {
|
||||||
|
|||||||
Reference in New Issue
Block a user