yammat/Handler/Barcode.hs

56 lines
1.5 KiB
Haskell
Raw Normal View History

2015-07-20 23:14:21 +00:00
module Handler.Barcode where
import Import
import Handler.Common
import qualified Data.Text as T
2015-07-20 23:42:52 +00:00
getHomeBarcodeR :: Handler Html
2015-07-21 07:14:38 +00:00
getHomeBarcodeR = do
c <- lookupGetParam "barcode"
case c of
Just code -> do
be <- runDB $ getBy $ UniqueBarcode code
case be of
Just (Entity _ bar) -> do
case barcodeIsUser bar of
True -> do
case barcodeUser bar of
Just uId -> do
redirect $ SelectR uId
Nothing -> do
error "Malformed barcode"
False -> do
setMessageI MsgBarcodeNotUser
redirect HomeR
Nothing -> do
setMessageI MsgBarcodeUnknown
redirect HomeR
Nothing -> do
setMessageI MsgProvideBarcode
redirect HomeR
2015-07-20 23:28:05 +00:00
2015-07-20 23:42:52 +00:00
getSelectBarcodeR :: UserId -> Handler Html
2015-07-21 07:14:38 +00:00
getSelectBarcodeR uId = do
c <- lookupGetParam "barcode"
case c of
Just code -> do
be <- runDB $ getBy $ UniqueBarcode code
case be of
Just (Entity _ bar) -> do
case barcodeIsUser bar of
False -> do
case barcodeBev bar of
Just bId -> do
redirect $ BuyR uId bId
Nothing -> do
error "Malformed barcode"
True -> do
setMessageI MsgBarcodeNotBev
redirect $ SelectR uId
Nothing -> do
setMessageI MsgBarcodeUnknown
redirect $ SelectR uId
Nothing -> do
setMessageI MsgProvideBarcode
redirect $ SelectR uId