mirror of
https://github.com/Start9Labs/registry.git
synced 2026-03-26 02:11:53 +00:00
add read instance for emver version
This commit is contained in:
committed by
Keagan McClelland
parent
d64e9b71c6
commit
f3c1a055df
@@ -169,20 +169,22 @@ getServiceListR = do
|
||||
, serviceListResServices = services
|
||||
}
|
||||
|
||||
-- >>> readMaybe $ "0.3.0" :: Maybe Version
|
||||
-- Just 0.3.0
|
||||
|
||||
getServiceR :: Handler ServiceRes
|
||||
getServiceR = do
|
||||
getParameters <- reqGetParams <$> getRequest
|
||||
(service, version) <- case lookup "id" getParameters of
|
||||
Nothing -> sendResponseStatus status404 ("id param should exist" :: Text)
|
||||
Just appId' -> do
|
||||
versionString <- T.filter (not . isSpace) . fromMaybe "*" <$> lookupGetParam "version"
|
||||
case readMaybe versionString of
|
||||
Nothing -> do
|
||||
sendResponseStatus status400 ("Invalid App Version Specification" :: Text)
|
||||
-- default to latest - need to determine best available based on OS version?
|
||||
-- runDB $ fetchLatestApp appId' >>= errOnNothing status404 "service not found"
|
||||
Just v -> runDB $ fetchLatestAppAtVersion appId' v >>= errOnNothing status404 ("service at version " <> show v <> " not found")
|
||||
$logInfo $ "*******************" <> show version
|
||||
case lookup "version" getParameters of
|
||||
-- default to latest - need to determine best available based on OS version?
|
||||
Nothing -> runDB $ fetchLatestApp appId' >>= errOnNothing status404 "service not found"
|
||||
Just v -> do
|
||||
case readMaybe v of
|
||||
Nothing -> sendResponseStatus status400 ("Invalid App Version Specification" :: Text)
|
||||
Just vv -> runDB $ fetchLatestAppAtVersion appId' vv >>= errOnNothing status404 ("service at version " <> show v <> " not found")
|
||||
(versions, mappedVersions) <- fetchAllAppVersions (entityKey service)
|
||||
categories <- runDB $ fetchAppCategories (entityKey service)
|
||||
(appsDir, appMgrDir) <- getsYesod $ ((</> "apps") . resourcesDir &&& staticBinDir) . appSettings
|
||||
@@ -310,4 +312,4 @@ mapEntityToServiceAvailable appMgrDir appsDir domain service = do
|
||||
, serviceAvailableDescShort = sAppDescShort $ entityVal service
|
||||
, serviceAvailableVersion = appVersion
|
||||
, serviceAvailableIcon = icon
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,8 +9,6 @@ import Database.Persist.Postgresql
|
||||
import Data.Aeson
|
||||
import Control.Monad
|
||||
import Yesod.Core
|
||||
import Data.String.Interpolate.IsString
|
||||
import qualified Data.ByteString.Lazy as BS
|
||||
|
||||
data CategoryTitle = FEATURED
|
||||
| BITCOIN
|
||||
@@ -42,6 +40,3 @@ instance ToContent CategoryTitle where
|
||||
instance ToTypedContent CategoryTitle where
|
||||
toTypedContent = toTypedContent . toJSON
|
||||
|
||||
cat :: BS.ByteString
|
||||
cat = [i|"featured"|]
|
||||
|
||||
|
||||
@@ -52,13 +52,16 @@ import Data.Aeson
|
||||
import Startlude (Hashable)
|
||||
|
||||
-- | 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
|
||||
show (Version (x, y, z, q)) =
|
||||
let postfix = if q == 0 then "" else '.' : show q in show x <> "." <> show y <> "." <> show z <> postfix
|
||||
instance IsString Version where
|
||||
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
|
||||
major :: Version -> Word
|
||||
major (Version (x, _, _, _)) = x
|
||||
|
||||
Reference in New Issue
Block a user