From 1592a6063d2f64d78f663a05c673acbf6172bed7 Mon Sep 17 00:00:00 2001 From: Stefan Vitanov Date: Mon, 21 Nov 2022 14:10:11 +0200 Subject: [PATCH 01/24] Set the Changelog.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index dce5b5c..4441e0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ 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) + ### Added - Set logger [#80](https://github.com/rokwire/notifications-building-block/issues/80) From e51f073ef9a7248f140b3fc9c0a77c426a46b825 Mon Sep 17 00:00:00 2001 From: Stefan Vitanov Date: Mon, 21 Nov 2022 14:19:22 +0200 Subject: [PATCH 02/24] fixing the docs - in progress --- driver/web/docs/gen/def.yaml | 6 +++--- driver/web/docs/resources/admin/message/message.yaml | 2 +- driver/web/docs/resources/client/message/message-read.yaml | 2 +- driver/web/docs/resources/client/message/messages-id.yaml | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/driver/web/docs/gen/def.yaml b/driver/web/docs/gen/def.yaml index c8cc952..66156dd 100644 --- a/driver/web/docs/gen/def.yaml +++ b/driver/web/docs/gen/def.yaml @@ -396,7 +396,7 @@ paths: parameters: - name: id in: path - description: offset + description: id required: true style: simple explode: false @@ -455,7 +455,7 @@ paths: parameters: - name: id in: path - description: offset + description: id required: true style: simple explode: false @@ -828,7 +828,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/Message' + $ref: '#/components/schemas/_client_req_messageV2' required: true responses: '200': diff --git a/driver/web/docs/resources/admin/message/message.yaml b/driver/web/docs/resources/admin/message/message.yaml index 1d0d1f5..d4cef89 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/Message.yaml" + $ref: "../../../schemas/apis/messageV2/request/Request.yaml" required: true responses: 200: diff --git a/driver/web/docs/resources/client/message/message-read.yaml b/driver/web/docs/resources/client/message/message-read.yaml index e62ab17..925a47b 100644 --- a/driver/web/docs/resources/client/message/message-read.yaml +++ b/driver/web/docs/resources/client/message/message-read.yaml @@ -9,7 +9,7 @@ put: 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-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 From c022ef6d7dd4fca94954d8209ba0cb5b55a4e65d Mon Sep 17 00:00:00 2001 From: Stefan Vitanov Date: Mon, 21 Nov 2022 14:41:25 +0200 Subject: [PATCH 03/24] docs in progress --- driver/web/docs/gen/def.yaml | 1 + driver/web/docs/resources/internal/v2/message.yaml | 1 + 2 files changed, 2 insertions(+) diff --git a/driver/web/docs/gen/def.yaml b/driver/web/docs/gen/def.yaml index 66156dd..5e9e803 100644 --- a/driver/web/docs/gen/def.yaml +++ b/driver/web/docs/gen/def.yaml @@ -56,6 +56,7 @@ paths: post: tags: - Internal + deprecated: true summary: Create message description: | Create message diff --git a/driver/web/docs/resources/internal/v2/message.yaml b/driver/web/docs/resources/internal/v2/message.yaml index 2fdc4fc..609009d 100644 --- a/driver/web/docs/resources/internal/v2/message.yaml +++ b/driver/web/docs/resources/internal/v2/message.yaml @@ -1,6 +1,7 @@ post: tags: - Internal + deprecated: true summary: Create message description: | Create message From d4a97b604716ef070017503a3a15c27d84346538 Mon Sep 17 00:00:00 2001 From: Petyo Stoyanov Date: Fri, 9 Dec 2022 09:13:09 +0200 Subject: [PATCH 04/24] Update CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ec33089..b9b90d5 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] +### Added +- Rate limits [#98](https://github.com/rokwire/notifications-building-block/issues/98) ## [1.6.0] - 2022-12-06 ### Added From e893cec5cd6699a758bf23618059270d4733efe6 Mon Sep 17 00:00:00 2001 From: Stefan Vitanov Date: Fri, 9 Dec 2022 09:39:44 +0200 Subject: [PATCH 05/24] in progress --- driver/web/docs/gen/def.yaml | 5 ----- driver/web/docs/resources/client/message/messages.yaml | 5 ----- 2 files changed, 10 deletions(-) diff --git a/driver/web/docs/gen/def.yaml b/driver/web/docs/gen/def.yaml index 48c8bc8..35fbeac 100644 --- a/driver/web/docs/gen/def.yaml +++ b/driver/web/docs/gen/def.yaml @@ -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: diff --git a/driver/web/docs/resources/client/message/messages.yaml b/driver/web/docs/resources/client/message/messages.yaml index 1026dd3..0b599e1 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: From ef07efe564f0f8a489261185f48d625750a3d31a Mon Sep 17 00:00:00 2001 From: Petyo Stoyanov Date: Fri, 9 Dec 2022 09:54:53 +0200 Subject: [PATCH 06/24] Fix docs in order to generate types --- driver/web/docs/gen/def.yaml | 2 +- driver/web/docs/gen/gen_types.go | 302 +++++++++++++++++++++++++++++++ driver/web/docs/index.yaml | 2 +- 3 files changed, 304 insertions(+), 2 deletions(-) create mode 100644 driver/web/docs/gen/gen_types.go diff --git a/driver/web/docs/gen/def.yaml b/driver/web/docs/gen/def.yaml index bb2a682..f5846cf 100644 --- a/driver/web/docs/gen/def.yaml +++ b/driver/web/docs/gen/def.yaml @@ -462,7 +462,7 @@ paths: description: Unauthorized '500': description: Internal error - '/api/message/{message_id}/read': + '/api/message/{id}/read': put: tags: - Client diff --git a/driver/web/docs/gen/gen_types.go b/driver/web/docs/gen/gen_types.go new file mode 100644 index 0000000..bef479c --- /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"` +} + +// InputMessage defines model for InputMessage. +type InputMessage struct { + AppId *string `json:"app_id,omitempty"` + Body *string `json:"body,omitempty"` + Data *[]string `json:"data,omitempty"` + OrgId *string `json:"org_id,omitempty"` + Priority *string `json:"priority,omitempty"` + RecipientAccountCriteria *map[string]interface{} `json:"recipient_account_criteria,omitempty"` + Recipients *InputMessageRecipient `json:"recipients,omitempty"` + RecipientsCriteriaList *InputRecipientCriteria `json:"recipients_criteria_list,omitempty"` + Subject *string `json:"subject,omitempty"` + Topic *string `json:"topic,omitempty"` +} + +// InputMessageRecipient defines model for InputMessageRecipient. +type InputMessageRecipient struct { + Mute *bool `json:"mute,omitempty"` + UserId *string `json:"user_id,omitempty"` +} + +// InputRecipientCriteria defines model for InputRecipientCriteria. +type InputRecipientCriteria struct { + AppPlatform *string `json:"app_platform,omitempty"` + AppVersion *string `json:"app_version,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 *InputMessage `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"` +} + +// PostApiAdminMessageJSONBody defines parameters for PostApiAdminMessage. +type PostApiAdminMessageJSONBody = InputMessage + +// PutApiAdminMessageJSONBody defines parameters for PutApiAdminMessage. +type PutApiAdminMessageJSONBody = InputMessage + +// 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 = InputMessage + +// PostApiIntV2MessageJSONBody defines parameters for PostApiIntV2Message. +type PostApiIntV2MessageJSONBody = ClientReqMessageV2 + +// PostApiMessageJSONBody defines parameters for PostApiMessage. +type PostApiMessageJSONBody = InputMessage + +// 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" From 6e8d9a81689d4a11d2b8ccde76822afaa5713eab Mon Sep 17 00:00:00 2001 From: Petyo Stoyanov Date: Fri, 9 Dec 2022 10:21:21 +0200 Subject: [PATCH 07/24] Docs clean up - in progress --- .../docs/resources/admin/message/message.yaml | 4 ++-- .../docs/resources/client/message/message.yaml | 2 +- driver/web/docs/resources/internal/message.yaml | 2 +- .../schemas/apis/messageV2/request/Request.yaml | 2 +- .../create-message}/InputMessageRecipient.yaml | 0 .../create-message}/InputRecipientCriteria.yaml | 0 .../requests/create-message/Request.yaml} | 0 driver/web/docs/schemas/index.yaml | 17 +++++++++++------ 8 files changed, 16 insertions(+), 11 deletions(-) rename driver/web/docs/schemas/{application => apis/shared/requests/create-message}/InputMessageRecipient.yaml (100%) rename driver/web/docs/schemas/{application => apis/shared/requests/create-message}/InputRecipientCriteria.yaml (100%) rename driver/web/docs/schemas/{application/InputMessage.yaml => apis/shared/requests/create-message/Request.yaml} (100%) diff --git a/driver/web/docs/resources/admin/message/message.yaml b/driver/web/docs/resources/admin/message/message.yaml index b35cc0b..e38668a 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/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/internal/message.yaml b/driver/web/docs/resources/internal/message.yaml index c91cd8a..f436232 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/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 100% rename from driver/web/docs/schemas/application/InputMessageRecipient.yaml rename to driver/web/docs/schemas/apis/shared/requests/create-message/InputMessageRecipient.yaml 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 100% rename from driver/web/docs/schemas/application/InputMessage.yaml rename to driver/web/docs/schemas/apis/shared/requests/create-message/Request.yaml diff --git a/driver/web/docs/schemas/index.yaml b/driver/web/docs/schemas/index.yaml index cea1245..ea0f0d1 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,14 @@ _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" + +### responses \ No newline at end of file From 226e5ad0531a4db64c56445575620c54715f2017 Mon Sep 17 00:00:00 2001 From: Petyo Stoyanov Date: Fri, 9 Dec 2022 10:32:49 +0200 Subject: [PATCH 08/24] Fix paths --- driver/web/docs/gen/def.yaml | 86 +++++++++---------- .../docs/resources/admin/message/message.yaml | 2 +- .../web/docs/resources/internal/message.yaml | 2 +- 3 files changed, 42 insertions(+), 48 deletions(-) diff --git a/driver/web/docs/gen/def.yaml b/driver/web/docs/gen/def.yaml index f5846cf..ddfe3dd 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': @@ -234,7 +234,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/InputMessage' + $ref: '#/components/schemas/_shared_req_CreateMessage' required: true responses: '200': @@ -847,7 +847,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/InputMessage' + $ref: '#/components/schemas/_shared_req_CreateMessage' required: true responses: '200': @@ -877,7 +877,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/InputMessage' + $ref: '#/components/schemas/_shared_req_CreateMessage' required: true responses: '200': @@ -1122,47 +1122,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 +1217,7 @@ components: async: type: boolean message: - $ref: '#/components/schemas/InputMessage' + $ref: '#/components/schemas/_shared_req_CreateMessage' _client_req_token: required: - token @@ -1279,3 +1238,38 @@ components: properties: notifications_disabled: type: boolean + _shared_req_CreateMessage: + 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 + properties: + user_id: + type: string + mute: + type: boolean + recipients_criteria_list: + type: array + properties: + app_version: + type: string + app_platform: + type: string + recipient_account_criteria: + type: object diff --git a/driver/web/docs/resources/admin/message/message.yaml b/driver/web/docs/resources/admin/message/message.yaml index e38668a..252f4a9 100644 --- a/driver/web/docs/resources/admin/message/message.yaml +++ b/driver/web/docs/resources/admin/message/message.yaml @@ -41,7 +41,7 @@ put: content: application/json: schema: - $ref: "../../../schemas/apis/shared/requests/create-message/Request.yaml" + $ref: "../../../schemas/apis/shared/requests/create-message/Request.yaml" required: true responses: 200: diff --git a/driver/web/docs/resources/internal/message.yaml b/driver/web/docs/resources/internal/message.yaml index f436232..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/apis/shared/requests/create-message/Request.yaml" + $ref: "../../schemas/apis/shared/requests/create-message/Request.yaml" required: true responses: 200: From 4d8046390cb414c112eb6d647b6306e3bb1de725 Mon Sep 17 00:00:00 2001 From: Stefan Vitanov Date: Fri, 9 Dec 2022 10:50:47 +0200 Subject: [PATCH 09/24] fix the serveDocUI --- driver/web/adapter.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/driver/web/adapter.go b/driver/web/adapter.go index 4ab73e8..2313c98 100644 --- a/driver/web/adapter.go +++ b/driver/web/adapter.go @@ -39,8 +39,9 @@ import ( // Adapter entity type Adapter struct { - host string - port string + host string + port string + notificationsServiceURL string auth *Auth @@ -132,7 +133,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)) } From 3254a18c16585bf87322d1376cfa05071cda6a6e Mon Sep 17 00:00:00 2001 From: Petyo Stoyanov Date: Fri, 9 Dec 2022 11:14:16 +0200 Subject: [PATCH 10/24] Extract InputMessage from the core component - in progress --- core/interfaces.go | 13 ++++++-- core/services.go | 81 ++++++++++++++++++++++------------------------ 2 files changed, 49 insertions(+), 45 deletions(-) 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/services.go b/core/services.go index 3197e92..73e6976 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, recipients, 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 + + recipients[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,18 @@ 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 { + if (recipientsCriteriaList != nil) && checkCriteria { + criteriaList := make([]model.RecipientCriteria, len(recipientsCriteriaList)) + for i, item := range recipientsCriteriaList { criteriaList[i] = model.RecipientCriteria{AppVersion: item.AppVersion, AppPlatform: item.AppPlatform} } criteriaUsers, err := app.storage.GetUsersByRecipientCriteriasWithContext(context, - inputMessage.OrgID, inputMessage.AppID, criteriaList) + orgID, appID, criteriaList) if err != nil { fmt.Printf("error retrieving recipients by criteria: %s", err) return nil, err @@ -253,7 +250,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 +265,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, } From 4a90de27175695c0f576e13e85fc99ba8e5f9768 Mon Sep 17 00:00:00 2001 From: Stefan Vitanov Date: Fri, 9 Dec 2022 11:20:52 +0200 Subject: [PATCH 11/24] fix the deleteMessage docs --- driver/web/docs/gen/def.yaml | 6 ------ driver/web/docs/resources/client/message/messages.yaml | 6 ------ 2 files changed, 12 deletions(-) diff --git a/driver/web/docs/gen/def.yaml b/driver/web/docs/gen/def.yaml index 35fbeac..75d4dd9 100644 --- a/driver/web/docs/gen/def.yaml +++ b/driver/web/docs/gen/def.yaml @@ -320,12 +320,6 @@ paths: responses: '200': description: Success - content: - application/json: - schema: - type: array - items: - $ref: '#/components/schemas/Message' '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 0b599e1..703a70f 100644 --- a/driver/web/docs/resources/client/message/messages.yaml +++ b/driver/web/docs/resources/client/message/messages.yaml @@ -66,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: From ff4bef39197b45ebae6b0eeaf92ee2b38167873a Mon Sep 17 00:00:00 2001 From: Petyo Stoyanov Date: Fri, 9 Dec 2022 11:55:56 +0200 Subject: [PATCH 12/24] Extract InputMessage from the core component and clean up --- core/services.go | 7 +--- .../web/rest/{adminapis.go => apis_admin.go} | 17 ++++++-- driver/web/rest/{bbs.go => apis_bbs.go} | 16 ++++++- driver/web/rest/{apis.go => apis_client.go} | 17 ++++++-- .../rest/{internal.go => apis_internal.go} | 42 ++++++++++++++++--- driver/web/rest/convertions_message.go | 21 ++++++++++ 6 files changed, 102 insertions(+), 18 deletions(-) rename driver/web/rest/{adminapis.go => apis_admin.go} (94%) rename driver/web/rest/{bbs.go => apis_bbs.go} (86%) rename driver/web/rest/{apis.go => apis_client.go} (97%) rename driver/web/rest/{internal.go => apis_internal.go} (72%) create mode 100644 driver/web/rest/convertions_message.go diff --git a/core/services.go b/core/services.go index 73e6976..de76fd2 100644 --- a/core/services.go +++ b/core/services.go @@ -235,13 +235,8 @@ func (app *Application) calculateRecipients(context storage.TransactionContext, // recipients from criteria if (recipientsCriteriaList != nil) && checkCriteria { - criteriaList := make([]model.RecipientCriteria, len(recipientsCriteriaList)) - for i, item := range recipientsCriteriaList { - criteriaList[i] = model.RecipientCriteria{AppVersion: item.AppVersion, AppPlatform: item.AppPlatform} - } - criteriaUsers, err := app.storage.GetUsersByRecipientCriteriasWithContext(context, - orgID, appID, criteriaList) + orgID, appID, recipientsCriteriaList) if err != nil { fmt.Printf("error retrieving recipients by criteria: %s", err) return nil, err diff --git a/driver/web/rest/adminapis.go b/driver/web/rest/apis_admin.go similarity index 94% rename from driver/web/rest/adminapis.go rename to driver/web/rest/apis_admin.go index 1ce2aaf..2aa51fe 100644 --- a/driver/web/rest/adminapis.go +++ b/driver/web/rest/apis_admin.go @@ -148,12 +148,23 @@ func (h AdminApisHandler) CreateMessage(l *logs.Log, r *http.Request, claims *to 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 := inputMessage.Data + 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/rest/apis_bbs.go similarity index 86% rename from driver/web/rest/bbs.go rename to driver/web/rest/apis_bbs.go index 035e86a..987b188 100644 --- a/driver/web/rest/bbs.go +++ b/driver/web/rest/apis_bbs.go @@ -71,9 +71,23 @@ func (h BBsAPIsHandler) SendMessage(l *logs.Log, r *http.Request, claims *tokena 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 := inputMessage.Data + 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/rest/apis_client.go similarity index 97% rename from driver/web/rest/apis.go rename to driver/web/rest/apis_client.go index 5411b95..f72af83 100644 --- a/driver/web/rest/apis.go +++ b/driver/web/rest/apis_client.go @@ -459,12 +459,23 @@ func (h ApisHandler) CreateMessage(l *logs.Log, r *http.Request, claims *tokenau 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 := inputMessage.Data + 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/rest/apis_internal.go similarity index 72% rename from driver/web/rest/internal.go rename to driver/web/rest/apis_internal.go index 7f86881..3de9dfa 100644 --- a/driver/web/rest/internal.go +++ b/driver/web/rest/apis_internal.go @@ -52,7 +52,19 @@ func (h InternalApisHandler) SendMessage(l *logs.Log, r *http.Request, claims *t 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 := message.Data + 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 @@ -82,17 +94,37 @@ 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 := message.Data + 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/convertions_message.go b/driver/web/rest/convertions_message.go new file mode 100644 index 0000000..c9fc27b --- /dev/null +++ b/driver/web/rest/convertions_message.go @@ -0,0 +1,21 @@ +package rest + +import "notifications/core/model" + +// RecipientCriteria Type +func recipientsCriteriaListFromDef(items []model.InputRecipientCriteria) []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 []model.InputMessageRecipient) []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 +} From 10dea6338159a3e0a55c9ef083c2567a132052ee Mon Sep 17 00:00:00 2001 From: Stefan Vitanov Date: Fri, 9 Dec 2022 12:46:33 +0200 Subject: [PATCH 13/24] fix docs --- driver/web/docs/gen/def.yaml | 19 ++++++++++--------- .../client/message/message-read.yaml | 16 +++++++--------- .../apis/message-read/request/Request.yaml | 4 ++++ 3 files changed, 21 insertions(+), 18 deletions(-) create mode 100644 driver/web/docs/schemas/apis/message-read/request/Request.yaml diff --git a/driver/web/docs/gen/def.yaml b/driver/web/docs/gen/def.yaml index 75d4dd9..f94a264 100644 --- a/driver/web/docs/gen/def.yaml +++ b/driver/web/docs/gen/def.yaml @@ -460,15 +460,16 @@ paths: Update message security: - bearerAuth: [] - parameters: - - name: id - in: path - description: id - 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 diff --git a/driver/web/docs/resources/client/message/message-read.yaml b/driver/web/docs/resources/client/message/message-read.yaml index 925a47b..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: id - 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/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 From 26239eff860316845c45e0ba0e325428c9d37b26 Mon Sep 17 00:00:00 2001 From: Stefan Vitanov Date: Fri, 9 Dec 2022 13:34:08 +0200 Subject: [PATCH 14/24] fix the docs --- driver/web/docs/gen/def.yaml | 17 ++++++++++++++++- .../resources/admin/message/messages-id.yaml | 2 +- .../resources/client/message/messages-read.yaml | 17 ++++++++++++++++- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/driver/web/docs/gen/def.yaml b/driver/web/docs/gen/def.yaml index f94a264..01de6b4 100644 --- a/driver/web/docs/gen/def.yaml +++ b/driver/web/docs/gen/def.yaml @@ -365,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': @@ -928,7 +943,7 @@ paths: 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-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/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: From e89fdf6c276a3a4032f583f567ac9b38da5335ba Mon Sep 17 00:00:00 2001 From: Stefan Vitanov Date: Fri, 9 Dec 2022 13:47:58 +0200 Subject: [PATCH 15/24] in progress --- driver/web/docs/gen/def.yaml | 5 ----- driver/web/docs/resources/client/topic/topics-messages.yaml | 5 ----- 2 files changed, 10 deletions(-) diff --git a/driver/web/docs/gen/def.yaml b/driver/web/docs/gen/def.yaml index 01de6b4..4c5d7f2 100644 --- a/driver/web/docs/gen/def.yaml +++ b/driver/web/docs/gen/def.yaml @@ -545,7 +545,6 @@ paths: - name: offset in: query description: offset - required: true style: simple explode: false schema: @@ -553,7 +552,6 @@ paths: - name: limit in: query description: limit - limit the result - required: true style: simple explode: false schema: @@ -561,7 +559,6 @@ paths: - name: order in: query description: 'order - Possible values: asc, desc. Default: desc' - required: true style: simple explode: false schema: @@ -569,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: @@ -577,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: 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: From 8751cac9db4c855369b5c8d17e5a8a03c1676fd8 Mon Sep 17 00:00:00 2001 From: Stefan Vitanov Date: Fri, 9 Dec 2022 13:59:12 +0200 Subject: [PATCH 16/24] in progress --- driver/web/docs/gen/def.yaml | 6 ------ driver/web/docs/schemas/apis/token/request/Request.yaml | 6 ------ 2 files changed, 12 deletions(-) diff --git a/driver/web/docs/gen/def.yaml b/driver/web/docs/gen/def.yaml index 4c5d7f2..f6a0131 100644 --- a/driver/web/docs/gen/def.yaml +++ b/driver/web/docs/gen/def.yaml @@ -1266,12 +1266,6 @@ components: properties: token: type: string - previous_token: - type: string - app_version: - type: string - app_platform: - type: string _client_req_user: required: - notifications_disabled 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 From dc297f10c2f76d3637347b58f0327d56335530c1 Mon Sep 17 00:00:00 2001 From: Stefan Vitanov Date: Sun, 11 Dec 2022 15:16:08 +0200 Subject: [PATCH 17/24] in progress --- driver/web/docs/gen/def.yaml | 43 +++++++++++++++-- .../resources/admin/message/messages.yaml | 47 ++++++++++++++++--- 2 files changed, 79 insertions(+), 11 deletions(-) diff --git a/driver/web/docs/gen/def.yaml b/driver/web/docs/gen/def.yaml index f6a0131..7fd08d9 100644 --- a/driver/web/docs/gen/def.yaml +++ b/driver/web/docs/gen/def.yaml @@ -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 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 From 80ff84683e31204f3245934d7bea3063ccbf94bc Mon Sep 17 00:00:00 2001 From: Stefan Vitanov Date: Sun, 11 Dec 2022 15:29:36 +0200 Subject: [PATCH 18/24] go.mod --- go.mod | 1 + go.sum | 6 ++++++ 2 files changed, 7 insertions(+) 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= From 3ea857fc44cce159ef4fef5c109145fb9ae79b7e Mon Sep 17 00:00:00 2001 From: Petyo Stoyanov Date: Mon, 12 Dec 2022 09:42:37 +0200 Subject: [PATCH 19/24] Fix error --- core/services.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/services.go b/core/services.go index de76fd2..cf03660 100644 --- a/core/services.go +++ b/core/services.go @@ -234,7 +234,7 @@ func (app *Application) calculateRecipients(context storage.TransactionContext, } // recipients from criteria - if (recipientsCriteriaList != nil) && checkCriteria { + if (recipientsCriteriaList != nil && len(recipientAccountCriteria) > 0) && checkCriteria { criteriaUsers, err := app.storage.GetUsersByRecipientCriteriasWithContext(context, orgID, appID, recipientsCriteriaList) if err != nil { From 0a45be0a659d95ea35e2147cfcd11ccfb2f30f32 Mon Sep 17 00:00:00 2001 From: Petyo Stoyanov Date: Mon, 12 Dec 2022 09:48:56 +0200 Subject: [PATCH 20/24] Fix wrong parameter --- core/services.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/services.go b/core/services.go index cf03660..9aeb08c 100644 --- a/core/services.go +++ b/core/services.go @@ -90,7 +90,7 @@ func (app *Application) createMessage(orgID string, appID string, //calculate the recipients recipients, err = app.calculateRecipients(context, orgID, appID, - subject, body, recipients, recipientsCriteriaList, + subject, body, inputRecipients, recipientsCriteriaList, recipientAccountCriteria, topic, messageID) if err != nil { fmt.Printf("error on calculating recipients for a message: %s", err) From c417fc3defd96816e8d1c6402b6666f19d637e12 Mon Sep 17 00:00:00 2001 From: Petyo Stoyanov Date: Mon, 12 Dec 2022 09:54:13 +0200 Subject: [PATCH 21/24] Fix calculate recipients --- core/services.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/services.go b/core/services.go index 9aeb08c..e48963f 100644 --- a/core/services.go +++ b/core/services.go @@ -194,7 +194,7 @@ func (app *Application) calculateRecipients(context storage.TransactionContext, item.MessageID = messageID item.Read = false - recipients[i] = item + list[i] = item } messageRecipients = append(messageRecipients, list...) From f9dbde4c76fed56a6c0fe05441e0862ae4d8d9b1 Mon Sep 17 00:00:00 2001 From: Petyo Stoyanov Date: Mon, 12 Dec 2022 10:18:28 +0200 Subject: [PATCH 22/24] Update docs --- driver/web/docs/gen/def.yaml | 26 +++++++----- driver/web/docs/gen/gen_types.go | 64 +++++++++++++++--------------- driver/web/docs/schemas/index.yaml | 4 ++ 3 files changed, 52 insertions(+), 42 deletions(-) diff --git a/driver/web/docs/gen/def.yaml b/driver/web/docs/gen/def.yaml index ddfe3dd..20cfbc3 100644 --- a/driver/web/docs/gen/def.yaml +++ b/driver/web/docs/gen/def.yaml @@ -1259,17 +1259,23 @@ components: type: string recipients: type: array - properties: - user_id: - type: string - mute: - type: boolean + $ref: '#/components/schemas/_shared_req_CreateMessage_InputMessageRecipient' recipients_criteria_list: type: array - properties: - app_version: - type: string - app_platform: - type: string + $ref: '#/components/schemas/_shared_req_CreateMessage_InputRecipientCriteria' recipient_account_criteria: type: object + _shared_req_CreateMessage_InputMessageRecipient: + 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 index bef479c..2d8e663 100644 --- a/driver/web/docs/gen/gen_types.go +++ b/driver/web/docs/gen/gen_types.go @@ -22,32 +22,6 @@ type FirebaseToken struct { Token *string `json:"token,omitempty"` } -// InputMessage defines model for InputMessage. -type InputMessage struct { - AppId *string `json:"app_id,omitempty"` - Body *string `json:"body,omitempty"` - Data *[]string `json:"data,omitempty"` - OrgId *string `json:"org_id,omitempty"` - Priority *string `json:"priority,omitempty"` - RecipientAccountCriteria *map[string]interface{} `json:"recipient_account_criteria,omitempty"` - Recipients *InputMessageRecipient `json:"recipients,omitempty"` - RecipientsCriteriaList *InputRecipientCriteria `json:"recipients_criteria_list,omitempty"` - Subject *string `json:"subject,omitempty"` - Topic *string `json:"topic,omitempty"` -} - -// InputMessageRecipient defines model for InputMessageRecipient. -type InputMessageRecipient struct { - Mute *bool `json:"mute,omitempty"` - UserId *string `json:"user_id,omitempty"` -} - -// InputRecipientCriteria defines model for InputRecipientCriteria. -type InputRecipientCriteria struct { - AppPlatform *string `json:"app_platform,omitempty"` - AppVersion *string `json:"app_version,omitempty"` -} - // Message defines model for Message. type Message struct { Id *string `json:"_id,omitempty"` @@ -122,8 +96,8 @@ type ClientReqMessage struct { // ClientReqMessageV2 defines model for _client_req_messageV2. type ClientReqMessageV2 struct { - Async *bool `json:"async,omitempty"` - Message *InputMessage `json:"message,omitempty"` + Async *bool `json:"async,omitempty"` + Message *SharedReqCreateMessage `json:"message,omitempty"` } // ClientReqToken defines model for _client_req_token. @@ -139,11 +113,37 @@ type ClientReqUser struct { NotificationsDisabled bool `json:"notifications_disabled"` } +// SharedReqCreateMessage defines model for _shared_req_CreateMessage. +type SharedReqCreateMessage struct { + AppId *string `json:"app_id,omitempty"` + Body *string `json:"body,omitempty"` + Data *[]string `json:"data,omitempty"` + OrgId *string `json:"org_id,omitempty"` + Priority *string `json:"priority,omitempty"` + RecipientAccountCriteria *map[string]interface{} `json:"recipient_account_criteria,omitempty"` + Recipients *SharedReqCreateMessageInputMessageRecipient `json:"recipients,omitempty"` + RecipientsCriteriaList *SharedReqCreateMessageInputRecipientCriteria `json:"recipients_criteria_list,omitempty"` + Subject *string `json:"subject,omitempty"` + Topic *string `json:"topic,omitempty"` +} + +// SharedReqCreateMessageInputMessageRecipient defines model for _shared_req_CreateMessage_InputMessageRecipient. +type SharedReqCreateMessageInputMessageRecipient struct { + Mute *bool `json:"mute,omitempty"` + UserId *string `json:"user_id,omitempty"` +} + +// 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 = InputMessage +type PostApiAdminMessageJSONBody = SharedReqCreateMessage // PutApiAdminMessageJSONBody defines parameters for PutApiAdminMessage. -type PutApiAdminMessageJSONBody = InputMessage +type PutApiAdminMessageJSONBody = SharedReqCreateMessage // GetApiAdminMessagesJSONBody defines parameters for GetApiAdminMessages. type GetApiAdminMessagesJSONBody = ClientReqMessage @@ -179,13 +179,13 @@ type PostApiBbsMessageJSONBody = ClientReqMessageV2 type PostApiIntMailJSONBody = ClientReqToken // PostApiIntMessageJSONBody defines parameters for PostApiIntMessage. -type PostApiIntMessageJSONBody = InputMessage +type PostApiIntMessageJSONBody = SharedReqCreateMessage // PostApiIntV2MessageJSONBody defines parameters for PostApiIntV2Message. type PostApiIntV2MessageJSONBody = ClientReqMessageV2 // PostApiMessageJSONBody defines parameters for PostApiMessage. -type PostApiMessageJSONBody = InputMessage +type PostApiMessageJSONBody = SharedReqCreateMessage // DeleteApiMessagesJSONBody defines parameters for DeleteApiMessages. type DeleteApiMessagesJSONBody = ClientReqMessage diff --git a/driver/web/docs/schemas/index.yaml b/driver/web/docs/schemas/index.yaml index ea0f0d1..eeb4f13 100644 --- a/driver/web/docs/schemas/index.yaml +++ b/driver/web/docs/schemas/index.yaml @@ -45,5 +45,9 @@ _client_req_user: ### 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 From e10e3bcefbba33bcd6c7fba75ce1336967c693bf Mon Sep 17 00:00:00 2001 From: Petyo Stoyanov Date: Mon, 12 Dec 2022 10:37:36 +0200 Subject: [PATCH 23/24] Update docs --- driver/web/docs/gen/def.yaml | 3 +++ driver/web/docs/gen/gen_types.go | 4 ++-- .../shared/requests/create-message/InputMessageRecipient.yaml | 3 +++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/driver/web/docs/gen/def.yaml b/driver/web/docs/gen/def.yaml index 20cfbc3..c345358 100644 --- a/driver/web/docs/gen/def.yaml +++ b/driver/web/docs/gen/def.yaml @@ -1266,6 +1266,9 @@ components: recipient_account_criteria: type: object _shared_req_CreateMessage_InputMessageRecipient: + required: + - user_id + - mute type: object properties: user_id: diff --git a/driver/web/docs/gen/gen_types.go b/driver/web/docs/gen/gen_types.go index 2d8e663..da08b86 100644 --- a/driver/web/docs/gen/gen_types.go +++ b/driver/web/docs/gen/gen_types.go @@ -129,8 +129,8 @@ type SharedReqCreateMessage struct { // SharedReqCreateMessageInputMessageRecipient defines model for _shared_req_CreateMessage_InputMessageRecipient. type SharedReqCreateMessageInputMessageRecipient struct { - Mute *bool `json:"mute,omitempty"` - UserId *string `json:"user_id,omitempty"` + Mute bool `json:"mute"` + UserId string `json:"user_id"` } // SharedReqCreateMessageInputRecipientCriteria defines model for _shared_req_CreateMessage_InputRecipientCriteria. diff --git a/driver/web/docs/schemas/apis/shared/requests/create-message/InputMessageRecipient.yaml b/driver/web/docs/schemas/apis/shared/requests/create-message/InputMessageRecipient.yaml index 3cd3e73..f6c2734 100644 --- a/driver/web/docs/schemas/apis/shared/requests/create-message/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: From 268dcc1f1bac1d68eb323ba221ab7f80c0a708eb Mon Sep 17 00:00:00 2001 From: Petyo Stoyanov Date: Mon, 12 Dec 2022 11:26:43 +0200 Subject: [PATCH 24/24] Use generated struct for create message apis + a bit refactroing --- core/model/message.go | 29 ------------------- driver/web/adapter.go | 17 +++++------ driver/web/{rest => }/apis_admin.go | 12 ++++++-- driver/web/{rest => }/apis_bbs.go | 17 +++++++---- driver/web/{rest => }/apis_client.go | 10 +++++-- driver/web/{rest => }/apis_internal.go | 28 +++++++++++------- driver/web/{rest => }/common.go | 2 +- driver/web/convertions_message.go | 24 +++++++++++++++ driver/web/docs/gen/def.yaml | 22 ++++++++++---- driver/web/docs/gen/gen_types.go | 20 ++++++------- .../requests/create-message/Request.yaml | 24 ++++++++++----- driver/web/rest/convertions_message.go | 21 -------------- 12 files changed, 121 insertions(+), 105 deletions(-) rename driver/web/{rest => }/apis_admin.go (97%) rename driver/web/{rest => }/apis_bbs.go (90%) rename driver/web/{rest => }/apis_client.go (98%) rename driver/web/{rest => }/apis_internal.go (91%) rename driver/web/{rest => }/common.go (99%) create mode 100644 driver/web/convertions_message.go delete mode 100644 driver/web/rest/convertions_message.go 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/driver/web/adapter.go b/driver/web/adapter.go index 4ab73e8..b67b3e5 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" @@ -46,10 +45,10 @@ type Adapter struct { 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 @@ -206,10 +205,10 @@ 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} diff --git a/driver/web/rest/apis_admin.go b/driver/web/apis_admin.go similarity index 97% rename from driver/web/rest/apis_admin.go rename to driver/web/apis_admin.go index 2aa51fe..3aef33a 100644 --- a/driver/web/rest/apis_admin.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,7 +145,7 @@ 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) @@ -154,7 +157,10 @@ func (h AdminApisHandler) CreateMessage(l *logs.Log, r *http.Request, claims *to priority := inputMessage.Priority subject := inputMessage.Subject body := inputMessage.Body - inputData := inputMessage.Data + 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 diff --git a/driver/web/rest/apis_bbs.go b/driver/web/apis_bbs.go similarity index 90% rename from driver/web/rest/apis_bbs.go rename to driver/web/apis_bbs.go index 987b188..650d930 100644 --- a/driver/web/rest/apis_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,11 +65,11 @@ 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) } @@ -77,7 +79,10 @@ func (h BBsAPIsHandler) SendMessage(l *logs.Log, r *http.Request, claims *tokena priority := inputMessage.Priority subject := inputMessage.Subject body := inputMessage.Body - inputData := inputMessage.Data + 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 diff --git a/driver/web/rest/apis_client.go b/driver/web/apis_client.go similarity index 98% rename from driver/web/rest/apis_client.go rename to driver/web/apis_client.go index f72af83..052a2c8 100644 --- a/driver/web/rest/apis_client.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,7 +454,7 @@ 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) @@ -465,7 +466,10 @@ func (h ApisHandler) CreateMessage(l *logs.Log, r *http.Request, claims *tokenau priority := inputMessage.Priority subject := inputMessage.Subject body := inputMessage.Body - inputData := inputMessage.Data + 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 diff --git a/driver/web/rest/apis_internal.go b/driver/web/apis_internal.go similarity index 91% rename from driver/web/rest/apis_internal.go rename to driver/web/apis_internal.go index 3de9dfa..9262209 100644 --- a/driver/web/rest/apis_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,18 +48,21 @@ 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) } - orgID := message.OrgID - appID := message.AppID + orgID := message.OrgId + appID := message.AppId priority := message.Priority subject := message.Subject body := message.Body - inputData := message.Data + 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 @@ -69,8 +74,8 @@ func (h InternalApisHandler) SendMessage(l *logs.Log, r *http.Request, claims *t // 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 @@ -95,12 +100,15 @@ func (h InternalApisHandler) SendMessageV2(l *logs.Log, r *http.Request, claims async = *bodyData.Async } - orgID := message.OrgID - appID := message.AppID + orgID := message.OrgId + appID := message.AppId priority := message.Priority subject := message.Subject body := message.Body - inputData := message.Data + 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 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 c345358..bd669eb 100644 --- a/driver/web/docs/gen/def.yaml +++ b/driver/web/docs/gen/def.yaml @@ -1239,6 +1239,16 @@ components: 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: @@ -1246,7 +1256,7 @@ components: app_id: type: string priority: - type: string + type: integer topic: type: string subject: @@ -1254,15 +1264,15 @@ components: body: type: string data: - type: array - items: - type: string + type: object recipients: type: array - $ref: '#/components/schemas/_shared_req_CreateMessage_InputMessageRecipient' + items: + $ref: '#/components/schemas/_shared_req_CreateMessage_InputMessageRecipient' recipients_criteria_list: type: array - $ref: '#/components/schemas/_shared_req_CreateMessage_InputRecipientCriteria' + items: + $ref: '#/components/schemas/_shared_req_CreateMessage_InputRecipientCriteria' recipient_account_criteria: type: object _shared_req_CreateMessage_InputMessageRecipient: diff --git a/driver/web/docs/gen/gen_types.go b/driver/web/docs/gen/gen_types.go index da08b86..2506b65 100644 --- a/driver/web/docs/gen/gen_types.go +++ b/driver/web/docs/gen/gen_types.go @@ -115,16 +115,16 @@ type ClientReqUser struct { // SharedReqCreateMessage defines model for _shared_req_CreateMessage. type SharedReqCreateMessage struct { - AppId *string `json:"app_id,omitempty"` - Body *string `json:"body,omitempty"` - Data *[]string `json:"data,omitempty"` - OrgId *string `json:"org_id,omitempty"` - Priority *string `json:"priority,omitempty"` - RecipientAccountCriteria *map[string]interface{} `json:"recipient_account_criteria,omitempty"` - Recipients *SharedReqCreateMessageInputMessageRecipient `json:"recipients,omitempty"` - RecipientsCriteriaList *SharedReqCreateMessageInputRecipientCriteria `json:"recipients_criteria_list,omitempty"` - Subject *string `json:"subject,omitempty"` - Topic *string `json:"topic,omitempty"` + 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. diff --git a/driver/web/docs/schemas/apis/shared/requests/create-message/Request.yaml b/driver/web/docs/schemas/apis/shared/requests/create-message/Request.yaml index f127fbf..037d31d 100644 --- a/driver/web/docs/schemas/apis/shared/requests/create-message/Request.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/rest/convertions_message.go b/driver/web/rest/convertions_message.go deleted file mode 100644 index c9fc27b..0000000 --- a/driver/web/rest/convertions_message.go +++ /dev/null @@ -1,21 +0,0 @@ -package rest - -import "notifications/core/model" - -// RecipientCriteria Type -func recipientsCriteriaListFromDef(items []model.InputRecipientCriteria) []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 []model.InputMessageRecipient) []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 -}