summaryrefslogtreecommitdiff
path: root/src/repository/routes.rs
blob: ebfff8e1cde1c87c01c7e25a903da717812b1916 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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)));
}