Merge pull request 'refactorisationJS' (#17) from refactorisationJS into develop
Reviewed-on: cheeze.fr/mdnotes#17pull/18/head
commit
fb536b2438
@ -0,0 +1,64 @@
|
|||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"type": "lldb",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Debug unit tests in library 'cheezenotes'",
|
||||||
|
"cargo": {
|
||||||
|
"args": [
|
||||||
|
"test",
|
||||||
|
"--no-run",
|
||||||
|
"--lib",
|
||||||
|
"--package=cheezenotes"
|
||||||
|
],
|
||||||
|
"filter": {
|
||||||
|
"name": "cheezenotes",
|
||||||
|
"kind": "lib"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"args": [],
|
||||||
|
"cwd": "${workspaceFolder}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "lldb",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Debug executable 'cheezenotes'",
|
||||||
|
"cargo": {
|
||||||
|
"args": [
|
||||||
|
"build",
|
||||||
|
"--bin=cheezenotes",
|
||||||
|
"--package=cheezenotes"
|
||||||
|
],
|
||||||
|
"filter": {
|
||||||
|
"name": "cheezenotes",
|
||||||
|
"kind": "bin"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"args": [],
|
||||||
|
"cwd": "${workspaceFolder}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "lldb",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Debug unit tests in executable 'cheezenotes'",
|
||||||
|
"cargo": {
|
||||||
|
"args": [
|
||||||
|
"test",
|
||||||
|
"--no-run",
|
||||||
|
"--bin=cheezenotes",
|
||||||
|
"--package=cheezenotes"
|
||||||
|
],
|
||||||
|
"filter": {
|
||||||
|
"name": "cheezenotes",
|
||||||
|
"kind": "bin"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"args": [],
|
||||||
|
"cwd": "${workspaceFolder}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
Binary file not shown.
@ -0,0 +1,5 @@
|
|||||||
|
create table pages (
|
||||||
|
page_name text primary key,
|
||||||
|
page_text text,
|
||||||
|
active boolean default true not null
|
||||||
|
);
|
||||||
Binary file not shown.
@ -1,13 +1,2 @@
|
|||||||
[retour](BPCE-SI-Notes)
|
[retour](BPCE-SI-Notes)
|
||||||
[](\\Prdgce7v2115\d\gcedoc\referentielproduction\clients\csctrmif\csctrmif\Documents)
|
# Bidouille
|
||||||
[](\\Prdgce7v2116\d\gcedoc\referentielproduction\clients\csctrmif\csctrmif\Documents)
|
|
||||||
[](\\Prdgce7v2117\d\gcedoc\referentielproduction\clients\csctrmif\csctrmif\Documents)
|
|
||||||
[](\\Prdgce7v2118\d\gcedoc\referentielproduction\clients\csctrmif\csctrmif\Documents)
|
|
||||||
[](\\Prdgce7v2119\d\gcedoc\referentielproduction\clients\csctrmif\csctrmif\Documents)
|
|
||||||
[](\\Prdgce7v2120\d\gcedoc\referentielproduction\clients\csctrmif\csctrmif\Documents)
|
|
||||||
[](\\Prdgce7v2121\d\gcedoc\referentielproduction\clients\csctrmif\csctrmif\Documents)
|
|
||||||
[](\\Prdgce7v2122\d\gcedoc\referentielproduction\clients\csctrmif\csctrmif\Documents)
|
|
||||||
[](\\Prdgce7v2123\d\gcedoc\referentielproduction\clients\csctrmif\csctrmif\Documents)
|
|
||||||
[](\\Prdgce7v2124\d\gcedoc\referentielproduction\clients\csctrmif\csctrmif\Documents)
|
|
||||||
[](\\Prdgce7v2125\d\gcedoc\referentielproduction\clients\csctrmif\csctrmif\Documents)
|
|
||||||
[](\\Prdgce7v2126\d\gcedoc\referentielproduction\clients\csctrmif\csctrmif\Documents)
|
|
||||||
@ -0,0 +1 @@
|
|||||||
|
# test DB
|
||||||
@ -1,12 +0,0 @@
|
|||||||
use rusqlite::{params, Connection, Result};
|
|
||||||
|
|
||||||
pub struct DatabaseConnection {
|
|
||||||
connection_string: String,
|
|
||||||
connection: Option<Connection>,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new(connection_string: String) -> DatabaseConnection {
|
|
||||||
let mut con = DatabaseConnection{ connection_string: connection_string.to_owned(), connection: None};
|
|
||||||
con.connection = Some(Connection::open(connection_string).unwrap());
|
|
||||||
con
|
|
||||||
}
|
|
||||||
@ -0,0 +1,51 @@
|
|||||||
|
use actix_web::{error, web, Error};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
pub type Pool = r2d2::Pool<r2d2_sqlite::SqliteConnectionManager>;
|
||||||
|
pub type Connection = r2d2::PooledConnection<r2d2_sqlite::SqliteConnectionManager>;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
pub struct Page {
|
||||||
|
pub page_name: String,
|
||||||
|
pub page_text: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_page_by_name(pool: &Pool, pagename: String) -> Result<Vec<Page>, Error> {
|
||||||
|
let pool = pool.clone();
|
||||||
|
|
||||||
|
let conn = web::block(move || pool.get())
|
||||||
|
.await?
|
||||||
|
.map_err(error::ErrorInternalServerError)?;
|
||||||
|
|
||||||
|
web::block(move || {
|
||||||
|
let mut stmt = conn
|
||||||
|
.prepare("SELECT page_name, page_text from pages WHERE active=true and page_name=?")?;
|
||||||
|
|
||||||
|
stmt.query_map([pagename], |row| {
|
||||||
|
Ok(Page {
|
||||||
|
page_name: row.get(0)?,
|
||||||
|
page_text: row.get(1)?,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.and_then(Iterator::collect)
|
||||||
|
})
|
||||||
|
.await?
|
||||||
|
.map_err(error::ErrorInternalServerError)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn update_page(pool: &Pool, page_name: String, page_text: String) -> Result<usize, Error> {
|
||||||
|
let pool = pool.clone();
|
||||||
|
|
||||||
|
let conn = web::block(move || pool.get())
|
||||||
|
.await?
|
||||||
|
.map_err(error::ErrorInternalServerError)?;
|
||||||
|
|
||||||
|
web::block(move || {
|
||||||
|
let mut stmt = conn
|
||||||
|
.prepare("insert or replace into pages (page_name, page_text, active) values (?, ?, true)")?;
|
||||||
|
stmt.execute([page_name, page_text, ])
|
||||||
|
})
|
||||||
|
.await?
|
||||||
|
.map_err(error::ErrorInternalServerError)
|
||||||
|
}
|
||||||
|
|
||||||
@ -1,4 +1,4 @@
|
|||||||
pub mod page;
|
pub mod page;
|
||||||
pub mod index;
|
pub mod index;
|
||||||
pub mod commons;
|
pub mod commons;
|
||||||
pub mod database;
|
pub mod db;
|
||||||
|
After Width: | Height: | Size: 11 KiB |
Loading…
Reference in new issue