summaryrefslogtreecommitdiff
path: root/src/repository
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2021-03-14 13:00:59 +0100
committerSanto Cariotti <santo@dcariotti.me>2021-03-14 13:00:59 +0100
commit6afd0e59f62889d44b90193f0d8581668eae9c28 (patch)
tree36b1b950c49a3e51832f984938e2b76fedd5b2c6 /src/repository
parent6acc53da212e7506fd33534fd5cf9baa0d01e4ea (diff)
fix: parse uuid fields for get repo
Diffstat (limited to 'src/repository')
-rw-r--r--src/repository/routes.rs12
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