diff options
author | Santo Cariotti <santo@dcariotti.me> | 2021-03-14 13:00:59 +0100 |
---|---|---|
committer | Santo Cariotti <santo@dcariotti.me> | 2021-03-14 13:00:59 +0100 |
commit | 6afd0e59f62889d44b90193f0d8581668eae9c28 (patch) | |
tree | 36b1b950c49a3e51832f984938e2b76fedd5b2c6 /src | |
parent | 6acc53da212e7506fd33534fd5cf9baa0d01e4ea (diff) |
fix: parse uuid fields for get repo
Diffstat (limited to 'src')
-rw-r--r-- | src/repository/routes.rs | 12 |
1 files changed, 10 insertions, 2 deletions
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<AppState>) -> impl Responder { /// It is a String, casted in an Uuid format. async fn get_repo( state: web::Data<AppState>, - 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 |