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