Update to latest actix-web

This commit is contained in:
LukeMathWalker 2021-07-11 16:10:55 +01:00
parent 01d975dad9
commit 1fead190a7
3 changed files with 307 additions and 227 deletions

505
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"
[dependencies]
actix-http = "=3.0.0-beta.5"
actix-service = "=2.0.0-beta.5"
actix-web = "=4.0.0-beta.5"
actix-web = "=4.0.0-beta.8"
actix-http = "=3.0.0-beta.8"
serde = "1.0.115"
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"] }
chrono = "0.4.15"
tracing = "0.1.19"
@ -29,7 +27,7 @@ tracing-bunyan-formatter = "0.1.6"
tracing-log = "0.1.1"
serde-aux = "1.0.1"
unicode-segmentation = "1.7.1"
tracing-actix-web = "0.4.0-beta.4"
tracing-actix-web = "0.4.0-beta.8"
[dev-dependencies]
reqwest = { version = "0.11", features = ["json"] }

View file

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