Skip to content

Custom extractor for Queries with fields that have enums with enum values #2683

Answered by jplatte
Gautham-kj asked this question in Q&A
Discussion options

You must be logged in to vote

You don't need a custom extractor in that case. You just need to change your data structures or how Deserialize is implemented for them.

If changing your data types and the serialized format is an option, the easiest fix would probably be to move the order to a separate parameter, i.e.

// Order defined as before

#[derive(Deserialize, PartialEq, ToSchema)]
pub enum Filter {
    Rating,
    DateOfCreation,
    Alphabetical,
    Price,
}

#[derive(Deserialize, ToSchema, IntoParams)]
pub struct ItemsQuery {
    take: Option<u32>,
    page_no: Option<u32>,
    filter: Option<Filter>,
    order: Option<Order>,
    search_string: Option<String>,
}

If you want to keep the types defined as-is, yo…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@Gautham-kj
Comment options

@jplatte
Comment options

Answer selected by Gautham-kj
@Gautham-kj
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants