2022-03-16 07:12:15 +03:00
|
|
|
{-# LANGUAGE DeriveAnyClass #-}
|
2022-03-31 07:45:03 +03:00
|
|
|
{-# LANGUAGE OverloadedLists #-}
|
2022-03-16 07:12:15 +03:00
|
|
|
|
|
|
|
--
|
2022-05-02 08:03:12 +03:00
|
|
|
module Hasura.Backends.DataConnector.API.V0.OrderBy
|
2022-03-16 07:12:15 +03:00
|
|
|
( OrderBy (..),
|
|
|
|
OrderType (..),
|
|
|
|
)
|
|
|
|
where
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
2022-07-27 08:27:34 +03:00
|
|
|
import Autodocodec
|
2022-03-31 07:45:03 +03:00
|
|
|
import Autodocodec.OpenAPI ()
|
2022-04-01 04:20:23 +03:00
|
|
|
import Control.DeepSeq (NFData)
|
2022-03-16 07:12:15 +03:00
|
|
|
import Data.Aeson (FromJSON, ToJSON)
|
2022-04-01 04:20:23 +03:00
|
|
|
import Data.Data (Data)
|
|
|
|
import Data.Hashable (Hashable)
|
2022-03-31 07:45:03 +03:00
|
|
|
import Data.OpenApi (ToSchema)
|
2022-04-01 04:20:23 +03:00
|
|
|
import GHC.Generics (Generic)
|
2022-05-02 08:03:12 +03:00
|
|
|
import Hasura.Backends.DataConnector.API.V0.Column qualified as API.V0
|
2022-04-01 04:20:23 +03:00
|
|
|
import Prelude
|
2022-03-16 07:12:15 +03:00
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
data OrderBy = OrderBy
|
|
|
|
{ column :: API.V0.ColumnName,
|
|
|
|
ordering :: OrderType
|
|
|
|
}
|
|
|
|
deriving stock (Data, Eq, Generic, Ord, Show)
|
2022-04-01 04:20:23 +03:00
|
|
|
deriving anyclass (Hashable, NFData)
|
2022-03-31 07:45:03 +03:00
|
|
|
deriving (FromJSON, ToJSON, ToSchema) via Autodocodec OrderBy
|
2022-03-16 07:12:15 +03:00
|
|
|
|
2022-03-31 07:45:03 +03:00
|
|
|
instance HasCodec OrderBy where
|
|
|
|
codec =
|
|
|
|
object "OrderBy" $
|
|
|
|
OrderBy
|
|
|
|
<$> requiredField "column" "Column to order by" .= column
|
|
|
|
<*> requiredField "ordering" "Ordering" .= ordering
|
2022-03-16 07:12:15 +03:00
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
data OrderType
|
|
|
|
= Ascending
|
|
|
|
| Descending
|
2022-03-31 07:45:03 +03:00
|
|
|
deriving stock (Data, Eq, Generic, Ord, Show, Enum, Bounded)
|
2022-04-01 04:20:23 +03:00
|
|
|
deriving anyclass (Hashable, NFData)
|
2022-03-31 07:45:03 +03:00
|
|
|
deriving (FromJSON, ToJSON, ToSchema) via Autodocodec OrderType
|
2022-03-16 07:12:15 +03:00
|
|
|
|
2022-03-31 07:45:03 +03:00
|
|
|
instance HasCodec OrderType where
|
|
|
|
codec =
|
|
|
|
named "OrderType" $
|
2022-07-27 08:27:34 +03:00
|
|
|
stringConstCodec [(Ascending, "asc"), (Descending, "desc")]
|