summaryrefslogtreecommitdiff
path: root/src/commit/routes.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/commit/routes.rs')
-rw-r--r--src/commit/routes.rs20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/commit/routes.rs b/src/commit/routes.rs
index bf04108..1b73c4f 100644
--- a/src/commit/routes.rs
+++ b/src/commit/routes.rs
@@ -19,10 +19,28 @@ async fn index(state: web::Data<AppState>) -> impl Responder {
}
}
+// Endpoint used for getting one commit
+async fn get_commit(
+ state: web::Data<AppState>,
+ hash: web::Path<(String,)>,
+) -> impl Responder {
+ info!(state.log, "GET /commit/{}/", &hash.0);
+
+ let result = Commit::find(state.pool.clone(), hash.0.clone()).await;
+
+ result
+ .map(|commit| HttpResponse::Ok().json(commit))
+ .map_err(|e| e)
+}
+
/// Routes for commits
pub fn config(cfg: &mut web::ServiceConfig) {
cfg.service(
web::scope("/commit")
- .service(web::resource("{_:/?}").route(web::get().to(index))),
+ .service(web::resource("{_:/?}").route(web::get().to(index)))
+ .service(
+ web::resource("/{hash}{_:/?}")
+ .route(web::get().to(get_commit)),
+ ),
);
}