From ec2322f04cc7d1acbfb78a3dcdc28636c0af99ee Mon Sep 17 00:00:00 2001 From: linlkin Date: Fri, 6 Dec 2024 03:52:12 +0100 Subject: [PATCH 01/14] better api and yyyy/mm/dd format for dates in the db --- back/src/create_db.rs | 4 ++- back/src/main.rs | 67 +++++++++++++++++++++++++++++++++++++------ 2 files changed, 61 insertions(+), 10 deletions(-) diff --git a/back/src/create_db.rs b/back/src/create_db.rs index 67eb2af..21cb84a 100644 --- a/back/src/create_db.rs +++ b/back/src/create_db.rs @@ -12,7 +12,9 @@ pub fn init() -> sqlite::Result<()> { "CREATE TABLE IF NOT EXISTS articles ( id INTEGER PRIMARY KEY, title TEXT NOT NULL, - subTitle TEXT, + auteur TEXT, + edited_at DATE_FORMAT('now', '%YYYY-%mm-%dd'), + published_at DATE_FORMAT('now', '%YYYY-%mm-%dd'), content TEXT NOT NULL )", )?; diff --git a/back/src/main.rs b/back/src/main.rs index ad8f7f5..141544d 100644 --- a/back/src/main.rs +++ b/back/src/main.rs @@ -1,7 +1,7 @@ mod create_db; use create_db::init; -use actix_web::{App, HttpServer, get, Responder, HttpResponse, http::header::ContentType}; +use actix_web::{App, web, HttpServer, get, Responder, HttpResponse, http::header::ContentType}; use actix_files::Files; use serde_json::json; use sqlite::{Connection, State}; @@ -11,9 +11,9 @@ use serde::{Serialize, Deserialize}; struct Article { id: i64, title: String, - auteur: Option, - edited_at: Option, - published_at: Option, + auteur: String, + edited_at: String, + published_at: String, content: String, } @@ -31,13 +31,13 @@ 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 content = stmt.read::(3).unwrap(); + let content = stmt.read::(5).unwrap(); articles.push(Article { id, title, - auteur: None, - edited_at: None, - published_at: None, + auteur: "".to_string(), + edited_at: "".to_string(), + published_at: "".to_string(), content }); } @@ -45,6 +45,54 @@ async fn get_articles() -> impl Responder { HttpResponse::Ok().json(articles) } + +#[get("/api/articles/{id}")] +async fn get_article(path: web::Path) -> impl Responder { + let id = path.into_inner(); + + // Open the database connection + let conn = match Connection::open("./data/data.db") { + Ok(conn) => conn, + Err(err) => { + eprintln!("Failed to connect to database: {}", err); + return HttpResponse::InternalServerError().body("Failed to connect to database"); + } + }; + + // Fetch the article from the database + match fetch_article_by_id(&conn, id) { + Ok(Some(article)) => HttpResponse::Ok().json(article), + Ok(None) => HttpResponse::NotFound().body(format!("Article with ID {} not found", id)), + Err(err) => { + eprintln!("Database query error: {}", err); + HttpResponse::InternalServerError().body("Database query failed") + } + } +} + +/// Fetches an article by its ID from the database. +fn fetch_article_by_id(conn: &Connection, id: i64) -> Result, sqlite::Error> { + let mut stmt = conn.prepare( + "SELECT id, title, auteur, edited_at, published_at, content + FROM articles WHERE id = ?1" + )?; + stmt.bind((1, id))?; + + let mut article = None; + while let State::Row = stmt.next()? { + article = Some(Article { + id: stmt.read::(0)?, + title: stmt.read::(1)?, + auteur: stmt.read::(2)?, + edited_at: stmt.read::(3)?, + published_at: stmt.read::(4)?, + content: stmt.read::(5)?, + }); + } + + Ok(article) +} + #[get("/api")] async fn api() -> impl Responder { let value = json!({ @@ -72,9 +120,10 @@ async fn main() -> Result<(), std::io::Error> { .service(hello) .service(get_articles) .service(api) + .service(get_article) .service(Files::new("/", "public").index_file("index.html")) }) - .bind(("0.0.0.0", 8080))? + .bind(("0.0.0.0", 2486))? .run() .await } From ac3fc5c39140e049eaac5fb259f560804f3bd130 Mon Sep 17 00:00:00 2001 From: Lukian Date: Fri, 6 Dec 2024 04:34:40 +0100 Subject: [PATCH 02/14] Updated ports --- docker-compose.yml | 2 +- dockerfile | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 1e0df8d..9bcaab9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,7 +6,7 @@ services: container_name: web restart: always ports: - - 8080:8080 + - 8080:2486 volumes: - ./back/data:/app/data diff --git a/dockerfile b/dockerfile index d8e8f78..f092a14 100644 --- a/dockerfile +++ b/dockerfile @@ -10,9 +10,9 @@ RUN cargo build --release FROM debian:bookworm-slim WORKDIR /app -RUN apt-get update & apt-get install -y extra-runtime-dependencies & rm -rf /var/lib/apt/lists/* +RUN apt update && apt install -y libsqlite3-0 COPY --from=front /app/dist /app/public COPY --from=back /app/target/release/back /app/back -EXPOSE 8080 +EXPOSE 2486 CMD ["/app/back"] From e1bcb4b02252001f56a5316dc557e38fe30f48fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?SwimJ=C3=A9j=C3=A9?= Date: Fri, 6 Dec 2024 05:35:47 +0100 Subject: [PATCH 03/14] Chaos Commit --- front/src/components/chaos/MonInput.tsx | 10 ++++ front/src/components/chaos/monButton.tsx | 19 +++++++ front/src/components/chaos/style.css | 11 ++++ front/src/pages/ChaosPage.tsx | 67 ++++++++++++++++++++++++ 4 files changed, 107 insertions(+) create mode 100644 front/src/components/chaos/MonInput.tsx create mode 100644 front/src/components/chaos/monButton.tsx create mode 100644 front/src/components/chaos/style.css create mode 100644 front/src/pages/ChaosPage.tsx diff --git a/front/src/components/chaos/MonInput.tsx b/front/src/components/chaos/MonInput.tsx new file mode 100644 index 0000000..184896e --- /dev/null +++ b/front/src/components/chaos/MonInput.tsx @@ -0,0 +1,10 @@ +//import { useState } from "react"; + +export default function MonInput({text, new_focus}) { + + return ( +
+ +
+ ) +} \ No newline at end of file diff --git a/front/src/components/chaos/monButton.tsx b/front/src/components/chaos/monButton.tsx new file mode 100644 index 0000000..9951303 --- /dev/null +++ b/front/src/components/chaos/monButton.tsx @@ -0,0 +1,19 @@ +import { useState } from "react"; + + + +export default function MonButton({letter,changetext,sizeFrontw,sizeFronth,rdmFront,color}) { + + + + function clicked() {rdmFront(); + changetext(letter)} + + + + return ( +
+ +
+ ) +} \ No newline at end of file diff --git a/front/src/components/chaos/style.css b/front/src/components/chaos/style.css new file mode 100644 index 0000000..6e3a951 --- /dev/null +++ b/front/src/components/chaos/style.css @@ -0,0 +1,11 @@ +#keys { + display: grid; + grid-template-columns: auto auto 1fr; + + +} + +.key { + font-size: 10px; + border: solid black; +} \ No newline at end of file diff --git a/front/src/pages/ChaosPage.tsx b/front/src/pages/ChaosPage.tsx new file mode 100644 index 0000000..d5f8beb --- /dev/null +++ b/front/src/pages/ChaosPage.tsx @@ -0,0 +1,67 @@ +import MonButton from "../components/chaos/monButton"; +import MonInput from "../components/chaos/MonInput"; +import "../components/chaos/style.css" +import { useState } from "react"; + + +export default function ChaosPage(){ + + const array_input = [1,2,3,4]; + const [array_letter,setArray_letter]=useState(["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"," ","!"]); + + const [sizeFrontw,setSizeFrontw] = useState(16) + const [sizeFronth,setSizeFronth] = useState(10) + const [color,setColor] = useState("#ffffff") + + function randomFront(){setSizeFronth(Math.floor(Math.random() * (1000))); + setSizeFrontw(Math.floor(Math.random() * (1000))); + setColor(`#${Math.floor(Math.random() * 16777215).toString(16)}`)} + + function shuffleArray(arr) { + for (let i = arr.length - 1; i > 0; i--) { + const j = Math.floor(Math.random() * (i + 1)); // Choisir un index aléatoire + [arr[i], arr[j]] = [arr[j], arr[i]]; // Échanger les éléments + } + return arr; + } + + const myArray = [1, 2, 3, 4, 5]; + const shuffledArray = shuffleArray(myArray); + + console.log(shuffledArray); // Affiche un tableau mélangé + + + const [entry1,setEntry1] = useState("champ1") + function E1(ent:string) { + setEntry1(entry1+ent); + } + const [connarddefocus,setFocus] = useState(()=>E1) + + const [entry2,setEntry2] = useState("champ2") + function E2(ent:string) { + setEntry2(entry2+ent); + } + + function changeFocus(E) { + setArray_letter(shuffleArray(array_letter)); + setFocus(()=>E); + } + + + return( +
+

