diff --git a/CHANGELOG.md b/CHANGELOG.md index ec33089..92bb21e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Fixed +- Fix API docs [#110](https://github.com/rokwire/notifications-building-block/issues/110) ## [1.6.0] - 2022-12-06 ### Added diff --git a/core/interfaces.go b/core/interfaces.go index 28a791d..ad9e3f1 100644 --- a/core/interfaces.go +++ b/core/interfaces.go @@ -37,7 +37,10 @@ type Services interface { GetMessagesStats(orgID string, appID string, userID string) (*model.MessagesStats, error) GetMessage(orgID string, appID string, ID string) (*model.Message, error) GetUserMessage(orgID string, appID string, ID string, accountID string) (*model.Message, error) - CreateMessage(inputMessage model.InputMessage, sender model.Sender, async bool) (*model.Message, error) + CreateMessage(orgID string, appID string, + sender model.Sender, priority int, subject string, body string, data map[string]string, + inputRecipients []model.MessageRecipient, recipientsCriteriaList []model.RecipientCriteria, + recipientAccountCriteria map[string]interface{}, topic *string, async bool) (*model.Message, error) UpdateMessage(userID *string, message *model.Message) (*model.Message, error) DeleteUserMessage(orgID string, appID string, userID string, messageID string) error DeleteMessage(orgID string, appID string, ID string) error @@ -98,8 +101,12 @@ func (s *servicesImpl) GetUserMessage(orgID string, appID string, ID string, acc return s.app.getUserMessage(orgID, appID, ID, accountID) } -func (s *servicesImpl) CreateMessage(inputMessage model.InputMessage, sender model.Sender, async bool) (*model.Message, error) { - return s.app.createMessage(inputMessage, sender, async) +func (s *servicesImpl) CreateMessage(orgID string, appID string, + sender model.Sender, priority int, subject string, body string, data map[string]string, + inputRecipients []model.MessageRecipient, recipientsCriteriaList []model.RecipientCriteria, + recipientAccountCriteria map[string]interface{}, topic *string, async bool) (*model.Message, error) { + return s.app.createMessage(orgID, appID, sender, priority, subject, body, data, + inputRecipients, recipientsCriteriaList, recipientAccountCriteria, topic, async) } func (s *servicesImpl) UpdateMessage(userID *string, message *model.Message) (*model.Message, error) { diff --git a/core/model/message.go b/core/model/message.go index 3f7e538..8344478 100644 --- a/core/model/message.go +++ b/core/model/message.go @@ -82,32 +82,3 @@ type MessagesStats struct { } /// - -//InputMessage is passed by the adapters for creating a message in the core module -type InputMessage struct { - OrgID string `json:"org_id"` - AppID string `json:"app_id"` - - Priority int `json:"priority"` - Subject string `json:"subject"` - Body string `json:"body"` - Data map[string]string `json:"data"` - - //recipients related - Recipients []InputMessageRecipient `json:"recipients"` - RecipientsCriteriaList []InputRecipientCriteria `json:"recipients_criteria_list"` - RecipientAccountCriteria map[string]interface{} `json:"recipient_account_criteria"` - Topic *string `json:"topic"` -} - -// InputMessageRecipient is passed by the adapters for creating a message in the core module -type InputMessageRecipient struct { - UserID string `json:"user_id"` - Mute bool `json:"mute"` -} - -// InputRecipientCriteria is passed by the adapters for creating a message in the core module -type InputRecipientCriteria struct { - AppVersion *string `json:"app_version"` - AppPlatform *string `json:"app_platform"` -} diff --git a/core/services.go b/core/services.go index 3197e92..e48963f 100644 --- a/core/services.go +++ b/core/services.go @@ -73,7 +73,11 @@ func (app *Application) updateTopic(topic *model.Topic) (*model.Topic, error) { return app.storage.UpdateTopic(topic) } -func (app *Application) createMessage(inputMessage model.InputMessage, sender model.Sender, async bool) (*model.Message, error) { +func (app *Application) createMessage(orgID string, appID string, + sender model.Sender, priority int, subject string, body string, data map[string]string, + inputRecipients []model.MessageRecipient, recipientsCriteriaList []model.RecipientCriteria, + recipientAccountCriteria map[string]interface{}, topic *string, async bool) (*model.Message, error) { + var err error var persistedMessage *model.Message var recipients []model.MessageRecipient @@ -85,29 +89,16 @@ func (app *Application) createMessage(inputMessage model.InputMessage, sender mo messageID := uuid.NewString() //calculate the recipients - recipients, err = app.calculateRecipients(context, inputMessage, messageID) + recipients, err = app.calculateRecipients(context, orgID, appID, + subject, body, inputRecipients, recipientsCriteriaList, + recipientAccountCriteria, topic, messageID) if err != nil { fmt.Printf("error on calculating recipients for a message: %s", err) return err } //create message object - orgID := inputMessage.OrgID - appID := inputMessage.AppID - - priority := inputMessage.Priority - subject := inputMessage.Subject - body := inputMessage.Body - data := inputMessage.Data calculatedRecipients := len(recipients) - var recipientsCriteriaList []model.RecipientCriteria - if len(inputMessage.RecipientsCriteriaList) > 0 { - recipientsCriteriaList = make([]model.RecipientCriteria, len(inputMessage.RecipientsCriteriaList)) - for i, item := range inputMessage.RecipientsCriteriaList { - recipientsCriteriaList[i] = model.RecipientCriteria{AppVersion: item.AppVersion, AppPlatform: item.AppPlatform} - } - } - topic := inputMessage.Topic dateCreated := time.Now() message := model.Message{OrgID: orgID, AppID: appID, ID: messageID, Priority: priority, Subject: subject, Sender: sender, Body: body, Data: data, RecipientsCriteriaList: recipientsCriteriaList, @@ -185,38 +176,44 @@ func (app *Application) sendMessage(allRecipients []model.MessageRecipient, mess } func (app *Application) calculateRecipients(context storage.TransactionContext, - inputMessage model.InputMessage, messageID string) ([]model.MessageRecipient, error) { + orgID string, appID string, + subject string, body string, + recipients []model.MessageRecipient, recipientsCriteriaList []model.RecipientCriteria, + recipientAccountCriteria map[string]interface{}, topic *string, messageID string) ([]model.MessageRecipient, error) { messageRecipients := []model.MessageRecipient{} checkCriteria := true // recipients from message - if len(inputMessage.Recipients) > 0 { - list := make([]model.MessageRecipient, len(inputMessage.Recipients)) - for i, item := range inputMessage.Recipients { - cItem := model.MessageRecipient{OrgID: inputMessage.OrgID, AppID: inputMessage.AppID, - ID: uuid.NewString(), UserID: item.UserID, - MessageID: messageID, Mute: item.Mute, Read: false} - list[i] = cItem + if len(recipients) > 0 { + list := make([]model.MessageRecipient, len(recipients)) + for i, item := range recipients { + item.OrgID = orgID + item.AppID = appID + item.ID = uuid.NewString() + item.MessageID = messageID + item.Read = false + + list[i] = item } messageRecipients = append(messageRecipients, list...) } // recipients from topic - if inputMessage.Topic != nil { - topicUsers, err := app.storage.GetUsersByTopicWithContext(context, inputMessage.OrgID, - inputMessage.AppID, *inputMessage.Topic) + if topic != nil { + topicUsers, err := app.storage.GetUsersByTopicWithContext(context, orgID, + appID, *topic) if err != nil { - fmt.Printf("error retrieving recipients by topic (%s): %s", *inputMessage.Topic, err) + fmt.Printf("error retrieving recipients by topic (%s): %s", *topic, err) return nil, err } - log.Printf("retrieve recipients (%+v) for topic (%s)", topicUsers, *inputMessage.Topic) + log.Printf("retrieve recipients (%+v) for topic (%s)", topicUsers, *topic) topicRecipients := make([]model.MessageRecipient, len(topicUsers)) for i, item := range topicUsers { topicRecipients[i] = model.MessageRecipient{ - OrgID: inputMessage.OrgID, AppID: inputMessage.AppID, + OrgID: orgID, AppID: appID, ID: uuid.NewString(), UserID: item.UserID, MessageID: messageID, } } @@ -233,18 +230,13 @@ func (app *Application) calculateRecipients(context storage.TransactionContext, } log.Printf("construct recipients (%+v) for message (%s:%s:%s)", - messageRecipients, messageID, inputMessage.Subject, inputMessage.Body) + messageRecipients, messageID, subject, body) } // recipients from criteria - if (inputMessage.RecipientsCriteriaList != nil) && checkCriteria { - criteriaList := make([]model.RecipientCriteria, len(inputMessage.RecipientsCriteriaList)) - for i, item := range inputMessage.RecipientsCriteriaList { - criteriaList[i] = model.RecipientCriteria{AppVersion: item.AppVersion, AppPlatform: item.AppPlatform} - } - + if (recipientsCriteriaList != nil && len(recipientAccountCriteria) > 0) && checkCriteria { criteriaUsers, err := app.storage.GetUsersByRecipientCriteriasWithContext(context, - inputMessage.OrgID, inputMessage.AppID, criteriaList) + orgID, appID, recipientsCriteriaList) if err != nil { fmt.Printf("error retrieving recipients by criteria: %s", err) return nil, err @@ -253,7 +245,7 @@ func (app *Application) calculateRecipients(context storage.TransactionContext, criteriaRecipients := make([]model.MessageRecipient, len(criteriaUsers)) for i, item := range criteriaUsers { criteriaRecipients[i] = model.MessageRecipient{ - OrgID: inputMessage.OrgID, AppID: inputMessage.AppID, + OrgID: orgID, AppID: appID, ID: uuid.NewString(), UserID: item.UserID, MessageID: messageID, } } @@ -268,20 +260,20 @@ func (app *Application) calculateRecipients(context storage.TransactionContext, messageRecipients = nil } log.Printf("construct message criteria recipients (%+v) for message (%s:%s:%s)", - messageRecipients, messageID, inputMessage.Subject, inputMessage.Body) + messageRecipients, messageID, subject, body) } // recipients from account criteria - if len(inputMessage.RecipientAccountCriteria) > 0 { - accounts, err := app.core.RetrieveCoreUserAccountByCriteria(inputMessage.RecipientAccountCriteria, - &inputMessage.AppID, &inputMessage.OrgID) + if len(recipientAccountCriteria) > 0 { + accounts, err := app.core.RetrieveCoreUserAccountByCriteria(recipientAccountCriteria, + &appID, &orgID) if err != nil { fmt.Printf("error retrieving recipients by account criteria: %s", err) } for _, account := range accounts { messageRecipient := model.MessageRecipient{ - OrgID: inputMessage.OrgID, AppID: inputMessage.AppID, + OrgID: orgID, AppID: appID, ID: uuid.NewString(), UserID: account.ID, MessageID: messageID, } diff --git a/driver/web/adapter.go b/driver/web/adapter.go index 4ab73e8..909fd0b 100644 --- a/driver/web/adapter.go +++ b/driver/web/adapter.go @@ -21,7 +21,6 @@ import ( "net/http" "notifications/core" "notifications/core/model" - "notifications/driver/web/rest" "os" "time" @@ -39,17 +38,18 @@ import ( // Adapter entity type Adapter struct { - host string - port string + host string + port string + notificationsServiceURL string auth *Auth cachedYamlDoc []byte - apisHandler rest.ApisHandler - adminApisHandler rest.AdminApisHandler - internalApisHandler rest.InternalApisHandler - bbsApisHandler rest.BBsAPIsHandler + apisHandler ApisHandler + adminApisHandler AdminApisHandler + internalApisHandler InternalApisHandler + bbsApisHandler BBsAPIsHandler app *core.Application @@ -132,7 +132,7 @@ func (we Adapter) serveDoc(w http.ResponseWriter, r *http.Request) { } func (we Adapter) serveDocUI() http.Handler { - url := fmt.Sprintf("%s/doc", we.host) + url := fmt.Sprintf("%s/doc", we.notificationsServiceURL) return httpSwagger.Handler(httpSwagger.URL(url)) } @@ -206,13 +206,13 @@ func NewWebAdapter(host string, port string, app *core.Application, config *mode logger.Fatalf("error creating auth - %s", err.Error()) } - apisHandler := rest.NewApisHandler(app) - adminApisHandler := rest.NewAdminApisHandler(app) - internalApisHandler := rest.NewInternalApisHandler(app) - bbsApisHandler := rest.NewBBsAPIsHandler(app) + apisHandler := NewApisHandler(app) + adminApisHandler := NewAdminApisHandler(app) + internalApisHandler := NewInternalApisHandler(app) + bbsApisHandler := NewBBsAPIsHandler(app) return Adapter{host: host, port: port, cachedYamlDoc: yamlDoc, auth: auth, apisHandler: apisHandler, adminApisHandler: adminApisHandler, internalApisHandler: internalApisHandler, bbsApisHandler: bbsApisHandler, - app: app, logger: logger} + app: app, logger: logger, notificationsServiceURL: config.NotificationsServiceURL} } // AppListener implements core.ApplicationListener interface diff --git a/driver/web/rest/adminapis.go b/driver/web/apis_admin.go similarity index 92% rename from driver/web/rest/adminapis.go rename to driver/web/apis_admin.go index 1ce2aaf..3aef33a 100644 --- a/driver/web/rest/adminapis.go +++ b/driver/web/apis_admin.go @@ -12,11 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -package rest +package web import ( "encoding/json" "errors" + "fmt" "net/http" "notifications/core" "notifications/core/model" @@ -25,6 +26,8 @@ import ( "github.com/rokwire/logging-library-go/v2/logs" "github.com/rokwire/logging-library-go/v2/logutils" + Def "notifications/driver/web/docs/gen" + "github.com/gorilla/mux" ) @@ -142,18 +145,32 @@ func (h AdminApisHandler) GetMessages(l *logs.Log, r *http.Request, claims *toke // @Security AdminUserAuth // @Router /admin/message [post] func (h AdminApisHandler) CreateMessage(l *logs.Log, r *http.Request, claims *tokenauth.Claims) logs.HTTPResponse { - var inputMessage *model.InputMessage + var inputMessage Def.SharedReqCreateMessage err := json.NewDecoder(r.Body).Decode(&inputMessage) if err != nil { return l.HTTPResponseErrorAction(logutils.ActionDecode, logutils.TypeRequestBody, nil, err, http.StatusBadRequest, true) } - inputMessage.OrgID = claims.OrgID - inputMessage.AppID = claims.AppID + orgID := claims.OrgID + appID := claims.AppID + + priority := inputMessage.Priority + subject := inputMessage.Subject + body := inputMessage.Body + inputData := make(map[string]string, len(inputMessage.Data)) + for key, value := range inputMessage.Data { + inputData[key] = fmt.Sprintf("%v", value) + } + inputRecipients := messagesRecipientsListFromDef(inputMessage.Recipients) + recipientsCriteria := recipientsCriteriaListFromDef(inputMessage.RecipientsCriteriaList) + recipientsAccountCriteria := inputMessage.RecipientAccountCriteria + topic := inputMessage.Topic sender := model.Sender{Type: "user", User: &model.CoreAccountRef{UserID: claims.Subject, Name: claims.Name}} - message, err := h.app.Services.CreateMessage(*inputMessage, sender, false) + message, err := h.app.Services.CreateMessage(orgID, appID, + sender, priority, subject, body, inputData, inputRecipients, recipientsCriteria, + recipientsAccountCriteria, topic, false) if err != nil { return l.HTTPResponseErrorAction(logutils.ActionCreate, "message", nil, err, http.StatusInternalServerError, true) } diff --git a/driver/web/rest/bbs.go b/driver/web/apis_bbs.go similarity index 78% rename from driver/web/rest/bbs.go rename to driver/web/apis_bbs.go index 035e86a..650d930 100644 --- a/driver/web/rest/bbs.go +++ b/driver/web/apis_bbs.go @@ -12,13 +12,15 @@ // See the License for the specific language governing permissions and // limitations under the License. -package rest +package web import ( "encoding/json" + "fmt" "net/http" "notifications/core" "notifications/core/model" + Def "notifications/driver/web/docs/gen" "github.com/rokwire/core-auth-library-go/v2/tokenauth" "github.com/rokwire/logging-library-go/v2/logs" @@ -37,8 +39,8 @@ func NewBBsAPIsHandler(app *core.Application) BBsAPIsHandler { // sendMessageRequestBody message request body type bbsSendMessageRequestBody struct { - Async *bool `json:"async"` - Message model.InputMessage `json:"message"` + Async *bool `json:"async"` + Message Def.SharedReqCreateMessage `json:"message"` } // @name sendMessageRequestBody // SendMessage Sends a message to a user, list of users or a topic @@ -63,17 +65,34 @@ func (h BBsAPIsHandler) SendMessage(l *logs.Log, r *http.Request, claims *tokena async = *bodyData.Async } - if len(inputMessage.OrgID) == 0 || len(inputMessage.AppID) == 0 { + if len(inputMessage.OrgId) == 0 || len(inputMessage.AppId) == 0 { return l.HTTPResponseErrorData(logutils.StatusInvalid, "org or app id", nil, nil, http.StatusBadRequest, false) } - if !claims.AppOrg().CanAccessAppOrg(inputMessage.AppID, inputMessage.OrgID) { + if !claims.AppOrg().CanAccessAppOrg(inputMessage.AppId, inputMessage.OrgId) { return l.HTTPResponseErrorData(logutils.StatusInvalid, "org or app id", nil, nil, http.StatusForbidden, false) } + orgID := claims.OrgID + appID := claims.AppID + + priority := inputMessage.Priority + subject := inputMessage.Subject + body := inputMessage.Body + inputData := make(map[string]string, len(inputMessage.Data)) + for key, value := range inputMessage.Data { + inputData[key] = fmt.Sprintf("%v", value) + } + inputRecipients := messagesRecipientsListFromDef(inputMessage.Recipients) + recipientsCriteria := recipientsCriteriaListFromDef(inputMessage.RecipientsCriteriaList) + recipientsAccountCriteria := inputMessage.RecipientAccountCriteria + topic := inputMessage.Topic + sender := model.Sender{Type: "system", User: &model.CoreAccountRef{UserID: claims.Subject, Name: claims.Name}} - message, err := h.app.Services.CreateMessage(inputMessage, sender, async) + message, err := h.app.Services.CreateMessage(orgID, appID, + sender, priority, subject, body, inputData, inputRecipients, recipientsCriteria, + recipientsAccountCriteria, topic, async) if err != nil { return l.HTTPResponseErrorAction(logutils.ActionSend, "message", nil, err, http.StatusInternalServerError, true) } diff --git a/driver/web/rest/apis.go b/driver/web/apis_client.go similarity index 96% rename from driver/web/rest/apis.go rename to driver/web/apis_client.go index 5411b95..052a2c8 100644 --- a/driver/web/rest/apis.go +++ b/driver/web/apis_client.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package rest +package web import ( "encoding/json" @@ -22,6 +22,7 @@ import ( "net/http" "notifications/core" "notifications/core/model" + Def "notifications/driver/web/docs/gen" "strings" "github.com/rokwire/core-auth-library-go/v2/tokenauth" @@ -453,18 +454,32 @@ func (h ApisHandler) DeleteUserMessages(l *logs.Log, r *http.Request, claims *to // @Security UserAuth // @Router /message [post] func (h ApisHandler) CreateMessage(l *logs.Log, r *http.Request, claims *tokenauth.Claims) logs.HTTPResponse { - var inputMessage *model.InputMessage + var inputMessage *Def.SharedReqCreateMessage err := json.NewDecoder(r.Body).Decode(&inputMessage) if err != nil { return l.HTTPResponseErrorAction(logutils.ActionDecode, logutils.TypeRequestBody, nil, err, http.StatusBadRequest, true) } - inputMessage.OrgID = claims.OrgID - inputMessage.AppID = claims.AppID + orgID := claims.OrgID + appID := claims.AppID + + priority := inputMessage.Priority + subject := inputMessage.Subject + body := inputMessage.Body + inputData := make(map[string]string, len(inputMessage.Data)) + for key, value := range inputMessage.Data { + inputData[key] = fmt.Sprintf("%v", value) + } + inputRecipients := messagesRecipientsListFromDef(inputMessage.Recipients) + recipientsCriteria := recipientsCriteriaListFromDef(inputMessage.RecipientsCriteriaList) + recipientsAccountCriteria := inputMessage.RecipientAccountCriteria + topic := inputMessage.Topic sender := model.Sender{Type: "user", User: &model.CoreAccountRef{UserID: claims.Subject, Name: claims.Name}} - message, err := h.app.Services.CreateMessage(*inputMessage, sender, false) + message, err := h.app.Services.CreateMessage(orgID, appID, + sender, priority, subject, body, inputData, inputRecipients, recipientsCriteria, + recipientsAccountCriteria, topic, false) if err != nil { return l.HTTPResponseErrorAction(logutils.ActionCreate, "message", nil, err, http.StatusInternalServerError, true) } diff --git a/driver/web/rest/internal.go b/driver/web/apis_internal.go similarity index 66% rename from driver/web/rest/internal.go rename to driver/web/apis_internal.go index 7f86881..9262209 100644 --- a/driver/web/rest/internal.go +++ b/driver/web/apis_internal.go @@ -12,13 +12,15 @@ // See the License for the specific language governing permissions and // limitations under the License. -package rest +package web import ( "encoding/json" + "fmt" "net/http" "notifications/core" "notifications/core/model" + Def "notifications/driver/web/docs/gen" "github.com/rokwire/core-auth-library-go/v2/tokenauth" "github.com/rokwire/logging-library-go/v2/logs" @@ -46,19 +48,34 @@ func NewInternalApisHandler(app *core.Application) InternalApisHandler { // @Router /int/message [post] // @Deprecated func (h InternalApisHandler) SendMessage(l *logs.Log, r *http.Request, claims *tokenauth.Claims) logs.HTTPResponse { - var message *model.InputMessage + var message *Def.SharedReqCreateMessage err := json.NewDecoder(r.Body).Decode(&message) if err != nil { return l.HTTPResponseErrorAction(logutils.ActionDecode, logutils.TypeRequestBody, nil, err, http.StatusBadRequest, true) } - return h.processSendMessage(l, *message, false, r) + orgID := message.OrgId + appID := message.AppId + priority := message.Priority + subject := message.Subject + body := message.Body + inputData := make(map[string]string, len(message.Data)) + for key, value := range message.Data { + inputData[key] = fmt.Sprintf("%v", value) + } + inputRecipients := messagesRecipientsListFromDef(message.Recipients) + recipientsCriteria := recipientsCriteriaListFromDef(message.RecipientsCriteriaList) + recipientsAccountCriteria := message.RecipientAccountCriteria + topic := message.Topic + + return h.processSendMessage(l, orgID, appID, priority, subject, body, inputData, + inputRecipients, recipientsCriteria, recipientsAccountCriteria, topic, false, r) } // sendMessageRequestBody message request body type sendMessageRequestBody struct { - Async *bool `json:"async"` - Message model.InputMessage `json:"message"` + Async *bool `json:"async"` + Message Def.SharedReqCreateMessage `json:"message"` } // @name sendMessageRequestBody // SendMessageV2 Sends a message to a user, list of users or a topic @@ -82,17 +99,40 @@ func (h InternalApisHandler) SendMessageV2(l *logs.Log, r *http.Request, claims if bodyData.Async != nil { async = *bodyData.Async } - return h.processSendMessage(l, message, async, r) + + orgID := message.OrgId + appID := message.AppId + priority := message.Priority + subject := message.Subject + body := message.Body + inputData := make(map[string]string, len(message.Data)) + for key, value := range message.Data { + inputData[key] = fmt.Sprintf("%v", value) + } + inputRecipients := messagesRecipientsListFromDef(message.Recipients) + recipientsCriteria := recipientsCriteriaListFromDef(message.RecipientsCriteriaList) + recipientsAccountCriteria := message.RecipientAccountCriteria + topic := message.Topic + + return h.processSendMessage(l, orgID, appID, priority, subject, body, inputData, + inputRecipients, recipientsCriteria, recipientsAccountCriteria, topic, async, r) } -func (h InternalApisHandler) processSendMessage(l *logs.Log, inputMessage model.InputMessage, async bool, r *http.Request) logs.HTTPResponse { - if len(inputMessage.OrgID) == 0 || len(inputMessage.AppID) == 0 { +func (h InternalApisHandler) processSendMessage(l *logs.Log, + orgID string, appID string, priority int, subject string, body string, + inputData map[string]string, inputRecipients []model.MessageRecipient, recipientsCriteriaList []model.RecipientCriteria, + recipientAccountCriteria map[string]interface{}, topic *string, + async bool, r *http.Request) logs.HTTPResponse { + + if len(orgID) == 0 || len(appID) == 0 { return l.HTTPResponseErrorData(logutils.StatusInvalid, "org or app id", nil, nil, http.StatusBadRequest, false) } sender := model.Sender{Type: "system"} - message, err := h.app.Services.CreateMessage(inputMessage, sender, async) + message, err := h.app.Services.CreateMessage(orgID, appID, sender, priority, + subject, body, inputData, inputRecipients, recipientsCriteriaList, + recipientAccountCriteria, topic, async) if err != nil { return l.HTTPResponseErrorAction(logutils.ActionSend, "message", nil, err, http.StatusInternalServerError, true) } diff --git a/driver/web/rest/common.go b/driver/web/common.go similarity index 99% rename from driver/web/rest/common.go rename to driver/web/common.go index af2ba3a..4e654f6 100644 --- a/driver/web/rest/common.go +++ b/driver/web/common.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package rest +package web import ( "net/http" diff --git a/driver/web/convertions_message.go b/driver/web/convertions_message.go new file mode 100644 index 0000000..7947f22 --- /dev/null +++ b/driver/web/convertions_message.go @@ -0,0 +1,24 @@ +package web + +import ( + "notifications/core/model" + Def "notifications/driver/web/docs/gen" +) + +// RecipientCriteria Type +func recipientsCriteriaListFromDef(items []Def.SharedReqCreateMessageInputRecipientCriteria) []model.RecipientCriteria { + criteriaList := make([]model.RecipientCriteria, len(items)) + for i, item := range items { + criteriaList[i] = model.RecipientCriteria{AppVersion: item.AppVersion, AppPlatform: item.AppPlatform} + } + return criteriaList +} + +// MessageRecipient Type +func messagesRecipientsListFromDef(items []Def.SharedReqCreateMessageInputMessageRecipient) []model.MessageRecipient { + result := make([]model.MessageRecipient, len(items)) + for i, item := range items { + result[i] = model.MessageRecipient{UserID: item.UserId, Mute: item.Mute} + } + return result +} diff --git a/driver/web/docs/gen/def.yaml b/driver/web/docs/gen/def.yaml index bb2a682..d45f64f 100644 --- a/driver/web/docs/gen/def.yaml +++ b/driver/web/docs/gen/def.yaml @@ -35,7 +35,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/InputMessage' + $ref: '#/components/schemas/_shared_req_CreateMessage' required: true responses: '200': @@ -56,8 +56,8 @@ paths: post: tags: - Internal - summary: Create message deprecated: true + summary: Create message description: | Create message security: @@ -234,7 +234,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/InputMessage' + $ref: '#/components/schemas/_shared_req_CreateMessage' required: true responses: '200': @@ -285,7 +285,6 @@ paths: - name: offset in: query description: offset - required: true style: simple explode: false schema: @@ -293,7 +292,6 @@ paths: - name: limit in: query description: limit - required: true style: simple explode: false schema: @@ -301,7 +299,6 @@ paths: - name: order in: query description: 'order - Possible values: asc, desc. Default: desc' - required: true style: simple explode: false schema: @@ -309,7 +306,6 @@ paths: - name: start_date in: query description: start_date - Start date filter in milliseconds as an integer epoch value - required: true style: simple explode: false schema: @@ -317,7 +313,6 @@ paths: - name: end_date in: query description: end_date - End date filter in milliseconds as an integer epoch value - required: true style: simple explode: false schema: @@ -325,12 +320,6 @@ paths: responses: '200': description: Success - content: - application/json: - schema: - type: array - items: - $ref: '#/components/schemas/Message' '400': description: Bad request '401': @@ -376,9 +365,24 @@ paths: Update read status of all messages where the current user is defined as a recipient security: - bearerAuth: [] + parameters: + - name: id + in: path + description: The message id + required: true + style: simple + explode: false + schema: + type: string responses: '200': description: Success + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/Message' '400': description: Bad request '401': @@ -415,7 +419,7 @@ paths: parameters: - name: id in: path - description: offset + description: id required: true style: simple explode: false @@ -462,7 +466,7 @@ paths: description: Unauthorized '500': description: Internal error - '/api/message/{message_id}/read': + '/api/message/{id}/read': put: tags: - Client @@ -471,15 +475,16 @@ paths: Update message security: - bearerAuth: [] - parameters: - - name: id - in: path - description: offset - required: true - style: simple - explode: false - schema: - type: string + requestBody: + description: body json of the read boolean + content: + application/json: + schema: + type: object + properties: + read: + type: boolean + required: true responses: '200': description: Success @@ -540,7 +545,6 @@ paths: - name: offset in: query description: offset - required: true style: simple explode: false schema: @@ -548,7 +552,6 @@ paths: - name: limit in: query description: limit - limit the result - required: true style: simple explode: false schema: @@ -556,7 +559,6 @@ paths: - name: order in: query description: 'order - Possible values: asc, desc. Default: desc' - required: true style: simple explode: false schema: @@ -564,7 +566,6 @@ paths: - name: start_date in: query description: start_date - Start date filter in milliseconds as an integer epoch value - required: true style: simple explode: false schema: @@ -572,7 +573,6 @@ paths: - name: end_date in: query description: end_date - End date filter in milliseconds as an integer epoch value - required: true style: simple explode: false schema: @@ -778,10 +778,23 @@ paths: $ref: '#/components/schemas/_client_req_message' required: true parameters: + - name: read + in: query + description: read + style: simple + explode: false + schema: + type: boolean + - name: mute + in: query + description: mute + style: simple + explode: false + schema: + type: boolean - name: offset in: query description: offset - required: true style: simple explode: false schema: @@ -789,7 +802,6 @@ paths: - name: limit in: query description: limit - required: true style: simple explode: false schema: @@ -797,7 +809,6 @@ paths: - name: order in: query description: 'order - Possible values: asc, desc. Default: desc' - required: true style: simple explode: false schema: @@ -805,7 +816,6 @@ paths: - name: start_date in: query description: start_date - Start date filter in milliseconds as an integer epoch value - required: true style: simple explode: false schema: @@ -813,11 +823,34 @@ paths: - name: end_date in: query description: end_date - End date filter in milliseconds as an integer epoch value - required: true style: simple explode: false schema: type: string + responses: + '200': + description: Success + '400': + description: Bad request + '401': + description: Unauthorized + '500': + description: Internal error + delete: + tags: + - Client + summary: Removes the current user from the recipient list of all described + description: | + Removes the current user from the recipient list of all described + security: + - bearerAuth: [] + requestBody: + description: body json of the all message ids that need to be filtered + content: + application/json: + schema: + $ref: '#/components/schemas/_client_req_message' + required: true responses: '200': description: Success @@ -847,7 +880,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/InputMessage' + $ref: '#/components/schemas/_shared_req_CreateMessage' required: true responses: '200': @@ -877,7 +910,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/InputMessage' + $ref: '#/components/schemas/_shared_req_CreateMessage' required: true responses: '200': @@ -938,7 +971,7 @@ paths: parameters: - name: id in: path - description: The message + description: The message id required: true style: simple explode: false @@ -1122,47 +1155,6 @@ components: type: array items: type: string - InputMessage: - type: object - properties: - org_id: - type: string - app_id: - type: string - priority: - type: string - topic: - type: string - subject: - type: string - body: - type: string - data: - type: array - items: - type: string - recipients: - type: array - $ref: '#/components/schemas/InputMessageRecipient' - recipients_criteria_list: - type: array - $ref: '#/components/schemas/InputRecipientCriteria' - recipient_account_criteria: - type: object - InputMessageRecipient: - type: object - properties: - user_id: - type: string - mute: - type: boolean - InputRecipientCriteria: - type: object - properties: - app_version: - type: string - app_platform: - type: string Recipient: type: object properties: @@ -1258,7 +1250,7 @@ components: async: type: boolean message: - $ref: '#/components/schemas/InputMessage' + $ref: '#/components/schemas/_shared_req_CreateMessage' _client_req_token: required: - token @@ -1266,12 +1258,6 @@ components: properties: token: type: string - previous_token: - type: string - app_version: - type: string - app_platform: - type: string _client_req_user: required: - notifications_disabled @@ -1279,3 +1265,57 @@ components: properties: notifications_disabled: type: boolean + _shared_req_CreateMessage: + required: + - org_id + - app_id + - priority + - subject + - body + - data + - recipients + - recipients_criteria_list + - recipient_account_criteria + type: object + properties: + org_id: + type: string + app_id: + type: string + priority: + type: integer + topic: + type: string + subject: + type: string + body: + type: string + data: + type: object + recipients: + type: array + items: + $ref: '#/components/schemas/_shared_req_CreateMessage_InputMessageRecipient' + recipients_criteria_list: + type: array + items: + $ref: '#/components/schemas/_shared_req_CreateMessage_InputRecipientCriteria' + recipient_account_criteria: + type: object + _shared_req_CreateMessage_InputMessageRecipient: + required: + - user_id + - mute + type: object + properties: + user_id: + type: string + mute: + type: boolean + _shared_req_CreateMessage_InputRecipientCriteria: + type: object + properties: + app_version: + type: string + app_platform: + type: string diff --git a/driver/web/docs/gen/gen_types.go b/driver/web/docs/gen/gen_types.go new file mode 100644 index 0000000..2506b65 --- /dev/null +++ b/driver/web/docs/gen/gen_types.go @@ -0,0 +1,302 @@ +// Package Def provides primitives to interact with the openapi HTTP API. +// +// Code generated by github.com/deepmap/oapi-codegen version v1.11.0 DO NOT EDIT. +package Def + +const ( + BearerAuthScopes = "bearerAuth.Scopes" +) + +// CoreAccountRef defines model for CoreAccountRef. +type CoreAccountRef struct { + Name *string `json:"name,omitempty"` + UserId *string `json:"user_id,omitempty"` +} + +// FirebaseToken defines model for FirebaseToken. +type FirebaseToken struct { + AppPlatform *string `json:"app_platform,omitempty"` + AppVersion *string `json:"app_version,omitempty"` + DateCreated *string `json:"date_created,omitempty"` + DateUpdated *string `json:"date_updated,omitempty"` + Token *string `json:"token,omitempty"` +} + +// Message defines model for Message. +type Message struct { + Id *string `json:"_id,omitempty"` + AppId *string `json:"app_id,omitempty"` + Body *string `json:"body,omitempty"` + Data *[]string `json:"data,omitempty"` + DateCreated *string `json:"date_created,omitempty"` + DateUpdated *string `json:"date_updated,omitempty"` + OrgId *string `json:"org_id,omitempty"` + Priority *string `json:"priority,omitempty"` + RecipientAccountCriteria *map[string]interface{} `json:"recipient_account_criteria,omitempty"` + Recipients *Recipient `json:"recipients,omitempty"` + RecipientsCriteriaList *RecipientCriteria `json:"recipients_criteria_list,omitempty"` + Sender *Sender `json:"sender,omitempty"` + Subject *string `json:"subject,omitempty"` + Topic *string `json:"topic,omitempty"` +} + +// Recipient defines model for Recipient. +type Recipient struct { + Mute *bool `json:"mute,omitempty"` + Name *string `json:"name,omitempty"` + NotificationDisabled *bool `json:"notification_disabled,omitempty"` + Read *bool `json:"read,omitempty"` + UserId *string `json:"user_id,omitempty"` +} + +// RecipientCriteria defines model for RecipientCriteria. +type RecipientCriteria struct { + AppPlatform *string `json:"app_platform,omitempty"` + AppVersion *string `json:"app_version,omitempty"` +} + +// Sender defines model for Sender. +type Sender struct { + Type *string `json:"type,omitempty"` + User *CoreAccountRef `json:"user,omitempty"` +} + +// Topic defines model for Topic. +type Topic struct { + AppId *string `json:"app_id,omitempty"` + DateCreated *string `json:"date_created,omitempty"` + DateUpdated *string `json:"date_updated,omitempty"` + Description *string `json:"description,omitempty"` + Name *string `json:"name,omitempty"` + OrgId *string `json:"org_id,omitempty"` +} + +// User defines model for User. +type User struct { + Id *string `json:"_id,omitempty"` + DateCreated *string `json:"date_created,omitempty"` + DateUpdated *string `json:"date_updated,omitempty"` + FirebaseTokens *FirebaseToken `json:"firebase_tokens,omitempty"` + NotificationsDisabled *string `json:"notifications_disabled,omitempty"` + Topics *[]interface{} `json:"topics,omitempty"` + UserId *string `json:"user_id,omitempty"` +} + +// ClientReqMail defines model for _client_req_mail. +type ClientReqMail struct { + Body *string `json:"body,omitempty"` + Subject *string `json:"subject,omitempty"` + ToMail *string `json:"to_mail,omitempty"` +} + +// ClientReqMessage defines model for _client_req_message. +type ClientReqMessage struct { + Ids []string `json:"_ids"` +} + +// ClientReqMessageV2 defines model for _client_req_messageV2. +type ClientReqMessageV2 struct { + Async *bool `json:"async,omitempty"` + Message *SharedReqCreateMessage `json:"message,omitempty"` +} + +// ClientReqToken defines model for _client_req_token. +type ClientReqToken struct { + AppPlatform *string `json:"app_platform,omitempty"` + AppVersion *string `json:"app_version,omitempty"` + PreviousToken *string `json:"previous_token,omitempty"` + Token string `json:"token"` +} + +// ClientReqUser defines model for _client_req_user. +type ClientReqUser struct { + NotificationsDisabled bool `json:"notifications_disabled"` +} + +// SharedReqCreateMessage defines model for _shared_req_CreateMessage. +type SharedReqCreateMessage struct { + AppId string `json:"app_id"` + Body string `json:"body"` + Data map[string]interface{} `json:"data"` + OrgId string `json:"org_id"` + Priority int `json:"priority"` + RecipientAccountCriteria map[string]interface{} `json:"recipient_account_criteria"` + Recipients []SharedReqCreateMessageInputMessageRecipient `json:"recipients"` + RecipientsCriteriaList []SharedReqCreateMessageInputRecipientCriteria `json:"recipients_criteria_list"` + Subject string `json:"subject"` + Topic *string `json:"topic,omitempty"` +} + +// SharedReqCreateMessageInputMessageRecipient defines model for _shared_req_CreateMessage_InputMessageRecipient. +type SharedReqCreateMessageInputMessageRecipient struct { + Mute bool `json:"mute"` + UserId string `json:"user_id"` +} + +// SharedReqCreateMessageInputRecipientCriteria defines model for _shared_req_CreateMessage_InputRecipientCriteria. +type SharedReqCreateMessageInputRecipientCriteria struct { + AppPlatform *string `json:"app_platform,omitempty"` + AppVersion *string `json:"app_version,omitempty"` +} + +// PostApiAdminMessageJSONBody defines parameters for PostApiAdminMessage. +type PostApiAdminMessageJSONBody = SharedReqCreateMessage + +// PutApiAdminMessageJSONBody defines parameters for PutApiAdminMessage. +type PutApiAdminMessageJSONBody = SharedReqCreateMessage + +// GetApiAdminMessagesJSONBody defines parameters for GetApiAdminMessages. +type GetApiAdminMessagesJSONBody = ClientReqMessage + +// GetApiAdminMessagesParams defines parameters for GetApiAdminMessages. +type GetApiAdminMessagesParams struct { + // offset + Offset string `json:"offset"` + + // limit + Limit string `json:"limit"` + + // order - Possible values: asc, desc. Default: desc + Order string `json:"order"` + + // start_date - Start date filter in milliseconds as an integer epoch value + StartDate string `json:"start_date"` + + // end_date - End date filter in milliseconds as an integer epoch value + EndDate string `json:"end_date"` +} + +// PutApiAdminTopicJSONBody defines parameters for PutApiAdminTopic. +type PutApiAdminTopicJSONBody = Topic + +// PostApiBbsMailJSONBody defines parameters for PostApiBbsMail. +type PostApiBbsMailJSONBody = ClientReqMail + +// PostApiBbsMessageJSONBody defines parameters for PostApiBbsMessage. +type PostApiBbsMessageJSONBody = ClientReqMessageV2 + +// PostApiIntMailJSONBody defines parameters for PostApiIntMail. +type PostApiIntMailJSONBody = ClientReqToken + +// PostApiIntMessageJSONBody defines parameters for PostApiIntMessage. +type PostApiIntMessageJSONBody = SharedReqCreateMessage + +// PostApiIntV2MessageJSONBody defines parameters for PostApiIntV2Message. +type PostApiIntV2MessageJSONBody = ClientReqMessageV2 + +// PostApiMessageJSONBody defines parameters for PostApiMessage. +type PostApiMessageJSONBody = SharedReqCreateMessage + +// DeleteApiMessagesJSONBody defines parameters for DeleteApiMessages. +type DeleteApiMessagesJSONBody = ClientReqMessage + +// GetApiMessagesJSONBody defines parameters for GetApiMessages. +type GetApiMessagesJSONBody = ClientReqMessage + +// GetApiMessagesParams defines parameters for GetApiMessages. +type GetApiMessagesParams struct { + // read + Read *bool `json:"read,omitempty"` + + // mute + Mute *bool `json:"mute,omitempty"` + + // offset + Offset string `json:"offset"` + + // limit + Limit string `json:"limit"` + + // order - Possible values: asc, desc. Default: desc + Order string `json:"order"` + + // start_date - Start date filter in milliseconds as an integer epoch value + StartDate string `json:"start_date"` + + // end_date - End date filter in milliseconds as an integer epoch value + EndDate string `json:"end_date"` +} + +// PostApiTokenJSONBody defines parameters for PostApiToken. +type PostApiTokenJSONBody = ClientReqToken + +// GetApiTopicTopicMessagesParams defines parameters for GetApiTopicTopicMessages. +type GetApiTopicTopicMessagesParams struct { + // offset + Offset string `json:"offset"` + + // limit - limit the result + Limit string `json:"limit"` + + // order - Possible values: asc, desc. Default: desc + Order string `json:"order"` + + // start_date - Start date filter in milliseconds as an integer epoch value + StartDate string `json:"start_date"` + + // end_date - End date filter in milliseconds as an integer epoch value + EndDate string `json:"end_date"` +} + +// PostApiTopicTopicSubscribeJSONBody defines parameters for PostApiTopicTopicSubscribe. +type PostApiTopicTopicSubscribeJSONBody = ClientReqToken + +// PostApiTopicTopicUnsubscribeJSONBody defines parameters for PostApiTopicTopicUnsubscribe. +type PostApiTopicTopicUnsubscribeJSONBody = ClientReqToken + +// DeleteApiUserJSONBody defines parameters for DeleteApiUser. +type DeleteApiUserJSONBody = ClientReqUser + +// PutApiUserJSONBody defines parameters for PutApiUser. +type PutApiUserJSONBody = ClientReqUser + +// PostApiAdminMessageJSONRequestBody defines body for PostApiAdminMessage for application/json ContentType. +type PostApiAdminMessageJSONRequestBody = PostApiAdminMessageJSONBody + +// PutApiAdminMessageJSONRequestBody defines body for PutApiAdminMessage for application/json ContentType. +type PutApiAdminMessageJSONRequestBody = PutApiAdminMessageJSONBody + +// GetApiAdminMessagesJSONRequestBody defines body for GetApiAdminMessages for application/json ContentType. +type GetApiAdminMessagesJSONRequestBody = GetApiAdminMessagesJSONBody + +// PutApiAdminTopicJSONRequestBody defines body for PutApiAdminTopic for application/json ContentType. +type PutApiAdminTopicJSONRequestBody = PutApiAdminTopicJSONBody + +// PostApiBbsMailJSONRequestBody defines body for PostApiBbsMail for application/json ContentType. +type PostApiBbsMailJSONRequestBody = PostApiBbsMailJSONBody + +// PostApiBbsMessageJSONRequestBody defines body for PostApiBbsMessage for application/json ContentType. +type PostApiBbsMessageJSONRequestBody = PostApiBbsMessageJSONBody + +// PostApiIntMailJSONRequestBody defines body for PostApiIntMail for application/json ContentType. +type PostApiIntMailJSONRequestBody = PostApiIntMailJSONBody + +// PostApiIntMessageJSONRequestBody defines body for PostApiIntMessage for application/json ContentType. +type PostApiIntMessageJSONRequestBody = PostApiIntMessageJSONBody + +// PostApiIntV2MessageJSONRequestBody defines body for PostApiIntV2Message for application/json ContentType. +type PostApiIntV2MessageJSONRequestBody = PostApiIntV2MessageJSONBody + +// PostApiMessageJSONRequestBody defines body for PostApiMessage for application/json ContentType. +type PostApiMessageJSONRequestBody = PostApiMessageJSONBody + +// DeleteApiMessagesJSONRequestBody defines body for DeleteApiMessages for application/json ContentType. +type DeleteApiMessagesJSONRequestBody = DeleteApiMessagesJSONBody + +// GetApiMessagesJSONRequestBody defines body for GetApiMessages for application/json ContentType. +type GetApiMessagesJSONRequestBody = GetApiMessagesJSONBody + +// PostApiTokenJSONRequestBody defines body for PostApiToken for application/json ContentType. +type PostApiTokenJSONRequestBody = PostApiTokenJSONBody + +// PostApiTopicTopicSubscribeJSONRequestBody defines body for PostApiTopicTopicSubscribe for application/json ContentType. +type PostApiTopicTopicSubscribeJSONRequestBody = PostApiTopicTopicSubscribeJSONBody + +// PostApiTopicTopicUnsubscribeJSONRequestBody defines body for PostApiTopicTopicUnsubscribe for application/json ContentType. +type PostApiTopicTopicUnsubscribeJSONRequestBody = PostApiTopicTopicUnsubscribeJSONBody + +// DeleteApiUserJSONRequestBody defines body for DeleteApiUser for application/json ContentType. +type DeleteApiUserJSONRequestBody = DeleteApiUserJSONBody + +// PutApiUserJSONRequestBody defines body for PutApiUser for application/json ContentType. +type PutApiUserJSONRequestBody = PutApiUserJSONBody diff --git a/driver/web/docs/index.yaml b/driver/web/docs/index.yaml index e042d26..7a5a9f3 100644 --- a/driver/web/docs/index.yaml +++ b/driver/web/docs/index.yaml @@ -42,7 +42,7 @@ paths: $ref: "./resources/client/message/messages-stats.yaml" /api/message/{id}: $ref: "./resources/client/message/messages-id.yaml" - /api/message/{message_id}/read: + /api/message/{id}/read: $ref: "./resources/client/message/message-read.yaml" /api/topics: $ref: "./resources/client/topic/topics.yaml" diff --git a/driver/web/docs/resources/admin/message/message.yaml b/driver/web/docs/resources/admin/message/message.yaml index b35cc0b..252f4a9 100644 --- a/driver/web/docs/resources/admin/message/message.yaml +++ b/driver/web/docs/resources/admin/message/message.yaml @@ -11,7 +11,7 @@ post: content: application/json: schema: - $ref: "../../../schemas/application/InputMessage.yaml" + $ref: "../../../schemas/apis/shared/requests/create-message/Request.yaml" required: true responses: 200: @@ -41,7 +41,7 @@ put: content: application/json: schema: - $ref: "../../../schemas/application/InputMessage.yaml" + $ref: "../../../schemas/apis/shared/requests/create-message/Request.yaml" required: true responses: 200: diff --git a/driver/web/docs/resources/admin/message/messages-id.yaml b/driver/web/docs/resources/admin/message/messages-id.yaml index d7c526b..6d80639 100644 --- a/driver/web/docs/resources/admin/message/messages-id.yaml +++ b/driver/web/docs/resources/admin/message/messages-id.yaml @@ -41,7 +41,7 @@ delete: parameters: - name: id in: path - description: The message + description: The message id required: true style: simple explode: false diff --git a/driver/web/docs/resources/admin/message/messages.yaml b/driver/web/docs/resources/admin/message/messages.yaml index 1598616..be5c264 100644 --- a/driver/web/docs/resources/admin/message/messages.yaml +++ b/driver/web/docs/resources/admin/message/messages.yaml @@ -14,10 +14,23 @@ get: $ref: "../../../schemas/apis/message/request/Request.yaml" required: true parameters: + - name: read + in: query + description: read + style: simple + explode: false + schema: + type: boolean + - name: mute + in: query + description: mute + style: simple + explode: false + schema: + type: boolean - name: offset in: query description: offset - required: true style: simple explode: false schema: @@ -25,7 +38,6 @@ get: - name: limit in: query description: limit - required: true style: simple explode: false schema: @@ -33,7 +45,6 @@ get: - name: order in: query description: "order - Possible values: asc, desc. Default: desc" - required: true style: simple explode: false schema: @@ -41,7 +52,6 @@ get: - name: start_date in: query description: "start_date - Start date filter in milliseconds as an integer epoch value" - required: true style: simple explode: false schema: @@ -49,11 +59,34 @@ get: - name: end_date in: query description: "end_date - End date filter in milliseconds as an integer epoch value" - required: true style: simple explode: false schema: type: string + responses: + 200: + description: Success + 400: + description: Bad request + 401: + description: Unauthorized + 500: + description: Internal error +delete: + tags: + - Client + summary: Removes the current user from the recipient list of all described + description: | + Removes the current user from the recipient list of all described + security: + - bearerAuth: [] + requestBody: + description: "body json of the all message ids that need to be filtered" + content: + application/json: + schema: + $ref: "../../../schemas/apis/message/request/Request.yaml" + required: true responses: 200: description: Success @@ -68,5 +101,7 @@ get: 401: description: Unauthorized 500: - description: Internal error + description: Internal error + + \ No newline at end of file diff --git a/driver/web/docs/resources/client/message/message-read.yaml b/driver/web/docs/resources/client/message/message-read.yaml index e62ab17..88cacce 100644 --- a/driver/web/docs/resources/client/message/message-read.yaml +++ b/driver/web/docs/resources/client/message/message-read.yaml @@ -6,15 +6,13 @@ put: Update message security: - bearerAuth: [] - parameters: - - name: id - in: path - description: offset - required: true - style: simple - explode: false - schema: - type: string + requestBody: + description: "body json of the read boolean" + content: + application/json: + schema: + $ref: "../../../schemas/apis/message-read/request/Request.yaml" + required: true responses: 200: description: Success diff --git a/driver/web/docs/resources/client/message/message.yaml b/driver/web/docs/resources/client/message/message.yaml index e428f1a..13a521a 100644 --- a/driver/web/docs/resources/client/message/message.yaml +++ b/driver/web/docs/resources/client/message/message.yaml @@ -13,7 +13,7 @@ post: content: application/json: schema: - $ref: "../../../schemas/application/InputMessage.yaml" + $ref: "../../../schemas/apis/shared/requests/create-message/Request.yaml" required: true responses: 200: diff --git a/driver/web/docs/resources/client/message/messages-id.yaml b/driver/web/docs/resources/client/message/messages-id.yaml index 3a4f9c0..766039b 100644 --- a/driver/web/docs/resources/client/message/messages-id.yaml +++ b/driver/web/docs/resources/client/message/messages-id.yaml @@ -9,7 +9,7 @@ get: parameters: - name: id in: path - description: offset + description: id required: true style: simple explode: false diff --git a/driver/web/docs/resources/client/message/messages-read.yaml b/driver/web/docs/resources/client/message/messages-read.yaml index 9dd9ba4..f4fe7ab 100644 --- a/driver/web/docs/resources/client/message/messages-read.yaml +++ b/driver/web/docs/resources/client/message/messages-read.yaml @@ -5,10 +5,25 @@ put: description: | Update read status of all messages where the current user is defined as a recipient security: - - bearerAuth: [] + - bearerAuth: [] + parameters: + - name: id + in: path + description: The message id + required: true + style: simple + explode: false + schema: + type: string responses: 200: description: Success + content: + application/json: + schema: + type: array + items: + $ref: "../../../schemas/application/Message.yaml" 400: description: Bad request 401: diff --git a/driver/web/docs/resources/client/message/messages.yaml b/driver/web/docs/resources/client/message/messages.yaml index 1026dd3..703a70f 100644 --- a/driver/web/docs/resources/client/message/messages.yaml +++ b/driver/web/docs/resources/client/message/messages.yaml @@ -31,7 +31,6 @@ get: - name: offset in: query description: offset - required: true style: simple explode: false schema: @@ -39,7 +38,6 @@ get: - name: limit in: query description: limit - required: true style: simple explode: false schema: @@ -47,7 +45,6 @@ get: - name: order in: query description: "order - Possible values: asc, desc. Default: desc" - required: true style: simple explode: false schema: @@ -55,7 +52,6 @@ get: - name: start_date in: query description: "start_date - Start date filter in milliseconds as an integer epoch value" - required: true style: simple explode: false schema: @@ -63,7 +59,6 @@ get: - name: end_date in: query description: "end_date - End date filter in milliseconds as an integer epoch value" - required: true style: simple explode: false schema: @@ -71,12 +66,6 @@ get: responses: 200: description: Success - content: - application/json: - schema: - type: array - items: - $ref: "../../../schemas/application/Message.yaml" 400: description: Bad request 401: diff --git a/driver/web/docs/resources/client/topic/topics-messages.yaml b/driver/web/docs/resources/client/topic/topics-messages.yaml index b926fda..cfe4834 100644 --- a/driver/web/docs/resources/client/topic/topics-messages.yaml +++ b/driver/web/docs/resources/client/topic/topics-messages.yaml @@ -18,7 +18,6 @@ - name: offset in: query description: offset - required: true style: simple explode: false schema: @@ -26,7 +25,6 @@ - name: limit in: query description: limit - limit the result - required: true style: simple explode: false schema: @@ -34,7 +32,6 @@ - name: order in: query description: "order - Possible values: asc, desc. Default: desc" - required: true style: simple explode: false schema: @@ -42,7 +39,6 @@ - name: start_date in: query description: "start_date - Start date filter in milliseconds as an integer epoch value" - required: true style: simple explode: false schema: @@ -50,7 +46,6 @@ - name: end_date in: query description: "end_date - End date filter in milliseconds as an integer epoch value" - required: true style: simple explode: false schema: diff --git a/driver/web/docs/resources/internal/message.yaml b/driver/web/docs/resources/internal/message.yaml index c91cd8a..49b27dc 100644 --- a/driver/web/docs/resources/internal/message.yaml +++ b/driver/web/docs/resources/internal/message.yaml @@ -12,7 +12,7 @@ post: content: application/json: schema: - $ref: "../../schemas/application/InputMessage.yaml" + $ref: "../../schemas/apis/shared/requests/create-message/Request.yaml" required: true responses: 200: diff --git a/driver/web/docs/resources/internal/v2/message.yaml b/driver/web/docs/resources/internal/v2/message.yaml index 1ef2f41..609009d 100644 --- a/driver/web/docs/resources/internal/v2/message.yaml +++ b/driver/web/docs/resources/internal/v2/message.yaml @@ -1,8 +1,8 @@ post: tags: - Internal - summary: Create message deprecated: true + summary: Create message description: | Create message security: diff --git a/driver/web/docs/schemas/apis/message-read/request/Request.yaml b/driver/web/docs/schemas/apis/message-read/request/Request.yaml new file mode 100644 index 0000000..8e52bf3 --- /dev/null +++ b/driver/web/docs/schemas/apis/message-read/request/Request.yaml @@ -0,0 +1,4 @@ +type: object +properties: + read: + type: boolean diff --git a/driver/web/docs/schemas/apis/messageV2/request/Request.yaml b/driver/web/docs/schemas/apis/messageV2/request/Request.yaml index 1b8e641..d7fcfd4 100644 --- a/driver/web/docs/schemas/apis/messageV2/request/Request.yaml +++ b/driver/web/docs/schemas/apis/messageV2/request/Request.yaml @@ -3,4 +3,4 @@ properties: async: type: boolean message: - $ref: "../../../application/InputMessage.yaml" + $ref: "../../../apis/shared/requests/create-message/Request.yaml" diff --git a/driver/web/docs/schemas/application/InputMessageRecipient.yaml b/driver/web/docs/schemas/apis/shared/requests/create-message/InputMessageRecipient.yaml similarity index 71% rename from driver/web/docs/schemas/application/InputMessageRecipient.yaml rename to driver/web/docs/schemas/apis/shared/requests/create-message/InputMessageRecipient.yaml index 3cd3e73..f6c2734 100644 --- a/driver/web/docs/schemas/application/InputMessageRecipient.yaml +++ b/driver/web/docs/schemas/apis/shared/requests/create-message/InputMessageRecipient.yaml @@ -1,3 +1,6 @@ +required: + - user_id + - mute type: object properties: user_id: diff --git a/driver/web/docs/schemas/application/InputRecipientCriteria.yaml b/driver/web/docs/schemas/apis/shared/requests/create-message/InputRecipientCriteria.yaml similarity index 100% rename from driver/web/docs/schemas/application/InputRecipientCriteria.yaml rename to driver/web/docs/schemas/apis/shared/requests/create-message/InputRecipientCriteria.yaml diff --git a/driver/web/docs/schemas/application/InputMessage.yaml b/driver/web/docs/schemas/apis/shared/requests/create-message/Request.yaml similarity index 52% rename from driver/web/docs/schemas/application/InputMessage.yaml rename to driver/web/docs/schemas/apis/shared/requests/create-message/Request.yaml index f127fbf..037d31d 100644 --- a/driver/web/docs/schemas/application/InputMessage.yaml +++ b/driver/web/docs/schemas/apis/shared/requests/create-message/Request.yaml @@ -1,3 +1,13 @@ +required: + - org_id + - app_id + - priority + - subject + - body + - data + - recipients + - recipients_criteria_list + - recipient_account_criteria type: object properties: org_id: @@ -5,7 +15,7 @@ properties: app_id: type: string priority: - type: string + type: integer topic: type: string subject: @@ -13,14 +23,14 @@ properties: body: type: string data: - type: array - items: - type: string + type: object recipients: type: array - $ref: "./InputMessageRecipient.yaml" + items: + $ref: "./InputMessageRecipient.yaml" recipients_criteria_list: type: array - $ref: "./InputRecipientCriteria.yaml" + items: + $ref: "./InputRecipientCriteria.yaml" recipient_account_criteria: - type: object + type: object \ No newline at end of file diff --git a/driver/web/docs/schemas/apis/token/request/Request.yaml b/driver/web/docs/schemas/apis/token/request/Request.yaml index 0aa21e6..5ae8f11 100644 --- a/driver/web/docs/schemas/apis/token/request/Request.yaml +++ b/driver/web/docs/schemas/apis/token/request/Request.yaml @@ -3,10 +3,4 @@ required: type: object properties: token: - type: string - previous_token: - type: string - app_version: - type: string - app_platform: type: string \ No newline at end of file diff --git a/driver/web/docs/schemas/index.yaml b/driver/web/docs/schemas/index.yaml index cea1245..eeb4f13 100644 --- a/driver/web/docs/schemas/index.yaml +++ b/driver/web/docs/schemas/index.yaml @@ -13,12 +13,6 @@ FirebaseToken: $ref: "./application/FirebaseToken.yaml" Message: $ref: "./application/Message.yaml" -InputMessage: - $ref: "./application/InputMessage.yaml" -InputMessageRecipient: - $ref: "./application/InputMessageRecipient.yaml" -InputRecipientCriteria: - $ref: "./application/InputRecipientCriteria.yaml" Recipient: $ref: "./application/Recipients.yaml" RecipientCriteria: @@ -42,3 +36,18 @@ _client_req_token: $ref: "./apis/token/request/Request.yaml" _client_req_user: $ref: "./apis/user/request/Request.yaml" + + +##### APIs requests and responses - they are at bottom + +## SHARED requests and responses + +### requests +_shared_req_CreateMessage: + $ref: "./apis/shared/requests/create-message/Request.yaml" +_shared_req_CreateMessage_InputMessageRecipient: + $ref: "./apis/shared/requests/create-message/InputMessageRecipient.yaml" +_shared_req_CreateMessage_InputRecipientCriteria: + $ref: "./apis/shared/requests/create-message/InputRecipientCriteria.yaml" + +### responses \ No newline at end of file diff --git a/go.mod b/go.mod index ac30497..0d840b9 100644 --- a/go.mod +++ b/go.mod @@ -48,6 +48,7 @@ require ( github.com/mailru/easyjson v0.7.7 // indirect github.com/montanaflynn/stats v0.6.6 // indirect github.com/pkg/errors v0.9.1 // indirect + github.com/rokwire/logging-library-go v1.0.3 // indirect github.com/sirupsen/logrus v1.9.0 // indirect github.com/swaggo/files v0.0.0-20220728132757-551d4a08d97a // indirect github.com/swaggo/swag v1.8.8 // indirect diff --git a/go.sum b/go.sum index e5ab19d..c7f5f99 100644 --- a/go.sum +++ b/go.sum @@ -89,6 +89,7 @@ github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/martian/v3 v3.2.1 h1:d8MncMlErDFTwQGBK1xhv026j9kqhvw1Qv9IbWT1VLQ= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/enterprise-certificate-proxy v0.2.0 h1:y8Yozv7SZtlU//QXbezB6QkpuE6jMD2/gfzk4AftXjs= @@ -126,14 +127,18 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/rokwire/core-auth-library-go/v2 v2.2.0 h1:AMnYyGBIQMVY2w/+gYeVl05BqpBcjttRKj3urXO2OVo= github.com/rokwire/core-auth-library-go/v2 v2.2.0/go.mod h1:0MO0lt55BvVjLmegbbDeTyNQR+UL0wKzOvZvnMtRw0w= +github.com/rokwire/logging-library-go v1.0.3 h1:ONaEJO0NbBYtG+gV7+fn2zQqtPDkpSCif+nMuXvJFBA= +github.com/rokwire/logging-library-go v1.0.3/go.mod h1:yntksZF2TDmxid9MwDnAAt95TeLMYo6chL0VUyIaFHk= github.com/rokwire/logging-library-go/v2 v2.0.0 h1:Uo088Hs3G2LjLveyUCOK3ii0AWYYobb+oDs/dH9uCSY= github.com/rokwire/logging-library-go/v2 v2.0.0/go.mod h1:6QSqTlk5nNQcZweqg0sLCCoIwpRpTu3AmOi7EJy38Tg= +github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= @@ -197,6 +202,7 @@ golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=