init
This commit is contained in:
@@ -48,8 +48,8 @@ pub async fn login_user_pw(
|
||||
)
|
||||
)]
|
||||
pub async fn check(
|
||||
State(state): State<AppState>,
|
||||
user: CurrentUser,
|
||||
State(_state): State<AppState>,
|
||||
_user: CurrentUser,
|
||||
) -> Result<Json<CheckResponse>, HTTPError> {
|
||||
Ok(Json(CheckResponse {
|
||||
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 utoipa::ToSchema;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct CreateCategoryRequest {}
|
||||
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
||||
pub struct CreateCategoryRequest {
|
||||
pub server_id: Uuid,
|
||||
#[schema(example = "Discussion")]
|
||||
pub name: String,
|
||||
#[serde(default)]
|
||||
pub position: i32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct UpdateCategoryRequest {}
|
||||
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
||||
pub struct UpdateCategoryRequest {
|
||||
#[schema(example = "Discussion (Maj)")]
|
||||
pub name: String,
|
||||
pub position: i32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct CategoryResponse {}
|
||||
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
||||
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 axum::response::IntoResponse;
|
||||
use crate::core::state::AppState;
|
||||
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 {
|
||||
StatusCode::NOT_IMPLEMENTED
|
||||
/// Liste toutes les catégories
|
||||
#[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 {
|
||||
StatusCode::NOT_IMPLEMENTED
|
||||
/// Récupère une catégorie par son ID
|
||||
#[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 {
|
||||
StatusCode::NOT_IMPLEMENTED
|
||||
/// Crée une nouvelle catégorie
|
||||
#[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 {
|
||||
StatusCode::NOT_IMPLEMENTED
|
||||
/// Met à jour une catégorie existante
|
||||
#[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 {
|
||||
StatusCode::NOT_IMPLEMENTED
|
||||
/// Supprime une catégorie
|
||||
#[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 {
|
||||
todo!()
|
||||
pub fn category_model_to_category_response(model: category::Model) -> CategoryResponse {
|
||||
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;
|
||||
|
||||
pub fn router() -> Router {
|
||||
pub fn router() -> Router<AppState> {
|
||||
Router::new()
|
||||
.route("/categorys", get(handlers::get_all).post(handlers::create))
|
||||
.route("/categories", get(handlers::get_all).post(handlers::create))
|
||||
.route(
|
||||
"/categorys/:id",
|
||||
"/categories/:id",
|
||||
get(handlers::get_by_id)
|
||||
.put(handlers::update)
|
||||
.delete(handlers::delete),
|
||||
|
||||
@@ -1,21 +1,2 @@
|
||||
use super::domain::Category;
|
||||
|
||||
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!()
|
||||
}
|
||||
// Ce fichier est conservé pour structure mais n'est plus utilisé.
|
||||
// La logique a été déplacée directement dans les handlers.
|
||||
|
||||
@@ -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 utoipa::ToSchema;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct CreateChannelRequest {}
|
||||
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
||||
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)]
|
||||
pub struct UpdateChannelRequest {}
|
||||
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
||||
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)]
|
||||
pub struct ChannelResponse {}
|
||||
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
||||
pub struct ChannelResponse {
|
||||
pub id: Uuid,
|
||||
pub server_id: Option<Uuid>,
|
||||
pub category_id: Option<Uuid>,
|
||||
pub position: i32,
|
||||
pub channel_type: ChannelType,
|
||||
pub name: Option<String>,
|
||||
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 axum::response::IntoResponse;
|
||||
use crate::core::state::AppState;
|
||||
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 {
|
||||
StatusCode::NOT_IMPLEMENTED
|
||||
/// Liste tous les channels
|
||||
#[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 {
|
||||
StatusCode::NOT_IMPLEMENTED
|
||||
/// Récupère un channel par son ID
|
||||
#[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 {
|
||||
StatusCode::NOT_IMPLEMENTED
|
||||
/// Crée un nouveau channel
|
||||
#[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 {
|
||||
StatusCode::NOT_IMPLEMENTED
|
||||
/// Met à jour un channel existant
|
||||
#[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 {
|
||||
StatusCode::NOT_IMPLEMENTED
|
||||
/// Supprime un channel
|
||||
#[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 {
|
||||
todo!()
|
||||
pub fn channel_model_to_channel_response(model: channel::Model) -> ChannelResponse {
|
||||
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 crate::core::state::AppState;
|
||||
use axum::{routing::get, Router};
|
||||
|
||||
pub fn router() -> Router {
|
||||
pub fn router() -> Router<AppState> {
|
||||
Router::new()
|
||||
.route("/channels", get(handlers::get_all).post(handlers::create))
|
||||
.route(
|
||||
|
||||
@@ -1,21 +1,2 @@
|
||||
use super::domain::Channel;
|
||||
|
||||
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!()
|
||||
}
|
||||
// Ce fichier est conservé pour structure mais n'est plus utilisé.
|
||||
// La logique a été déplacée directement dans les handlers.
|
||||
|
||||
@@ -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 utoipa::ToSchema;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct CreateGroupRequest {}
|
||||
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
||||
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)]
|
||||
pub struct UpdateGroupRequest {}
|
||||
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
||||
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)]
|
||||
pub struct GroupResponse {}
|
||||
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
||||
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 axum::response::IntoResponse;
|
||||
use crate::core::state::AppState;
|
||||
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 {
|
||||
StatusCode::NOT_IMPLEMENTED
|
||||
/// Liste tous les groupes
|
||||
#[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 {
|
||||
StatusCode::NOT_IMPLEMENTED
|
||||
/// Récupère un groupe par son ID
|
||||
#[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 {
|
||||
StatusCode::NOT_IMPLEMENTED
|
||||
/// Crée un nouveau groupe
|
||||
#[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 {
|
||||
StatusCode::NOT_IMPLEMENTED
|
||||
/// Met à jour un groupe existant
|
||||
#[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 {
|
||||
StatusCode::NOT_IMPLEMENTED
|
||||
/// Supprime un groupe
|
||||
#[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 {
|
||||
todo!()
|
||||
pub fn group_model_to_group_response(model: group::Model) -> GroupResponse {
|
||||
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;
|
||||
|
||||
pub fn router() -> Router {
|
||||
pub fn router() -> Router<AppState> {
|
||||
Router::new()
|
||||
.route("/groups", get(handlers::get_all).post(handlers::create))
|
||||
.route(
|
||||
|
||||
@@ -1,21 +1,2 @@
|
||||
use super::domain::Group;
|
||||
|
||||
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!()
|
||||
}
|
||||
// Ce fichier est conservé pour structure mais n'est plus utilisé.
|
||||
// La logique a été déplacée directement dans les handlers.
|
||||
|
||||
@@ -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 utoipa::ToSchema;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct CreateMessageRequest {}
|
||||
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
||||
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)]
|
||||
pub struct UpdateMessageRequest {}
|
||||
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
||||
pub struct CreateMessageRequest {
|
||||
pub channel_id: Uuid,
|
||||
pub content: String,
|
||||
pub reply_to_id: Option<Uuid>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct MessageResponse {}
|
||||
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
||||
pub struct UpdateMessageRequest {
|
||||
pub content: String,
|
||||
}
|
||||
|
||||
+177
-12
@@ -1,22 +1,187 @@
|
||||
use axum::http::StatusCode;
|
||||
use axum::response::IntoResponse;
|
||||
use crate::core::state::AppState;
|
||||
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 {
|
||||
StatusCode::NOT_IMPLEMENTED
|
||||
/// Liste tous les messages
|
||||
#[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 {
|
||||
StatusCode::NOT_IMPLEMENTED
|
||||
/// Récupère un message par son ID
|
||||
#[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 {
|
||||
StatusCode::NOT_IMPLEMENTED
|
||||
/// Crée un nouveau message
|
||||
#[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 {
|
||||
StatusCode::NOT_IMPLEMENTED
|
||||
/// Met à jour un message existant
|
||||
#[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 {
|
||||
StatusCode::NOT_IMPLEMENTED
|
||||
/// Supprime un message
|
||||
#[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 {
|
||||
todo!()
|
||||
pub fn message_model_to_message_response(model: message::Model) -> MessageResponse {
|
||||
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 crate::core::state::AppState;
|
||||
use axum::{routing::get, Router};
|
||||
|
||||
pub fn router() -> Router {
|
||||
pub fn router() -> Router<AppState> {
|
||||
Router::new()
|
||||
.route("/messages", get(handlers::get_all).post(handlers::create))
|
||||
.route(
|
||||
|
||||
@@ -1,21 +1 @@
|
||||
use super::domain::Message;
|
||||
|
||||
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!()
|
||||
}
|
||||
// Service layer for Message - currently unused in the simplified architecture
|
||||
|
||||
+8
-7
@@ -12,12 +12,13 @@ pub mod server;
|
||||
pub mod user;
|
||||
|
||||
pub fn router() -> OxRouter {
|
||||
Router::new().merge(auth::routes::router())
|
||||
// .merge(user::routes::router())
|
||||
// .merge(server::routes::router())
|
||||
// .merge(channel::routes::router())
|
||||
// .merge(message::routes::router())
|
||||
// .merge(group::routes::router())
|
||||
// .merge(category::routes::router())
|
||||
Router::new()
|
||||
.merge(auth::routes::router())
|
||||
.merge(server::routes::router())
|
||||
.merge(category::routes::router())
|
||||
.merge(channel::routes::router())
|
||||
.merge(group::routes::router())
|
||||
.merge(message::routes::router())
|
||||
.merge(user::routes::router())
|
||||
// .merge(attachment::routes::router())
|
||||
}
|
||||
|
||||
@@ -1,10 +1,35 @@
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use utoipa::ToSchema;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct CreateServerRequest {}
|
||||
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
||||
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)]
|
||||
pub struct UpdateServerRequest {}
|
||||
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
||||
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)]
|
||||
pub struct ServerResponse {}
|
||||
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
||||
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 axum::response::IntoResponse;
|
||||
use crate::core::state::AppState;
|
||||
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 {
|
||||
StatusCode::NOT_IMPLEMENTED
|
||||
/// Liste tous les serveurs
|
||||
#[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 {
|
||||
StatusCode::NOT_IMPLEMENTED
|
||||
/// Récupère un serveur par son ID
|
||||
#[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 {
|
||||
StatusCode::NOT_IMPLEMENTED
|
||||
/// Crée un nouveau serveur
|
||||
#[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 {
|
||||
StatusCode::NOT_IMPLEMENTED
|
||||
/// Met à jour un serveur existant
|
||||
#[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 {
|
||||
StatusCode::NOT_IMPLEMENTED
|
||||
/// Supprime un serveur
|
||||
#[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 {
|
||||
todo!()
|
||||
pub fn server_model_to_server_response(model: server::Model) -> ServerResponse {
|
||||
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 crate::core::state::AppState;
|
||||
use axum::{routing::get, Router};
|
||||
|
||||
pub fn router() -> Router {
|
||||
pub fn router() -> Router<AppState> {
|
||||
Router::new()
|
||||
.route("/servers", get(handlers::get_all).post(handlers::create))
|
||||
.route(
|
||||
|
||||
@@ -1,21 +1,2 @@
|
||||
use super::domain::Server;
|
||||
|
||||
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!()
|
||||
}
|
||||
// Ce fichier est conservé pour structure mais n'est plus utilisé.
|
||||
// La logique a été déplacée directement dans les handlers.
|
||||
|
||||
@@ -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 utoipa::ToSchema;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct CreateUserRequest {}
|
||||
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
||||
pub struct CreateUserRequest {
|
||||
pub username: String,
|
||||
pub password: String,
|
||||
pub pub_key: String,
|
||||
pub is_superuser: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct UpdateUserRequest {}
|
||||
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
||||
pub struct UpdateUserRequest {
|
||||
pub username: String,
|
||||
pub pub_key: String,
|
||||
pub is_superuser: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct UserResponse {}
|
||||
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
||||
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 axum::response::IntoResponse;
|
||||
use crate::core::state::AppState;
|
||||
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 {
|
||||
StatusCode::NOT_IMPLEMENTED
|
||||
/// Liste tous les utilisateurs
|
||||
#[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 {
|
||||
StatusCode::NOT_IMPLEMENTED
|
||||
/// Récupère un utilisateur par son ID
|
||||
#[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 {
|
||||
StatusCode::NOT_IMPLEMENTED
|
||||
/// Crée un nouvel utilisateur
|
||||
#[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 {
|
||||
StatusCode::NOT_IMPLEMENTED
|
||||
/// Met à jour un utilisateur existant
|
||||
#[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 {
|
||||
StatusCode::NOT_IMPLEMENTED
|
||||
/// Supprime un utilisateur
|
||||
#[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 {
|
||||
todo!()
|
||||
pub fn user_model_to_user_response(model: user::Model) -> UserResponse {
|
||||
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 super::handlers;
|
||||
|
||||
pub fn router() -> Router {
|
||||
pub fn router() -> Router<AppState> {
|
||||
Router::new()
|
||||
.route("/users", get(handlers::get_all).post(handlers::create))
|
||||
.route(
|
||||
|
||||
@@ -1,21 +1 @@
|
||||
use super::domain::User;
|
||||
|
||||
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!()
|
||||
}
|
||||
// Ce fichier est conservé pour la structure mais la logique est directement dans les handlers.
|
||||
|
||||
Reference in New Issue
Block a user