Visitar URL original
Provide snapshot content as JSON by zudov · Pull Request #152 · commercialhaskell/stackage-server · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions Handler/StackageHome.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Stackage.Database
import Stackage.Database.Types (isLts)
import Stackage.Snapshot.Diff

getStackageHomeR :: SnapName -> Handler Html
getStackageHomeR :: SnapName -> Handler TypedContent
getStackageHomeR name = do
Entity sid snapshot <- lookupSnapshot name >>= maybe notFound return
previousSnapName <- fromMaybe name . map snd <$> snapshotBefore (snapshotName snapshot)
Expand All @@ -22,12 +22,26 @@ getStackageHomeR name = do
exact = False
in $(widgetFile "hoogle-form")
packageCount <- getPackageCount sid
defaultLayout $ do
setTitle $ toHtml $ snapshotTitle snapshot
packages <- getPackages sid
$(widgetFile "stackage-home")
packages <- getPackages sid
selectRep $ do
provideRep $ do
defaultLayout $ do
setTitle $ toHtml $ snapshotTitle snapshot
$(widgetFile "stackage-home")
provideRep $ pure $ toJSON $ SnapshotInfo snapshot packages


where strip x = fromMaybe x (stripSuffix "." x)

data SnapshotInfo
= SnapshotInfo { snapshot :: Snapshot
, packages :: [PackageListingInfo]
}
instance ToJSON SnapshotInfo where
toJSON SnapshotInfo{..} = object [ "snapshot" .= snapshot
, "packages" .= packages
]

getStackageDiffR :: SnapName -> SnapName -> Handler TypedContent
getStackageDiffR name1 name2 = do
Entity sid1 _ <- lookupSnapshot name1 >>= maybe notFound return
Expand Down
15 changes: 15 additions & 0 deletions Stackage/Database.hs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ Deprecated
UniqueDeprecated package
|]

instance A.ToJSON Snapshot where
toJSON Snapshot{..} =
A.object [ "name" A..= snapshotName
, "ghc" A..= snapshotGhc
, "created" A..= formatTime defaultTimeLocale "%F" snapshotCreated
]

_hideUnusedWarnings
:: ( SnapshotPackageId
, SchemaId
Expand Down Expand Up @@ -490,6 +497,14 @@ data PackageListingInfo = PackageListingInfo
, pliIsCore :: !Bool
}

instance A.ToJSON PackageListingInfo where
toJSON PackageListingInfo{..} =
A.object [ "name" A..= pliName
, "version" A..= pliVersion
, "synopsis" A..= pliSynopsis
, "isCore" A..= pliIsCore
]

getPackages :: GetStackageDatabase m => SnapshotId -> m [PackageListingInfo]
getPackages sid = liftM (map toPLI) $ run $ do
E.select $ E.from $ \(p,sp) -> do
Expand Down
3 changes: 3 additions & 0 deletions Stackage/Database/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ isNightly SNNightly{} = True
instance ToJSONKey SnapName where
toJSONKey = toPathPiece

instance ToJSON SnapName where
toJSON = String . toPathPiece

instance PersistField SnapName where
toPersistValue = toPersistValue . toPathPiece
fromPersistValue v = do
Expand Down