mirror of
https://github.com/aelve/guide.git
synced 2024-12-26 14:23:14 +03:00
Descriptions for the remaining fields
This commit is contained in:
parent
c7d747478a
commit
fd9e954533
@ -75,11 +75,11 @@ type Api = ToServant (Site AsApi)
|
|||||||
|
|
||||||
-- | A "light-weight" client type of `Category`, which describes a category info
|
-- | A "light-weight" client type of `Category`, which describes a category info
|
||||||
data CCategoryInfo = CCategoryInfo
|
data CCategoryInfo = CCategoryInfo
|
||||||
{ cciUid :: Uid Category <?> "Category ID"
|
{ cciUid :: Uid Category ? "Category ID"
|
||||||
, cciTitle :: Text <?> "Title"
|
, cciTitle :: Text ? "Category title"
|
||||||
, cciCreated :: UTCTime <?> "When the category was created"
|
, cciCreated :: UTCTime ? "When the category was created"
|
||||||
, cciGroup_ :: Text <?> "Category group ('grandcategory')"
|
, cciGroup_ :: Text ? "Category group ('grandcategory')"
|
||||||
, cciStatus :: CategoryStatus <?> "Status (done, in progress, ...)"
|
, cciStatus :: CategoryStatus ? "Status (done, in progress, ...)"
|
||||||
}
|
}
|
||||||
deriving (Show, Generic)
|
deriving (Show, Generic)
|
||||||
|
|
||||||
@ -101,12 +101,12 @@ toCategoryInfo Category{..} = CCategoryInfo
|
|||||||
|
|
||||||
-- | A "light-weight" client type of `Category`, which describes a category detail
|
-- | A "light-weight" client type of `Category`, which describes a category detail
|
||||||
data CCategoryDetail = CCategoryDetail
|
data CCategoryDetail = CCategoryDetail
|
||||||
{ ccdUid :: Uid Category <?> "Category ID"
|
{ ccdUid :: Uid Category ? "Category ID"
|
||||||
, ccdTitle :: Text <?> "Title"
|
, ccdTitle :: Text ? "Category title"
|
||||||
, ccdGroup :: Text <?> "Category group ('grandcategory')"
|
, ccdGroup :: Text ? "Category group ('grandcategory')"
|
||||||
, ccdStatus :: CategoryStatus <?> "Status, e.g. done, in progress, ..."
|
, ccdStatus :: CategoryStatus ? "Status, e.g. done, in progress, ..."
|
||||||
, ccdDescription :: CMarkdown <?> "Category description/notes (Markdown)"
|
, ccdDescription :: CMarkdown ? "Category description/notes (Markdown)"
|
||||||
, ccdItems :: [CItem] <?> "All items in the category"
|
, ccdItems :: [CItem] ? "All items in the category"
|
||||||
}
|
}
|
||||||
deriving (Show, Generic)
|
deriving (Show, Generic)
|
||||||
|
|
||||||
@ -129,19 +129,17 @@ toCCategoryDetail Category{..} = CCategoryDetail
|
|||||||
|
|
||||||
-- | Client type of `Item`
|
-- | Client type of `Item`
|
||||||
data CItem = CItem
|
data CItem = CItem
|
||||||
{ ciUid :: Uid Item
|
{ ciUid :: Uid Item ? "Item ID"
|
||||||
, ciName :: Text
|
, ciName :: Text ? "Item name"
|
||||||
, ciCreated :: UTCTime
|
, ciCreated :: UTCTime ? "When the item was created"
|
||||||
, ciGroup :: Maybe Text
|
, ciGroup :: Maybe Text ? "Item group"
|
||||||
, ciDescription :: CMarkdown
|
, ciDescription :: CMarkdown ? "Item summary (Markdown)"
|
||||||
, ciPros :: [CTrait]
|
, ciPros :: [CTrait] ? "Pros (positive traits)"
|
||||||
, ciProsDeleted :: [CTrait]
|
, ciCons :: [CTrait] ? "Cons (negative traits)"
|
||||||
, ciCons :: [CTrait]
|
, ciEcosystem :: CMarkdown ? "The ecosystem description (Markdown)"
|
||||||
, ciConsDeleted :: [CTrait]
|
, ciNotes :: CMarkdown ? "Notes (Markdown)"
|
||||||
, ciEcosystem :: CMarkdown
|
, ciLink :: Maybe Url ? "Link to the official site, if exists"
|
||||||
, ciNotes :: CMarkdown
|
, ciKind :: ItemKind ? "Item kind, e.g. library, ..."
|
||||||
, ciLink :: Maybe Url
|
|
||||||
, ciKind :: ItemKind
|
|
||||||
} deriving (Show, Generic)
|
} deriving (Show, Generic)
|
||||||
|
|
||||||
instance A.ToJSON CItem where
|
instance A.ToJSON CItem where
|
||||||
@ -153,25 +151,23 @@ instance ToSchema CItem where
|
|||||||
-- | Factory to create a `CItem` from an `Item`
|
-- | Factory to create a `CItem` from an `Item`
|
||||||
toCItem :: Item -> CItem
|
toCItem :: Item -> CItem
|
||||||
toCItem Item{..} = CItem
|
toCItem Item{..} = CItem
|
||||||
{ ciUid = _itemUid
|
{ ciUid = H $ _itemUid
|
||||||
, ciName = _itemName
|
, ciName = H $ _itemName
|
||||||
, ciCreated = _itemCreated
|
, ciCreated = H $ _itemCreated
|
||||||
, ciGroup = _itemGroup_
|
, ciGroup = H $ _itemGroup_
|
||||||
, ciDescription = toCMarkdown _itemDescription
|
, ciDescription = H $ toCMarkdown _itemDescription
|
||||||
, ciPros = fmap toCTrait _itemPros
|
, ciPros = H $ fmap toCTrait _itemPros
|
||||||
, ciProsDeleted = fmap toCTrait _itemProsDeleted
|
, ciCons = H $ fmap toCTrait _itemCons
|
||||||
, ciCons = fmap toCTrait _itemCons
|
, ciEcosystem = H $ toCMarkdown _itemEcosystem
|
||||||
, ciConsDeleted = fmap toCTrait _itemConsDeleted
|
, ciNotes = H $ toCMarkdown _itemNotes
|
||||||
, ciEcosystem = toCMarkdown _itemEcosystem
|
, ciLink = H $ _itemLink
|
||||||
, ciNotes = toCMarkdown _itemNotes
|
, ciKind = H $ _itemKind
|
||||||
, ciLink = _itemLink
|
|
||||||
, ciKind = _itemKind
|
|
||||||
}
|
}
|
||||||
|
|
||||||
-- | Client type of `Trait`
|
-- | Client type of `Trait`
|
||||||
data CTrait = CTrait
|
data CTrait = CTrait
|
||||||
{ ctUid :: Uid Trait
|
{ ctUid :: Uid Trait ? "Trait ID"
|
||||||
, ctContent :: CMarkdown
|
, ctContent :: CMarkdown ? "Trait text (Markdown)"
|
||||||
} deriving (Show, Generic)
|
} deriving (Show, Generic)
|
||||||
|
|
||||||
instance A.ToJSON CTrait where
|
instance A.ToJSON CTrait where
|
||||||
@ -183,14 +179,14 @@ instance ToSchema CTrait where
|
|||||||
-- | Factory to create a `CTrait` from a `Trait`
|
-- | Factory to create a `CTrait` from a `Trait`
|
||||||
toCTrait :: Trait -> CTrait
|
toCTrait :: Trait -> CTrait
|
||||||
toCTrait trait = CTrait
|
toCTrait trait = CTrait
|
||||||
{ ctUid = trait ^. uid
|
{ ctUid = H $ trait ^. uid
|
||||||
, ctContent = toCMarkdown $ trait ^. content
|
, ctContent = H $ toCMarkdown $ trait ^. content
|
||||||
}
|
}
|
||||||
|
|
||||||
-- | Client type of `Markdown`
|
-- | Client type of `Markdown`
|
||||||
data CMarkdown = CMarkdown
|
data CMarkdown = CMarkdown
|
||||||
{ text :: Text <?> "Markdown source"
|
{ text :: Text ? "Markdown source"
|
||||||
, html :: Text <?> "Rendered HTML"
|
, html :: Text ? "Rendered HTML"
|
||||||
} deriving (Show, Generic)
|
} deriving (Show, Generic)
|
||||||
|
|
||||||
instance A.ToJSON CMarkdown
|
instance A.ToJSON CMarkdown
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
module Guide.Api.Utils
|
module Guide.Api.Utils
|
||||||
( jsonOptions
|
( jsonOptions
|
||||||
, schemaOptions
|
, schemaOptions
|
||||||
, type (<?>)(..)
|
, type (?)(..)
|
||||||
) where
|
) where
|
||||||
|
|
||||||
|
|
||||||
@ -35,13 +35,13 @@ schemaOptions :: SchemaOptions
|
|||||||
schemaOptions = fromAesonOptions jsonOptions
|
schemaOptions = fromAesonOptions jsonOptions
|
||||||
|
|
||||||
-- | A way to provide descriptions for record fields.
|
-- | A way to provide descriptions for record fields.
|
||||||
newtype (<?>) (field :: *) (help :: Symbol) = H field
|
newtype (?) (field :: *) (help :: Symbol) = H field
|
||||||
deriving (Generic, Show)
|
deriving (Generic, Show)
|
||||||
|
|
||||||
instance ToJSON field => ToJSON (field <?> help) where
|
instance ToJSON field => ToJSON (field ? help) where
|
||||||
toJSON (H a) = toJSON a
|
toJSON (H a) = toJSON a
|
||||||
|
|
||||||
instance (KnownSymbol help, ToSchema a) => ToSchema (a <?> help) where
|
instance (KnownSymbol help, ToSchema a) => ToSchema (a ? help) where
|
||||||
declareNamedSchema _ = do
|
declareNamedSchema _ = do
|
||||||
NamedSchema _ s <- declareNamedSchema (Proxy @a)
|
NamedSchema _ s <- declareNamedSchema (Proxy @a)
|
||||||
return $ NamedSchema Nothing (s & description ?~ T.toStrict desc)
|
return $ NamedSchema Nothing (s & description ?~ T.toStrict desc)
|
||||||
|
Loading…
Reference in New Issue
Block a user