{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
module Server.DTOs.CreateTextRevision (CreateTextRevision (..)) where
import Data.Aeson (FromJSON (parseJSON), ToJSON, (.!=), (.:), (.:?))
import Data.OpenApi (ToSchema)
import Data.Text (Text)
import GHC.Generics (Generic)
import Data.Aeson.Types (withObject)
import Data.Vector (Vector)
import qualified Data.Vector as Vector
import Docs.Comment (CommentAnchor)
import Docs.TextRevision (TextRevisionID)
data CreateTextRevision = CreateTextRevision
{ CreateTextRevision -> Maybe TextRevisionID
parent :: Maybe TextRevisionID
, CreateTextRevision -> Text
content :: Text
, :: Vector CommentAnchor
}
deriving ((forall x. CreateTextRevision -> Rep CreateTextRevision x)
-> (forall x. Rep CreateTextRevision x -> CreateTextRevision)
-> Generic CreateTextRevision
forall x. Rep CreateTextRevision x -> CreateTextRevision
forall x. CreateTextRevision -> Rep CreateTextRevision x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. CreateTextRevision -> Rep CreateTextRevision x
from :: forall x. CreateTextRevision -> Rep CreateTextRevision x
$cto :: forall x. Rep CreateTextRevision x -> CreateTextRevision
to :: forall x. Rep CreateTextRevision x -> CreateTextRevision
Generic)
instance ToJSON CreateTextRevision
instance FromJSON CreateTextRevision where
parseJSON :: Value -> Parser CreateTextRevision
parseJSON = String
-> (Object -> Parser CreateTextRevision)
-> Value
-> Parser CreateTextRevision
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"CreateTextRevision" ((Object -> Parser CreateTextRevision)
-> Value -> Parser CreateTextRevision)
-> (Object -> Parser CreateTextRevision)
-> Value
-> Parser CreateTextRevision
forall a b. (a -> b) -> a -> b
$ \Object
o ->
Maybe TextRevisionID
-> Text -> Vector CommentAnchor -> CreateTextRevision
CreateTextRevision
(Maybe TextRevisionID
-> Text -> Vector CommentAnchor -> CreateTextRevision)
-> Parser (Maybe TextRevisionID)
-> Parser (Text -> Vector CommentAnchor -> CreateTextRevision)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (Maybe TextRevisionID)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"parent"
Parser (Text -> Vector CommentAnchor -> CreateTextRevision)
-> Parser Text
-> Parser (Vector CommentAnchor -> CreateTextRevision)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"content"
Parser (Vector CommentAnchor -> CreateTextRevision)
-> Parser (Vector CommentAnchor) -> Parser CreateTextRevision
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Object
o Object -> Key -> Parser (Maybe (Vector CommentAnchor))
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"commentAnchors" Parser (Maybe (Vector CommentAnchor))
-> Vector CommentAnchor -> Parser (Vector CommentAnchor)
forall a. Parser (Maybe a) -> a -> Parser a
.!= Vector CommentAnchor
forall a. Vector a
Vector.empty)
instance ToSchema CreateTextRevision