65 lines
1.5 KiB
Haskell
65 lines
1.5 KiB
Haskell
{-# LANGUAGE OverloadedStrings #-}
|
|
{-# LANGUAGE PackageImports #-}
|
|
module Control.Product where
|
|
|
|
import Servant
|
|
import Servant.Client
|
|
|
|
import Data.String (fromString)
|
|
|
|
import qualified Data.Text as T
|
|
|
|
import Control.Monad.IO.Class (liftIO)
|
|
|
|
-- imports from "mateamt"
|
|
|
|
import qualified "mateamt" Types as MT
|
|
|
|
-- internal imports
|
|
|
|
import Types
|
|
import View
|
|
import Util
|
|
import Client
|
|
import ClientAuth
|
|
import API
|
|
import Hash
|
|
|
|
productGetPriceList
|
|
:: Maybe T.Text
|
|
-> UserHandler ProductPriceListPage
|
|
productGetPriceList mcookie = do
|
|
(token, muser, loc, l10n, backend) <- controlInit mcookie
|
|
elist <- liftIO $ runClientM
|
|
(productShortList
|
|
(Just MT.AllProducts)
|
|
)
|
|
backend
|
|
case elist of
|
|
Right list ->
|
|
return (productPriceListPage l10n loc mcookie list)
|
|
Left err ->
|
|
throwError $
|
|
addMessage (fromString $ show err) $
|
|
redirect303 userSelectLink
|
|
|
|
productGetRefill
|
|
:: Maybe T.Text
|
|
-> UserHandler ProductRefillPage
|
|
productGetRefill mcookie = do
|
|
(token, muser, loc, l10n, backend) <- controlInit mcookie
|
|
case muser of
|
|
Just _ -> do
|
|
elist <- liftIO $ runClientM
|
|
(productShortList (Just MT.AllProducts))
|
|
backend
|
|
case elist of
|
|
Right list -> do
|
|
return $ productRefillPage l10n loc mcookie list
|
|
Left err ->
|
|
throwError $
|
|
addMessage (fromString $ show err) $
|
|
redirect303 userSelectLink
|
|
Nothing ->
|
|
redirectOverAuth Nothing (Just productGetRefillLink) Nothing
|