remove category enum (#97)

* remove category enum

* priority inversion, 0 is always first

* set marketplace name default to something more obviously wrong.
This commit is contained in:
Keagan McClelland
2022-03-01 16:39:13 -07:00
committed by GitHub
parent 75663b65e4
commit cdadae707c
7 changed files with 9 additions and 59 deletions

View File

@@ -35,6 +35,7 @@ registry-hostname: "_env:REGISTRY_HOSTNAME:alpha-registry.start9labs.com"
tor-port: "_env:TOR_PORT:447"
static-bin-dir: "_env:STATIC_BIN:/usr/local/bin/"
error-log-root: "_env:ERROR_LOG_ROOT:/var/log/embassy-os/"
marketplace-name: "_env:MARKETPLACE_NAME:CHANGE ME"
database:
database: "_env:PG_DATABASE:start9_registry"

View File

@@ -39,10 +39,8 @@ import Database.Persist.Postgresql
, selectSource
, (||.)
)
import Handler.Types.Marketplace ( PackageDependencyMetadata(..)
)
import Handler.Types.Marketplace ( PackageDependencyMetadata(..) )
import Lib.Types.AppIndex ( PkgId )
import Lib.Types.Category
import Lib.Types.Emver ( Version )
import Model
import Startlude hiding ( (%)
@@ -51,6 +49,8 @@ import Startlude hiding ( (%)
, yield
)
type CategoryTitle = Text
searchServices :: (MonadResource m, MonadIO m)
=> Maybe CategoryTitle
-> Text

View File

@@ -56,6 +56,7 @@ import Database.Esqueleto.Experimental
( Entity(entityKey, entityVal)
, SqlBackend
, (^.)
, asc
, desc
, from
, orderBy
@@ -85,7 +86,6 @@ import Lib.PkgRepository ( PkgRepo
, getManifest
)
import Lib.Types.AppIndex ( PkgId )
import Lib.Types.Category ( CategoryTitle(..) )
import Lib.Types.Emver ( Version
, VersionRange
, parseRange
@@ -138,7 +138,7 @@ getInfoR = do
name <- getsYesod $ marketplaceName . appSettings
allCategories <- runDB $ select $ do
cats <- from $ table @Category
orderBy [desc (cats ^. CategoryPriority)]
orderBy [asc (cats ^. CategoryPriority)]
pure cats
pure $ InfoRes name $ categoryName . entityVal <$> allCategories

View File

@@ -5,7 +5,6 @@ module Handler.Types.Marketplace where
import Data.Aeson
import qualified Data.HashMap.Internal.Strict as HM
import Lib.Types.AppIndex ( PkgId )
import Lib.Types.Category ( CategoryTitle )
import Lib.Types.Emver ( Version
, VersionRange
)
@@ -19,6 +18,7 @@ import Yesod
type URL = Text
type CategoryTitle = Text
data InfoRes = InfoRes
{ name :: Text
, categories :: [CategoryTitle]

View File

@@ -1,50 +0,0 @@
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE DeriveGeneric #-}
module Lib.Types.Category where
import Startlude
import Database.Persist.Postgresql
import Data.Aeson
import Control.Monad
import Yesod.Core
data CategoryTitle = FEATURED
| BITCOIN
| LIGHTNING
| DATA
| MESSAGING
| SOCIAL
| ALTCOIN
deriving (Eq, Enum, Show, Read, Generic)
instance PersistField CategoryTitle where
fromPersistValue = fromPersistValueJSON
toPersistValue = toPersistValueJSON
instance PersistFieldSql CategoryTitle where
sqlType _ = SqlString
instance ToJSON CategoryTitle where
-- toJSON = String . T.toLower . show
toJSON = \case
FEATURED -> "featured"
BITCOIN -> "bitcoin"
LIGHTNING -> "lightning"
DATA -> "data"
MESSAGING -> "messaging"
SOCIAL -> "social"
ALTCOIN -> "alt coin"
instance FromJSON CategoryTitle where
parseJSON = withText "CategoryTitle" $ \case
"featured" -> pure FEATURED
"bitcoin" -> pure BITCOIN
"lightning" -> pure LIGHTNING
"data" -> pure DATA
"messaging" -> pure MESSAGING
"social" -> pure SOCIAL
"alt coin" -> pure ALTCOIN
_ -> fail "unknown category title"
instance ToContent CategoryTitle where
toContent = toContent . toJSON
instance ToTypedContent CategoryTitle where
toTypedContent = toTypedContent . toJSON
instance Hashable CategoryTitle

View File

@@ -13,7 +13,6 @@ module Model where
import Database.Persist.TH
import Lib.Types.AppIndex
import Lib.Types.Category
import Lib.Types.Emver
import Orphans.Emver ( )
import Startlude
@@ -60,7 +59,7 @@ Metric
Category
createdAt UTCTime
name CategoryTitle
name Text
parent CategoryId Maybe
description Text
priority Int default=0

View File

@@ -95,7 +95,7 @@ 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"
marketplaceName <- o .: "marketplace-name"
return AppSettings { .. }