Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Wulf committed Jan 15, 2024
1 parent 34bf6c0 commit c3e5548
Show file tree
Hide file tree
Showing 15 changed files with 49 additions and 1,326 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion create-rust-app/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "create-rust-app"
description = "Set up a modern rust+react web app by running one command."
version = "10.0.0"
version = "11.0.0"
edition = "2018"
authors = ["Haris <[email protected]>"]
readme = "../README.md"
Expand Down
2 changes: 1 addition & 1 deletion create-rust-app_cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "create-rust-app_cli"
description = "Set up a modern rust+react web app by running one command."
version = "10.0.0"
version = "11.0.0"
authors = ["Haris <[email protected]>"]
edition = "2018"
readme = "../README.md"
Expand Down
3 changes: 2 additions & 1 deletion create-rust-app_cli/src/content/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ struct Asset;
// version.to_string()
// }
fn get_current_cra_lib_version() -> String {
"10.0.0".to_string()
"11.0.0".to_string()
}

#[derive(Clone)]
Expand Down Expand Up @@ -411,6 +411,7 @@ pub fn create(project_name: &str, creation_options: CreationOptions) -> Result<(
)?;
}
}
add_dependency(&project_dir, "simple_logger", r#"simple_logger = "4.3.3""#)?;
add_dependency(&project_dir, "futures-util", r#"futures-util = "0.3.21""#)?;
add_dependency(
&project_dir,
Expand Down
6 changes: 3 additions & 3 deletions create-rust-app_cli/src/plugins/graphql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ ReactDOM.createRoot"#,
"frontend/package.json",
r#""dependencies": {"#,
r#""dependencies": {
"@apollo/client": "^3.5.10",
"graphql-ws": "^5.6.4",
"graphql": "^16.3.0","#,
"@apollo/client": "^5.14.3",
"graphql-ws": "^5.14.3",
"graphql": "^16.8.1","#,
)?;

fs::replace("backend/main.rs", "mod mail;", "mod mail;\nmod graphql;")?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct FileInfo {

#[actix_web::get("")]
async fn all(db: Data<Database>, storage: Data<Storage>) -> HttpResponse {
let mut db = db.pool.get().unwrap();
let mut db = db.get_connection().unwrap();
let files = Attachment::find_all_for_record(&mut db, "file".to_string(), "NULL".to_string(), 0).unwrap_or_default();
let blob_ids = files.iter().map(|f| f.blob_id).collect::<Vec<_>>();
let blobs = AttachmentBlob::find_all_by_id(&mut db, blob_ids).unwrap_or_default();
Expand All @@ -42,7 +42,7 @@ async fn all(db: Data<Database>, storage: Data<Storage>) -> HttpResponse {

#[actix_web::delete("/{id}")]
async fn delete(db: Data<Database>, storage: Data<Storage>, file_id: Path<i32>) -> HttpResponse {
let mut db = db.pool.get().unwrap();
let mut db = db.get_connection().unwrap();
let file_id = file_id.into_inner();

let detach_op = Attachment::detach(&mut db, &storage, file_id).await;
Expand All @@ -56,7 +56,7 @@ async fn delete(db: Data<Database>, storage: Data<Storage>, file_id: Path<i32>)

#[actix_web::post("")]
async fn create(db: Data<Database>, store: Data<Storage>, mut payload: Multipart) -> HttpResponse {
let mut db = db.pool.get().unwrap();
let mut db = db.get_connection().unwrap();

while let Some(item) = payload.next().await {
let mut field = if item.is_ok() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use create_rust_app::Connection;
use fang::{FangError, Queueable, Scheduled};
use fang::PgConnection;
use fang::Runnable;
use fang::serde::{Deserialize, Serialize};
use fang::typetag;
use fang::PgConnection;
use fang::Runnable;
use fang::{FangError, Queueable, Scheduled};

use crate::models::todos::{CreateTodo, Todo};

Expand All @@ -19,11 +19,15 @@ impl Runnable for DailyTodo {
println!("Adding daily todo {}", self.text);
let db = create_rust_app::Database::new();

let con = &mut db.get_connection();
let con = &mut db.get_connection().unwrap();

Todo::create(con, &CreateTodo {
text: self.text.clone(),
}).unwrap();
Todo::create(
con,
&CreateTodo {
text: self.text.clone(),
},
)
.unwrap();

Ok(())
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use fang::{AsyncRunnable, FangError, Scheduled, typetag};
use fang::async_trait;
use fang::asynk::async_queue::AsyncQueueable;
use fang::serde::{Deserialize, Serialize};
use fang::async_trait;
use fang::{typetag, AsyncRunnable, FangError, Scheduled};

use crate::models::todos::{CreateTodo, Todo};

Expand All @@ -18,11 +18,15 @@ impl AsyncRunnable for DailyTodoAsync {
println!("(async) Adding daily todo {}", self.text);
let db = create_rust_app::Database::new();

let con = &mut db.get_connection();
let con = &mut db.get_connection().unwrap();

Todo::create(con, &CreateTodo {
text: self.text.clone(),
}).unwrap();
Todo::create(
con,
&CreateTodo {
text: self.text.clone(),
},
)
.unwrap();

Ok(())
}
Expand All @@ -33,7 +37,6 @@ impl AsyncRunnable for DailyTodoAsync {
"async".to_string()
}


// If `uniq` is set to true and the task is already in the storage, it won't be inserted again
// The existing record will be returned for for any insertions operation
fn uniq(&self) -> bool {
Expand Down
1 change: 1 addition & 0 deletions create-rust-app_cli/template/.env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
RUST_LOG=debug
SECRET_KEY=secret
DATABASE_URL=postgres://postgres:postgres@localhost/database
RUST_BACKTRACE=1
Expand Down
1 change: 1 addition & 0 deletions create-rust-app_cli/template/backend/main.rs+actix_web
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ mod mail;
async fn main() -> std::io::Result<()> {
#[cfg(debug_assertions)] create_rust_app::setup_development().await;
let app_data = create_rust_app::setup();
simple_logger::init_with_env().unwrap();

HttpServer::new(move || {
let mut app = App::new()
Expand Down
1 change: 1 addition & 0 deletions create-rust-app_cli/template/backend/main.rs+poem
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ async fn main() -> Result<(), std::io::Error> {
tracing_subscriber::fmt::init();

let data = create_rust_app::setup();
simple_logger::init_with_env().unwrap();

let mut api_routes = Route::new();
api_routes = api_routes.nest("/todos", services::todo::api());
Expand Down
10 changes: 5 additions & 5 deletions create-rust-app_cli/template/backend/services/todo.rs+actix_web
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ async fn index(
db: Data<Database>,
Query(info): Query<PaginationParams>,
) -> HttpResponse {
let mut con = db.get_connection();
let mut con = db.get_connection().unwrap();

let result = Todo::paginate(&mut con, info.page, info.page_size);

Expand All @@ -30,7 +30,7 @@ async fn read(
db: Data<Database>,
item_id: Path<i32>,
) -> HttpResponse {
let mut con = db.get_connection();
let mut con = db.get_connection().unwrap();

let result = Todo::read(&mut con, item_id.into_inner());

Expand All @@ -48,7 +48,7 @@ async fn create(
db: Data<Database>,
Json(item): Json<CreateTodo>,
) -> Result<HttpResponse, Error> {
let mut con = db.get_connection();
let mut con = db.get_connection().unwrap();

let result = Todo::create(&mut con, &item).expect("Creation error");

Expand All @@ -61,7 +61,7 @@ async fn update(
item_id: Path<i32>,
Json(item): Json<UpdateTodo>,
) -> HttpResponse {
let mut con = db.get_connection();
let mut con = db.get_connection().unwrap();

let result = Todo::update(&mut con, item_id.into_inner(), &item);

Expand All @@ -77,7 +77,7 @@ async fn destroy(
db: Data<Database>,
item_id: Path<i32>,
) -> HttpResponse {
let mut con = db.get_connection();
let mut con = db.get_connection().unwrap();

let result = Todo::delete(&mut con, item_id.into_inner());

Expand Down
10 changes: 5 additions & 5 deletions create-rust-app_cli/template/backend/services/todo.rs+poem
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async fn index(
db: Data<&Database>,
Query(pagination): Query<PaginationParams>,
) -> Result<impl IntoResponse> {
let mut con = db.get_connection();
let mut con = db.get_connection().unwrap();

let result = Todo::paginate(&mut con, pagination.page, pagination.page_size)
.map(|items| Json(items))
Expand All @@ -31,7 +31,7 @@ async fn index(

#[handler]
async fn read(db: Data<&Database>, Path(item_id): Path<i32>) -> Result<impl IntoResponse> {
let mut con = db.get_connection();
let mut con = db.get_connection().unwrap();

let result = Todo::read(&mut con, item_id)
.map(|item| Json(item))
Expand All @@ -45,7 +45,7 @@ async fn create(
db: Data<&Database>,
Json(item): Json<CreateTodo>,
) -> Result<impl IntoResponse> {
let mut con = db.get_connection();
let mut con = db.get_connection().unwrap();

let result = Todo::create(&mut con, &item)
.map(|item| Json(item))
Expand All @@ -60,7 +60,7 @@ async fn update(
Path(item_id): Path<i32>,
Json(item): Json<UpdateTodo>,
) -> Result<impl IntoResponse> {
let mut con = db.get_connection();
let mut con = db.get_connection().unwrap();

let result = Todo::update(&mut con, item_id, &item)
.map(|item| Json(item))
Expand All @@ -71,7 +71,7 @@ async fn update(

#[handler]
async fn destroy(db: Data<&Database>, Path(item_id): Path<i32>) -> Result<impl IntoResponse> {
let mut con = db.get_connection();
let mut con = db.get_connection().unwrap();

let result = Todo::delete(&mut con, item_id)
.map(|amount| {
Expand Down
Loading

0 comments on commit c3e5548

Please sign in to comment.