diff --git a/frontend/src/pages/server/channel/index.vue b/frontend/src/pages/server/channel/index.vue
index c96d1b1..8d59964 100644
--- a/frontend/src/pages/server/channel/index.vue
+++ b/frontend/src/pages/server/channel/index.vue
@@ -1,35 +1,37 @@
diff --git a/frontend/src/stores/message.ts b/frontend/src/stores/message.ts
index 7307d21..39dcdb3 100644
--- a/frontend/src/stores/message.ts
+++ b/frontend/src/stores/message.ts
@@ -1,20 +1,48 @@
import {defineStore} from "pinia";
import {useApi} from "@/composables/useApi.ts";
+interface Message {
+ id: string;
+ content: string;
+ user: { name: string; avatar: string };
+ timestamp: string;
+}
+
export const useMessageStore = defineStore("message", {
state: () => ({
- messages: []
+ messages: [] as Message[],
+ loading: false,
}),
actions: {
async fetchMessages(channel_id: string) {
- // todo : ici, les messages ne doivent pas être tous récupérés. Un filtre doit être appliqué.
- // pour ne récupérer que les messages du channel actif
- let api = useApi();
- let response = await api.get("/api/messages");
- this.messages = await response.json();
+ this.loading = true;
+ try {
+ const api = useApi();
+ // Utilisation du paramètre pour cibler le channel
+ const response = await api.get(`/api/messages/${channel_id}`);
+ this.messages = await response.json();
+ } catch (error) {
+ console.error("Erreur lors du chargement des messages:", error);
+ } finally {
+ this.loading = false;
+ }
+ },
+ async sendMessage(channelId: string, content: string) {
+ const api = useApi();
+ try {
+ // Envoi au serveur pour persistance
+ const response = await api.post(`/api/messages/${channelId}`, {content});
+ const newMessage = await response.json();
+
+ // Ajout local immédiat (optimistic update)
+ this.messages.push(newMessage);
+ } catch (error) {
+ console.error("Erreur lors de l'envoi du message:", error);
+ throw error;
+ }
},
reset() {
this.messages = [];
}
}
-});
+});
\ No newline at end of file
diff --git a/src/http/middleware.rs b/src/http/middleware.rs
index 38d8c51..46658ab 100644
--- a/src/http/middleware.rs
+++ b/src/http/middleware.rs
@@ -8,7 +8,7 @@ use axum::{
use axum_extra::extract::CookieJar;
use std::sync::Arc;
use std::time::Instant;
-use tracing::{info, Instrument};
+use tracing::{debug, info, Instrument};
use uuid::Uuid;
use super::context::{CurrentUser, RequestContext};
@@ -92,7 +92,7 @@ pub async fn auth_middleware(
mut req: Request,
next: Next,
) -> Response {
- // Extraction du JWT : d'abord via le header Authorization, sinon via la query string "token"
+ // Extraction du JWT : d'abord via le header Authorization, ou via le cookie, sinon via la query string "token"
let token = req
.headers()
.get(header::AUTHORIZATION)
@@ -132,7 +132,7 @@ pub async fn auth_middleware(
// Mise à jour du RequestContext existant
if let Some(user) = &user {
- info!(user_id = %user.id, username = %user.username, "User identified");
+ debug!(user_id = %user.id, username = %user.username, "User identified");
if let Some(ctx) = req.extensions_mut().get_mut::() {
ctx.user = Some(user.clone());
}
diff --git a/src/main.rs b/src/main.rs
index a492dc3..b270d30 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -9,7 +9,8 @@ async fn main() -> Result<(), Box> {
tracing_subscriber::fmt()
.with_env_filter(
std::env::var("RUST_LOG")
- .unwrap_or_else(|_| "info,sqlx=debug,sea_orm=debug,sea_orm_migration=info".into()),
+ // .unwrap_or_else(|_| "info,sqlx=debug,sea_orm=debug,sea_orm_migration=info".into()),
+ .unwrap_or_else(|_| "info,sqlx=info,sea_orm=info,sea_orm_migration=info".into()),
)
.with_target(true)
.with_level(true)