From bc9a0de90f0463b59e69e6bb2f2e75f3c29062e5 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Wed, 17 Mar 2021 09:15:15 +0100 Subject: feat: add commit models and get all of them --- src/commit/routes.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/commit/routes.rs (limited to 'src/commit/routes.rs') 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) -> 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))), + ); +} -- cgit v1.2.3-18-g5258