diff options
author | Santo Cariotti <santo@dcariotti.me> | 2021-03-24 20:58:39 +0100 |
---|---|---|
committer | Santo Cariotti <santo@dcariotti.me> | 2021-03-24 20:58:39 +0100 |
commit | 06103e396a428ab693ee48df93236602114924b7 (patch) | |
tree | 3d37cd79664d15f3ba57a5ae2ce82aaba4127171 /src/commit/routes.rs | |
parent | 005e85c170890e12df4fe407b27a539a4c9d963a (diff) |
feat: add endpoint to search commits by repository
Diffstat (limited to 'src/commit/routes.rs')
-rw-r--r-- | src/commit/routes.rs | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/src/commit/routes.rs b/src/commit/routes.rs index a1da519..542edbb 100644 --- a/src/commit/routes.rs +++ b/src/commit/routes.rs @@ -21,9 +21,31 @@ async fn index( None => String::new(), }; - info!(state.log, "GET /commit/?q={}", &hash); + let repo_user = match query.get("repository_user") { + Some(x) => x.clone(), + None => String::new(), + }; + let repo_name = match query.get("repository_name") { + Some(x) => x.clone(), + None => String::new(), + }; - let result = Commit::find_all(state.pool.clone(), &hash).await; + let result; + if repo_user != "" && repo_name != "" { + info!( + state.log, + "GET /commit/?repository_user={}&repository_name={}", + &repo_user, + &repo_name + ); + let repository_url = format!("{}/{}", repo_user, repo_name); + result = + Commit::find_by_repository(state.pool.clone(), repository_url) + .await; + } else { + info!(state.log, "GET /commit/?q={}", &hash); + result = Commit::find_all(state.pool.clone(), &hash).await; + } match result { Ok(commits) => HttpResponse::Ok().json(commits), |