From 3688d031b4ff20a63237f934cb20c94b2f0674cb Mon Sep 17 00:00:00 2001 From: linlkin Date: Fri, 6 Dec 2024 00:42:10 +0000 Subject: [PATCH] Actualiser back/src/main.rs finito ? --- back/src/main.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/back/src/main.rs b/back/src/main.rs index 320c18f..ad8f7f5 100644 --- a/back/src/main.rs +++ b/back/src/main.rs @@ -5,6 +5,17 @@ use actix_web::{App, HttpServer, get, Responder, HttpResponse, http::header::Con use actix_files::Files; use serde_json::json; use sqlite::{Connection, State}; +use serde::{Serialize, Deserialize}; + +#[derive(serde::Serialize)] +struct Article { + id: i64, + title: String, + auteur: Option, + edited_at: Option, + published_at: Option, + content: String, +} #[get("/api/hello")] async fn hello() -> impl Responder { @@ -20,9 +31,15 @@ async fn get_articles() -> impl Responder { while let State::Row = stmt.next().unwrap() { let id = stmt.read::(0).unwrap(); let title = stmt.read::(1).unwrap(); - let subTitle = stmt.read::(2).unwrap(); let content = stmt.read::(3).unwrap(); - articles.push((id, title, subTitle, content)); + articles.push(Article { + id, + title, + auteur: None, + edited_at: None, + published_at: None, + content + }); } HttpResponse::Ok().json(articles)