Update to latest actix-web

This commit is contained in:
LukeMathWalker 2021-07-11 16:10:55 +01:00
parent b5faa745f1
commit 203a796cfe
3 changed files with 317 additions and 239 deletions

525
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -13,13 +13,11 @@ path = "src/main.rs"
name = "zero2prod" name = "zero2prod"
[dependencies] [dependencies]
actix-http = "=3.0.0-beta.5" actix-web = "=4.0.0-beta.8"
actix-service = "=2.0.0-beta.5" actix-http = "=3.0.0-beta.8"
actix-web = "=4.0.0-beta.5"
serde = "1.0.115" serde = "1.0.115"
config = { version = "0.10.1", default-features = false, features = ["yaml"] } config = { version = "0.10.1", default-features = false, features = ["yaml"] }
sqlx = { version = "0.5.1", default-features = false, features = [ "runtime-actix-rustls", "macros", "postgres", "uuid", "chrono", "migrate", "offline"] } sqlx = { version = "0.5.5", default-features = false, features = [ "runtime-actix-rustls", "macros", "postgres", "uuid", "chrono", "migrate"] }
uuid = { version = "0.8.1", features = ["v4"] } uuid = { version = "0.8.1", features = ["v4"] }
chrono = "0.4.15" chrono = "0.4.15"
reqwest = { version = "0.11", default-features = false, features = ["json", "rustls-tls"] } reqwest = { version = "0.11", default-features = false, features = ["json", "rustls-tls"] }
@ -31,7 +29,7 @@ tracing-log = "0.1.1"
serde-aux = "1.0.1" serde-aux = "1.0.1"
unicode-segmentation = "1.7.1" unicode-segmentation = "1.7.1"
validator = "0.12.0" validator = "0.12.0"
tracing-actix-web = "0.4.0-beta.4" tracing-actix-web = "0.4.0-beta.8"
[dev-dependencies] [dev-dependencies]
once_cell = "1.7.2" once_cell = "1.7.2"

View file

@ -29,18 +29,15 @@ impl TryInto<NewSubscriber> for FormData {
name = %form.name name = %form.name
) )
)] )]
pub async fn subscribe( pub async fn subscribe(form: web::Form<FormData>, pool: web::Data<PgPool>) -> HttpResponse {
form: web::Form<FormData>, let new_subscriber = match form.0.try_into() {
pool: web::Data<PgPool>, Ok(form) => form,
) -> Result<HttpResponse, HttpResponse> { Err(_) => return HttpResponse::BadRequest().finish(),
let new_subscriber = form };
.0 match insert_subscriber(&pool, &new_subscriber).await {
.try_into() Ok(_) => HttpResponse::Ok().finish(),
.map_err(|_| HttpResponse::BadRequest().finish())?; Err(_) => HttpResponse::InternalServerError().finish(),
insert_subscriber(&pool, &new_subscriber) }
.await
.map_err(|_| HttpResponse::InternalServerError().finish())?;
Ok(HttpResponse::Ok().finish())
} }
#[tracing::instrument( #[tracing::instrument(