summaryrefslogtreecommitdiff
path: root/src/repository
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2021-03-14 00:39:27 +0100
committerSanto Cariotti <santo@dcariotti.me>2021-03-14 00:39:27 +0100
commit3232579f29d1c91e70e7dc76305d6589c4acbaae (patch)
tree94800b34135dc3e0017675306629655a006c593b /src/repository
parent6a901654fac3952c953bafd4ac378ba1ebc648c3 (diff)
chore: get repos error in json mode
Diffstat (limited to 'src/repository')
-rw-r--r--src/repository/routes.rs18
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)))
}