Add GET handler for retrieving auction data.
[?]
Mar 20, 2016, 10:14 PM
Z3MK2PJ5U222DXRS22WCDHVPZ7HVAR3HOCUNXIGX6VMEPBQDF6PQCDependencies
- [2]
5OI44E4EAdd authentication to auction search. - [3]
NLZ3JXLOFix formatting with stylish-haskell. - [4]
GCVQD44VCreate amends endpoint, switch to UUID primary keys - [5]
QMRKFEPGRefactor QDB to use a free monad algebra instead. - [6]
NEDDHXUKReformat via stylish-haskell - [7]
Z7KS5XHHVery WIP. Wow. - [8]
W35DDBFYFactor common JSON conversions up into client lib module. - [9]
RPAJLHMTChange to use UUIDs instead of ints for primary keys. - [10]
XTBSG4C7Adding serveJSON combinator to eliminate some boilerplate from handlers. - [11]
PBD7LZYQPostgres & auth are beginning to function. - [12]
HALRDT2FAdded initial auction create route. - [13]
I2KHGVD4Require project permissions for access to most data. - [14]
7HPY3QPFFix linting errors. (yay hlint!) - [15]
2XQD6KKKAdd invitation logic and clean up DBProg error handling. - [16]
A6HKMINBAttempting to improve JSON handling. - [17]
O5FVTOM6Undo JSON silliness, enable a couple more routes. - [*]
KEP5WUFJConvert project to stack-based build. - [*]
ADMKQQGCInitial empty Snap project.
Change contents
- replacement in lib/Aftok/Json.hs at line 11
import qualified Data.Attoparsec.ByteString.Char8 as Pimport qualified Data.Attoparsec.ByteString.Char8 as PC - edit in lib/Aftok/Json.hs at line 18
import Aftok.Auction as A - replacement in lib/Aftok/Json.hs at line 21
import Aftok.Projectimport Aftok.Project as P - edit in lib/Aftok/Json.hs at line 23
import Aftok.Types - replacement in lib/Aftok/Json.hs at line 35
versionParser :: P.Parser VersionversionParser = Version <$> P.decimal <*> (P.char '.' >> P.decimal)versionParser :: PC.Parser VersionversionParser = Version <$> PC.decimal <*> (PC.char '.' >> PC.decimal) - replacement in lib/Aftok/Json.hs at line 48
v <- either (fail . show) pure $ P.parseOnly versionParser (C.pack s)v <- either (fail . show) pure $ PC.parseOnly versionParser (C.pack s) - replacement in lib/Aftok/Json.hs at line 62
vers <- either fail pure $ P.parseOnly versionParser (encodeUtf8 verstr)vers <- either fail pure $ PC.parseOnly versionParser (encodeUtf8 verstr) - replacement in lib/Aftok/Json.hs at line 95
, "initiator" .= tshow (p ^. (initiator._UserId)), "initiator" .= tshow (p ^. (P.initiator._UserId))]auctionJSON :: Auction -> ValueauctionJSON x = v1 $object [ "projectId" .= tshow (x ^. (A.projectId._ProjectId)), "initiator" .= tshow (x ^. (A.initiator._UserId)), "raiseAmount" .= (x ^. (raiseAmount._Satoshi)) - edit in lib/Aftok/Types.hs at line 2
{-# LANGUAGE TemplateHaskell #-} - edit in lib/Aftok/Types.hs at line 7
import Control.Lens - edit in lib/Aftok/Types.hs at line 11
makePrisms ''Satoshi - edit in server/Aftok/Snaplet/Auctions.hs at line 5
, auctionGetHandler - edit in server/Aftok/Snaplet/Auctions.hs at line 13
--import Data.Thyme.Format.Aeson () - edit in server/Aftok/Snaplet/Auctions.hs at line 14
import Aftok.Database (createAuction) - edit in server/Aftok/Snaplet/Auctions.hs at line 15
import Aftok.Database (createAuction, findAuction) - replacement in server/Aftok/Snaplet/Auctions.hs at line 22
import Snap.Snapletimport Snap - edit in server/Aftok/Snaplet/Auctions.hs at line 41[2.1121]
auctionGetHandler :: Handler App App AuctionauctionGetHandler = douid <- requireUserIdaid <- requireAuctionIdmaybeAuc <- snapEval $ findAuction aid uidmaybe (snapError 404 $ "Auction not found for id " <> tshow aid) pure maybeAuc - edit in server/Aftok/Snaplet/Auth.hs at line 6
-- import Control.Monad.State - edit in server/Aftok/Snaplet/Auth.hs at line 10
import Aftok.Auction (AuctionId(..)) - edit in server/Aftok/Snaplet/Auth.hs at line 18
-- import Snap.Snaplet.PostgresqlSimple - edit in server/Aftok/Snaplet/Auth.hs at line 51
requireAuctionId :: MonadSnap m => m AuctionIdrequireAuctionId = domaybeAid <- parseParam "auctionId" aidParsermaybe (snapError 400 "Value of parameter \"auctionId\" cannot be parsed as a valid UUID")puremaybeAidwhereaidParser = dobs <- takeByteStringpure $ AuctionId <$> fromASCIIBytes bs - replacement in server/Main.hs at line 49
logIntervalsRoute = serveJSON workIndexJSON $ method GET loggedIntervalsHandlerlogIntervalsRoute = serveJSON workIndexJSON $ method GET loggedIntervalsHandler - edit in server/Main.hs at line 54
auctionRoute = serveJSON auctionJSON $ method GET auctionGetHandler - edit in server/Main.hs at line 74
, ("auctions/:auctionId", auctionRoute)