Commit 121606d4 authored by MrMan's avatar MrMan

Working get by UUID endpoint

parent 77ad3ff8
......@@ -9,34 +9,42 @@ module Server
(buildApp)
where
import Components.EntityStore.SQLite
import Control.Monad.IO.Class (liftIO)
import Control.Monad.Trans.Reader (ask)
import Data.Aeson (ToJSON(..))
import Data.Maybe (isJust, fromJust)
import Data.Proxy
import Data.Semigroup ((<>))
import Data.UUID (UUID)
import Database.SQLite.Simple (FromRow)
import Servant.API
import Servant.Server (ServerT, Application, serve, hoistServer)
import qualified Data.Text as DT
import Util (rightOrServantErr, genericServerError)
import Types
import Data.Aeson (ToJSON(..))
import Database.SQLite.Simple (FromRow)
import Components.EntityStore.SQLite
import Data.Maybe (isJust, fromJust)
import Util (rightOrServantErr, genericServerError)
import qualified Data.Text as DT
type Name = DT.Text
type Greeting = DT.Text
type TodoAPI =
"todos" :> Get '[JSON] [WithUUID Task]
:<|> "todos" :> Capture "uuid" UUID :> Get '[JSON] (WithUUID Task)
todoServer :: ServerT TodoAPI AppHandler
todoServer = listTodos
:<|> getTodoByUUID
listTodos :: AppHandler [WithUUID Task]
listTodos = ask
>>= \(AppState _ estore) -> liftIO (list estore :: IO (Either EntityStoreError [WithUUID Task]))
>>= rightOrServantErr genericServerError
getTodoByUUID :: UUID -> AppHandler (WithUUID Task)
getTodoByUUID uuid = ask
>>= \(AppState _ estore) -> liftIO (getByUUID estore uuid :: IO (Either EntityStoreError (WithUUID Task)))
>>= rightOrServantErr genericServerError
todoAPI :: Proxy TodoAPI
todoAPI = Proxy
......
......@@ -57,6 +57,7 @@ executables:
- transformers
- aeson
- sqlite-simple
- uuid
tests:
haskell-restish-todo-test:
......
......@@ -332,12 +332,12 @@ class SQLEntityStore store where
-- | Get an entity by ID
getByUUID :: forall entity.
( SQLInsertable (Complete entity)
, FromRow (WithUUID (Complete entity))
( SQLInsertable entity
, FromRow (WithUUID entity)
)
=> store
-> UUID
-> IO (Either EntityStoreError (WithUUID (Complete entity)))
-> IO (Either EntityStoreError (WithUUID entity))
-- | Update an existing entity by ID
updateByUUID :: forall (entity :: FBounded).
......
......@@ -89,7 +89,7 @@ spec = do
>> (getByUUID store uuid :: IO (Either EntityStoreError (WithUUID (Complete NotStartedTask))))
>>= (`shouldSatisfy` isLeft)
describe "entity store lsit" $
describe "entity store list" $
it "works with default config" $ \_ -> liftIO makeDefaultStore
>>= rightOrThrow
>>= \store -> migrate store
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment