mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-07-27 00:31:02 +00:00
WIP jayson integration
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
use actix_web::{dev::Payload, web::Json, FromRequest, HttpRequest};
|
||||
use futures::ready;
|
||||
use jayson::{DeserializeError, DeserializeFromValue};
|
||||
use meilisearch_types::error::{Code, ErrorCode, ResponseError};
|
||||
use meilisearch_types::error::{ErrorCode, ResponseError};
|
||||
use std::{
|
||||
fmt::Debug,
|
||||
future::Future,
|
||||
@ -34,7 +34,7 @@ where
|
||||
E: DeserializeError + ErrorCode + 'static,
|
||||
T: DeserializeFromValue<E>,
|
||||
{
|
||||
type Error = ResponseError;
|
||||
type Error = actix_web::Error;
|
||||
type Future = ValidatedJsonExtractFut<T, E>;
|
||||
|
||||
#[inline]
|
||||
@ -56,7 +56,7 @@ where
|
||||
T: DeserializeFromValue<E>,
|
||||
E: DeserializeError + ErrorCode + 'static,
|
||||
{
|
||||
type Output = Result<ValidatedJson<T, E>, ResponseError>;
|
||||
type Output = Result<ValidatedJson<T, E>, actix_web::Error>;
|
||||
|
||||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
let this = self.get_mut();
|
||||
@ -64,13 +64,10 @@ where
|
||||
let res = ready!(Pin::new(&mut this.fut).poll(cx));
|
||||
|
||||
let res = match res {
|
||||
Err(err) => Err(ResponseError::from_msg(
|
||||
format!("{err}"),
|
||||
Code::MalformedPayload,
|
||||
)),
|
||||
Err(err) => Err(err),
|
||||
Ok(data) => match jayson::deserialize::<_, _, E>(data.into_inner()) {
|
||||
Ok(data) => Ok(ValidatedJson::new(data)),
|
||||
Err(e) => Err(e.into()),
|
||||
Err(e) => Err(ResponseError::from(e).into()),
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -1,5 +1,9 @@
|
||||
use log::debug;
|
||||
|
||||
use crate::analytics::Analytics;
|
||||
use crate::extractors::authentication::{policies::*, GuardedData};
|
||||
use crate::extractors::jayson::ValidatedJson;
|
||||
use crate::task::SummarizedTaskView;
|
||||
use actix_web::{web, HttpRequest, HttpResponse};
|
||||
use meilisearch_lib::index::Settings;
|
||||
use meilisearch_lib::index_controller::Update;
|
||||
@ -7,11 +11,6 @@ use meilisearch_lib::MeiliSearch;
|
||||
use meilisearch_types::error::{MeiliDeserError, ResponseError};
|
||||
use serde_json::json;
|
||||
|
||||
use crate::analytics::Analytics;
|
||||
use crate::extractors::authentication::{policies::*, GuardedData};
|
||||
use crate::extractors::jayson::ValidatedJson;
|
||||
use crate::task::SummarizedTaskView;
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! make_setting_route {
|
||||
($route:literal, $update_verb:ident, $type:ty, $attr:ident, $camelcase_attr:literal, $analytics_var:ident, $analytics:expr) => {
|
||||
@ -55,7 +54,10 @@ macro_rules! make_setting_route {
|
||||
pub async fn update(
|
||||
meilisearch: GuardedData<ActionPolicy<{ actions::SETTINGS_UPDATE }>, MeiliSearch>,
|
||||
index_uid: actix_web::web::Path<String>,
|
||||
body: actix_web::web::Json<Option<$type>>,
|
||||
body: crate::extractors::jayson::ValidatedJson<
|
||||
Option<$type>,
|
||||
meilisearch_types::error::MeiliDeserError,
|
||||
>,
|
||||
req: HttpRequest,
|
||||
$analytics_var: web::Data<dyn Analytics>,
|
||||
) -> std::result::Result<HttpResponse, ResponseError> {
|
||||
|
Reference in New Issue
Block a user