Skip to content

Commit

Permalink
[#500] Trails: Modify endpoints to match requirements discussed today.
Browse files Browse the repository at this point in the history
  • Loading branch information
a-stacey committed Jul 22, 2019
1 parent 4ec6f8b commit fec715b
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 25 deletions.
7 changes: 4 additions & 3 deletions projects/trails/src/Mirza/Trails/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

module Mirza.Trails.API where

import Mirza.Trails.Types (TrailEntryResponse)
import Mirza.Trails.Types (SignaturePlaceholder, TrailEntryResponse)

import Mirza.Common.Types (HealthResponse)

Expand Down Expand Up @@ -34,5 +34,6 @@ serverAPI = Proxy
type PublicAPI =
"healthz" :> Get '[JSON] HealthResponse
:<|> "version" :> Get '[JSON] String
:<|> "trail" :> Capture "eventId" EventId :> Get '[JSON] [TrailEntryResponse]
:<|> "trail" :> ReqBody '[JSON] TrailEntryResponse :> Post '[JSON] NoContent
:<|> "trail" :> Capture "eventId" EventId :> Get '[JSON] [TrailEntryResponse]
:<|> "trail" :> Capture "signature" SignaturePlaceholder :> Get '[JSON] [TrailEntryResponse]
:<|> "trail" :> ReqBody '[JSON] [TrailEntryResponse] :> Post '[JSON] NoContent
11 changes: 7 additions & 4 deletions projects/trails/src/Mirza/Trails/Client/Servant.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ module Mirza.Trails.Client.Servant
-- * Public API
health
, versionInfo
, getTrail
, getTrailByEventId
, getTrailBySignature
, addTrail
) where

Expand All @@ -23,8 +24,9 @@ import Servant.Client

health :: ClientM HealthResponse
versionInfo :: ClientM String
getTrail :: EventId -> ClientM [TrailEntryResponse]
addTrail :: TrailEntryResponse -> ClientM NoContent
getTrailByEventId :: EventId -> ClientM [TrailEntryResponse]
getTrailBySignature :: SignaturePlaceholder -> ClientM [TrailEntryResponse]
addTrail :: [TrailEntryResponse] -> ClientM NoContent


_api :: Client ClientM ServerAPI
Expand All @@ -33,7 +35,8 @@ _api@(
_pubAPI@(
health
:<|> versionInfo
:<|> getTrail
:<|> getTrailByEventId
:<|> getTrailBySignature
:<|> addTrail
)
) = client (Proxy :: Proxy ServerAPI)
43 changes: 28 additions & 15 deletions projects/trails/src/Mirza/Trails/Handlers/Trails.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,36 @@ import Data.GS1.EPC (GS1CompanyPrefix (..))
import Data.GS1.EventId (EventId (..))

import Data.Time.Clock
-- import Data.UUID.V4
import Data.UUID.V4

import Servant


getTrail :: EventId -> AppM context err [TrailEntryResponse]
getTrail (EventId uuid) = do
time <- liftIO getCurrentTime
--uuid1 <- liftIO nextRandom
pure $ [ TrailEntryResponse 1
(EntryTime time)
(GS1CompanyPrefix "0000001")
(EventId uuid)
[]
(SignaturePlaceholder "TODO")
]


addTrail :: TrailEntryResponse -> AppM context err NoContent
getTrailByEventId :: EventId -> AppM context err [TrailEntryResponse]
getTrailByEventId (EventId uuid) = do
time <- liftIO getCurrentTime
--uuid1 <- liftIO nextRandom
pure $ [ TrailEntryResponse 1
(EntryTime time)
(GS1CompanyPrefix "0000001")
(EventId uuid)
[]
(SignaturePlaceholder "TODO")
]


getTrailBySignature :: SignaturePlaceholder -> AppM context err [TrailEntryResponse]
getTrailBySignature (SignaturePlaceholder sig) = do
time <- liftIO getCurrentTime
uuid <- liftIO nextRandom
pure $ [ TrailEntryResponse 1
(EntryTime time)
(GS1CompanyPrefix "0000002")
(EventId uuid)
[]
(SignaturePlaceholder sig)
]


addTrail :: [TrailEntryResponse] -> AppM context err NoContent
addTrail _ = pure NoContent
3 changes: 2 additions & 1 deletion projects/trails/src/Mirza/Trails/Service.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ publicServer :: ( Member context '[HasDB]
publicServer =
health
:<|> versionInfo
:<|> getTrail
:<|> getTrailByEventId
:<|> getTrailBySignature
:<|> addTrail


Expand Down
11 changes: 9 additions & 2 deletions projects/trails/src/Mirza/Trails/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ import Katip as K
import Data.Aeson (FromJSON (..), ToJSON (..), object,
withObject, (.:), (.=))

import Data.Swagger (ToSchema)
import Data.Swagger (ToParamSchema, ToSchema)

import Servant (FromHttpApiData (..),
ToHttpApiData (..))

import Control.Lens hiding ((.=))

Expand Down Expand Up @@ -127,7 +130,11 @@ instance FromJSON SignaturePlaceholder where
instance ToJSON SignaturePlaceholder where
toJSON = toJSON . getSignature
instance ToSchema SignaturePlaceholder

instance ToParamSchema SignaturePlaceholder
instance FromHttpApiData SignaturePlaceholder where
parseUrlPiece t = SignaturePlaceholder <$> (parseUrlPiece t)
instance ToHttpApiData SignaturePlaceholder where
toUrlPiece (SignaturePlaceholder sig) = toUrlPiece sig


-- *****************************************************************************
Expand Down

0 comments on commit fec715b

Please sign in to comment.