From 9ad4be6ba43362a7fc8e2fabec55e118f0d5b00b Mon Sep 17 00:00:00 2001 From: Stefan Dresselhaus Date: Fri, 7 Aug 2015 02:26:16 +0200 Subject: [PATCH] a bit templating --- Application.hs | 1 + Handler/Stock.hs | 6 ++++++ Handler/Update.hs | 7 +------ Handler/Wallet.hs | 12 ++++++++++++ config/routes | 1 + neat.cabal | 1 + test/Handler/StockSpec.hs | 10 ++++++++++ test/Handler/UpdateSpec.hs | 10 ++++++++++ 8 files changed, 42 insertions(+), 6 deletions(-) create mode 100644 Handler/Stock.hs create mode 100644 test/Handler/StockSpec.hs create mode 100644 test/Handler/UpdateSpec.hs diff --git a/Application.hs b/Application.hs index 484a5e9..1094a81 100644 --- a/Application.hs +++ b/Application.hs @@ -35,6 +35,7 @@ import Handler.Home import Handler.Wallet import Handler.Settings import Handler.Update +import Handler.Stock -- This line actually creates our YesodDispatch instance. It is the second half -- of the call to mkYesodData which occurs in Foundation.hs. Please see the diff --git a/Handler/Stock.hs b/Handler/Stock.hs new file mode 100644 index 0000000..c334ed9 --- /dev/null +++ b/Handler/Stock.hs @@ -0,0 +1,6 @@ +module Handler.Stock where + +import Import + +getStockR :: Handler Html +getStockR = error "Not yet implemented: getStockR" diff --git a/Handler/Update.hs b/Handler/Update.hs index 15a625c..471d2fe 100644 --- a/Handler/Update.hs +++ b/Handler/Update.hs @@ -8,7 +8,6 @@ import qualified Eve.Api.Types as T import qualified Eve.Api.Char.Standings as ST import qualified Eve.Api.Char.Skills as SK import Database.Persist.Sql -import qualified Debug.Trace as Debug accountingId :: Int64 accountingId = 16622 @@ -97,11 +96,7 @@ updateProfits dat = updateProfits' [] dat t' = t {transactionInStock = transactionInStock t + m} ct' = ct {transactionInStock = transactionInStock ct - m} prof' = (transactionPriceCents t - transactionPriceCents ct) * m - (t'',ct'') = if prof' > 0 then - Debug.trace ("Item "++show (transactionTypeId t)++" has profit "++show prof'++" ("++show (transactionPriceCents t)++" - "++show (transactionPriceCents ct)++")*"++show m) - $ updateProfits'' (Entity et (t' { transactionProfit = maybe (Just prof') (\a -> Just (a + prof')) (transactionProfit t')})) ts - else - updateProfits'' (Entity et (t' { transactionProfit = maybe (Just prof') (\a -> Just (a + prof')) (transactionProfit t')})) ts + (t'',ct'') = updateProfits'' (Entity et (t' { transactionProfit = maybe (Just prof') (\a -> Just (a + prof')) (transactionProfit t')})) ts in (t'' ,(Entity cet ct'):ct'') else diff --git a/Handler/Wallet.hs b/Handler/Wallet.hs index 68a3226..60e7281 100644 --- a/Handler/Wallet.hs +++ b/Handler/Wallet.hs @@ -15,13 +15,25 @@ getWalletDetailsR hrs days = loginOrDo (\(uid,user) -> do show last 7 days

Transactions in the last #{hrs} hours + +
Time + Price + Name + Profit $forall Entity _ t <- trans
#{show $ transactionDateTime t} #{transactionPriceCents t} #{transactionClientName t} + + $maybe profit <- transRealProfit t + #{profit} + $nothing + -

Statistices for the last #{days} days |] ) +transRealProfit :: Transaction -> Maybe Int64 +transRealProfit t = (\a b c -> a - b - c) <$> transactionProfit t <*> transactionFee t <*> transactionTax t diff --git a/config/routes b/config/routes index 77d15e9..1ef39b2 100644 --- a/config/routes +++ b/config/routes @@ -10,3 +10,4 @@ -- /register RegisterR GET POST /settings SettingsR GET POST /update UpdateR GET +/stock StockR GET diff --git a/neat.cabal b/neat.cabal index 3929462..6f264f4 100644 --- a/neat.cabal +++ b/neat.cabal @@ -25,6 +25,7 @@ library Handler.Wallet Handler.Settings Handler.Update + Handler.Stock if flag(dev) || flag(library-only) cpp-options: -DDEVELOPMENT diff --git a/test/Handler/StockSpec.hs b/test/Handler/StockSpec.hs new file mode 100644 index 0000000..b15d565 --- /dev/null +++ b/test/Handler/StockSpec.hs @@ -0,0 +1,10 @@ +module Handler.StockSpec (spec) where + +import TestImport + +spec :: Spec +spec = withApp $ do + + describe "getStockR" $ do + error "Spec not implemented: getStockR" + diff --git a/test/Handler/UpdateSpec.hs b/test/Handler/UpdateSpec.hs new file mode 100644 index 0000000..ce641a1 --- /dev/null +++ b/test/Handler/UpdateSpec.hs @@ -0,0 +1,10 @@ +module Handler.UpdateSpec (spec) where + +import TestImport + +spec :: Spec +spec = withApp $ do + + describe "getUpdateR" $ do + error "Spec not implemented: getUpdateR" +