summaryrefslogtreecommitdiff
path: root/src/repository/routes.rs
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2021-03-13 10:17:02 +0100
committerSanto Cariotti <santo@dcariotti.me>2021-03-13 10:17:02 +0100
commit44a35e651741afb6c417da47d636e4380cdd225f (patch)
tree72302a7bea06350b1e7175a6dddb08daebbbb135 /src/repository/routes.rs
parent48a9ac895b6e8b01622810ec4bf2f3a423426ca3 (diff)
feat: add get all repos from db
Diffstat (limited to 'src/repository/routes.rs')
-rw-r--r--src/repository/routes.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/repository/routes.rs b/src/repository/routes.rs
new file mode 100644
index 0000000..ebfff8e
--- /dev/null
+++ b/src/repository/routes.rs
@@ -0,0 +1,23 @@
+use crate::config::AppState;
+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;
+ 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")
+ }
+ }
+}
+
+pub fn config(cfg: &mut web::ServiceConfig) {
+ cfg.service(web::resource("/repo/").route(web::get().to(index)));
+}