mz_frontegg_mock/models/
utils.rs

1// Copyright Materialize, Inc. and contributors. All rights reserved.
2//
3// Use of this software is governed by the Business Source License
4// included in the LICENSE file.
5//
6// As of the Change Date specified in that file, in accordance with
7// the Business Source License, use of this software will be governed
8// by the Apache License, Version 2.0.
9
10use serde::Serialize;
11
12#[derive(Serialize)]
13pub struct ErrorResponse {
14    pub errors: Vec<String>,
15}
16
17#[derive(Debug, PartialEq)]
18pub enum SortBy {
19    Email,
20    Id,
21}
22
23#[derive(Debug, PartialEq)]
24pub enum Order {
25    ASC,
26    DESC,
27}
28
29impl TryFrom<&str> for Order {
30    type Error = String;
31
32    fn try_from(value: &str) -> Result<Self, Self::Error> {
33        match value.to_uppercase().as_str() {
34            "ASC" => Ok(Order::ASC),
35            "DESC" => Ok(Order::DESC),
36            _ => Err(format!("'{}' is not a valid order option", value)),
37        }
38    }
39}
40
41impl TryFrom<&str> for SortBy {
42    type Error = String;
43
44    fn try_from(value: &str) -> Result<Self, Self::Error> {
45        match value {
46            "email" => Ok(SortBy::Email),
47            "id" => Ok(SortBy::Id),
48            _ => Err(format!("'{}' is not a valid sort option", value)),
49        }
50    }
51}