1
1
mirror of https://github.com/aelve/guide.git synced 2024-11-24 13:52:44 +03:00

[api] Provide more information at the /categories endpoint

This commit is contained in:
Artyom 2017-09-01 12:31:03 +03:00
parent 76d76974ad
commit 62c91eb45d
No known key found for this signature in database
GPG Key ID: B8E35A33FF522710

View File

@ -37,7 +37,7 @@ data Site route = Site
-- | A list of all categories (the /haskell page). Returns category
-- titles.
_getCategories :: route :-
"categories" :> Get '[JSON] [Text]
"categories" :> Get '[JSON] [CategoryInfo]
-- | Details of a single category (and items in it, etc)
, _getCategory :: route :-
@ -76,10 +76,28 @@ runApiServer db = do
-- Implementations of methods
----------------------------------------------------------------------------
getCategories :: DB -> Handler [Text]
data CategoryInfo = CategoryInfo {
_categoryInfoUid :: Uid Category,
_categoryInfoTitle :: Text,
_categoryInfoCreated :: UTCTime,
_categoryInfoGroup_ :: Text,
_categoryInfoStatus :: CategoryStatus
}
deriving (Show, Generic)
instance ToJSON CategoryInfo
getCategories :: DB -> Handler [CategoryInfo]
getCategories db = do
liftIO (Acid.query db GetCategories) <&> \xs ->
map (view title) xs
map categoryToInfo xs
where
categoryToInfo Category{..} = CategoryInfo {
_categoryInfoUid = _categoryUid,
_categoryInfoTitle = _categoryTitle,
_categoryInfoCreated = _categoryCreated,
_categoryInfoGroup_ = _categoryGroup_,
_categoryInfoStatus = _categoryStatus }
getCategory :: DB -> Uid Category -> Handler (Either ApiError Category)
getCategory db catId =