mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-23 10:37:41 +08:00
Make it work in the CreateApiKey struct
This commit is contained in:
parent
29961b8c6b
commit
184b8afd9e
@ -12,15 +12,15 @@ use uuid::Uuid;
|
|||||||
|
|
||||||
use crate::error::deserr_codes::*;
|
use crate::error::deserr_codes::*;
|
||||||
use crate::error::{unwrap_any, Code, DeserrError, ErrorCode, TakeErrorMessage};
|
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;
|
use crate::star_or::StarOr;
|
||||||
|
|
||||||
pub type KeyId = Uuid;
|
pub type KeyId = Uuid;
|
||||||
|
|
||||||
impl<C: Default + ErrorCode> MergeWithError<IndexUidFormatError> for DeserrError<C> {
|
impl<C: Default + ErrorCode> MergeWithError<IndexUidPatternFormatError> for DeserrError<C> {
|
||||||
fn merge(
|
fn merge(
|
||||||
_self_: Option<Self>,
|
_self_: Option<Self>,
|
||||||
other: IndexUidFormatError,
|
other: IndexUidPatternFormatError,
|
||||||
merge_location: deserr::ValuePointerRef,
|
merge_location: deserr::ValuePointerRef,
|
||||||
) -> std::result::Result<Self, Self> {
|
) -> std::result::Result<Self, Self> {
|
||||||
DeserrError::error::<Infallible>(
|
DeserrError::error::<Infallible>(
|
||||||
@ -47,10 +47,11 @@ pub struct CreateApiKey {
|
|||||||
#[deserr(error = DeserrError<InvalidApiKeyActions>)]
|
#[deserr(error = DeserrError<InvalidApiKeyActions>)]
|
||||||
pub actions: Vec<Action>,
|
pub actions: Vec<Action>,
|
||||||
#[deserr(error = DeserrError<InvalidApiKeyIndexes>)]
|
#[deserr(error = DeserrError<InvalidApiKeyIndexes>)]
|
||||||
pub indexes: Vec<StarOr<IndexUid>>,
|
pub indexes: Vec<StarOr<IndexUidPattern>>,
|
||||||
#[deserr(error = DeserrError<InvalidApiKeyExpiresAt>, default = None, from(&String) = parse_expiration_date -> TakeErrorMessage<ParseOffsetDateTimeError>)]
|
#[deserr(error = DeserrError<InvalidApiKeyExpiresAt>, default = None, from(&String) = parse_expiration_date -> TakeErrorMessage<ParseOffsetDateTimeError>)]
|
||||||
pub expires_at: Option<OffsetDateTime>,
|
pub expires_at: Option<OffsetDateTime>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CreateApiKey {
|
impl CreateApiKey {
|
||||||
pub fn to_key(self) -> Key {
|
pub fn to_key(self) -> Key {
|
||||||
let CreateApiKey { description, name, uid, actions, indexes, expires_at } = self;
|
let CreateApiKey { description, name, uid, actions, indexes, expires_at } = self;
|
||||||
@ -108,7 +109,7 @@ pub struct Key {
|
|||||||
pub name: Option<String>,
|
pub name: Option<String>,
|
||||||
pub uid: KeyId,
|
pub uid: KeyId,
|
||||||
pub actions: Vec<Action>,
|
pub actions: Vec<Action>,
|
||||||
pub indexes: Vec<StarOr<IndexUid>>,
|
pub indexes: Vec<StarOr<IndexUidPattern>>,
|
||||||
#[serde(with = "time::serde::rfc3339::option")]
|
#[serde(with = "time::serde::rfc3339::option")]
|
||||||
pub expires_at: Option<OffsetDateTime>,
|
pub expires_at: Option<OffsetDateTime>,
|
||||||
#[serde(with = "time::serde::rfc3339")]
|
#[serde(with = "time::serde::rfc3339")]
|
||||||
|
@ -61,6 +61,7 @@ pub struct ListApiKeys {
|
|||||||
#[deserr(error = DeserrError<InvalidApiKeyLimit>, default = PAGINATION_DEFAULT_LIMIT(), from(&String) = parse_usize_take_error_message -> TakeErrorMessage<std::num::ParseIntError>)]
|
#[deserr(error = DeserrError<InvalidApiKeyLimit>, default = PAGINATION_DEFAULT_LIMIT(), from(&String) = parse_usize_take_error_message -> TakeErrorMessage<std::num::ParseIntError>)]
|
||||||
pub limit: usize,
|
pub limit: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ListApiKeys {
|
impl ListApiKeys {
|
||||||
fn as_pagination(self) -> Pagination {
|
fn as_pagination(self) -> Pagination {
|
||||||
Pagination { offset: self.offset, limit: self.limit }
|
Pagination { offset: self.offset, limit: self.limit }
|
||||||
|
@ -56,6 +56,7 @@ where
|
|||||||
{
|
{
|
||||||
Ok(Some(input.parse()?))
|
Ok(Some(input.parse()?))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_string_to_option_take_error_message<T, E>(
|
pub fn from_string_to_option_take_error_message<T, E>(
|
||||||
input: &str,
|
input: &str,
|
||||||
) -> Result<Option<T>, TakeErrorMessage<E>>
|
) -> Result<Option<T>, TakeErrorMessage<E>>
|
||||||
@ -90,6 +91,7 @@ impl From<Task> for SummarizedTaskView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Pagination {
|
pub struct Pagination {
|
||||||
pub offset: usize,
|
pub offset: usize,
|
||||||
pub limit: usize,
|
pub limit: usize,
|
||||||
|
Loading…
Reference in New Issue
Block a user