mirror of
https://github.com/Start9Labs/registry.git
synced 2026-03-26 02:11:53 +00:00
* wip * finishes initial refactor * prune unused code * finished massive refactor * remove commented deps * fix import * fix bug
40 lines
1.4 KiB
Haskell
40 lines
1.4 KiB
Haskell
{-# LANGUAGE RecordWildCards #-}
|
|
|
|
module Handler.Package.V0.ReleaseNotes where
|
|
|
|
import Data.Aeson (ToJSON (..))
|
|
import Data.HashMap.Strict (HashMap)
|
|
import Data.HashMap.Strict qualified as HM
|
|
import Database.Queries (fetchAllAppVersions)
|
|
import Foundation (Handler, RegistryCtx (..))
|
|
import Lib.Types.Core (PkgId)
|
|
import Lib.Types.Emver (Version)
|
|
import Model (VersionRecord (..))
|
|
import Startlude (Down (..), Eq, Show, Text, fst, pure, sortOn, ($), (&&&), (.), (<$>))
|
|
import Yesod (ToContent (..), ToTypedContent (..), YesodPersist (runDB), getYesod)
|
|
|
|
|
|
newtype ReleaseNotes = ReleaseNotes {unReleaseNotes :: HashMap Version Text}
|
|
deriving (Eq, Show)
|
|
instance ToJSON ReleaseNotes where
|
|
toJSON ReleaseNotes{..} = toJSON unReleaseNotes
|
|
instance ToContent ReleaseNotes where
|
|
toContent = toContent . toJSON
|
|
instance ToTypedContent ReleaseNotes where
|
|
toTypedContent = toTypedContent . toJSON
|
|
|
|
|
|
getReleaseNotesR :: PkgId -> Handler ReleaseNotes
|
|
getReleaseNotesR pkg = do
|
|
appConnPool <- appConnPool <$> getYesod
|
|
versionRecords <- runDB $ fetchAllAppVersions appConnPool pkg
|
|
pure $ constructReleaseNotesApiRes versionRecords
|
|
where
|
|
constructReleaseNotesApiRes :: [VersionRecord] -> ReleaseNotes
|
|
constructReleaseNotesApiRes vers = do
|
|
ReleaseNotes $
|
|
HM.fromList $
|
|
sortOn (Down . fst) $
|
|
(versionRecordNumber &&& versionRecordReleaseNotes)
|
|
<$> vers
|