mirror of
https://github.com/Start9Labs/registry.git
synced 2026-03-26 10:21:51 +00:00
alter category to optional
This commit is contained in:
@@ -13,8 +13,8 @@ import Data.HashMap.Strict
|
||||
import Data.Version
|
||||
import Data.Aeson
|
||||
|
||||
searchServices :: MonadIO m => CategoryTitle -> Int64 -> Int64 -> Text -> ReaderT SqlBackend m [P.Entity SApp]
|
||||
searchServices ANY pageItems offset' query = select $ do
|
||||
searchServices :: MonadIO m => Maybe CategoryTitle -> Int64 -> Int64 -> Text -> ReaderT SqlBackend m [P.Entity SApp]
|
||||
searchServices Nothing pageItems offset' query = select $ do
|
||||
service <- from $ table @SApp
|
||||
where_ ((service ^. SAppDescShort `ilike` (%) ++. val query ++. (%))
|
||||
||. (service ^. SAppDescLong `ilike` (%) ++. val query ++. (%))
|
||||
@@ -24,7 +24,7 @@ searchServices ANY pageItems offset' query = select $ do
|
||||
limit pageItems
|
||||
offset offset'
|
||||
pure service
|
||||
searchServices category pageItems offset' query = select $ do
|
||||
searchServices (Just category) pageItems offset' query = select $ do
|
||||
services <- from
|
||||
(do
|
||||
(service :& sc) <-
|
||||
|
||||
@@ -142,7 +142,7 @@ data ServiceListDefaults = ServiceListDefaults
|
||||
{ serviceListOrder :: OrderArrangement
|
||||
, serviceListPageLimit :: Int64 -- the number of items per page
|
||||
, serviceListPageNumber :: Int64 -- the page you are on
|
||||
, serviceListCategory :: CategoryTitle
|
||||
, serviceListCategory :: Maybe CategoryTitle
|
||||
, serviceListQuery :: Text
|
||||
}
|
||||
deriving (Eq, Show, Read)
|
||||
@@ -224,7 +224,7 @@ getPackageListR = do
|
||||
{ serviceListOrder = DESC
|
||||
, serviceListPageLimit = 20
|
||||
, serviceListPageNumber = 1
|
||||
, serviceListCategory = ANY
|
||||
, serviceListCategory = Nothing
|
||||
, serviceListQuery = ""
|
||||
}
|
||||
case lookup "ids" getParameters of
|
||||
@@ -236,7 +236,7 @@ getPackageListR = do
|
||||
Nothing -> do
|
||||
$logInfo c
|
||||
sendResponseStatus status400 ("could not read category" :: Text)
|
||||
Just t -> pure t
|
||||
Just t -> pure $ Just t
|
||||
page <- case lookup "page" getParameters of
|
||||
Nothing -> pure $ serviceListPageNumber defaults
|
||||
Just p -> case readMaybe p of
|
||||
|
||||
@@ -8,15 +8,14 @@ import Database.Persist.Postgresql
|
||||
import Data.Aeson
|
||||
import Control.Monad
|
||||
import Yesod.Core
|
||||
import qualified Data.Text as T
|
||||
|
||||
data CategoryTitle = FEATURED
|
||||
| BITCOIN
|
||||
| LIGHTNING
|
||||
| DATA
|
||||
| MESSAGING
|
||||
| SOCIAL
|
||||
| NONE
|
||||
| ANY
|
||||
| ALTCOIN
|
||||
deriving (Eq, Enum, Show, Read)
|
||||
instance PersistField CategoryTitle where
|
||||
fromPersistValue = fromPersistValueJSON
|
||||
@@ -24,7 +23,15 @@ instance PersistField CategoryTitle where
|
||||
instance PersistFieldSql CategoryTitle where
|
||||
sqlType _ = SqlString
|
||||
instance ToJSON CategoryTitle where
|
||||
toJSON = String . T.toLower . show
|
||||
-- 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
|
||||
@@ -33,8 +40,7 @@ instance FromJSON CategoryTitle where
|
||||
"data" -> pure DATA
|
||||
"messaging" -> pure MESSAGING
|
||||
"social" -> pure SOCIAL
|
||||
"none" -> pure NONE
|
||||
"any" -> pure ANY
|
||||
"alt coin" -> pure ALTCOIN
|
||||
_ -> fail "unknown category title"
|
||||
instance ToContent CategoryTitle where
|
||||
toContent = toContent . toJSON
|
||||
|
||||
Reference in New Issue
Block a user