From 184b8afd9e479651cc6063e7fab2d6bc3f3a0d9a Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Wed, 25 Jan 2023 14:42:03 +0100 Subject: [PATCH] Make it work in the CreateApiKey struct --- meilisearch-types/src/keys.rs | 11 ++++++----- meilisearch/src/routes/api_key.rs | 1 + meilisearch/src/routes/mod.rs | 2 ++ 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/meilisearch-types/src/keys.rs b/meilisearch-types/src/keys.rs index b41bb06b6..50afa755c 100644 --- a/meilisearch-types/src/keys.rs +++ b/meilisearch-types/src/keys.rs @@ -12,15 +12,15 @@ use uuid::Uuid; use crate::error::deserr_codes::*; use crate::error::{unwrap_any, Code, DeserrError, ErrorCode, TakeErrorMessage}; -use crate::index_uid::{IndexUid, IndexUidFormatError}; +use crate::index_uid_pattern::{IndexUidPattern, IndexUidPatternFormatError}; use crate::star_or::StarOr; pub type KeyId = Uuid; -impl MergeWithError for DeserrError { +impl MergeWithError for DeserrError { fn merge( _self_: Option, - other: IndexUidFormatError, + other: IndexUidPatternFormatError, merge_location: deserr::ValuePointerRef, ) -> std::result::Result { DeserrError::error::( @@ -47,10 +47,11 @@ pub struct CreateApiKey { #[deserr(error = DeserrError)] pub actions: Vec, #[deserr(error = DeserrError)] - pub indexes: Vec>, + pub indexes: Vec>, #[deserr(error = DeserrError, default = None, from(&String) = parse_expiration_date -> TakeErrorMessage)] pub expires_at: Option, } + impl CreateApiKey { pub fn to_key(self) -> Key { let CreateApiKey { description, name, uid, actions, indexes, expires_at } = self; @@ -108,7 +109,7 @@ pub struct Key { pub name: Option, pub uid: KeyId, pub actions: Vec, - pub indexes: Vec>, + pub indexes: Vec>, #[serde(with = "time::serde::rfc3339::option")] pub expires_at: Option, #[serde(with = "time::serde::rfc3339")] diff --git a/meilisearch/src/routes/api_key.rs b/meilisearch/src/routes/api_key.rs index 76912bbaa..b43398da1 100644 --- a/meilisearch/src/routes/api_key.rs +++ b/meilisearch/src/routes/api_key.rs @@ -61,6 +61,7 @@ pub struct ListApiKeys { #[deserr(error = DeserrError, default = PAGINATION_DEFAULT_LIMIT(), from(&String) = parse_usize_take_error_message -> TakeErrorMessage)] pub limit: usize, } + impl ListApiKeys { fn as_pagination(self) -> Pagination { Pagination { offset: self.offset, limit: self.limit } diff --git a/meilisearch/src/routes/mod.rs b/meilisearch/src/routes/mod.rs index 2e619540a..5111478c9 100644 --- a/meilisearch/src/routes/mod.rs +++ b/meilisearch/src/routes/mod.rs @@ -56,6 +56,7 @@ where { Ok(Some(input.parse()?)) } + pub fn from_string_to_option_take_error_message( input: &str, ) -> Result, TakeErrorMessage> @@ -90,6 +91,7 @@ impl From for SummarizedTaskView { } } } + pub struct Pagination { pub offset: usize, pub limit: usize,