-
Notifications
You must be signed in to change notification settings - Fork 325
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create first endpoint in Federation API
- Loading branch information
Showing
5 changed files
with
106 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,3 +38,4 @@ tests: | |
- wire-api-federation | ||
- hspec | ||
- hspec-discover | ||
- metrics-wai |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
63 changes: 63 additions & 0 deletions
63
libs/wire-api-federation/src/Wire/API/Federation/API/Conversation.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters