|
| 1 | +-- This file is part of the Wire Server implementation. |
| 2 | +-- |
| 3 | +-- Copyright (C) 2025 Wire Swiss GmbH <opensource@wire.com> |
| 4 | +-- |
| 5 | +-- This program is free software: you can redistribute it and/or modify it under |
| 6 | +-- the terms of the GNU Affero General Public License as published by the Free |
| 7 | +-- Software Foundation, either version 3 of the License, or (at your option) any |
| 8 | +-- later version. |
| 9 | +-- |
| 10 | +-- This program is distributed in the hope that it will be useful, but WITHOUT |
| 11 | +-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 12 | +-- FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more |
| 13 | +-- details. |
| 14 | +-- |
| 15 | +-- You should have received a copy of the GNU Affero General Public License along |
| 16 | +-- with this program. If not, see <https://www.gnu.org/licenses/>. |
| 17 | + |
| 18 | +module Wire.API.Meeting where |
| 19 | + |
| 20 | +import Control.Lens ((?~)) |
| 21 | +import Data.Aeson () |
| 22 | +import Data.Id (ConvId, UserId, uuidSchema) |
| 23 | +import Data.Json.Util (utcTimeSchema) |
| 24 | +import Data.OpenApi qualified as S |
| 25 | +import Data.Qualified (Qualified, qualifiedSchema) |
| 26 | +import Data.Schema |
| 27 | +import Data.Time.Clock |
| 28 | +import Data.UUID (UUID) |
| 29 | +import Deriving.Aeson |
| 30 | +import Imports |
| 31 | +import Servant (FromHttpApiData, ToHttpApiData) |
| 32 | +import Wire.API.User.Identity (EmailAddress) |
| 33 | +import Wire.Arbitrary (Arbitrary, GenericUniform (..)) |
| 34 | + |
| 35 | +-- | Unique identifier for a meeting |
| 36 | +newtype MeetingId = MeetingId {unMeetingId :: UUID} |
| 37 | + deriving stock (Eq, Ord, Show, Generic) |
| 38 | + deriving newtype (ToJSON, FromJSON, FromHttpApiData, ToHttpApiData, S.ToSchema, S.ToParamSchema) |
| 39 | + deriving (Arbitrary) via (GenericUniform MeetingId) |
| 40 | + |
| 41 | +instance ToSchema MeetingId where |
| 42 | + schema = MeetingId <$> unMeetingId .= uuidSchema |
| 43 | + |
| 44 | +instance ToSchema (Qualified MeetingId) where |
| 45 | + schema = qualifiedSchema "MeetingId" "id" schema |
| 46 | + |
| 47 | +-- | Core Meeting type |
| 48 | +data Meeting = Meeting |
| 49 | + { id :: Qualified MeetingId, |
| 50 | + title :: Text, |
| 51 | + creator :: Qualified UserId, |
| 52 | + startDate :: UTCTime, |
| 53 | + endDate :: UTCTime, |
| 54 | + recurrence :: Maybe Recurrence, |
| 55 | + conversationId :: Qualified ConvId, |
| 56 | + invitedEmails :: [EmailAddress], |
| 57 | + trial :: Bool |
| 58 | + } |
| 59 | + deriving stock (Eq, Show, Generic) |
| 60 | + deriving (ToJSON, FromJSON, S.ToSchema) via (Schema Meeting) |
| 61 | + deriving (Arbitrary) via (GenericUniform Meeting) |
| 62 | + |
| 63 | +instance ToSchema Meeting where |
| 64 | + schema = |
| 65 | + objectWithDocModifier "Meeting" (description ?~ "A scheduled meeting") $ |
| 66 | + Meeting |
| 67 | + <$> (.id) .= field "qualified_id" schema |
| 68 | + <*> (.title) .= field "title" schema |
| 69 | + <*> (.creator) .= field "qualified_creator" schema |
| 70 | + <*> (.startDate) .= field "start_date" utcTimeSchema |
| 71 | + <*> (.endDate) .= field "end_date" utcTimeSchema |
| 72 | + <*> (.recurrence) .= maybe_ (optField "recurrence" schema) |
| 73 | + <*> (.conversationId) .= field "qualified_conversation" schema |
| 74 | + <*> (.invitedEmails) .= field "invited_emails" (array schema) |
| 75 | + <*> (.trial) .= field "trial" schema |
| 76 | + |
| 77 | +-- | Request to create a new meeting |
| 78 | +data NewMeeting = NewMeeting |
| 79 | + { startDate :: UTCTime, |
| 80 | + endDate :: UTCTime, |
| 81 | + recurrence :: Maybe Recurrence, |
| 82 | + title :: Text, |
| 83 | + invitedEmails :: [EmailAddress] |
| 84 | + } |
| 85 | + deriving stock (Eq, Show, Generic) |
| 86 | + deriving (ToJSON, FromJSON, S.ToSchema) via (Schema NewMeeting) |
| 87 | + deriving (Arbitrary) via (GenericUniform NewMeeting) |
| 88 | + |
| 89 | +data Recurrence = Recurrence |
| 90 | + { freq :: Frequency, |
| 91 | + interval :: Maybe Int, |
| 92 | + until :: Maybe UTCTime |
| 93 | + } |
| 94 | + deriving stock (Eq, Show, Generic) |
| 95 | + deriving (ToJSON, FromJSON, S.ToSchema) via (Schema Recurrence) |
| 96 | + deriving (Arbitrary) via (GenericUniform Recurrence) |
| 97 | + |
| 98 | +data Frequency = Daily | Weekly | Monthly | Yearly |
| 99 | + deriving stock (Eq, Show, Generic) |
| 100 | + deriving (ToJSON, FromJSON, S.ToSchema) via (Schema Frequency) |
| 101 | + deriving (Arbitrary) via (GenericUniform Frequency) |
| 102 | + |
| 103 | +instance ToSchema NewMeeting where |
| 104 | + schema = |
| 105 | + objectWithDocModifier "NewMeeting" (description ?~ "Request to create a new meeting") $ |
| 106 | + NewMeeting |
| 107 | + <$> (.startDate) .= field "start_date" utcTimeSchema |
| 108 | + <*> (.endDate) .= field "end_date" utcTimeSchema |
| 109 | + <*> (.recurrence) .= maybe_ (optField "recurrence" schema) |
| 110 | + <*> (.title) .= field "title" schema |
| 111 | + <*> (.invitedEmails) .= (fromMaybe [] <$> optField "invited_emails" (array schema)) |
| 112 | + |
| 113 | +-- | Request to update an existing meeting |
| 114 | +data UpdateMeeting = UpdateMeeting |
| 115 | + { startDate :: Maybe UTCTime, |
| 116 | + endDate :: Maybe UTCTime, |
| 117 | + title :: Maybe Text, |
| 118 | + recurrence :: Maybe Recurrence |
| 119 | + } |
| 120 | + deriving stock (Eq, Show, Generic) |
| 121 | + deriving (ToJSON, FromJSON, S.ToSchema) via (Schema UpdateMeeting) |
| 122 | + deriving (Arbitrary) via (GenericUniform UpdateMeeting) |
| 123 | + |
| 124 | +instance ToSchema UpdateMeeting where |
| 125 | + schema = |
| 126 | + objectWithDocModifier "UpdateMeeting" (description ?~ "Request to update a meeting") $ |
| 127 | + UpdateMeeting |
| 128 | + <$> (.startDate) .= maybe_ (optField "start_date" utcTimeSchema) |
| 129 | + <*> (.endDate) .= maybe_ (optField "end_date" utcTimeSchema) |
| 130 | + <*> (.title) .= maybe_ (optField "title" schema) |
| 131 | + <*> (.recurrence) .= maybe_ (optField "recurrence" schema) |
| 132 | + |
| 133 | +instance ToSchema Frequency where |
| 134 | + schema = |
| 135 | + enum @Text "Frequency" $ |
| 136 | + mconcat |
| 137 | + [ element "Daily" Daily, |
| 138 | + element "Weekly" Weekly, |
| 139 | + element "Monthly" Monthly, |
| 140 | + element "Yearly" Yearly |
| 141 | + ] |
| 142 | + |
| 143 | +instance ToSchema Recurrence where |
| 144 | + schema = |
| 145 | + objectWithDocModifier "Recurrence" (description ?~ "Recurrence pattern for meetings") $ |
| 146 | + Recurrence |
| 147 | + <$> (.freq) .= field "frequency" schema |
| 148 | + <*> (.interval) .= maybe_ (optField "interval" schema) |
| 149 | + <*> (.until) .= maybe_ (optField "until" utcTimeSchema) |
| 150 | + |
| 151 | +-- | Request to add/remove invited email |
| 152 | +newtype MeetingEmailsInvitation = MeetingEmailsInvitation |
| 153 | + { emails :: [EmailAddress] |
| 154 | + } |
| 155 | + deriving stock (Eq, Show, Generic) |
| 156 | + deriving (ToJSON, FromJSON, S.ToSchema) via (Schema MeetingEmailsInvitation) |
| 157 | + deriving (Arbitrary) via (GenericUniform MeetingEmailsInvitation) |
| 158 | + |
| 159 | +instance ToSchema MeetingEmailsInvitation where |
| 160 | + schema = |
| 161 | + objectWithDocModifier "MeetingEmailsInvitation" (description ?~ "Emails invitation") $ |
| 162 | + MeetingEmailsInvitation |
| 163 | + <$> (.emails) .= field "emails" (array schema) |
0 commit comments