mirror of
https://github.com/Start9Labs/registry.git
synced 2026-03-30 11:51:57 +00:00
add read instance for emver version
This commit is contained in:
committed by
Keagan McClelland
parent
bde94383d0
commit
256bd53c26
@@ -169,20 +169,22 @@ getServiceListR = do
|
|||||||
, serviceListResServices = services
|
, serviceListResServices = services
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-- >>> readMaybe $ "0.3.0" :: Maybe Version
|
||||||
|
-- Just 0.3.0
|
||||||
|
|
||||||
getServiceR :: Handler ServiceRes
|
getServiceR :: Handler ServiceRes
|
||||||
getServiceR = do
|
getServiceR = do
|
||||||
getParameters <- reqGetParams <$> getRequest
|
getParameters <- reqGetParams <$> getRequest
|
||||||
(service, version) <- case lookup "id" getParameters of
|
(service, version) <- case lookup "id" getParameters of
|
||||||
Nothing -> sendResponseStatus status404 ("id param should exist" :: Text)
|
Nothing -> sendResponseStatus status404 ("id param should exist" :: Text)
|
||||||
Just appId' -> do
|
Just appId' -> do
|
||||||
versionString <- T.filter (not . isSpace) . fromMaybe "*" <$> lookupGetParam "version"
|
case lookup "version" getParameters of
|
||||||
case readMaybe versionString of
|
-- default to latest - need to determine best available based on OS version?
|
||||||
Nothing -> do
|
Nothing -> runDB $ fetchLatestApp appId' >>= errOnNothing status404 "service not found"
|
||||||
sendResponseStatus status400 ("Invalid App Version Specification" :: Text)
|
Just v -> do
|
||||||
-- default to latest - need to determine best available based on OS version?
|
case readMaybe v of
|
||||||
-- runDB $ fetchLatestApp appId' >>= errOnNothing status404 "service not found"
|
Nothing -> sendResponseStatus status400 ("Invalid App Version Specification" :: Text)
|
||||||
Just v -> runDB $ fetchLatestAppAtVersion appId' v >>= errOnNothing status404 ("service at version " <> show v <> " not found")
|
Just vv -> runDB $ fetchLatestAppAtVersion appId' vv >>= errOnNothing status404 ("service at version " <> show v <> " not found")
|
||||||
$logInfo $ "*******************" <> show version
|
|
||||||
(versions, mappedVersions) <- fetchAllAppVersions (entityKey service)
|
(versions, mappedVersions) <- fetchAllAppVersions (entityKey service)
|
||||||
categories <- runDB $ fetchAppCategories (entityKey service)
|
categories <- runDB $ fetchAppCategories (entityKey service)
|
||||||
(appsDir, appMgrDir) <- getsYesod $ ((</> "apps") . resourcesDir &&& staticBinDir) . appSettings
|
(appsDir, appMgrDir) <- getsYesod $ ((</> "apps") . resourcesDir &&& staticBinDir) . appSettings
|
||||||
|
|||||||
@@ -9,8 +9,6 @@ import Database.Persist.Postgresql
|
|||||||
import Data.Aeson
|
import Data.Aeson
|
||||||
import Control.Monad
|
import Control.Monad
|
||||||
import Yesod.Core
|
import Yesod.Core
|
||||||
import Data.String.Interpolate.IsString
|
|
||||||
import qualified Data.ByteString.Lazy as BS
|
|
||||||
|
|
||||||
data CategoryTitle = FEATURED
|
data CategoryTitle = FEATURED
|
||||||
| BITCOIN
|
| BITCOIN
|
||||||
@@ -42,6 +40,3 @@ instance ToContent CategoryTitle where
|
|||||||
instance ToTypedContent CategoryTitle where
|
instance ToTypedContent CategoryTitle where
|
||||||
toTypedContent = toTypedContent . toJSON
|
toTypedContent = toTypedContent . toJSON
|
||||||
|
|
||||||
cat :: BS.ByteString
|
|
||||||
cat = [i|"featured"|]
|
|
||||||
|
|
||||||
|
|||||||
@@ -52,13 +52,16 @@ import Data.Aeson
|
|||||||
import Startlude (Hashable)
|
import Startlude (Hashable)
|
||||||
|
|
||||||
-- | AppVersion is the core representation of the SemverQuad type.
|
-- | AppVersion is the core representation of the SemverQuad type.
|
||||||
newtype Version = Version { unVersion :: (Word, Word, Word, Word) } deriving (Eq, Ord, ToJSONKey, Hashable, Read)
|
newtype Version = Version { unVersion :: (Word, Word, Word, Word) } deriving (Eq, Ord, ToJSONKey, Hashable)
|
||||||
instance Show Version where
|
instance Show Version where
|
||||||
show (Version (x, y, z, q)) =
|
show (Version (x, y, z, q)) =
|
||||||
let postfix = if q == 0 then "" else '.' : show q in show x <> "." <> show y <> "." <> show z <> postfix
|
let postfix = if q == 0 then "" else '.' : show q in show x <> "." <> show y <> "." <> show z <> postfix
|
||||||
instance IsString Version where
|
instance IsString Version where
|
||||||
fromString s = either error id $ Atto.parseOnly parseVersion (T.pack s)
|
fromString s = either error id $ Atto.parseOnly parseVersion (T.pack s)
|
||||||
|
instance Read Version where
|
||||||
|
readsPrec _ s = case Atto.parseOnly parseVersion (T.pack s) of
|
||||||
|
Left _ -> []
|
||||||
|
Right a -> [(a, "")]
|
||||||
-- | A change in the value found at 'major' implies a breaking change in the API that this version number describes
|
-- | A change in the value found at 'major' implies a breaking change in the API that this version number describes
|
||||||
major :: Version -> Word
|
major :: Version -> Word
|
||||||
major (Version (x, _, _, _)) = x
|
major (Version (x, _, _, _)) = x
|
||||||
|
|||||||
Reference in New Issue
Block a user