summaryrefslogtreecommitdiff
path: root/src/repository/routes.rs
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2021-03-14 12:55:21 +0100
committerSanto Cariotti <santo@dcariotti.me>2021-03-14 12:55:21 +0100
commit6acc53da212e7506fd33534fd5cf9baa0d01e4ea (patch)
treefa9c35bace83a46f74ae11ad23eb58f47eba2161 /src/repository/routes.rs
parentf7932c366bab2f5d0726f4d1cdf5b9dbeddf92eb (diff)
chore: add docs
Diffstat (limited to 'src/repository/routes.rs')
-rw-r--r--src/repository/routes.rs7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/repository/routes.rs b/src/repository/routes.rs
index 634d210..0683b47 100644
--- a/src/repository/routes.rs
+++ b/src/repository/routes.rs
@@ -5,9 +5,12 @@ use actix_web::{web, HttpResponse, Responder};
use slog::info;
use uuid::Uuid;
+/// Endpoint used for retrieve all repositories
async fn index(state: web::Data<AppState>) -> impl Responder {
let result = Repository::find_all(state.pool.clone()).await;
info!(state.log, "GET /repo/");
+
+ // If raises an `Err`, returns an error in JSON format
match result {
Ok(repos) => HttpResponse::Ok().json(repos),
_ => HttpResponse::BadRequest().json(AppErrorResponse {
@@ -17,12 +20,16 @@ async fn index(state: web::Data<AppState>) -> impl Responder {
}
}
+/// Endpoint used for retrieve a repository that matches with an `id`.
+/// It is a String, casted in an Uuid format.
async fn get_repo(
state: web::Data<AppState>,
id: web::Path<(Uuid,)>,
) -> impl Responder {
let result = Repository::find(state.pool.clone(), &id.0).await;
info!(state.log, "GET /repo/{}/", id.0);
+
+ // `map_err` is also used when repo is not found
result
.map(|repo| HttpResponse::Ok().json(repo))
.map_err(|e| e)