Update the /indexes/{indexUid}/settings/* verbs by adding a macro parameter

This commit is contained in:
Kerollmops 2022-06-02 11:53:16 +02:00
parent f8d3f739ad
commit 10a71fdb10
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4

View File

@ -13,7 +13,7 @@ use crate::task::SummarizedTaskView;
#[macro_export] #[macro_export]
macro_rules! make_setting_route { macro_rules! make_setting_route {
($route:literal, $type:ty, $attr:ident, $camelcase_attr:literal, $analytics_var:ident, $analytics:expr) => { ($route:literal, $update_verb:ident, $type:ty, $attr:ident, $camelcase_attr:literal, $analytics_var:ident, $analytics:expr) => {
pub mod $attr { pub mod $attr {
use actix_web::{web, HttpRequest, HttpResponse, Resource}; use actix_web::{web, HttpRequest, HttpResponse, Resource};
use log::debug; use log::debug;
@ -100,18 +100,27 @@ macro_rules! make_setting_route {
pub fn resources() -> Resource { pub fn resources() -> Resource {
Resource::new($route) Resource::new($route)
.route(web::get().to(SeqHandler(get))) .route(web::get().to(SeqHandler(get)))
.route(web::post().to(SeqHandler(update))) .route(web::$update_verb().to(SeqHandler(update)))
.route(web::delete().to(SeqHandler(delete))) .route(web::delete().to(SeqHandler(delete)))
} }
} }
}; };
($route:literal, $type:ty, $attr:ident, $camelcase_attr:literal) => { ($route:literal, $update_verb:ident, $type:ty, $attr:ident, $camelcase_attr:literal) => {
make_setting_route!($route, $type, $attr, $camelcase_attr, _analytics, |_, _| {}); make_setting_route!(
$route,
$update_verb,
$type,
$attr,
$camelcase_attr,
_analytics,
|_, _| {}
);
}; };
} }
make_setting_route!( make_setting_route!(
"/filterable-attributes", "/filterable-attributes",
put,
std::collections::BTreeSet<String>, std::collections::BTreeSet<String>,
filterable_attributes, filterable_attributes,
"filterableAttributes", "filterableAttributes",
@ -134,6 +143,7 @@ make_setting_route!(
make_setting_route!( make_setting_route!(
"/sortable-attributes", "/sortable-attributes",
put,
std::collections::BTreeSet<String>, std::collections::BTreeSet<String>,
sortable_attributes, sortable_attributes,
"sortableAttributes", "sortableAttributes",
@ -156,6 +166,7 @@ make_setting_route!(
make_setting_route!( make_setting_route!(
"/displayed-attributes", "/displayed-attributes",
put,
Vec<String>, Vec<String>,
displayed_attributes, displayed_attributes,
"displayedAttributes" "displayedAttributes"
@ -163,6 +174,7 @@ make_setting_route!(
make_setting_route!( make_setting_route!(
"/typo-tolerance", "/typo-tolerance",
patch,
meilisearch_lib::index::updates::TypoSettings, meilisearch_lib::index::updates::TypoSettings,
typo_tolerance, typo_tolerance,
"typoTolerance", "typoTolerance",
@ -204,6 +216,7 @@ make_setting_route!(
make_setting_route!( make_setting_route!(
"/searchable-attributes", "/searchable-attributes",
put,
Vec<String>, Vec<String>,
searchable_attributes, searchable_attributes,
"searchableAttributes", "searchableAttributes",
@ -225,6 +238,7 @@ make_setting_route!(
make_setting_route!( make_setting_route!(
"/stop-words", "/stop-words",
put,
std::collections::BTreeSet<String>, std::collections::BTreeSet<String>,
stop_words, stop_words,
"stopWords" "stopWords"
@ -232,6 +246,7 @@ make_setting_route!(
make_setting_route!( make_setting_route!(
"/synonyms", "/synonyms",
put,
std::collections::BTreeMap<String, Vec<String>>, std::collections::BTreeMap<String, Vec<String>>,
synonyms, synonyms,
"synonyms" "synonyms"
@ -239,6 +254,7 @@ make_setting_route!(
make_setting_route!( make_setting_route!(
"/distinct-attribute", "/distinct-attribute",
put,
String, String,
distinct_attribute, distinct_attribute,
"distinctAttribute" "distinctAttribute"
@ -246,6 +262,7 @@ make_setting_route!(
make_setting_route!( make_setting_route!(
"/ranking-rules", "/ranking-rules",
put,
Vec<String>, Vec<String>,
ranking_rules, ranking_rules,
"rankingRules", "rankingRules",