fix release note json serialization

This commit is contained in:
Lucy Cifferello
2022-07-01 14:25:45 -06:00
parent 04f7f7bbf6
commit 18b951388b

View File

@@ -2,7 +2,7 @@
module Handler.Package.V0.ReleaseNotes where module Handler.Package.V0.ReleaseNotes where
import Data.Aeson (ToJSON (..)) import Data.Aeson (ToJSON (..), object, KeyValue((.=)))
import Data.HashMap.Strict (HashMap) import Data.HashMap.Strict (HashMap)
import Data.HashMap.Strict qualified as HM import Data.HashMap.Strict qualified as HM
import Database.Queries (fetchAllAppVersions) import Database.Queries (fetchAllAppVersions)
@@ -10,14 +10,15 @@ import Foundation (Handler, RegistryCtx (..))
import Lib.Types.Core (PkgId) import Lib.Types.Core (PkgId)
import Lib.Types.Emver (Version) import Lib.Types.Emver (Version)
import Model (VersionRecord (..)) import Model (VersionRecord (..))
import Startlude (Down (..), Eq, Show, Text, fst, pure, sortOn, ($), (&&&), (.), (<$>)) import Startlude (Down (..), Eq, Show, Text, fst, pure, sortOn, ($), (&&&), (.), (<$>), show)
import Yesod (ToContent (..), ToTypedContent (..), YesodPersist (runDB), getYesod) import Yesod (ToContent (..), ToTypedContent (..), YesodPersist (runDB), getYesod)
import Data.Aeson.Key (fromText)
newtype ReleaseNotes = ReleaseNotes {unReleaseNotes :: HashMap Version Text} newtype ReleaseNotes = ReleaseNotes {unReleaseNotes :: HashMap Version Text}
deriving (Eq, Show) deriving (Eq, Show)
instance ToJSON ReleaseNotes where instance ToJSON ReleaseNotes where
toJSON ReleaseNotes{..} = toJSON unReleaseNotes toJSON ReleaseNotes {..} = object [ version .= value | (key, value) <- HM.toList unReleaseNotes, let version = fromText $ show key]
instance ToContent ReleaseNotes where instance ToContent ReleaseNotes where
toContent = toContent . toJSON toContent = toContent . toJSON
instance ToTypedContent ReleaseNotes where instance ToTypedContent ReleaseNotes where