1
0
mirror of https://github.com/actix/examples synced 2025-04-22 08:34:52 +02:00

build: updated from main

This commit is contained in:
Alex Ted 2025-02-08 20:49:01 +03:00
parent 661438af4a
commit dbea1221d8
4 changed files with 41 additions and 7 deletions

36
Cargo.lock generated
View File

@ -2640,7 +2640,7 @@ version = "1.0.0"
dependencies = [ dependencies = [
"actix-web", "actix-web",
"env_logger", "env_logger",
"redis 0.27.6", "redis 0.28.2",
"serde", "serde",
"tracing", "tracing",
] ]
@ -6578,6 +6578,29 @@ dependencies = [
"pin-project-lite", "pin-project-lite",
"ryu", "ryu",
"sha1_smol", "sha1_smol",
"tokio",
"tokio-util",
"url",
]
[[package]]
name = "redis"
version = "0.28.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e37ec3fd44bea2ec947ba6cc7634d7999a6590aca7c35827c250bc0de502bda6"
dependencies = [
"arc-swap",
"backon",
"bytes",
"combine",
"futures-channel",
"futures-util",
"itoa",
"num-bigint",
"percent-encoding",
"pin-project-lite",
"ryu",
"sha1_smol",
"socket2", "socket2",
"tokio", "tokio",
"tokio-util", "tokio-util",
@ -10056,6 +10079,17 @@ dependencies = [
"syn 2.0.98", "syn 2.0.98",
] ]
[[package]]
name = "zerocopy-derive"
version = "0.8.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06718a168365cad3d5ff0bb133aad346959a2074bd4a85c121255a11304a8626"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.93",
]
[[package]] [[package]]
name = "zerofrom" name = "zerofrom"
version = "0.1.5" version = "0.1.5"

View File

@ -110,7 +110,7 @@ openssl = { version = "0.10.60", features = ["v110"] }
parking_lot = "0.12" parking_lot = "0.12"
pin-project-lite = "0.2" pin-project-lite = "0.2"
rand = "0.9" rand = "0.9"
redis = { version = "0.27" } redis = { version = "0.28" }
reqwest = { version = "0.12", features = ["json", "stream"] } reqwest = { version = "0.12", features = ["json", "stream"] }
rustls = "0.23" rustls = "0.23"
rustls-pemfile = "2" rustls-pemfile = "2"

View File

@ -9,7 +9,7 @@ use diesel_async::RunQueryDsl;
type DbError = Box<dyn std::error::Error + Send + Sync>; type DbError = Box<dyn std::error::Error + Send + Sync>;
// /// Run query using Diesel to find item by uid and return it. // /// Run query using Diesel to find item by uid and return it.
pub async fn find_item_by_uid( pub async fn find_item_by_id(
conn: &mut AsyncPgConnection, conn: &mut AsyncPgConnection,
uid: Uuid, uid: Uuid,
) -> Result<Option<models::Item>, DbError> { ) -> Result<Option<models::Item>, DbError> {

View File

@ -24,16 +24,16 @@ type DbPool = Pool<AsyncPgConnection>;
#[get("/items/{item_id}")] #[get("/items/{item_id}")]
async fn get_item( async fn get_item(
pool: web::Data<DbPool>, pool: web::Data<DbPool>,
item_uid: web::Path<Uuid>, item_id: web::Path<Uuid>,
) -> actix_web::Result<impl Responder> { ) -> actix_web::Result<impl Responder> {
let item_uid = item_uid.into_inner(); let item_id = item_id.into_inner();
let mut conn = pool let mut conn = pool
.get() .get()
.await .await
.expect("Couldn't get db connection from the pool"); .expect("Couldn't get db connection from the pool");
let item = actions::find_item_by_uid(&mut conn, item_uid) let item = actions::find_item_by_id(&mut conn, item_id)
.await .await
// map diesel query errors to a 500 error response // map diesel query errors to a 500 error response
.map_err(error::ErrorInternalServerError)?; .map_err(error::ErrorInternalServerError)?;
@ -43,7 +43,7 @@ async fn get_item(
Some(item) => HttpResponse::Ok().json(item), Some(item) => HttpResponse::Ok().json(item),
// item was not found; return 404 response with error message // item was not found; return 404 response with error message
None => HttpResponse::NotFound().body(format!("No item found with UID: {item_uid}")), None => HttpResponse::NotFound().body(format!("No item found with UID: {item_id}")),
}) })
} }