diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/repository/routes.rs | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/src/repository/routes.rs b/src/repository/routes.rs index ebfff8e..6b3a942 100644 --- a/src/repository/routes.rs +++ b/src/repository/routes.rs @@ -1,23 +1,21 @@ use crate::config::AppState; +use crate::errors::AppErrorResponse; use crate::repository::models::Repository; use actix_web::{web, HttpResponse, Responder}; use slog::info; async fn index(state: web::Data<AppState>) -> impl Responder { let result = Repository::find_all(state.pool.clone()).await; + info!(state.log, "GET /repo/"); match result { - Ok(repos) => { - info!(state.log, "GET /repo/ 200"); - HttpResponse::Ok().json(repos) - } - _ => { - info!(state.log, "GET /repo/ 500"); - HttpResponse::BadRequest() - .body("Error trying to read all repositories from database") - } + Ok(repos) => HttpResponse::Ok().json(repos), + _ => HttpResponse::BadRequest().json(AppErrorResponse { + detail: "Error trying to read all repositories from database" + .to_string(), + }), } } pub fn config(cfg: &mut web::ServiceConfig) { - cfg.service(web::resource("/repo/").route(web::get().to(index))); + cfg.service(web::resource("/repo{_:/?}").route(web::get().to(index))) } |