From 6afd0e59f62889d44b90193f0d8581668eae9c28 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Sun, 14 Mar 2021 13:00:59 +0100 Subject: fix: parse uuid fields for get repo --- src/repository/routes.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/repository') diff --git a/src/repository/routes.rs b/src/repository/routes.rs index 0683b47..56e42ab 100644 --- a/src/repository/routes.rs +++ b/src/repository/routes.rs @@ -24,9 +24,17 @@ async fn index(state: web::Data) -> impl Responder { /// It is a String, casted in an Uuid format. async fn get_repo( state: web::Data, - id: web::Path<(Uuid,)>, + id: web::Path<(String,)>, ) -> impl Responder { - let result = Repository::find(state.pool.clone(), &id.0).await; + // I have to match the &id.0 because if it's not a valid Uuid, the server + // must response "Repository not found". + // If I pass a not valid Uuid to Repository::find() it raises an error. + let uuid: Uuid = match Uuid::parse_str(&id.0) { + Ok(x) => x, + Err(_) => Uuid::parse_str("00000000000000000000000000000000").unwrap(), + }; + + let result = Repository::find(state.pool.clone(), &uuid).await; info!(state.log, "GET /repo/{}/", id.0); // `map_err` is also used when repo is not found -- cgit v1.2.3-18-g5258