generated from lucien/actix-react-template
Actualiser back/src/main.rs
finito ?
This commit is contained in:
parent
9b91a5acf3
commit
3688d031b4
1 changed files with 19 additions and 2 deletions
|
@ -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<String>,
|
||||
edited_at: Option<String>,
|
||||
published_at: Option<String>,
|
||||
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::<i64, _>(0).unwrap();
|
||||
let title = stmt.read::<String, _>(1).unwrap();
|
||||
let subTitle = stmt.read::<String, _>(2).unwrap();
|
||||
let content = stmt.read::<String, _>(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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue