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

Finish galley servantification #4018

Merged
merged 18 commits into from
Apr 30, 2024
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 changelog.d/5-internal/servantify-galley-internal
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Finish servantifying galley and remove wai-routing dependency
2 changes: 0 additions & 2 deletions libs/galley-types/galley-types.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ library
-- cabal-fmt: expand src
exposed-modules:
Galley.Types
Galley.Types.Bot
Galley.Types.Bot.Service
Galley.Types.Conversations.Members
Galley.Types.Conversations.One2One
Galley.Types.Conversations.Roles
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}

-- This file is part of the Wire Server implementation.
Expand All @@ -18,7 +17,7 @@
-- 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 Galley.Types.Bot
module Wire.API.Bot
( AddBot,
addBot,
addBotService,
Expand All @@ -33,8 +32,10 @@ module Galley.Types.Bot
where

import Control.Lens (makeLenses)
import Data.Aeson
import Data.Aeson (FromJSON (..), ToJSON (..))
import Data.Id
import Data.OpenApi qualified as S
import Data.Schema
import Imports
import Wire.API.Provider.Service (ServiceRef)

Expand All @@ -46,50 +47,37 @@ data AddBot = AddBot
_addBotId :: !BotId,
_addBotClient :: !ClientId
}

makeLenses ''AddBot
deriving (FromJSON, ToJSON, S.ToSchema) via Schema AddBot

addBot :: ServiceRef -> ConvId -> BotId -> ClientId -> AddBot
addBot = AddBot

instance FromJSON AddBot where
parseJSON = withObject "AddBot" $ \o ->
AddBot
<$> o .: "service"
<*> o .: "conversation"
<*> o .: "bot"
<*> o .: "client"

instance ToJSON AddBot where
toJSON a =
object
[ "service" .= _addBotService a,
"conversation" .= _addBotConv a,
"bot" .= _addBotId a,
"client" .= _addBotClient a
]
instance ToSchema AddBot where
schema =
object "AddBot" $
AddBot
<$> _addBotService .= field "service" schema
<*> _addBotConv .= field "conversation" schema
<*> _addBotId .= field "bot" schema
<*> _addBotClient .= field "client" schema

-- RemoveBot ------------------------------------------------------------------

data RemoveBot = RemoveBot
{ _rmBotConv :: !ConvId,
_rmBotId :: !BotId
}

makeLenses ''RemoveBot
deriving (FromJSON, ToJSON, S.ToSchema) via Schema RemoveBot

removeBot :: ConvId -> BotId -> RemoveBot
removeBot = RemoveBot

instance FromJSON RemoveBot where
parseJSON = withObject "RemoveBot" $ \o ->
RemoveBot
<$> o .: "conversation"
<*> o .: "bot"
instance ToSchema RemoveBot where
schema =
object "RemoveBot" $
RemoveBot
<$> _rmBotConv .= field "conversation" schema
<*> _rmBotId .= field "bot" schema

instance ToJSON RemoveBot where
toJSON a =
object
[ "conversation" .= _rmBotConv a,
"bot" .= _rmBotId a
]
makeLenses ''AddBot
makeLenses ''RemoveBot
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}

-- This file is part of the Wire Server implementation.
Expand All @@ -18,7 +17,7 @@
-- 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 Galley.Types.Bot.Service
module Wire.API.Bot.Service
( Service (..),
newService,
serviceRef,
Expand All @@ -30,8 +29,10 @@ module Galley.Types.Bot.Service
where

import Control.Lens (makeLenses)
import Data.Aeson
import Data.Aeson (FromJSON (..), ToJSON (..))
import Data.Misc (Fingerprint, HttpsUrl, Rsa)
import Data.OpenApi qualified as S
import Data.Schema
import Imports
import Wire.API.Provider.Service hiding (Service (..))

Expand All @@ -45,27 +46,19 @@ data Service = Service
_serviceFingerprints :: ![Fingerprint Rsa],
_serviceEnabled :: !Bool
}

makeLenses ''Service
deriving (FromJSON, ToJSON, S.ToSchema) via Schema Service

newService :: ServiceRef -> HttpsUrl -> ServiceToken -> [Fingerprint Rsa] -> Service
newService ref url tok fps = Service ref url tok fps True

instance FromJSON Service where
parseJSON = withObject "Service" $ \o ->
Service
<$> o .: "ref"
<*> o .: "base_url"
<*> o .: "auth_token"
<*> o .: "fingerprints"
<*> o .: "enabled"
instance ToSchema Service where
schema =
object "BotService" $
Service
<$> _serviceRef .= field "ref" schema
<*> _serviceUrl .= field "base_url" schema
<*> _serviceToken .= field "auth_token" schema
<*> _serviceFingerprints .= field "fingerprints" (array schema)
<*> _serviceEnabled .= field "enabled" schema

instance ToJSON Service where
toJSON s =
object
[ "ref" .= _serviceRef s,
"base_url" .= _serviceUrl s,
"auth_token" .= _serviceToken s,
"fingerprints" .= _serviceFingerprints s,
"enabled" .= _serviceEnabled s
]
makeLenses ''Service
Loading
Loading