2019-07-27 14:34:28 +00:00
|
|
|
{-# LANGUAGE DeriveGeneric #-}
|
2020-08-26 19:29:39 +00:00
|
|
|
{-# LANGUAGE TypeFamilies #-}
|
2019-07-27 14:34:28 +00:00
|
|
|
module Types.Amount where
|
|
|
|
|
|
|
|
import GHC.Generics
|
|
|
|
|
|
|
|
import Data.Aeson
|
|
|
|
|
2020-08-26 19:29:39 +00:00
|
|
|
import Data.Time (UTCTime)
|
|
|
|
|
|
|
|
-- internal imports
|
|
|
|
|
|
|
|
import Classes
|
|
|
|
|
2019-07-27 14:34:28 +00:00
|
|
|
data AmountUpdate = AmountUpdate
|
|
|
|
{ amountUpdateProductId :: Int
|
|
|
|
, amountUpdateRealAmount :: Int
|
|
|
|
}
|
|
|
|
deriving (Show, Generic)
|
|
|
|
|
|
|
|
instance ToJSON AmountUpdate where
|
|
|
|
toEncoding = genericToEncoding defaultOptions
|
|
|
|
|
|
|
|
instance FromJSON AmountUpdate
|
2019-08-05 16:10:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
data AmountRefill = AmountRefill
|
2019-12-14 23:03:49 +00:00
|
|
|
{ amountRefillProductId :: Int
|
|
|
|
, amountRefillAmountSingles :: Int
|
|
|
|
, amountRefillAmountCrates :: Int
|
2019-08-05 16:10:21 +00:00
|
|
|
}
|
|
|
|
deriving (Show, Generic)
|
|
|
|
|
|
|
|
instance ToJSON AmountRefill where
|
|
|
|
toEncoding = genericToEncoding defaultOptions
|
|
|
|
|
|
|
|
instance FromJSON AmountRefill
|
2020-08-26 19:29:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
data Amount = Amount
|
|
|
|
{ amountProductId :: Int
|
|
|
|
, amountTimestamp :: UTCTime
|
|
|
|
, amountAmount :: Int
|
|
|
|
, amountPrice :: Int
|
|
|
|
, amountVerified :: Bool
|
|
|
|
}
|
|
|
|
deriving (Show)
|
|
|
|
|
|
|
|
instance ToDatabase Amount where
|
|
|
|
|
|
|
|
type InTuple Amount = (Int, UTCTime, Int, Int, Bool)
|
|
|
|
|
|
|
|
toDatabase (Amount pid ts amount price ver) =
|
|
|
|
(pid, ts, amount, price, ver)
|
|
|
|
|
|
|
|
instance FromDatabase Amount where
|
|
|
|
|
|
|
|
type OutTuple Amount = (Int, UTCTime, Int, Int, Bool)
|
|
|
|
|
|
|
|
fromDatabase (pid, ts, amount, price, ver) =
|
|
|
|
Amount pid ts amount price ver
|