diff options
author | Santo Cariotti <santo@dcariotti.me> | 2021-03-17 09:15:15 +0100 |
---|---|---|
committer | Santo Cariotti <santo@dcariotti.me> | 2021-03-17 09:15:15 +0100 |
commit | bc9a0de90f0463b59e69e6bb2f2e75f3c29062e5 (patch) | |
tree | fae30f2cd8f008321d5abe0c409fe4f0e829df76 /src/commit/routes.rs | |
parent | eda7ce792c9875a437314924f90d66a37d81a1bb (diff) |
feat: add commit models and get all of them
Diffstat (limited to 'src/commit/routes.rs')
-rw-r--r-- | src/commit/routes.rs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/commit/routes.rs b/src/commit/routes.rs new file mode 100644 index 0000000..bf04108 --- /dev/null +++ b/src/commit/routes.rs @@ -0,0 +1,28 @@ +use crate::commit::models::Commit; +use crate::config::AppState; +use crate::errors::AppErrorResponse; + +use actix_web::{web, HttpResponse, Responder}; +use slog::info; + +/// Endpoint used for getting all commits +async fn index(state: web::Data<AppState>) -> impl Responder { + info!(state.log, "GET /commit/"); + let result = Commit::find_all(state.pool.clone()).await; + + match result { + Ok(commits) => HttpResponse::Ok().json(commits), + _ => HttpResponse::BadRequest().json(AppErrorResponse { + detail: "Error trying to read all commits from database" + .to_string(), + }), + } +} + +/// Routes for commits +pub fn config(cfg: &mut web::ServiceConfig) { + cfg.service( + web::scope("/commit") + .service(web::resource("{_:/?}").route(web::get().to(index))), + ); +} |