Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
memowe committed Nov 13, 2023
1 parent 90086d5 commit a609630
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 4 deletions.
18 changes: 18 additions & 0 deletions lib/LiBro/WebService.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module LiBro.WebService where

import LiBro.Config
import LiBro.Control
import Control.Concurrent
import LiBro.Data (LiBroData)

data LiBroState = LiBroState
{ config :: Config
, mvBlocking :: MVar Blocking
, mvData :: MVar LiBroData
}

lsConfig :: LiBroState -> IO Config
lsConfig = return . config

lsData :: LiBroState -> IO LiBroData
lsData = readMVar . mvData
4 changes: 3 additions & 1 deletion lib/LiBro/WebService/API.hs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
module LiBro.WebService.API where

import LiBro.WebService.Types
import Data.Proxy
import Servant.API

type LiBroAPI = "hello" :> Get '[PlainText] String
type LiBroAPI = "hello" :> Get '[JSON] PersonIDs
:<|> "yay" :> Get '[PlainText] String

libroApi :: Proxy LiBroAPI
libroApi = Proxy
12 changes: 9 additions & 3 deletions lib/LiBro/WebService/Server.hs
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
module LiBro.WebService.Server where

import LiBro.WebService.API
import LiBro.WebService.Types
import Servant

server :: Server LiBroAPI
server = return "Hello LiBro!"
handleHello :: Handler PersonIDs
handleHello = return $ PersonIDs [17, 42]

handleYay :: Handler String
handleYay = return "Yay!"

libro :: Application
libro = serve libroApi server
libro = serve libroApi
$ handleHello
:<|> handleYay
7 changes: 7 additions & 0 deletions lib/LiBro/WebService/Types.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module LiBro.WebService.Types where

import Data.Aeson
import GHC.Generics

newtype PersonIDs = PersonIDs {personIDs :: [Int]} deriving Generic
instance ToJSON PersonIDs
3 changes: 3 additions & 0 deletions libro-backend.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ library
, LiBro.Data.Storage
, LiBro.Data.SafeText
, LiBro.Control
, LiBro.WebService
, LiBro.WebService.API
, LiBro.WebService.Types
, LiBro.WebService.Server
, LiBro.Util
build-depends: base >=4.14.0.0
Expand Down Expand Up @@ -102,4 +104,5 @@ test-suite libro-backend-test
, text
, transformers
, vector
, wai
build-tool-depends: hspec-discover:hspec-discover

0 comments on commit a609630

Please sign in to comment.