From fc3af9d8a90ca033a5a21da2892123e508a95ae4 Mon Sep 17 00:00:00 2001 From: Keagan McClelland Date: Wed, 2 Feb 2022 11:12:21 -0700 Subject: [PATCH] adds name to /package/data --- config/routes | 2 +- src/Application.hs | 1 - src/Handler/Marketplace.hs | 7 ++++--- src/Handler/Types/Marketplace.hs | 14 ++++++++------ src/Settings.hs | 3 +++ stack.yaml | 6 +----- 6 files changed, 17 insertions(+), 16 deletions(-) diff --git a/config/routes b/config/routes index eaa6d1d..14caec5 100644 --- a/config/routes +++ b/config/routes @@ -1,5 +1,5 @@ !/package/#S9PK AppR GET -- get most recent appId at appversion spec, defaults to >=0.0.0 -- ?spec={semver-spec} -/package/data CategoriesR GET -- get all marketplace categories +/package/data InfoR GET -- get all marketplace categories /package/index PackageListR GET -- filter marketplace services by various query params -- /package/updates /eos/latest EosVersionR GET -- get eos information diff --git a/src/Application.hs b/src/Application.hs index c5fe486..7373e93 100644 --- a/src/Application.hs +++ b/src/Application.hs @@ -78,7 +78,6 @@ import Yesod.Core import Yesod.Core.Types hiding ( Logger ) import Yesod.Default.Config2 -import Control.Arrow ( (***) ) import Control.Lens import Data.List ( lookup ) import Data.String.Interpolate.IsString diff --git a/src/Handler/Marketplace.hs b/src/Handler/Marketplace.hs index e417d35..0b8da0c 100644 --- a/src/Handler/Marketplace.hs +++ b/src/Handler/Marketplace.hs @@ -129,13 +129,14 @@ import Yesod.Core ( MonadResource import Yesod.Persist ( YesodDB ) import Yesod.Persist.Core ( YesodPersist(runDB) ) -getCategoriesR :: Handler CategoryRes -getCategoriesR = do +getInfoR :: Handler InfoRes +getInfoR = do + name <- getsYesod $ marketplaceName . appSettings allCategories <- runDB $ select $ do cats <- from $ table @Category orderBy [desc (cats ^. CategoryPriority)] pure cats - pure $ CategoryRes $ categoryName . entityVal <$> allCategories + pure $ InfoRes name $ categoryName . entityVal <$> allCategories getEosVersionR :: Handler EosRes getEosVersionR = do diff --git a/src/Handler/Types/Marketplace.hs b/src/Handler/Types/Marketplace.hs index c57f753..9f471fb 100644 --- a/src/Handler/Types/Marketplace.hs +++ b/src/Handler/Types/Marketplace.hs @@ -19,13 +19,15 @@ import Yesod type URL = Text -newtype CategoryRes = CategoryRes { - categories :: [CategoryTitle] -} deriving (Show, Generic) -instance ToJSON CategoryRes -instance ToContent CategoryRes where +data InfoRes = InfoRes + { name :: Text + , categories :: [CategoryTitle] + } + deriving (Show, Generic) +instance ToJSON InfoRes +instance ToContent InfoRes where toContent = toContent . toJSON -instance ToTypedContent CategoryRes where +instance ToTypedContent InfoRes where toTypedContent = toTypedContent . toJSON data PackageRes = PackageRes { packageResIcon :: URL diff --git a/src/Settings.hs b/src/Settings.hs index eca9ddb..3ff887c 100644 --- a/src/Settings.hs +++ b/src/Settings.hs @@ -56,6 +56,7 @@ data AppSettings = AppSettings , torPort :: AppPort , staticBinDir :: FilePath , errorLogRoot :: FilePath + , marketplaceName :: Text } instance Has PkgRepo AppSettings where extract = liftA2 PkgRepo (( "apps") . resourcesDir) staticBinDir @@ -84,6 +85,8 @@ instance FromJSON AppSettings where let sslCertLocation = sslPath "certificate.pem" let registryVersion = fromJust . parseMaybe parseJSON . String . toS . showVersion $ version + marketplaceName <- o .:? "marketplace-name" .!= "Start9 Embassy Marketplace" + return AppSettings { .. } -- | Raw bytes at compile time of @config/settings.yml@ diff --git a/stack.yaml b/stack.yaml index 78874c0..1ba6103 100644 --- a/stack.yaml +++ b/stack.yaml @@ -44,11 +44,7 @@ extra-deps: - esqueleto-3.5.1.0 - monad-logger-extras-0.1.1.1 - wai-request-spec-0.10.2.4 - - git: https://github.com/ProofOfKeags/wai - commit: 2eef8506c7eec67fa5c1be0e0470a38e277ab5d8 - subdirs: - - warp - - warp-tls + - warp-3.3.19 # Override default flag values for local packages and extra-deps # flags: {}