add post method

This commit is contained in:
mpostma 2020-05-28 19:37:54 +02:00
parent 8cd224899c
commit 3e13e728aa

View File

@ -3,7 +3,7 @@ use std::collections::{HashSet, HashMap};
use log::warn; use log::warn;
use actix_web::web; use actix_web::web;
use actix_web::HttpResponse; use actix_web::HttpResponse;
use actix_web_macros::get; use actix_web_macros::{get, post};
use serde::Deserialize; use serde::Deserialize;
use serde_json::Value; use serde_json::Value;
@ -36,6 +36,26 @@ struct SearchQuery {
facets_distribution: Option<String>, facets_distribution: Option<String>,
} }
#[get("/indexes/{index_uid}/search", wrap = "Authentication::Public")]
async fn search_with_url_query(
data: web::Data<Data>,
path: web::Path<IndexParam>,
params: web::Query<SearchQuery>,
) -> Result<HttpResponse, ResponseError> {
let search_result = params.search(&path.index_uid, data)?;
Ok(HttpResponse::Ok().json(search_result))
}
#[post("/indexes/{index_uid}/search", wrap = "Authentication::Public")]
async fn search_with_post(
data: web::Data<Data>,
path: web::Path<IndexParam>,
params: web::Query<SearchQuery>,
) -> Result<HttpResponse, ResponseError> {
let search_result = params.search(&path.index_uid, data)?;
Ok(HttpResponse::Ok().json(search_result))
}
impl SearchQuery { impl SearchQuery {
fn search(&self, index_uid: &str, data: web::Data<Data>) -> Result<SearchResult, ResponseError> { fn search(&self, index_uid: &str, data: web::Data<Data>) -> Result<SearchResult, ResponseError> {
let index = data let index = data
@ -157,15 +177,6 @@ impl SearchQuery {
} }
} }
#[get("/indexes/{index_uid}/search", wrap = "Authentication::Public")]
async fn search_with_url_query(
data: web::Data<Data>,
path: web::Path<IndexParam>,
params: web::Query<SearchQuery>,
) -> Result<HttpResponse, ResponseError> {
let search_result = params.search(&path.index_uid, data)?;
Ok(HttpResponse::Ok().json(search_result))
}
/// Parses the incoming string into an array of attributes for which to return a count. It returns /// Parses the incoming string into an array of attributes for which to return a count. It returns
/// a Vec of attribute names ascociated with their id. /// a Vec of attribute names ascociated with their id.