Chaos Page

+ changeFocus(E1)}/> + changeFocus(E2)}/> +
+ {array_letter.map((letter) => {return })} +
+
+ ) +} \ No newline at end of file From ea2bb7ac3cc885fdcfaf70272d652184b97672a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?SwimJ=C3=A9j=C3=A9?= Date: Fri, 6 Dec 2024 05:38:08 +0100 Subject: [PATCH 04/14] Second commit --- front/src/main.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/front/src/main.tsx b/front/src/main.tsx index ce00332..a7c672a 100644 --- a/front/src/main.tsx +++ b/front/src/main.tsx @@ -2,6 +2,7 @@ import { BrowserRouter, Route, Routes } from "react-router"; import { createRoot } from 'react-dom/client' import MainPage from "./pages/MainPage.tsx"; import GamePage from "./pages/GamePage.tsx"; +import ChaosPage from "./pages/ChaosPage.tsx"; createRoot(document.getElementById('root')!).render( @@ -9,6 +10,7 @@ createRoot(document.getElementById('root')!).render( } /> } /> + } /> , ) From b8fa053ca3e41c63612efdc5ea2da5ca40c1ec6a Mon Sep 17 00:00:00 2001 From: Lukian Date: Fri, 6 Dec 2024 05:43:21 +0100 Subject: [PATCH 05/14] Updated docker-compose.yml --- docker-compose.yml | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 9bcaab9..f689f10 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,10 +3,22 @@ services: build: context: . dockerfile: dockerfile - container_name: web + network: host + container_name: nuitdelinfo restart: always - ports: - - 8080:2486 volumes: - ./back/data:/app/data + networks: + - traefik + labels: + - "traefik.enable=true" + - "traefik.http.routers.nuitdelinfo.rule=Host(`nuitdelinfo.leizour.fr`)" + - "traefik.http.routers.nuitdelinfo.entrypoints=websecure" + - "traefik.http.routers.nuitdelinfo.tls=true" + - "traefik.http.routers.nuitdelinfo.tls.certresolver=myresolver" + - "traefik.http.services.nuitdelinfo.loadbalancer.server.port=2486" + +networks: + traefik: + external: true From 4682f8a61ed8ba3c37b3f5044f08526c2983b93e Mon Sep 17 00:00:00 2001 From: iMax Date: Fri, 6 Dec 2024 05:46:34 +0100 Subject: [PATCH 06/14] Hot fix - Marker.tsx --- front/src/components/3d/Marker.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/front/src/components/3d/Marker.tsx b/front/src/components/3d/Marker.tsx index 893f4f1..e38fe3e 100644 --- a/front/src/components/3d/Marker.tsx +++ b/front/src/components/3d/Marker.tsx @@ -3,21 +3,21 @@ import { Group } from 'three' import * as THREE from 'three' interface MarkerProps { - position: [number, number, number], + position: number[], color: string, onClick?: () => void } export default function Marker({ position, color, onClick }: MarkerProps) { - const [positionState, setPositionState] = React.useState(position) + const [positionState, setPositionState] = React.useState(new THREE.Vector3(...position)) // Return the marker object // return return ( - setPositionState([positionState[0], positionState[1], positionState[2] + 0.1])} onPointerOut={(e) => setPositionState(position)}> + setPositionState(positionState.clone().setZ(positionState.z + 0.1))} onPointerOut={(e) => setPositionState(new THREE.Vector3(...position))}> - ) + ) } From 0e31e90af982fa9c615a85a0cd26e074cd63a55e Mon Sep 17 00:00:00 2001 From: iMax Date: Fri, 6 Dec 2024 05:58:13 +0100 Subject: [PATCH 07/14] =?UTF-8?q?Cr=C3=A9ation=20d'un=20formulaire=20basiq?= =?UTF-8?q?ue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- front/src/components/NavBar.tsx | 2 +- front/src/pages/ChaosPage.tsx | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/front/src/components/NavBar.tsx b/front/src/components/NavBar.tsx index b5ebe21..cf2b130 100644 --- a/front/src/components/NavBar.tsx +++ b/front/src/components/NavBar.tsx @@ -7,7 +7,7 @@ export default function NavBar(){