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
|
|
|
|
|
|
|
--
|
|
|
|
module Hasura.Backends.DataWrapper.API.V0.OrderBy
|
|
|
|
( OrderBy (..),
|
|
|
|
OrderType (..),
|
|
|
|
)
|
|
|
|
where
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
2022-03-31 07:45:03 +03:00
|
|
|
import Autodocodec.Extended
|
|
|
|
import Autodocodec.OpenAPI ()
|
2022-03-16 07:12:15 +03:00
|
|
|
import Data.Aeson (FromJSON, ToJSON)
|
2022-03-31 07:45:03 +03:00
|
|
|
import Data.OpenApi (ToSchema)
|
2022-03-16 07:12:15 +03:00
|
|
|
import Hasura.Backends.DataWrapper.API.V0.Column qualified as API.V0
|
|
|
|
import Hasura.Incremental (Cacheable)
|
|
|
|
import Hasura.Prelude
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
data OrderBy = OrderBy
|
|
|
|
{ column :: API.V0.ColumnName,
|
|
|
|
ordering :: OrderType
|
|
|
|
}
|
|
|
|
deriving stock (Data, Eq, Generic, Ord, Show)
|
|
|
|
deriving anyclass (Cacheable, 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-03-16 07:12:15 +03:00
|
|
|
deriving anyclass (Cacheable, 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" $
|
|
|
|
disjointStringConstCodec [(Ascending, "asc"), (Descending, "desc")]
|