30 lines
1.2 KiB
Haskell
30 lines
1.2 KiB
Haskell
module Feed.V1.Section (feedSectionCached) where
|
|
|
|
import Relude
|
|
|
|
import Api.V1.Cached (request)
|
|
import Api.V1.Types (Request (IGetTopics), Response (OGetTopics), GetTopics (GetTopics), TopicInfo (..))
|
|
import Feed.V1.Core
|
|
import Feed.V1.Types (TopicNew (..), TopicsNew (..))
|
|
import Servant.Client.Streaming
|
|
import Servant.Server (err500)
|
|
import Utils (responseToServerError, throwToHandler)
|
|
|
|
feedSectionCached :: Integer -> App TopicsNew
|
|
feedSectionCached section_id = do
|
|
result <- request [IGetTopics GetTopics]
|
|
-- TODO: add logging of errors
|
|
case result of
|
|
Right [OGetTopics ok] -> pure $ sectionToNewTopics section_id ok
|
|
Right _notOk -> throwToHandler err500
|
|
Left (FailureResponse _ remoteErr) ->
|
|
throwToHandler $ responseToServerError remoteErr
|
|
Left _clientErr -> do
|
|
throwToHandler err500
|
|
|
|
sectionToNewTopics :: Integer -> [TopicInfo] -> TopicsNew
|
|
sectionToNewTopics section_id topics =
|
|
TopicsNew{section_id, topics = topicInfoToNew <$> filter ((section_id ==) . (.group_id)) topics}
|
|
where
|
|
topicInfoToNew TopicInfo{id = topic_id, thrname, date, name} = TopicNew{id = topic_id, thrname, date, name, message = "(post preview unavailable)"}
|