aboutsummaryrefslogtreecommitdiff
path: root/src/Model.hs
blob: a7a5304a164ab56ef3d577cba096149b001b54d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
{-# LANGUAGE OverloadedStrings, NoImplicitPrelude #-}
module Model
    ( Drink(..)
    , drinkId
    , drinkDescription
    , drinkTimestamp
    , drinkLiters
    , DrinkDB(..)
    , Model(..)
    , drinkDB
    , drinkDialogActive
    ) where

import ClassyPrelude
import Control.Category.Unicode ((∘))
import Control.Lens
import qualified Data.Aeson.TH as AesonTH
import qualified Data.Scientific as Scientific
import qualified Data.Time.Clock as Clock

data Drink = Drink
  { _drinkId          ∷ Int32
  , _drinkDescription ∷ Text
  , _drinkTimestamp   ∷ Clock.UTCTime
  , _drinkLiters      ∷ Scientific.Scientific
  }
$(makeLenses ''Drink)
$(AesonTH.deriveJSON (AesonTH.defaultOptions{AesonTH.fieldLabelModifier = toLower ∘ (drop 6)}) ''Drink)

data DrinkDB = DrinkDB { unDrinkDB ∷ [Drink] }
$(makeLenses ''DrinkDB)
$(AesonTH.deriveJSON AesonTH.defaultOptions ''DrinkDB)

data Model = Model
  { _drinkDB           ∷ DrinkDB
  , _drinkDialogActive ∷ Bool
  }
$(makeLenses ''Model)