This commit is contained in:
Greg Burri 2023-04-10 09:35:10 +02:00
parent e7d2f8f6c7
commit 57d7e7a3ce
17 changed files with 608 additions and 500 deletions

View file

@ -117,6 +117,7 @@ impl Connection {
fn get(&self) -> Result<PooledConnection<SqliteConnectionManager>> {
let con = self.pool.get()?;
// ('foreign_keys' is ON by default).
con.pragma_update(None, "synchronous", "NORMAL")?;
Ok(con)
}
@ -124,13 +125,12 @@ impl Connection {
/// Called after the connection has been established for creating or updating the database.
/// The 'Version' table tracks the current state of the database.
fn create_or_update_db(&self) -> Result<()> {
// Check the Database version.
let mut con = self.get()?;
con.pragma_update(None, "journal_mode", "WAL")?;
con.pragma_update(None, "journal_mode", "WAL")?; // Note: use "WAL2" when available.
let tx = con.transaction()?;
// Version 0 corresponds to an empty database.
// Check current database version. (Version 0 corresponds to an empty database).
let mut version = {
match tx.query_row(
"SELECT [name] FROM [sqlite_master] WHERE [type] = 'table' AND [name] = 'Version'",
@ -456,11 +456,14 @@ impl Connection {
match con
.query_row(
"SELECT [Recipe].[id] FROM [Recipe]
INNER JOIN [Image] ON [Image].[recipe_id] = [Recipe].[id]
INNER JOIN [Group] ON [Group].[recipe_id] = [Recipe].[id]
WHERE [Recipe].[user_id] = ?1
AND [Recipe].[estimate_time] = NULL
AND [Recipe].[description] = NULL",
LEFT JOIN [Image] ON [Image].[recipe_id] = [Recipe].[id]
LEFT JOIN [Group] ON [Group].[recipe_id] = [Recipe].[id]
WHERE [Recipe].[user_id] = ?1
AND [Recipe].[title] = ''
AND [Recipe].[estimate_time] IS NULL
AND [Recipe].[description] = ''
AND [Image].[id] IS NULL
AND [Group].[id] IS NULL",
[user_id],
|r| Ok(r.get::<&str, i64>("id")?),
)

View file

@ -50,6 +50,9 @@ async fn main() -> std::io::Result<()> {
.service(services::sign_out)
.service(services::view_recipe)
.service(services::edit_recipe)
.service(services::new_recipe)
.service(services::webapi::set_recipe_title)
.service(services::webapi::set_recipe_description)
.service(fs::Files::new("/static", "static"))
.default_service(web::to(services::not_found))
});

View file

@ -18,7 +18,7 @@ use crate::{
email, model, utils,
};
mod api;
pub mod webapi;
///// UTILS /////
@ -255,7 +255,6 @@ pub async fn edit_recipe(
#[get("/recipe/new")]
pub async fn new_recipe(
req: HttpRequest,
path: web::Path<(i64,)>,
connection: web::Data<db::Connection>,
) -> Result<HttpResponse> {
let user = match get_current_user(&req, connection.clone()).await {