2020-07-24 20:00:29 +02:00
|
|
|
{-# LANGUAGE DataKinds #-}
|
2020-07-24 23:46:54 +02:00
|
|
|
{-# LANGUAGE TypeOperators #-}
|
2020-07-24 20:00:29 +02:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
module API where
|
|
|
|
--------------------------------------------------------------------------------
|
2020-07-24 23:46:54 +02:00
|
|
|
import Data.Text
|
|
|
|
import Servant.API
|
2020-07-29 15:14:47 +02:00
|
|
|
import Web.Cookie
|
2020-07-24 20:00:29 +02:00
|
|
|
|
2020-07-24 23:46:54 +02:00
|
|
|
import qualified Types as T
|
2020-07-24 20:00:29 +02:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
2020-07-29 15:14:47 +02:00
|
|
|
-- | Once authenticated, users receive a SessionCookie.
|
2020-07-29 21:26:23 +02:00
|
|
|
type SessionCookie = Header' '[Required] "Cookie" T.SessionCookie
|
2020-07-29 15:14:47 +02:00
|
|
|
|
2020-07-28 11:57:15 +02:00
|
|
|
type API =
|
|
|
|
-- accounts: Create
|
|
|
|
"accounts"
|
2020-07-28 13:49:16 +02:00
|
|
|
:> ReqBody '[JSON] T.CreateAccountRequest
|
|
|
|
:> Post '[JSON] NoContent
|
2020-07-30 19:38:46 +02:00
|
|
|
:<|> "verify"
|
|
|
|
:> QueryParam' '[Required] "username" Text
|
|
|
|
:> QueryParam' '[Required] "secret" Text
|
|
|
|
:> Get '[JSON] NoContent
|
2020-07-28 11:57:15 +02:00
|
|
|
-- accounts: Read
|
|
|
|
-- accounts: Update
|
|
|
|
-- accounts: Delete
|
|
|
|
:<|> "accounts"
|
2020-07-29 15:14:47 +02:00
|
|
|
:> SessionCookie
|
2020-07-28 11:57:15 +02:00
|
|
|
:> QueryParam' '[Required] "username" Text
|
|
|
|
:> Delete '[JSON] NoContent
|
|
|
|
-- accounts: List
|
|
|
|
:<|> "accounts"
|
2020-07-29 15:14:47 +02:00
|
|
|
:> SessionCookie
|
2020-07-28 11:57:15 +02:00
|
|
|
:> Get '[JSON] [T.User]
|
|
|
|
|
|
|
|
-- trips: Create
|
2020-07-28 11:14:33 +02:00
|
|
|
:<|> "trips"
|
2020-07-29 15:14:47 +02:00
|
|
|
:> SessionCookie
|
2020-07-28 10:10:54 +02:00
|
|
|
:> ReqBody '[JSON] T.Trip
|
2020-07-28 11:12:25 +02:00
|
|
|
:> Post '[JSON] NoContent
|
2020-07-28 11:57:15 +02:00
|
|
|
-- trips: Read
|
|
|
|
-- trips: Update
|
2020-07-31 12:25:36 +02:00
|
|
|
:<|> "trips"
|
|
|
|
:> SessionCookie
|
|
|
|
:> ReqBody '[JSON] T.UpdateTripRequest
|
|
|
|
:> Patch '[JSON] NoContent
|
2020-07-28 11:57:15 +02:00
|
|
|
-- trips: Delete
|
2020-07-28 11:14:33 +02:00
|
|
|
:<|> "trips"
|
2020-07-29 15:14:47 +02:00
|
|
|
:> SessionCookie
|
2020-07-28 11:14:33 +02:00
|
|
|
:> ReqBody '[JSON] T.TripPK
|
|
|
|
:> Delete '[JSON] NoContent
|
2020-07-28 11:57:15 +02:00
|
|
|
-- trips: List
|
|
|
|
:<|> "trips"
|
2020-07-31 11:55:10 +02:00
|
|
|
:> SessionCookie
|
2020-07-28 11:57:15 +02:00
|
|
|
:> Get '[JSON] [T.Trip]
|
2020-07-28 15:15:41 +02:00
|
|
|
|
|
|
|
-- Miscellaneous
|
|
|
|
:<|> "login"
|
|
|
|
:> ReqBody '[JSON] T.AccountCredentials
|
2020-07-31 19:28:41 +02:00
|
|
|
:> Post '[JSON] (Headers '[Header "Set-Cookie" SetCookie] T.Session)
|
2020-07-29 15:14:47 +02:00
|
|
|
:<|> "logout"
|
|
|
|
:> SessionCookie
|
|
|
|
:> Get '[JSON] (Headers '[Header "Set-Cookie" SetCookie] NoContent)
|
2020-07-31 12:37:45 +02:00
|
|
|
:<|> "unfreeze"
|
|
|
|
:> SessionCookie
|
|
|
|
:> ReqBody '[JSON] T.UnfreezeAccountRequest
|
|
|
|
:> Post '[JSON] NoContent
|