rework user inti and add beverage init
This commit is contained in:
parent
7f12f0116e
commit
1a8f09d2ad
3 changed files with 32 additions and 22 deletions
|
@ -29,6 +29,7 @@ main = do
|
||||||
conn <- connectPostgreSQL
|
conn <- connectPostgreSQL
|
||||||
"host='localhost' port=5432 dbname='mateamt' user='mateamt' password='mateamt'"
|
"host='localhost' port=5432 dbname='mateamt' user='mateamt' password='mateamt'"
|
||||||
execute_ conn initUser
|
execute_ conn initUser
|
||||||
|
execute_ conn initBeverage
|
||||||
withStdoutLogger $ \log -> do
|
withStdoutLogger $ \log -> do
|
||||||
let settings = setPort 3000 $ setLogger log defaultSettings
|
let settings = setPort 3000 $ setLogger log defaultSettings
|
||||||
runSettings settings (app conn)
|
runSettings settings (app conn)
|
||||||
|
|
|
@ -1,13 +1,16 @@
|
||||||
{-# LANGUAGE DeriveGeneric #-}
|
{-# LANGUAGE DeriveGeneric #-}
|
||||||
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
module Model.Beverage where
|
module Model.Beverage where
|
||||||
|
|
||||||
import Data.Text as T
|
import Data.Text as T
|
||||||
import Data.Time.Calendar (Day)
|
import Data.Time.Calendar (Day)
|
||||||
import Data.Profunctor.Product (p12)
|
import Data.Profunctor.Product (p13)
|
||||||
|
|
||||||
import Data.Aeson
|
import Data.Aeson
|
||||||
import Data.Aeson.Types
|
import Data.Aeson.Types
|
||||||
|
|
||||||
|
import qualified Database.PostgreSQL.Simple as PGS
|
||||||
|
|
||||||
import GHC.Generics
|
import GHC.Generics
|
||||||
|
|
||||||
import Opaleye as O
|
import Opaleye as O
|
||||||
|
@ -32,36 +35,42 @@ instance ToJSON Beverage where
|
||||||
|
|
||||||
instance FromJSON Beverage
|
instance FromJSON Beverage
|
||||||
|
|
||||||
|
initBeverage :: PGS.Query
|
||||||
|
initBeverage = "create Table if not exists \"beverage\" (id serial primary key, ident varchar(128) not null, price integer not null, amount integer not null, vanish integer not null, ml integer not null, avatar integer, supplier integer, max_amount integer not null, total_bought integer not null, amount_per_crate integer not null, price_per_crate integer, art_nr varchar(128))"
|
||||||
|
|
||||||
beverageTable :: Table
|
beverageTable :: Table
|
||||||
( Field SqlText
|
( Maybe (Field SqlInt4)
|
||||||
, Field SqlInt8
|
, Field SqlText
|
||||||
, Field SqlInt8
|
, Field SqlInt4
|
||||||
, Field SqlInt8
|
, Field SqlInt4
|
||||||
, Field SqlInt8
|
, Field SqlInt4
|
||||||
|
, Field SqlInt4
|
||||||
, FieldNullable SqlInt4
|
, FieldNullable SqlInt4
|
||||||
, FieldNullable SqlInt4
|
, FieldNullable SqlInt4
|
||||||
, Field SqlInt8
|
, Field SqlInt4
|
||||||
, Field SqlInt8
|
, Field SqlInt4
|
||||||
, Field SqlInt8
|
, Field SqlInt4
|
||||||
, FieldNullable SqlInt8
|
, FieldNullable SqlInt4
|
||||||
, FieldNullable SqlText
|
, FieldNullable SqlText
|
||||||
)
|
)
|
||||||
( Field SqlText
|
( Field SqlInt4
|
||||||
, Field SqlInt8
|
, Field SqlText
|
||||||
, Field SqlInt8
|
, Field SqlInt4
|
||||||
, Field SqlInt8
|
, Field SqlInt4
|
||||||
, Field SqlInt8
|
, Field SqlInt4
|
||||||
|
, Field SqlInt4
|
||||||
, FieldNullable SqlInt4
|
, FieldNullable SqlInt4
|
||||||
, FieldNullable SqlInt4
|
, FieldNullable SqlInt4
|
||||||
, Field SqlInt8
|
, Field SqlInt4
|
||||||
, Field SqlInt8
|
, Field SqlInt4
|
||||||
, Field SqlInt8
|
, Field SqlInt4
|
||||||
, FieldNullable SqlInt8
|
, FieldNullable SqlInt4
|
||||||
, FieldNullable SqlText
|
, FieldNullable SqlText
|
||||||
)
|
)
|
||||||
beverageTable = table "beverage" (
|
beverageTable = table "beverage" (
|
||||||
p12
|
p13
|
||||||
( tableField "ident"
|
( tableField "id"
|
||||||
|
, tableField "ident"
|
||||||
, tableField "price"
|
, tableField "price"
|
||||||
, tableField "amount"
|
, tableField "amount"
|
||||||
, tableField "vanish"
|
, tableField "vanish"
|
||||||
|
|
|
@ -63,7 +63,7 @@ instance ToJSON UserSubmit where
|
||||||
instance FromJSON UserSubmit
|
instance FromJSON UserSubmit
|
||||||
|
|
||||||
initUser :: PGS.Query
|
initUser :: PGS.Query
|
||||||
initUser = "create table if not exists \"user\" (id serial, ident varchar(128) not null, balance integer not null, time_stamp date not null, email varchar(128), avatar integer, pin varchar(128))"
|
initUser = "create table if not exists \"user\" (id serial primary key, ident varchar(128) not null, balance integer not null, time_stamp date not null, email varchar(128), avatar integer, pin varchar(128))"
|
||||||
|
|
||||||
userTable :: Table
|
userTable :: Table
|
||||||
( Maybe (Field SqlInt4)
|
( Maybe (Field SqlInt4)
|
||||||
|
|
Loading…
Reference in a new issue