Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create first endpoint in Federation API #1188

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libs/wire-api-federation/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ tests:
- wire-api-federation
- hspec
- hspec-discover
- metrics-wai
30 changes: 30 additions & 0 deletions libs/wire-api-federation/src/Wire/API/Federation/API.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
-- This file is part of the Wire Server implementation.
--
-- Copyright (C) 2020 Wire Swiss GmbH <opensource@wire.com>
--
-- This program is free software: you can redistribute it and/or modify it under
-- the terms of the GNU Affero General Public License as published by the Free
-- Software Foundation, either version 3 of the License, or (at your option) any
-- later version.
--
-- This program is distributed in the hope that it will be useful, but WITHOUT
-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-- FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
-- details.
--
-- You should have received a copy of the GNU Affero General Public License along
-- with this program. If not, see <https://www.gnu.org/licenses/>.

module Wire.API.Federation.API where

import GHC.Generics (Generic)
import Servant.API.Generic (AsApi, ToServant, (:-))
import qualified Wire.API.Federation.API.Conversation as Conversation (Api)

type PlainApi = ToServant Api AsApi

-- FUTUREWORK: Add Swagger docs
data Api routes = Api
{ conversation :: routes :- ToServant Conversation.Api AsApi
}
deriving stock (Generic)
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{-# LANGUAGE DerivingVia #-}

-- This file is part of the Wire Server implementation.
--
-- Copyright (C) 2020 Wire Swiss GmbH <opensource@wire.com>
--
-- This program is free software: you can redistribute it and/or modify it under
-- the terms of the GNU Affero General Public License as published by the Free
-- Software Foundation, either version 3 of the License, or (at your option) any
-- later version.
--
-- This program is distributed in the hope that it will be useful, but WITHOUT
-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-- FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
-- details.
--
-- You should have received a copy of the GNU Affero General Public License along
-- with this program. If not, see <https://www.gnu.org/licenses/>.

module Wire.API.Federation.API.Conversation where

import Data.Aeson (FromJSON, ToJSON)
import Data.Id (ConvId, UserId)
import Data.Qualified (Qualified)
import Imports
import Servant.API (Capture, JSON, Post, ReqBody, (:>))
import Servant.API.Generic ((:-))
import Test.QuickCheck (Arbitrary (arbitrary))
import qualified Test.QuickCheck as QC
import Wire.API.Federation.Event (ConversationEvent, MemberJoin)
import Wire.API.Federation.Util.Aeson (CustomEncoded (CustomEncoded))

data Api routes = Api
{ joinConversationById ::
routes
:- "f"
:> "conversation"
:> Capture "cnv" (Qualified ConvId)
:> "join"
:> ReqBody '[JSON] JoinConversationByIdRequest
:> Post '[JSON] (ConversationUpdateResult MemberJoin)
}
deriving stock (Generic)

data JoinConversationByIdRequest = JoinConversationByIdRequest
{ joinUserId :: Qualified UserId
}
deriving stock (Eq, Show, Generic)
deriving (ToJSON, FromJSON) via (CustomEncoded JoinConversationByIdRequest)

data ConversationUpdateResult a
= ConversationUpdated (ConversationEvent a)
| ConversationUnchanged
deriving stock (Eq, Show, Generic, Foldable, Functor, Traversable)
deriving (ToJSON, FromJSON) via (CustomEncoded (ConversationUpdateResult a))

-- Arbitrary

instance Arbitrary JoinConversationByIdRequest where
arbitrary = JoinConversationByIdRequest <$> arbitrary

instance Arbitrary a => Arbitrary (ConversationUpdateResult a) where
arbitrary = QC.oneof [pure ConversationUnchanged, ConversationUpdated <$> arbitrary]
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@
-- You should have received a copy of the GNU Affero General Public License along
-- with this program. If not, see <https://www.gnu.org/licenses/>.

module Test.SerializationSpec where
module Test.Wire.API.Federation.APISpec where

import Data.Metrics.Servant (routesToPaths)
import Data.Metrics.Test (pathsConsistencyCheck)
import Imports
import Test.Hspec
import Test.Hspec (Spec, it, shouldBe)
import Wire.API.Federation.API as API

spec :: Spec
spec = do
pure ()
it "API consistency" $ do
pathsConsistencyCheck (routesToPaths @API.PlainApi) `shouldBe` mempty
7 changes: 5 additions & 2 deletions libs/wire-api-federation/wire-api-federation.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ cabal-version: 1.12
--
-- see: https://github.com/sol/hpack
--
-- hash: 365781b146aeb5cff30955591ab1c8141b368aaa3b9a25b566331dfa677431b2
-- hash: 942d9870717b6c174641f5f84d1344154f017118bd6870e939fba4eedc747d34

name: wire-api-federation
version: 0.1.0
Expand All @@ -20,6 +20,8 @@ build-type: Simple

library
exposed-modules:
Wire.API.Federation.API
Wire.API.Federation.API.Conversation
Wire.API.Federation.Event
Wire.API.Federation.Util.Aeson
other-modules:
Expand Down Expand Up @@ -49,7 +51,7 @@ test-suite spec
type: exitcode-stdio-1.0
main-is: Spec.hs
other-modules:
Test.SerializationSpec
Test.Wire.API.Federation.APISpec
Paths_wire_api_federation
hs-source-dirs:
test
Expand All @@ -67,6 +69,7 @@ test-suite spec
, hspec
, hspec-discover
, imports
, metrics-wai
, servant >=0.16
, text >=0.11
, time >=1.8
Expand Down