summaryrefslogtreecommitdiff
path: root/src/commit/routes.rs
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2021-03-23 21:35:31 +0100
committerGitHub <noreply@github.com>2021-03-23 21:35:31 +0100
commit005e85c170890e12df4fe407b27a539a4c9d963a (patch)
treed9b75bf40fd8997067118ef3001badbd13644ba5 /src/commit/routes.rs
parent5a99c285de3a5cb9c44a5495c6bf2766259f7ecb (diff)
parent97ffa100d67ac1ea7fdec1f4a720447a15476e70 (diff)
Merge pull request #22 from gico-net/feat/search-commit
Search commits with "LIKE"
Diffstat (limited to 'src/commit/routes.rs')
-rw-r--r--src/commit/routes.rs20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/commit/routes.rs b/src/commit/routes.rs
index 95a74a2..a1da519 100644
--- a/src/commit/routes.rs
+++ b/src/commit/routes.rs
@@ -4,12 +4,26 @@ use crate::errors::{AppError, AppErrorResponse, AppErrorType};
use actix_web::http::header;
use actix_web::{web, HttpRequest, HttpResponse, Responder};
use slog::info;
+use std::collections::HashMap;
use std::env;
/// Endpoint used for getting all commits
-async fn index(state: web::Data<AppState>) -> impl Responder {
- info!(state.log, "GET /commit/");
- let result = Commit::find_all(state.pool.clone()).await;
+async fn index(
+ req: HttpRequest,
+ state: web::Data<AppState>,
+) -> impl Responder {
+ let query =
+ web::Query::<HashMap<String, String>>::from_query(req.query_string())
+ .unwrap();
+
+ let hash = match query.get("q") {
+ Some(x) => x.clone(),
+ None => String::new(),
+ };
+
+ info!(state.log, "GET /commit/?q={}", &hash);
+
+ let result = Commit::find_all(state.pool.clone(), &hash).await;
match result {
Ok(commits) => HttpResponse::Ok().json(commits),