matebeamter/src/Client.hs

137 lines
3.4 KiB
Haskell
Raw Normal View History

2019-10-16 16:07:12 +00:00
{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
2019-09-08 10:48:57 +00:00
{-# LANGUAGE MultiParamTypeClasses #-}
2019-10-16 16:07:12 +00:00
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE PackageImports #-}
2019-09-08 10:48:57 +00:00
module Client where
import Servant
import Servant.Client
2019-10-16 16:07:12 +00:00
import Servant.Client.Core.Auth
import Servant.Client.Core.Request
2019-09-08 10:48:57 +00:00
-- imports from mateamt
2019-10-16 16:07:12 +00:00
import qualified "mateamt" API as MA
import qualified "mateamt" Types as MT
2019-09-08 10:48:57 +00:00
-- internal imports
2019-10-16 16:07:12 +00:00
mateApi :: Proxy MA.MateAPI
2019-09-08 10:48:57 +00:00
mateApi = Proxy
2019-10-16 16:07:12 +00:00
authGet :: MT.TicketRequest -> ClientM MT.AuthInfo
authSend :: MT.AuthRequest -> ClientM MT.AuthResult
authLogout :: AuthenticatedRequest (AuthProtect "header-auth") -> ClientM ()
authManageList
:: AuthenticatedRequest (AuthProtect "header-auth")
-> ClientM [MT.AuthOverview]
authManageNewAuth
:: AuthenticatedRequest (AuthProtect "header-auth")
-> MT.AuthSubmit
-> ClientM Int
authManageDeleteAuth
:: AuthenticatedRequest (AuthProtect "header-auth")
-> Int
-> ClientM ()
userNew :: MT.UserSubmit -> ClientM Int
userGet
:: AuthenticatedRequest (AuthProtect "header-auth")
-> ClientM MT.UserDetails
userUpdate
:: AuthenticatedRequest (AuthProtect "header-auth")
-> MT.UserDetailsSubmit
-> ClientM ()
userList :: Maybe MT.UserRefine -> ClientM [MT.UserSummary]
userRecharge
:: AuthenticatedRequest (AuthProtect "header-auth")
-> MT.UserRecharge
-> ClientM ()
userTransfer
:: AuthenticatedRequest (AuthProtect "header-auth")
-> MT.UserTransfer
-> ClientM ()
productNew
:: AuthenticatedRequest (AuthProtect "header-auth")
-> MT.ProductSubmit
-> ClientM Int
productOverview :: Int -> ClientM MT.ProductOverview
productStockRefill
:: AuthenticatedRequest (AuthProtect "header-auth")
-> [MT.AmountRefill]
-> ClientM ()
productStockUpdate
:: AuthenticatedRequest (AuthProtect "header-auth")
-> [MT.AmountUpdate]
-> ClientM ()
productList :: Maybe MT.ProductRefine -> ClientM [MT.ProductOverview]
productShortList :: Maybe MT.ProductRefine -> ClientM [MT.ProductShortOverview]
buy
:: AuthenticatedRequest (AuthProtect "header-auth")
-> [MT.PurchaseDetail]
-> ClientM MT.PurchaseResult
journalShow
:: AuthenticatedRequest (AuthProtect "header-auth")
-> Maybe Int
-> Maybe Int
-> ClientM [MT.JournalEntry]
avatarGet
:: Int
-> (Servant.Client.Core.Request.Request
-> Servant.Client.Core.Request.Request)
-> ClientM Response
avatarInsert
:: AuthenticatedRequest (AuthProtect "header-auth")
-> MT.AvatarData
-> ClientM Int
avatarUpdate
:: AuthenticatedRequest (AuthProtect "header-auth")
-> Int
-> MT.AvatarData
-> ClientM ()
avatarList :: ClientM [MT.Avatar]
2019-09-08 10:48:57 +00:00
( authGet :<|>
authSend :<|>
authLogout :<|>
2019-09-15 22:00:15 +00:00
authManageList :<|>
authManageNewAuth :<|>
authManageDeleteAuth :<|>
2019-09-08 10:48:57 +00:00
userNew :<|>
userGet :<|>
userUpdate :<|>
userList :<|>
userRecharge :<|>
userTransfer :<|>
productNew :<|>
productOverview :<|>
productStockRefill :<|>
productStockUpdate :<|>
productList :<|>
2019-09-18 13:24:23 +00:00
productShortList :<|>
2019-09-08 10:48:57 +00:00
buy :<|>
journalShow :<|>
2019-12-11 23:45:22 +00:00
journalPostCashCheck :<|>
2019-09-08 10:48:57 +00:00
avatarGet :<|>
avatarInsert :<|>
avatarUpdate :<|>
avatarList
) = client mateApi
getClients clientEnv = hoistClient
mateApi
( fmap (either (error . show) id)
. (`runClientM` mkClientEnv clientEnv (BaseUrl Http "localhost" 8000 "/")))
(client mateApi)