1
0
mirror of https://github.com/actix/examples synced 2025-06-26 17:17:42 +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

View File

@ -9,7 +9,7 @@ use diesel_async::RunQueryDsl;
type DbError = Box<dyn std::error::Error + Send + Sync>;
// /// 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,
uid: Uuid,
) -> Result<Option<models::Item>, DbError> {

View File

@ -24,16 +24,16 @@ type DbPool = Pool<AsyncPgConnection>;
#[get("/items/{item_id}")]
async fn get_item(
pool: web::Data<DbPool>,
item_uid: web::Path<Uuid>,
item_id: web::Path<Uuid>,
) -> actix_web::Result<impl Responder> {
let item_uid = item_uid.into_inner();
let item_id = item_id.into_inner();
let mut conn = pool
.get()
.await
.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
// map diesel query errors to a 500 error response
.map_err(error::ErrorInternalServerError)?;
@ -43,7 +43,7 @@ async fn get_item(
Some(item) => HttpResponse::Ok().json(item),
// 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}")),
})
}