rework user inti and add beverage init

This commit is contained in:
nek0 2019-04-16 14:02:41 +02:00
parent 7f12f0116e
commit 1a8f09d2ad
3 changed files with 32 additions and 22 deletions

View file

@ -29,6 +29,7 @@ main = do
conn <- connectPostgreSQL
"host='localhost' port=5432 dbname='mateamt' user='mateamt' password='mateamt'"
execute_ conn initUser
execute_ conn initBeverage
withStdoutLogger $ \log -> do
let settings = setPort 3000 $ setLogger log defaultSettings
runSettings settings (app conn)

View file

@ -1,13 +1,16 @@
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
module Model.Beverage where
import Data.Text as T
import Data.Time.Calendar (Day)
import Data.Profunctor.Product (p12)
import Data.Profunctor.Product (p13)
import Data.Aeson
import Data.Aeson.Types
import qualified Database.PostgreSQL.Simple as PGS
import GHC.Generics
import Opaleye as O
@ -32,36 +35,42 @@ instance ToJSON Beverage where
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
( Field SqlText
, Field SqlInt8
, Field SqlInt8
, Field SqlInt8
, Field SqlInt8
( Maybe (Field SqlInt4)
, Field SqlText
, Field SqlInt4
, Field SqlInt4
, Field SqlInt4
, Field SqlInt4
, FieldNullable SqlInt4
, FieldNullable SqlInt4
, Field SqlInt8
, Field SqlInt8
, Field SqlInt8
, FieldNullable SqlInt8
, Field SqlInt4
, Field SqlInt4
, Field SqlInt4
, FieldNullable SqlInt4
, FieldNullable SqlText
)
( Field SqlText
, Field SqlInt8
, Field SqlInt8
, Field SqlInt8
, Field SqlInt8
( Field SqlInt4
, Field SqlText
, Field SqlInt4
, Field SqlInt4
, Field SqlInt4
, Field SqlInt4
, FieldNullable SqlInt4
, FieldNullable SqlInt4
, Field SqlInt8
, Field SqlInt8
, Field SqlInt8
, FieldNullable SqlInt8
, Field SqlInt4
, Field SqlInt4
, Field SqlInt4
, FieldNullable SqlInt4
, FieldNullable SqlText
)
beverageTable = table "beverage" (
p12
( tableField "ident"
p13
( tableField "id"
, tableField "ident"
, tableField "price"
, tableField "amount"
, tableField "vanish"

View file

@ -63,7 +63,7 @@ instance ToJSON UserSubmit where
instance FromJSON UserSubmit
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
( Maybe (Field SqlInt4)