mirror of
https://github.com/Start9Labs/registry.git
synced 2026-03-26 10:21:51 +00:00
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:
committed by
GitHub
parent
75663b65e4
commit
cdadae707c
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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 { .. }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user