2019-07-18 15:09:26 +00:00
|
|
|
{-# LANGUAGE DeriveGeneric #-}
|
2020-08-26 19:29:39 +00:00
|
|
|
{-# LANGUAGE TypeFamilies #-}
|
2019-07-18 15:09:26 +00:00
|
|
|
module Types.Product where
|
|
|
|
|
|
|
|
import GHC.Generics
|
|
|
|
|
|
|
|
import Data.Aeson
|
|
|
|
|
|
|
|
import qualified Data.Text as T
|
|
|
|
|
2020-08-26 19:29:39 +00:00
|
|
|
-- internal imports
|
|
|
|
|
|
|
|
import Classes
|
|
|
|
|
2019-07-18 15:09:26 +00:00
|
|
|
data Product = Product
|
|
|
|
{ productId :: Int
|
|
|
|
, productIdent :: T.Text
|
2019-07-27 14:34:28 +00:00
|
|
|
-- , productPrice :: Int
|
|
|
|
-- , productAmount :: Int
|
|
|
|
-- , productVanish :: Int
|
2019-07-18 15:09:26 +00:00
|
|
|
, productMl :: Int
|
|
|
|
, productAvatar :: Maybe Int
|
|
|
|
, productSupplier :: Maybe Int
|
|
|
|
, productMaxAmount :: Int
|
2021-07-12 11:29:40 +00:00
|
|
|
, productMinAmount :: Int
|
2019-07-28 09:55:22 +00:00
|
|
|
-- , productTotalBought :: Int
|
2019-07-18 15:09:26 +00:00
|
|
|
, productAmountPerCrate :: Int
|
|
|
|
, productPricePerCrate :: Maybe Int
|
|
|
|
, productArtNr :: Maybe T.Text
|
|
|
|
} deriving (Generic, Show)
|
|
|
|
|
|
|
|
instance ToJSON Product where
|
|
|
|
toEncoding = genericToEncoding defaultOptions
|
|
|
|
|
|
|
|
instance FromJSON Product
|
|
|
|
|
2020-08-26 19:29:39 +00:00
|
|
|
instance ToDatabase Product where
|
|
|
|
|
|
|
|
type InTuple Product =
|
2021-07-12 11:29:40 +00:00
|
|
|
(Int, T.Text, Int, Maybe Int, Maybe Int, Int, Int, Int, Maybe Int, Maybe T.Text)
|
2020-08-26 19:29:39 +00:00
|
|
|
|
2021-07-12 11:29:40 +00:00
|
|
|
toDatabase (Product id_ ident ml maid msid maxa mina apc ppc artnr) =
|
|
|
|
(id_, ident, ml, maid, msid, maxa, mina, apc, ppc, artnr)
|
2020-08-26 19:29:39 +00:00
|
|
|
|
|
|
|
instance FromDatabase Product where
|
|
|
|
|
|
|
|
type OutTuple Product =
|
2021-07-12 11:29:40 +00:00
|
|
|
(Int, T.Text, Int, Maybe Int, Maybe Int, Int, Int, Int, Maybe Int, Maybe T.Text)
|
2020-08-26 19:29:39 +00:00
|
|
|
|
2021-07-12 11:29:40 +00:00
|
|
|
fromDatabase (id_, ident, ml, maid, msid, maxa, mina, apc, ppc, artnr) =
|
|
|
|
Product id_ ident ml maid msid maxa mina apc ppc artnr
|
2020-08-26 19:29:39 +00:00
|
|
|
|
2019-07-18 15:09:26 +00:00
|
|
|
|
2019-07-28 09:55:22 +00:00
|
|
|
data ProductOverview = ProductOverview
|
|
|
|
{ productOverviewId :: Int
|
|
|
|
, productOverviewIdent :: T.Text
|
|
|
|
, productOverviewPrice :: Int
|
|
|
|
, productOverviewAmount :: Int
|
|
|
|
, productOverviewVanish :: Int
|
|
|
|
, productOverviewMl :: Int
|
|
|
|
, productOverviewAvatar :: Maybe Int
|
|
|
|
, productOverviewSupplier :: Maybe Int
|
|
|
|
, productOverviewMaxAmount :: Int
|
2021-07-12 11:29:40 +00:00
|
|
|
, productOverviewMinAmount :: Int
|
2019-07-28 09:55:22 +00:00
|
|
|
, productOverviewTotalBought :: Int
|
|
|
|
, productOverviewAmountPerCrate :: Int
|
|
|
|
, productOverviewPricePerCrate :: Maybe Int
|
|
|
|
, productOverviewArtNr :: Maybe T.Text
|
|
|
|
} deriving (Generic, Show)
|
|
|
|
|
|
|
|
instance ToJSON ProductOverview where
|
|
|
|
toEncoding = genericToEncoding defaultOptions
|
|
|
|
|
|
|
|
instance FromJSON ProductOverview
|
|
|
|
|
|
|
|
|
2019-08-03 07:30:18 +00:00
|
|
|
data ProductShortOverview = ProductShortOverview
|
|
|
|
{ productShortOverviewId :: Int
|
|
|
|
, productShortOverviewIdent :: T.Text
|
|
|
|
, productShortOverviewPrice :: Int
|
|
|
|
, productShortOverviewAmount :: Int
|
|
|
|
-- , productShortOverviewVanish :: Int
|
|
|
|
, productShortOverviewMl :: Int
|
|
|
|
, productShortOverviewAvatar :: Maybe Int
|
|
|
|
-- , productShortOverviewSupplier :: Maybe Int
|
|
|
|
-- , productShortOverviewMaxAmount :: Int
|
|
|
|
-- , productShortOverviewTotalBought :: Int
|
|
|
|
-- , productShortOverviewAmountPerCrate :: Int
|
|
|
|
-- , productShortOverviewPricePerCrate :: Maybe Int
|
|
|
|
-- , productShortOverviewArtNr :: Maybe T.Text
|
|
|
|
} deriving (Generic, Show)
|
|
|
|
|
|
|
|
instance ToJSON ProductShortOverview where
|
|
|
|
toEncoding = genericToEncoding defaultOptions
|
|
|
|
|
|
|
|
instance FromJSON ProductShortOverview
|
|
|
|
|
|
|
|
|
2019-07-18 15:09:26 +00:00
|
|
|
data ProductSubmit = ProductSubmit
|
|
|
|
{ productSubmitIdent :: T.Text
|
|
|
|
, productSubmitPrice :: Int
|
|
|
|
-- , productSubmitAmount :: Int
|
|
|
|
-- , productSubmitVanish :: Int
|
|
|
|
, productSubmitMl :: Int
|
|
|
|
, productSubmitAvatar :: Maybe Int
|
|
|
|
, productSubmitSupplier :: Maybe Int
|
|
|
|
, productSubmitMaxAmount :: Int
|
2021-07-12 11:29:40 +00:00
|
|
|
, productSubmitMinAmount :: Int
|
2019-07-18 15:09:26 +00:00
|
|
|
-- , productSubmitTotalBought :: Int
|
|
|
|
, productSubmitAmountPerCrate :: Int
|
|
|
|
, productSubmitPricePerCrate :: Maybe Int
|
|
|
|
, productSubmitArtNr :: Maybe T.Text
|
|
|
|
} deriving (Generic, Show)
|
|
|
|
|
|
|
|
instance ToJSON ProductSubmit where
|
|
|
|
toEncoding = genericToEncoding defaultOptions
|
|
|
|
|
|
|
|
instance FromJSON ProductSubmit
|