mirror of
https://github.com/aelve/guide.git
synced 2024-11-29 14:35:35 +03:00
fix getItem
This commit is contained in:
parent
958afba90b
commit
e3a8edbf94
@ -97,10 +97,21 @@ deleteCategory catId =
|
|||||||
----------------------------------------------------------------------------
|
----------------------------------------------------------------------------
|
||||||
|
|
||||||
-- | Get item by item ID.
|
-- | Get item by item ID.
|
||||||
getItem :: Uid Item -> Guider CItemFull
|
--
|
||||||
getItem itemId =
|
-- Pass 'True' to ignore disabled sections and get full item.
|
||||||
|
getItem :: Bool -> Uid Item -> Guider CItemFull
|
||||||
|
getItem isIgnored itemId =
|
||||||
logHandler "getItem" [attr "itemId" itemId] $ do
|
logHandler "getItem" [attr "itemId" itemId] $ do
|
||||||
toCItemFull <$> getItemOrFail itemId
|
item <- getItemOrFail itemId
|
||||||
|
sections <- categoryEnabledSections <$> dbQuery (GetCategoryByItem itemId)
|
||||||
|
if isIgnored then pure $ toCItemFull allSections item
|
||||||
|
else pure $ toCItemFull sections item
|
||||||
|
where
|
||||||
|
allSections = S.fromList
|
||||||
|
[ ItemProsConsSection
|
||||||
|
, ItemEcosystemSection
|
||||||
|
, ItemNotesSection
|
||||||
|
]
|
||||||
|
|
||||||
-- | Create a new item, given the name.
|
-- | Create a new item, given the name.
|
||||||
--
|
--
|
||||||
|
@ -153,6 +153,10 @@ data ItemSite route = ItemSite
|
|||||||
{ _getItem :: route :-
|
{ _getItem :: route :-
|
||||||
Summary "Get item by id"
|
Summary "Get item by id"
|
||||||
:> ErrorResponse 404 "Item not found"
|
:> ErrorResponse 404 "Item not found"
|
||||||
|
:> "ignore selections"
|
||||||
|
:> QueryParam' '[Required, Strict,
|
||||||
|
Description "Ignore disabled sections to get full item"]
|
||||||
|
"bool" Bool
|
||||||
:> "item"
|
:> "item"
|
||||||
:> Capture "itemId" (Uid Item)
|
:> Capture "itemId" (Uid Item)
|
||||||
:> Get '[JSON] CItemFull
|
:> Get '[JSON] CItemFull
|
||||||
@ -505,7 +509,7 @@ toCCategoryFull $(fields 'Category) = CCategoryFull
|
|||||||
, ccfStatus = categoryStatus
|
, ccfStatus = categoryStatus
|
||||||
, ccfDescription = toCMarkdown categoryNotes
|
, ccfDescription = toCMarkdown categoryNotes
|
||||||
, ccfSections = categoryEnabledSections
|
, ccfSections = categoryEnabledSections
|
||||||
, ccfItems = fmap toCItemFull categoryItems
|
, ccfItems = fmap (toCItemFull categoryEnabledSections) categoryItems
|
||||||
}
|
}
|
||||||
where
|
where
|
||||||
-- Ignored fields
|
-- Ignored fields
|
||||||
@ -674,23 +678,34 @@ instance ToSchema CItemFull where
|
|||||||
field "toc" . inlineSchema . description ?= "Table of contents"
|
field "toc" . inlineSchema . description ?= "Table of contents"
|
||||||
|
|
||||||
-- | Factory to create a 'CItemFull' from an 'Item'
|
-- | Factory to create a 'CItemFull' from an 'Item'
|
||||||
toCItemFull :: Item -> CItemFull
|
--
|
||||||
toCItemFull $(fields 'Item) = CItemFull
|
-- Pass to 'Set ItemSection' all kinds of sections
|
||||||
|
-- to ignore disabled sections and get full item content.
|
||||||
|
toCItemFull :: Set ItemSection -> Item -> CItemFull
|
||||||
|
toCItemFull selections $(fields 'Item) = CItemFull
|
||||||
{ cifId = itemUid
|
{ cifId = itemUid
|
||||||
, cifName = itemName
|
, cifName = itemName
|
||||||
, cifCreated = itemCreated
|
, cifCreated = itemCreated
|
||||||
, cifHackage = itemHackage
|
, cifHackage = itemHackage
|
||||||
, cifSummary = toCMarkdown itemSummary
|
, cifSummary = toCMarkdown itemSummary
|
||||||
, cifPros = fmap toCTrait itemPros
|
, cifPros = fmap toCTrait pros
|
||||||
, cifCons = fmap toCTrait itemCons
|
, cifCons = fmap toCTrait cons
|
||||||
, cifEcosystem = toCMarkdown itemEcosystem
|
, cifEcosystem = toCMarkdown ecosystem
|
||||||
, cifNotes = toCMarkdown itemNotes
|
, cifNotes = toCMarkdown notes
|
||||||
, cifLink = itemLink
|
, cifLink = itemLink
|
||||||
, cifToc = map toCTocHeading (markdownTreeTOC itemNotes)
|
, cifToc = map toCTocHeading (markdownTreeTOC itemNotes)
|
||||||
}
|
}
|
||||||
where
|
where
|
||||||
-- Ignored fields
|
|
||||||
_ = (itemProsDeleted, itemConsDeleted)
|
_ = (itemProsDeleted, itemConsDeleted)
|
||||||
|
ecosystem = if (ItemEcosystemSection `elem` selections)
|
||||||
|
then itemEcosystem
|
||||||
|
else toMarkdownBlock ""
|
||||||
|
notes = if (ItemNotesSection `elem` selections)
|
||||||
|
then itemNotes
|
||||||
|
else toMarkdownTree "" ""
|
||||||
|
(pros, cons) = if (ItemProsConsSection `elem` selections)
|
||||||
|
then (itemPros, itemCons)
|
||||||
|
else ([],[])
|
||||||
|
|
||||||
----------------------------------------------------------------------------
|
----------------------------------------------------------------------------
|
||||||
-- CTrait
|
-- CTrait
|
||||||
|
@ -845,6 +845,7 @@ deriving instance Show GetGlobalState
|
|||||||
-- category
|
-- category
|
||||||
deriving instance Show GetCategories
|
deriving instance Show GetCategories
|
||||||
deriving instance Show GetCategoryMaybe
|
deriving instance Show GetCategoryMaybe
|
||||||
|
deriving instance Show GetCategoryByItem
|
||||||
deriving instance Show AddCategory
|
deriving instance Show AddCategory
|
||||||
deriving instance Show DeleteCategory
|
deriving instance Show DeleteCategory
|
||||||
deriving instance Show SetCategoryGroup
|
deriving instance Show SetCategoryGroup
|
||||||
|
Loading…
Reference in New Issue
Block a user