Skip to content

Commit

Permalink
Update API to support submitting XML events
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Samways committed Aug 13, 2019
1 parent 3c44295 commit 2c2e8fd
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 8 deletions.
1 change: 0 additions & 1 deletion projects/entity-data-api/database/.#init.sql

This file was deleted.

1 change: 1 addition & 0 deletions projects/or_scs/Mirza.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ library
, hashable
, hoist-error >= 0.2
, http-client
, http-media
, insert-ordered-containers
, jose
, katip >= 0.5.4
Expand Down
21 changes: 20 additions & 1 deletion projects/or_scs/src/Mirza/SupplyChain/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ import Mirza.SupplyChain.Types as ST
import Mirza.SupplyChain.Handlers.UXUtils (PrettyEventResponse (..))

import qualified Data.GS1.Event as Ev
import Data.GS1.Parser.Parser ( parseBS )
import Data.GS1.EventId as EvId

import Data.ByteString.Lazy ( ByteString )
import Network.HTTP.Media ( (//) )
import Servant
import Servant.Swagger.UI

Expand All @@ -39,6 +42,22 @@ serverAPI :: Proxy ServerAPI
serverAPI = Proxy


data XML

class FromXML a where
fromXML :: ByteString -> Either String a

instance Accept XML where
contentType _ = "text" // "xml"

instance FromXML a => MimeUnrender XML a where
mimeUnrender _ = fromXML

instance FromXML Ev.Event where
fromXML bs = case parseBS bs of
[] -> Left "No events in document"
(x:_) -> either (Left . show) Right x

type ServerAPI =
-- Health
"healthz" :> Get '[JSON] HealthResponse
Expand All @@ -56,7 +75,7 @@ type ServerAPI =
:> Capture "eventId" EventId
:> Get '[JSON] EventInfo
-- Event Registration
:<|> "event" :> ReqBody '[JSON] Ev.Event
:<|> "event" :> ReqBody '[JSON, XML] Ev.Event
:> Post '[JSON] (EventInfo, Schema.EventId)
-- UI
:<|> "prototype" :> "list" :> "events"
Expand Down
2 changes: 1 addition & 1 deletion projects/or_scs/stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ extra-deps:
- git: https://github.com/sajidanower23/hs-jose.git
commit: d7aca4d13b27235af47d522b5d093e567750628e
- git: https://github.com/data61/GS1Combinators.git
commit: 7f0f0c9c2ec6d91378ac56ba63de033fcc313326 # Head on 2019-06-14
commit: ddb92e443055e7719fa46afa5913cf2276cfd71e # Head on 2019-08-13
- servant-flatten-0.2
- hoist-error-0.2.1.0

Expand Down
10 changes: 5 additions & 5 deletions projects/or_scs/stack.yaml.lock
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,18 @@ packages:
commit: d7aca4d13b27235af47d522b5d093e567750628e
- completed:
cabal-file:
size: 2908
sha256: cd111c999f253f8985a8b223cc3e493b97cd82cc2fbb03779afe54590ce29738
size: 2942
sha256: 8895b8bd234fe57d281f6a4db32c56850b9f0640fd07cb9753a09b8fbe1ce36e
name: GS1Combinators
version: 0.1.0.0
git: https://github.com/data61/GS1Combinators.git
pantry-tree:
size: 8991
sha256: 5c079cf09bfdce60cb82ac2454a30631b3565067a202dd5ea0351a95cb2edec7
commit: 7f0f0c9c2ec6d91378ac56ba63de033fcc313326
sha256: 3f045313a67962e750526f46a42ca7190feac345fa6eb1384c17655e532564c8
commit: ddb92e443055e7719fa46afa5913cf2276cfd71e
original:
git: https://github.com/data61/GS1Combinators.git
commit: 7f0f0c9c2ec6d91378ac56ba63de033fcc313326
commit: ddb92e443055e7719fa46afa5913cf2276cfd71e
- completed:
hackage: servant-flatten-0.2@sha256:276896f7c5cdec5b8f8493f6205fded0cc602d050b58fdb09a6d7c85c3bb0837,1234
pantry-tree:
Expand Down

0 comments on commit 2c2e8fd

Please sign in to comment.