mirror of
https://github.com/simonmichael/hledger.git
synced 2024-12-29 13:22:27 +03:00
api: cleanup
This commit is contained in:
parent
ab1d47cfe2
commit
cabcd80ad5
@ -82,7 +82,7 @@ hledgerApiApp j = Servant.serve hledgerApi hledgerApiServer
|
|||||||
|
|
||||||
-- add Reader to the server monad so handlers can see the journal
|
-- add Reader to the server monad so handlers can see the journal
|
||||||
hledgerApiServer :: Servant.Server HledgerApi
|
hledgerApiServer :: Servant.Server HledgerApi
|
||||||
hledgerApiServer = Servant.enter readerToEither hledgerServerT
|
hledgerApiServer = Servant.enter readerToEither hledgerAPIServer
|
||||||
where
|
where
|
||||||
readerToEither :: Reader Journal :~> EitherT ServantErr IO
|
readerToEither :: Reader Journal :~> EitherT ServantErr IO
|
||||||
readerToEither = Nat $ \r -> return (runReader r j)
|
readerToEither = Nat $ \r -> return (runReader r j)
|
||||||
@ -94,11 +94,10 @@ type HledgerApi =
|
|||||||
:<|> "commodities" :> Get '[JSON] [Commodity]
|
:<|> "commodities" :> Get '[JSON] [Commodity]
|
||||||
:<|> "accounts" :> Get '[JSON] [Account]
|
:<|> "accounts" :> Get '[JSON] [Account]
|
||||||
:<|> "reports" :>
|
:<|> "reports" :>
|
||||||
-- "accounttransactions" :> QueryParam "acct" AccountName :> Get '[JSON] AccountTransactionsReport
|
|
||||||
"accounttransactions" :> Capture "acct" AccountName :> Get '[JSON] AccountTransactionsReport
|
"accounttransactions" :> Capture "acct" AccountName :> Get '[JSON] AccountTransactionsReport
|
||||||
|
|
||||||
hledgerServerT :: ServerT HledgerApi (Reader Journal)
|
hledgerAPIServer :: ServerT HledgerApi (Reader Journal)
|
||||||
hledgerServerT =
|
hledgerAPIServer =
|
||||||
accountnamesH
|
accountnamesH
|
||||||
:<|> transactionsH
|
:<|> transactionsH
|
||||||
:<|> pricesH
|
:<|> pricesH
|
||||||
@ -123,8 +122,12 @@ hledgerServerT =
|
|||||||
thisacctq = Acct $ accountNameToAccountRegex a -- includes subs
|
thisacctq = Acct $ accountNameToAccountRegex a -- includes subs
|
||||||
return $ accountTransactionsReport ropts j q thisacctq
|
return $ accountTransactionsReport ropts j q thisacctq
|
||||||
|
|
||||||
instance ToJSON ClearedStatus where toJSON = genericToJSON defaultOptions -- avoid https://github.com/bos/aeson/issues/290
|
-- brief toJSON definitions included to avoid https://github.com/bos/aeson/issues/290
|
||||||
|
-- use toEncoding = genericToEncoding defaultOptions instead ?
|
||||||
|
instance ToJSON ClearedStatus where toJSON = genericToJSON defaultOptions
|
||||||
instance ToJSON GenericSourcePos where toJSON = genericToJSON defaultOptions
|
instance ToJSON GenericSourcePos where toJSON = genericToJSON defaultOptions
|
||||||
|
instance ToJSON Decimal where
|
||||||
|
toJSON = toJSON . show
|
||||||
instance ToJSON Amount where toJSON = genericToJSON defaultOptions
|
instance ToJSON Amount where toJSON = genericToJSON defaultOptions
|
||||||
instance ToJSON AmountStyle where toJSON = genericToJSON defaultOptions
|
instance ToJSON AmountStyle where toJSON = genericToJSON defaultOptions
|
||||||
instance ToJSON Side where toJSON = genericToJSON defaultOptions
|
instance ToJSON Side where toJSON = genericToJSON defaultOptions
|
||||||
@ -132,41 +135,31 @@ instance ToJSON DigitGroupStyle where toJSON = genericToJSON defaultOptions
|
|||||||
instance ToJSON MixedAmount where toJSON = genericToJSON defaultOptions
|
instance ToJSON MixedAmount where toJSON = genericToJSON defaultOptions
|
||||||
instance ToJSON Price where toJSON = genericToJSON defaultOptions
|
instance ToJSON Price where toJSON = genericToJSON defaultOptions
|
||||||
instance ToJSON MarketPrice where toJSON = genericToJSON defaultOptions
|
instance ToJSON MarketPrice where toJSON = genericToJSON defaultOptions
|
||||||
instance ToJSON Posting
|
|
||||||
where
|
|
||||||
toJSON Posting{..} =
|
|
||||||
object
|
|
||||||
["pdate" .= toJSON pdate
|
|
||||||
,"pdate2" .= toJSON pdate2
|
|
||||||
,"pstatus" .= toJSON pstatus
|
|
||||||
,"paccount" .= toJSON paccount
|
|
||||||
,"pamount" .= toJSON pamount
|
|
||||||
,"pcomment" .= toJSON pcomment
|
|
||||||
,"ptype" .= toJSON ptype
|
|
||||||
,"ptags" .= toJSON ptags
|
|
||||||
,"pbalanceassertion" .= toJSON pbalanceassertion
|
|
||||||
,"ptransactionidx" .= toJSON (maybe "" (show.tindex) ptransaction)
|
|
||||||
]
|
|
||||||
instance ToJSON PostingType where toJSON = genericToJSON defaultOptions
|
instance ToJSON PostingType where toJSON = genericToJSON defaultOptions
|
||||||
|
instance ToJSON Posting where
|
||||||
|
toJSON Posting{..} =
|
||||||
|
object
|
||||||
|
["pdate" .= toJSON pdate
|
||||||
|
,"pdate2" .= toJSON pdate2
|
||||||
|
,"pstatus" .= toJSON pstatus
|
||||||
|
,"paccount" .= toJSON paccount
|
||||||
|
,"pamount" .= toJSON pamount
|
||||||
|
,"pcomment" .= toJSON pcomment
|
||||||
|
,"ptype" .= toJSON ptype
|
||||||
|
,"ptags" .= toJSON ptags
|
||||||
|
,"pbalanceassertion" .= toJSON pbalanceassertion
|
||||||
|
,"ptransactionidx" .= toJSON (maybe "" (show.tindex) ptransaction)
|
||||||
|
]
|
||||||
instance ToJSON Transaction where toJSON = genericToJSON defaultOptions
|
instance ToJSON Transaction where toJSON = genericToJSON defaultOptions
|
||||||
instance ToJSON Decimal
|
instance ToJSON Account where
|
||||||
where
|
toJSON a =
|
||||||
-- toJSON (Decimal decimalPlaces decimalMantissa) =
|
object
|
||||||
-- object ["places" .= decimalPlaces, "mantissa" .= decimalMantissa]
|
["aname" .= toJSON (aname a)
|
||||||
-- toEncoding = genericToEncoding defaultOptions
|
,"aebalance" .= toJSON (aebalance a)
|
||||||
toJSON d = toJSON $ show d
|
,"aibalance" .= toJSON (aibalance a)
|
||||||
instance ToJSON Account
|
,"anumpostings" .= toJSON (anumpostings a)
|
||||||
where
|
,"aboring" .= toJSON (aboring a)
|
||||||
toJSON a =
|
,"aparentname" .= toJSON (maybe "" aname $ aparent a)
|
||||||
object
|
,"asubs" .= toJSON (map toJSON $ asubs a)
|
||||||
["aname" .= toJSON (aname a)
|
]
|
||||||
,"aebalance" .= toJSON (aebalance a)
|
|
||||||
,"aibalance" .= toJSON (aibalance a)
|
|
||||||
,"anumpostings" .= toJSON (anumpostings a)
|
|
||||||
,"aboring" .= toJSON (aboring a)
|
|
||||||
,"aparentname" .= toJSON (maybe "" aname $ aparent a)
|
|
||||||
,"asubs" .= toJSON (map toJSON $ asubs a)
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
instance ToJSON AccountTransactionsReport where toJSON = genericToJSON defaultOptions
|
instance ToJSON AccountTransactionsReport where toJSON = genericToJSON defaultOptions
|
||||||
|
Loading…
Reference in New Issue
Block a user