diff options
Diffstat (limited to 'lambda-calcul/haskell/src/Minilang/API.hs')
| -rw-r--r-- | lambda-calcul/haskell/src/Minilang/API.hs | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/lambda-calcul/haskell/src/Minilang/API.hs b/lambda-calcul/haskell/src/Minilang/API.hs index 2b8743f..0ae0784 100644 --- a/lambda-calcul/haskell/src/Minilang/API.hs +++ b/lambda-calcul/haskell/src/Minilang/API.hs @@ -1,13 +1,23 @@ {-# LANGUAGE DataKinds #-} {-# LANGUAGE DeriveAnyClass #-} +{-# LANGUAGE DerivingStrategies #-} +{-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE TypeOperators #-} +{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-} + +{-# HLINT ignore "Use newtype instead of data" #-} module Minilang.API where import Data.Aeson (FromJSON, ToJSON) +import Data.Bifunctor (first) +import Data.ByteString.Lazy (ByteString) +import qualified Data.ByteString.Lazy as LBS +import Data.Text (Text) import Data.Time (UTCTime) import GHC.Generics (Generic) -import Servant (Get, JSON, (:<|>), (:>), Raw) +import Servant (Get, JSON, Raw, ReqBody, StdMethod (POST), Verb, (:<|>), (:>)) +import System.Random (StdGen, uniformList) data Score = Score { name :: String, @@ -16,6 +26,16 @@ data Score = Score } deriving (Eq, Show, Generic, ToJSON, FromJSON) +newtype User = User {username :: Text} + deriving newtype (Eq, Show, ToJSON, FromJSON) + +data Token = Token {token :: Text} + deriving (Eq, Show, Generic, ToJSON, FromJSON) + +newToken :: StdGen -> (ByteString, StdGen) +newToken = first LBS.pack . uniformList 16 + type LambdaAPI = - "api" :> "leaderboard" :> Get '[JSON] [Score] + "api" :> "register" :> ReqBody '[JSON] User :> Verb 'POST 201 '[JSON] Token + :<|> "api" :> "leaderboard" :> Get '[JSON] [Score] :<|> Raw |
