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ROHCVVDA527WA4PHXCKEGZUJF2EN5MQAC
EMVTF2IWNQGRL44FC4JNG5FYYQTZSFPNM6SOM7IAEH6T7PPK2NVAC
7DBNV3GV773FH5ZLQWFX4RBOS4Q3CIK2RYZNNABY3ZOETYZCXRNQC
VJPT6HDRMJAJD5PT3VOYJYW43ISKLICEHLSDWSROX2XZWO2OFZPQC
ADMKQQGCGVSHHIMVQ4XFRDCG544SBJCYALSKZV45CQQBZ4ACUH2AC
I2KHGVD44KT4MQJXGCTVSQKMBO6TVCY72F26TLXGWRL6PHGF6RNQC
XTBSG4C7SCZUFOU2BTNFR6B6TCGYI35BWUV4PVTS3N7KNH5VEARQC
PBD7LZYQHXAA3KLH2ZUX5GW4UFML6BQ32KXZF4KZ6OYFASUYFJ5QC
BROSTG5KP3NUNLSYPVQID254TE47E5RKQAKLPIY7PGWETE6JNMTAC
recordEvent' :: ProjectId -> UserId -> LogEntry -> QDBM EventId
recordEvent' (ProjectId pid) (UserId uid) (LogEntry a e m) = do
createEvent' :: ProjectId -> UserId -> LogEntry -> QDBM EventId
createEvent' (ProjectId pid) (UserId uid) (LogEntry a e m) = do
, newAuction :: ProjectId -> Auction -> m AuctionId
, readAuction :: AuctionId -> m (Maybe Auction)
, recordBid :: AuctionId -> Bid -> m ()
, createAuction :: ProjectId -> Auction -> m AuctionId
, findAuction :: AuctionId -> m (Maybe Auction)
, createBid :: AuctionId -> Bid -> m ()
payoutsJSON :: Payouts -> Value
payoutsJSON (Payouts m) = toJSON $ MS.mapKeys (^. _BtcAddr) m
parsePayoutsJSON :: Value -> Parser Payouts
parsePayoutsJSON v =
Payouts . MS.mapKeys BtcAddr <$> parseJSON v
workIndexJSON :: WorkIndex -> Value
workIndexJSON (WorkIndex widx) =
toJSON $ (L.toList . fmap intervalJSON) <$> (MS.mapKeysMonotonic (^._BtcAddr) widx)
eventIdJSON :: EventId -> Value
eventIdJSON (EventId eid) = toJSON eid
payoutsJSON :: Payouts -> Value
payoutsJSON (Payouts m) = toJSON $ MS.mapKeys (^. _BtcAddr) m
parsePayoutsJSON :: Value -> Parser Payouts
parsePayoutsJSON v =
Payouts . MS.mapKeys BtcAddr <$> parseJSON v
instance A.ToJSON Payouts where
toJSON = versioned (Version 1 0 0) . payoutsJSON
instance A.FromJSON Payouts where
parseJSON v = let parsePayouts (Version 1 0 0) = parsePayoutsJSON
parsePayouts v' = \_ -> fail . show $ printVersion v'
in unversion parsePayouts $ v
addRoutes [ ("login", requireLogin >> (redirect "/home"))
, ("register", void $ method POST registerHandler)
, ("projects/:projectId/logStart/:btcAddr", serveJSON eventIdJSON . method POST $ logWorkHandler StartWork)
, ("projects/:projectId/logEnd/:btcAddr", serveJSON eventIdJSON . method POST $ logWorkHandler StopWork)
, ("projects/:projectId/log/:btcAddr", serveJSON workIndexJSON $ method GET loggedIntervalsHandler)
, ("projects/:projectId", serveJSON projectJSON $ method GET projectGetHandler)
, ("projects", void $ method POST projectCreateHandler)
, ("payouts/:projectId", serveJSON id $ method GET payoutsHandler)
let loginRoute = requireLogin >> redirect "/home"
registerRoute = void $ method POST registerHandler
logEventRoute f = serveJSON eventIdJSON . method POST $ logWorkHandler f
loggedIntervalsRoute = serveJSON workIndexJSON $ method GET loggedIntervalsHandler
projectCreateRoute = void $ method POST projectCreateHandler
projectRoute = serveJSON projectJSON $ method GET projectGetHandler
listProjectsRoute = serveJSON (fmap qdbProjectJSON) $ method GET projectListHandler
payoutsRoute = serveJSON payoutsJSON $ method GET payoutsHandler
addRoutes [ ("login", loginRoute)
, ("register", registerRoute)
, ("projects/:projectId/logStart/:btcAddr", logEventRoute StartWork)
, ("projects/:projectId/logEnd/:btcAddr", logEventRoute StopWork)
, ("projects/:projectId/log/:btcAddr", loggedIntervalsRoute)
, ("projects/:projectId", projectRoute)
, ("projects", listProjectsRoute)
, ("projects", projectCreateRoute)
, ("payouts/:projectId", payoutsRoute)
projectGetHandler :: Handler App App Project
projectGetHandler = do
QDB{..} <- view qdb <$> with qm get
uid <- requireUserId
pid <- requireProjectAccess uid
mp <- liftPG . runReaderT $ findProject pid
maybe (snapError 404 $ "Project not found for id " <> tshow pid) pure mp