From 97ffa100d67ac1ea7fdec1f4a720447a15476e70 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Tue, 23 Mar 2021 21:33:55 +0100 Subject: feat: search more than one commit --- src/commit/routes.rs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'src/commit/routes.rs') 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) -> impl Responder { - info!(state.log, "GET /commit/"); - let result = Commit::find_all(state.pool.clone()).await; +async fn index( + req: HttpRequest, + state: web::Data, +) -> impl Responder { + let query = + web::Query::>::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), -- cgit v1.2.3-18-g5258