diff --git a/frontend/src/pages/server/channel/index.vue b/frontend/src/pages/server/channel/index.vue
index 8d59964..f76ce86 100644
--- a/frontend/src/pages/server/channel/index.vue
+++ b/frontend/src/pages/server/channel/index.vue
@@ -1,5 +1,5 @@
@@ -48,14 +47,14 @@ onMounted(() => {
>
-
-
+
+
- {{ msg.user.name }}
- {{ msg.timestamp }}
+ {{ msg.user_id }}
+ {{ msg.created_at }}
diff --git a/frontend/src/stores/message.ts b/frontend/src/stores/message.ts
index 39dcdb3..a49c066 100644
--- a/frontend/src/stores/message.ts
+++ b/frontend/src/stores/message.ts
@@ -3,9 +3,12 @@ import {useApi} from "@/composables/useApi.ts";
interface Message {
id: string;
+ channel_id: string;
+ user_id: string;
content: string;
- user: { name: string; avatar: string };
- timestamp: string;
+ created_at: string;
+ updated_at: string | null;
+ reply_to_id: string | null;
}
export const useMessageStore = defineStore("message", {
@@ -16,10 +19,16 @@ export const useMessageStore = defineStore("message", {
actions: {
async fetchMessages(channel_id: string) {
this.loading = true;
+
+ // Query params
+ let params = new URLSearchParams();
+ params.append("channel_id", channel_id);
+ const queryString = params.toString();
+
try {
const api = useApi();
// Utilisation du paramètre pour cibler le channel
- const response = await api.get(`/api/messages/${channel_id}`);
+ const response = await api.get(`/messages${queryString ? `?${queryString}` : ""}`);
this.messages = await response.json();
} catch (error) {
console.error("Erreur lors du chargement des messages:", error);
@@ -29,9 +38,14 @@ export const useMessageStore = defineStore("message", {
},
async sendMessage(channelId: string, content: string) {
const api = useApi();
+ console.log("channelId", channelId);
try {
// Envoi au serveur pour persistance
- const response = await api.post(`/api/messages/${channelId}`, {content});
+ const response = await api.post('/messages', {
+ channel_id: channelId,
+ content: content,
+ reply_to_id: null
+ });
const newMessage = await response.json();
// Ajout local immédiat (optimistic update)
diff --git a/src/repositories/message.rs b/src/repositories/message.rs
index cb27e4b..9853a49 100644
--- a/src/repositories/message.rs
+++ b/src/repositories/message.rs
@@ -1,6 +1,6 @@
use crate::models::message;
use crate::repositories::{AnyResult, RepositoryContext};
-use sea_orm::{ActiveModelTrait, EntityTrait};
+use sea_orm::{ActiveModelTrait, ColumnTrait, EntityTrait, QueryFilter};
use std::sync::Arc;
#[derive(Clone, Debug)]
@@ -19,6 +19,13 @@ impl MessageRepository {
.await?)
}
+ pub async fn get_by_channel(&self, channel_id: uuid::Uuid) -> AnyResult> {
+ Ok(message::Entity::find()
+ .filter(message::Column::ChannelId.eq(channel_id))
+ .all(&self.context.db)
+ .await?)
+ }
+
pub async fn update(&self, active: message::ActiveModel) -> AnyResult {
let message = active.update(&self.context.db).await?;
self.context.events.emit("message_updated", message.clone());
diff --git a/src/routes/message/dto.rs b/src/routes/message/dto.rs
index 9546764..677cbe4 100644
--- a/src/routes/message/dto.rs
+++ b/src/routes/message/dto.rs
@@ -25,3 +25,8 @@ pub struct CreateMessageRequest {
pub struct UpdateMessageRequest {
pub content: String,
}
+
+#[derive(serde::Deserialize, utoipa::IntoParams)]
+pub struct MessageFilters {
+ pub channel_id: Option,
+}
diff --git a/src/routes/message/handlers.rs b/src/routes/message/handlers.rs
index bafb728..50d8964 100644
--- a/src/routes/message/handlers.rs
+++ b/src/routes/message/handlers.rs
@@ -1,10 +1,10 @@
+use super::dto::{CreateMessageRequest, MessageFilters, MessageResponse, UpdateMessageRequest};
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},
+ extract::{Path, Query, State},
http::StatusCode,
Json,
};
@@ -18,12 +18,24 @@ use uuid::Uuid;
(status = 200, description = "Liste des messages récupérée avec succès", body = [MessageResponse]),
(status = 500, description = "Erreur interne du serveur")
),
+ params(
+ MessageFilters
+ ),
tag = "Messages"
)]
pub async fn get_all(
State(state): State,
+ Query(filters): Query,
) -> Result>, HTTPError> {
- let messages = state.repositories.message.get_all().await?;
+ let messages = if let Some(channel_id) = filters.channel_id {
+ state
+ .repositories
+ .message
+ .get_by_channel(channel_id)
+ .await?
+ } else {
+ state.repositories.message.get_all().await?
+ };
Ok(Json(
messages
.into_iter()