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HLRNYQPXFHBQSNQN53OKRFCXLQEYDTC5I4QC
HE3JTXO37O4MOMWPZ4BRBHP53KBPZDG3PCSUCVNOKIS7IY26OCIAC
OBFPJS2GHO2PEHBHGEHKIUOUAFIQHPIZXEVD2YIE3ZIE2PVMH5VAC
PBD7LZYQHXAA3KLH2ZUX5GW4UFML6BQ32KXZF4KZ6OYFASUYFJ5QC
5DRIWGLUKMQZU2ZPBXSTLAWJKAMOD5YXAHM5LEDQHDFGYYLHWCDQC
7KZP4RHZ3QSYTPPQ257A65Z5UPX44TF2LAI2U5EMULQCLDCEUK2AC
WZUHEZSBRKHQMNWDKVG4X6DDIQEAXTGI6IGAJ5ERPRQ3W2KUMX4QC
ADMKQQGCGVSHHIMVQ4XFRDCG544SBJCYALSKZV45CQQBZ4ACUH2AC
2Y2QZFVFSKXEFEGYJB5A7GI735ONWPCF7DVTIY5T73AUEVTZTBBQC
TCOAKCGGHOIRJCTZYEZQ3K6KCGL2LGAYGYFRGSPCHBTJJY2V6AXAC
Z3M53KTLZMPOISMHE25SZJSWX5TA37IV33IRE7KNRAD3PKEAEJXQC
NJZ3DKZYZTAEHPAEXS3XFWIPCJFR3D4642UQMGQABVFGNKQUEQVAC
I2KHGVD44KT4MQJXGCTVSQKMBO6TVCY72F26TLXGWRL6PHGF6RNQC
BROSTG5KP3NUNLSYPVQID254TE47E5RKQAKLPIY7PGWETE6JNMTAC
XTBSG4C7SCZUFOU2BTNFR6B6TCGYI35BWUV4PVTS3N7KNH5VEARQC
findEvents' :: ProjectId -> UserId -> Interval' -> QDBM [LogEntry]
findEvents' (ProjectId pid) (UserId uid) ival =
let q (Before e) = pquery
"SELECT btc_addr, event_type, event_time, event_metadata FROM work_events \
\WHERE project_id = ? AND user_id = ? AND event_time <= ?"
(pid, uid, PUTCTime e)
q (During s e) = pquery
"SELECT btc_addr, event_type, event_time, event_metadata FROM work_events \
\WHERE project_id = ? AND user_id = ? \
\AND event_time >= ? AND event_time <= ?"
(pid, uid, PUTCTime s, PUTCTime e)
q (After s) = pquery
"SELECT btc_addr, event_type, event_time, event_metadata FROM work_events \
\WHERE project_id = ? AND user_id = ? AND event_time >= ?"
(pid, uid, PUTCTime s)
in fmap pLogEntry <$> q ival
base >= 4 && < 5
, classy-prelude >= 0.10.1
, aeson >= 0.8.0.2
, attoparsec >= 0.12.1.2
, base64-bytestring >= 1.0.0.1
base >= 4 && < 5
, classy-prelude >= 0.10.1
, aeson >= 0.8.0.2
, attoparsec >= 0.12.1.2
, base64-bytestring >= 1.0.0.1
, containers >= 0.5.5.1
, configurator
, either >= 4.3.1
, errors >= 1.4.7
, groups >= 0.4
, heaps >= 0.3.1
, hourglass >= 0.2.6 && < 0.3
, lens >= 4.4.0.2
, network-bitcoin >= 1.7.0
, containers >= 0.5.5.1
, configurator
, either >= 4.3.1
, errors >= 1.4.7
, groups >= 0.4
, heaps >= 0.3.1
, hourglass >= 0.2.6 && < 0.3
, lens >= 4.4.0.2
, network-bitcoin >= 1.7.0
loggedIntervalsRoute = serveJSON workIndexJSON $ method GET loggedIntervalsHandler
logEntriesRoute = serveJSON (fmap logEntryJSON) $ method GET logEntriesHandler
logIntervalsRoute = serveJSON workIndexJSON $ method GET loggedIntervalsHandler
--amendEventRoute = void $ method PUT amendEventHandler
, ("projects/:projectId/logEnd/:btcAddr", logEventRoute StopWork)
, ("projects/:projectId/log/:btcAddr", loggedIntervalsRoute)
, ("projects/:projectId", projectRoute)
, ("projects", listProjectsRoute)
, ("projects/:projectId/logEnd/:btcAddr", logEventRoute StopWork)
, ("projects/:projectId/logEntries", logEntriesRoute)
, ("projects/:projectId/intervals", logIntervalsRoute)
module Quixotic.Snaplet.Util where
import ClassyPrelude
import Control.Monad.Trans.Maybe
import Data.ByteString.Char8 as B
import Data.Time.ISO8601
import Data.Thyme.Time
import Data.Thyme.Clock as C
import Snap.Core
timeParam :: MonadSnap m => ByteString -> m (Maybe C.UTCTime)
timeParam k = runMaybeT $ do
bs <- MaybeT $ getParam k
t <- MaybeT . pure . parseISO8601 $ B.unpack bs
pure $ toThyme t
logEntriesHandler :: Handler App App [LogEntry]
logEntriesHandler = do
QDB{..} <- view qdb <$> with qm get
(uid, pid) <- requireProjectAccess
endpoints <- (,) <$> timeParam "after" <*> timeParam "before"
ival <- case endpoints of
(Just s, Just e) -> pure $ During s e
(Nothing, Just e) -> pure $ Before e
(Just s, Nothing) -> pure $ After s
(Nothing, Nothing) -> snapError 400 $ "You must at least one of the \"after\" or \"before\" query parameter"
liftPG . runReaderT $ findEvents pid uid ival
-- amendEventHandler :: Handler App App AmendmentId