fix bug wto show multiple versions in metadata

This commit is contained in:
Lucy Cifferello
2021-09-24 13:30:14 -06:00
committed by Keagan McClelland
parent beaace0238
commit 7e70ffe3f3
3 changed files with 74 additions and 4 deletions

View File

@@ -24,7 +24,7 @@ module Application
, getAppSettings , getAppSettings
-- * for GHCI -- * for GHCI
, handler , handler
) where ,db) where
import Startlude hiding (Handler) import Startlude hiding (Handler)
@@ -67,6 +67,8 @@ import Network.HTTP.Types.Header ( hOrigin )
import Data.List (lookup) import Data.List (lookup)
import Network.Wai.Middleware.RequestLogger.JSON import Network.Wai.Middleware.RequestLogger.JSON
import System.Directory (createDirectoryIfMissing) import System.Directory (createDirectoryIfMissing)
import Database.Persist.Sql (SqlBackend)
import Yesod
-- This line actually creates our YesodDispatch instance. It is the second half -- This line actually creates our YesodDispatch instance. It is the second half
-- of the call to mkYesodData which occurs in Foundation.hs. Please see the -- of the call to mkYesodData which occurs in Foundation.hs. Please see the
@@ -342,3 +344,7 @@ develMain = do
-- | Run a handler -- | Run a handler
handler :: Handler a -> IO a handler :: Handler a -> IO a
handler h = getAppSettings >>= makeFoundation >>= flip unsafeHandler h handler h = getAppSettings >>= makeFoundation >>= flip unsafeHandler h
-- | Run DB queries
db :: ReaderT SqlBackend (HandlerFor RegistryCtx) a -> IO a
db = handler . runDB

View File

@@ -318,6 +318,66 @@ getPackageListR = do
where where
getPackageDetails :: MonadIO m getPackageDetails :: MonadIO m
=> (HM.HashMap AppIdentifier ([Version], [CategoryTitle])) => (HM.HashMap AppIdentifier ([Version], [CategoryTitle]))
@@ -473,7 +533,8 @@ fetchLatestAppAtVersion appId version' = selectOne $ do
where_ $ (service ^. SAppAppId ==. val appId) &&. (version ^. SVersionNumber ==. val version') where_ $ (service ^. SAppAppId ==. val appId) &&. (version ^. SVersionNumber ==. val version')
pure (service, version) pure (service, version)
fetchPackageMetadata :: MonadUnliftIO m => ReaderT SqlBackend m (HM.HashMap AppIdentifier ([Version], [CategoryTitle])) fetchPackageMetadata :: (MonadLogger m, MonadUnliftIO m)
=> ReaderT SqlBackend m (HM.HashMap AppIdentifier ([Version], [CategoryTitle]))
fetchPackageMetadata = do fetchPackageMetadata = do
let categoriesQuery = select $ do let categoriesQuery = select $ do
(service :& category) <- (service :& category) <-
@@ -501,7 +562,8 @@ fetchPackageMetadata = do
c = foreach categories c = foreach categories
$ \(appId, categories') -> (unValue appId, catMaybes $ fromMaybe [] (unValue categories')) $ \(appId, categories') -> (unValue appId, catMaybes $ fromMaybe [] (unValue categories'))
let v = foreach versions $ \(appId, versions') -> (unValue appId, fromMaybe [] (unValue versions')) let v = foreach versions $ \(appId, versions') -> (unValue appId, fromMaybe [] (unValue versions'))
pure $ HM.intersectionWith (\vers cts -> (vers, cts)) (HM.fromList v) (HM.fromList c) let vv = HM.fromListWithKey (\_ vers vers' -> (++) vers vers') v
pure $ HM.intersectionWith (\vers cts -> (cts, vers)) (HM.fromList c) vv
fetchAppCategories :: MonadIO m => Key SApp -> ReaderT SqlBackend m [P.Entity ServiceCategory] fetchAppCategories :: MonadIO m => Key SApp -> ReaderT SqlBackend m [P.Entity ServiceCategory]
fetchAppCategories appId = select $ do fetchAppCategories appId = select $ do

View File

@@ -1,5 +1,6 @@
{-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE DeriveGeneric #-}
module Lib.Types.Category where module Lib.Types.Category where
@@ -16,7 +17,7 @@ data CategoryTitle = FEATURED
| MESSAGING | MESSAGING
| SOCIAL | SOCIAL
| ALTCOIN | ALTCOIN
deriving (Eq, Enum, Show, Read) deriving (Eq, Enum, Show, Read, Generic)
instance PersistField CategoryTitle where instance PersistField CategoryTitle where
fromPersistValue = fromPersistValueJSON fromPersistValue = fromPersistValueJSON
toPersistValue = toPersistValueJSON toPersistValue = toPersistValueJSON
@@ -46,3 +47,4 @@ instance ToContent CategoryTitle where
toContent = toContent . toJSON toContent = toContent . toJSON
instance ToTypedContent CategoryTitle where instance ToTypedContent CategoryTitle where
toTypedContent = toTypedContent . toJSON toTypedContent = toTypedContent . toJSON
instance Hashable CategoryTitle