From c79ba1e9dee9552415f8783b2fdc0372dfe395a8 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Sat, 20 Mar 2021 18:02:15 +0100 Subject: feat: add endpoint to get top authors --- src/commit/routes.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/commit/routes.rs') diff --git a/src/commit/routes.rs b/src/commit/routes.rs index 95c0faa..95a74a2 100644 --- a/src/commit/routes.rs +++ b/src/commit/routes.rs @@ -70,11 +70,24 @@ async fn delete_commit( .map_err(|e| e) } +/// Endpoint used for getting a raking of the post authors by commit number +async fn get_top_authors(state: web::Data) -> impl Responder { + info!(state.log, "GET /commit/top/"); + let result = Commit::most_authors(state.pool.clone()).await; + + result + .map(|authors| HttpResponse::Ok().json(authors)) + .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("/top/").route(web::get().to(get_top_authors)), + ) .service( web::resource("/{hash}/") .route(web::get().to(get_commit)) -- cgit v1.2.3-18-g5258