diff --git a/.gitignore b/.gitignore index f4214eb..e63b1ee 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ back/target/ front/dist/ back/public/ -back/data/ -back/Cargo.lock +back/Cargo.lock \ No newline at end of file diff --git a/back/Cargo.toml b/back/Cargo.toml index 6be9ee0..8b48126 100644 --- a/back/Cargo.toml +++ b/back/Cargo.toml @@ -6,7 +6,4 @@ edition = "2021" [dependencies] actix-files = "0.6.6" actix-web = "4" -sqlite = "0.36.1" -serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0.133" diff --git a/back/src/create_db.rs b/back/src/create_db.rs deleted file mode 100644 index 67eb2af..0000000 --- a/back/src/create_db.rs +++ /dev/null @@ -1,21 +0,0 @@ -use sqlite::{Connection, OpenFlags}; - -pub fn init() -> sqlite::Result<()> { - let conn = Connection::open_with_flags( - "./data/data.db", - OpenFlags::new() - .with_create() - .with_read_write() - )?; - - conn.execute( - "CREATE TABLE IF NOT EXISTS articles ( - id INTEGER PRIMARY KEY, - title TEXT NOT NULL, - subTitle TEXT, - content TEXT NOT NULL - )", - )?; - - Ok(()) -} diff --git a/back/src/main.rs b/back/src/main.rs index 7242d32..d4d0ee1 100644 --- a/back/src/main.rs +++ b/back/src/main.rs @@ -1,80 +1,13 @@ -mod create_db; -use create_db::init; - -use actix_web::{App, HttpServer, get, Responder, HttpResponse, http::header::ContentType}; +use actix_web::{App, HttpServer}; 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 { - HttpResponse::Ok().body("Hello world!") -} - -#[get("/api/articles")] -async fn get_articles() -> impl Responder { - let conn = Connection::open("./data/data.db").unwrap(); - let mut stmt = conn.prepare("SELECT * FROM articles").unwrap(); - let mut articles = Vec::new(); - - while let State::Row = stmt.next().unwrap() { - let id = stmt.read::(0).unwrap(); - let title = stmt.read::(1).unwrap(); - let content = stmt.read::(3).unwrap(); - articles.push(Article { - id, - title, - auteur: None, - edited_at: None, - published_at: None, - content - }); - } - - HttpResponse::Ok().json(articles) -} - -#[get("/api")] -async fn api() -> impl Responder { - let value = json!({ - "code": 200, - "success": true, - "payload": { - "features": [ - "serde", - "json" - ], - "homepage": null - } - }); - HttpResponse::Ok() - .content_type(ContentType::json()) - .body(value.to_string()) -} #[actix_web::main] -async fn main() -> Result<(), std::io::Error> { - let _ = init(); - +async fn main() -> std::io::Result<()> { HttpServer::new(|| { App::new() - .service(hello) - .service(get_articles) - .service(api) - .service(Files::new("/", "public").index_file("index.html")) + .service(Files::new("/", "./public").index_file("index.html")) }) - .bind(("0.0.0.0", 2486))? + .bind(("0.0.0.0", 8080))? .run() .await } diff --git a/docker-compose.yml b/docker-compose.yml index 1e0df8d..1e8480c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,6 +7,4 @@ services: restart: always ports: - 8080:8080 - volumes: - - ./back/data:/app/data