From e3e498ed23713b3cf4f016c5f6965f124925e7d5 Mon Sep 17 00:00:00 2001 From: tuannt20 <105765641+tuannt20@users.noreply.github.com> Date: Thu, 24 Nov 2022 09:06:48 +0700 Subject: [PATCH 1/7] add nasts campaign transaction --- client/campaign.go | 31 ++++++++++++++++++++++++++++++ model/campaign_request.go | 14 ++++++++++++++ model/campaign_response.go | 39 ++++++++++++++++++++++++++++++++++++++ subject/campaign.go | 15 +++++++++++++++ subject/config.go | 2 ++ 5 files changed, 101 insertions(+) create mode 100644 client/campaign.go create mode 100644 model/campaign_request.go create mode 100644 model/campaign_response.go create mode 100644 subject/campaign.go diff --git a/client/campaign.go b/client/campaign.go new file mode 100644 index 0000000..7a210e6 --- /dev/null +++ b/client/campaign.go @@ -0,0 +1,31 @@ +package client + +import ( + "encoding/json" + "errors" + "git.selly.red/Selly-Modules/natsio" + "git.selly.red/Selly-Modules/natsio/model" + "git.selly.red/Selly-Modules/natsio/subject" +) + +// Campaign ... +type Campaign struct{} + +// GetCampaignTransaction ... +func (c Campaign) GetCampaignTransaction(p model.GetCampaignTransactionsRequest) (*model.ResponseCampaignTransactionAll, error) { + msg, err := natsio.GetServer().Request(subject.Campaign.GetListCampaignTransactionAdminInfoByIDs, toBytes(p)) + if err != nil { + return nil, err + } + var r struct { + Data *model.ResponseCampaignTransactionAll `json:"data"` + Error string `json:"error"` + } + if err = json.Unmarshal(msg.Data, &r); err != nil { + return nil, err + } + if r.Error != "" { + return nil, errors.New(r.Error) + } + return r.Data, nil +} diff --git a/model/campaign_request.go b/model/campaign_request.go new file mode 100644 index 0000000..71227e4 --- /dev/null +++ b/model/campaign_request.go @@ -0,0 +1,14 @@ +package model + +import "time" + +// GetCampaignTransactionsRequest ... +type GetCampaignTransactionsRequest struct { + Campaign string `json:"campaign"` + Keyword string `json:"keyword"` + Status string `json:"status"` + FromAt time.Time `json:"fromAt"` + ToAt time.Time `json:"toAt"` + Page int64 `json:"page"` + Limit int64 `json:"limit"` +} diff --git a/model/campaign_response.go b/model/campaign_response.go new file mode 100644 index 0000000..7482099 --- /dev/null +++ b/model/campaign_response.go @@ -0,0 +1,39 @@ +package model + +// ResponseCampaignTransactionAll ... +type ResponseCampaignTransactionAll struct { + List []ResponseNatsCampaignTransaction `json:"list"` + Total int64 `json:"total"` + Limit int64 `json:"limit"` +} + +// ResponseNatsCampaignTransaction ... +type ResponseNatsCampaignTransaction struct { + ID string `json:"_id"` + Cash float64 `json:"cash"` + Campaign ResponseCampaignShortInfo `json:"campaign"` + Seller ResponseSellerInfo `json:"seller"` + Type string `json:"type"` + RejectedReason string `json:"rejectedReason"` + CreatedAt string `json:"createdAt"` + UpdatedAt string `json:"updatedAt"` + Item *ResponseCampaignItemShortInfo `json:"item"` + ApprovedBy *ResponseStaffInfo `json:"approvedBy,omitempty"` + RejectedBy *ResponseStaffInfo `json:"rejectedBy,omitempty"` + ApprovedAt string `json:"approvedAt,omitempty"` + RejectedAt string `json:"rejectedAt,omitempty"` +} + +// ResponseCampaignShortInfo ... +type ResponseCampaignShortInfo struct { + ID string `json:"_id"` + Name string `json:"name"` + Status string `json:"status"` +} + +// ResponseCampaignItemShortInfo ... +type ResponseCampaignItemShortInfo struct { + ID string `json:"_id"` + Name string `json:"name"` + Status string `json:"status"` +} diff --git a/subject/campaign.go b/subject/campaign.go new file mode 100644 index 0000000..8c7ddac --- /dev/null +++ b/subject/campaign.go @@ -0,0 +1,15 @@ +package subject + +import "fmt" + +// getCampaignValue ... +func getCampaignValue(val string) string { + return fmt.Sprintf("%s.%s", prefixes.Campaign, val) +} + +// Campaign ... +var Campaign = struct { + GetListCampaignTransactionAdminInfoByIDs string +}{ + GetListCampaignTransactionAdminInfoByIDs: getCampaignValue("get_list_campaign_transaction_admin_info_by_ids"), +} diff --git a/subject/config.go b/subject/config.go index 2a2f743..9d9b655 100644 --- a/subject/config.go +++ b/subject/config.go @@ -13,6 +13,7 @@ var prefixes = struct { SupplierRole string SocialPost string Staff string + Campaign string }{ Communication: "communication", Order: "order", @@ -26,4 +27,5 @@ var prefixes = struct { SupplierRole: "supplier_role", SocialPost: "social_post", Staff: "staff", + Campaign: "campaign", } -- 2.34.1 From 2f278526a91303bd07bbc30f54552136dd893e17 Mon Sep 17 00:00:00 2001 From: tuannt20 <105765641+tuannt20@users.noreply.github.com> Date: Thu, 24 Nov 2022 09:49:41 +0700 Subject: [PATCH 2/7] add GetCampaign --- client/campaign.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/client/campaign.go b/client/campaign.go index 7a210e6..82649d3 100644 --- a/client/campaign.go +++ b/client/campaign.go @@ -11,6 +11,11 @@ import ( // Campaign ... type Campaign struct{} +// GetCampaign ... +func GetCampaign() Campaign { + return Campaign{} +} + // GetCampaignTransaction ... func (c Campaign) GetCampaignTransaction(p model.GetCampaignTransactionsRequest) (*model.ResponseCampaignTransactionAll, error) { msg, err := natsio.GetServer().Request(subject.Campaign.GetListCampaignTransactionAdminInfoByIDs, toBytes(p)) -- 2.34.1 From af807784ec3d45a707b9d791a2f30f1297f172a9 Mon Sep 17 00:00:00 2001 From: tuannt20 <105765641+tuannt20@users.noreply.github.com> Date: Thu, 24 Nov 2022 11:14:15 +0700 Subject: [PATCH 3/7] fix response --- model/campaign_response.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/model/campaign_response.go b/model/campaign_response.go index 7482099..b563396 100644 --- a/model/campaign_response.go +++ b/model/campaign_response.go @@ -1,5 +1,7 @@ package model +import "go.mongodb.org/mongo-driver/bson/primitive" + // ResponseCampaignTransactionAll ... type ResponseCampaignTransactionAll struct { List []ResponseNatsCampaignTransaction `json:"list"` @@ -12,14 +14,14 @@ type ResponseNatsCampaignTransaction struct { ID string `json:"_id"` Cash float64 `json:"cash"` Campaign ResponseCampaignShortInfo `json:"campaign"` - Seller ResponseSellerInfo `json:"seller"` + Seller primitive.ObjectID `json:"seller"` Type string `json:"type"` RejectedReason string `json:"rejectedReason"` CreatedAt string `json:"createdAt"` UpdatedAt string `json:"updatedAt"` Item *ResponseCampaignItemShortInfo `json:"item"` - ApprovedBy *ResponseStaffInfo `json:"approvedBy,omitempty"` - RejectedBy *ResponseStaffInfo `json:"rejectedBy,omitempty"` + ApprovedBy primitive.ObjectID `json:"approvedBy,omitempty"` + RejectedBy primitive.ObjectID `json:"rejectedBy,omitempty"` ApprovedAt string `json:"approvedAt,omitempty"` RejectedAt string `json:"rejectedAt,omitempty"` } -- 2.34.1 From 8858688f0f5bed97ed78b7bc68be35bafed59ff4 Mon Sep 17 00:00:00 2001 From: Nguyen Minh Date: Thu, 24 Nov 2022 14:15:53 +0700 Subject: [PATCH 4/7] update options --- js/model/selly.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/js/model/selly.go b/js/model/selly.go index 856da44..68d3342 100644 --- a/js/model/selly.go +++ b/js/model/selly.go @@ -58,4 +58,8 @@ type CashFlowOptions struct { AffiliateTransactionCode string `json:"affiliateTransactionCode,omitempty"` AffiliateCampaignID string `json:"affiliateCampaignId,omitempty"` AffiliateCampaignName string `json:"affiliateCampaignName,omitempty"` + + // Campaign + CampaignID string `json:"campaignId,omitempty"` + CampaignName string `json:"campaignName,omitempty"` } -- 2.34.1 From 83e9aef3c92d30816a7228c13fe130a66e4ad626 Mon Sep 17 00:00:00 2001 From: tuannt20 <105765641+tuannt20@users.noreply.github.com> Date: Thu, 24 Nov 2022 15:44:25 +0700 Subject: [PATCH 5/7] add response --- model/campaign_response.go | 1 + 1 file changed, 1 insertion(+) diff --git a/model/campaign_response.go b/model/campaign_response.go index b563396..3a00735 100644 --- a/model/campaign_response.go +++ b/model/campaign_response.go @@ -16,6 +16,7 @@ type ResponseNatsCampaignTransaction struct { Campaign ResponseCampaignShortInfo `json:"campaign"` Seller primitive.ObjectID `json:"seller"` Type string `json:"type"` + Status string `json:"status"` RejectedReason string `json:"rejectedReason"` CreatedAt string `json:"createdAt"` UpdatedAt string `json:"updatedAt"` -- 2.34.1 From aff5a872e3f1ddb402c93ebf748594ca8b5e9fca Mon Sep 17 00:00:00 2001 From: tuannt20 <105765641+tuannt20@users.noreply.github.com> Date: Tue, 29 Nov 2022 13:54:39 +0700 Subject: [PATCH 6/7] add response --- model/campaign_response.go | 1 + 1 file changed, 1 insertion(+) diff --git a/model/campaign_response.go b/model/campaign_response.go index 3a00735..710ee47 100644 --- a/model/campaign_response.go +++ b/model/campaign_response.go @@ -25,6 +25,7 @@ type ResponseNatsCampaignTransaction struct { RejectedBy primitive.ObjectID `json:"rejectedBy,omitempty"` ApprovedAt string `json:"approvedAt,omitempty"` RejectedAt string `json:"rejectedAt,omitempty"` + CompletedAt string `json:"completedAt,omitempty"` } // ResponseCampaignShortInfo ... -- 2.34.1 From 9cec9d8c2f6357cf77dc1868e6b842351ddbbe01 Mon Sep 17 00:00:00 2001 From: tuannt20 <105765641+tuannt20@users.noreply.github.com> Date: Fri, 2 Dec 2022 10:15:58 +0700 Subject: [PATCH 7/7] update field --- model/campaign_response.go | 39 +++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/model/campaign_response.go b/model/campaign_response.go index 710ee47..db8a90b 100644 --- a/model/campaign_response.go +++ b/model/campaign_response.go @@ -11,21 +11,22 @@ type ResponseCampaignTransactionAll struct { // ResponseNatsCampaignTransaction ... type ResponseNatsCampaignTransaction struct { - ID string `json:"_id"` - Cash float64 `json:"cash"` - Campaign ResponseCampaignShortInfo `json:"campaign"` - Seller primitive.ObjectID `json:"seller"` - Type string `json:"type"` - Status string `json:"status"` - RejectedReason string `json:"rejectedReason"` - CreatedAt string `json:"createdAt"` - UpdatedAt string `json:"updatedAt"` - Item *ResponseCampaignItemShortInfo `json:"item"` - ApprovedBy primitive.ObjectID `json:"approvedBy,omitempty"` - RejectedBy primitive.ObjectID `json:"rejectedBy,omitempty"` - ApprovedAt string `json:"approvedAt,omitempty"` - RejectedAt string `json:"rejectedAt,omitempty"` - CompletedAt string `json:"completedAt,omitempty"` + ID string `json:"_id"` + Cash float64 `json:"cash"` + Campaign ResponseCampaignShortInfo `json:"campaign"` + Options ResponseCampaignTransactionOptions `json:"options"` + Seller primitive.ObjectID `json:"seller"` + Type string `json:"type"` + Status string `json:"status"` + RejectedReason string `json:"rejectedReason"` + CreatedAt string `json:"createdAt"` + UpdatedAt string `json:"updatedAt"` + Item *ResponseCampaignItemShortInfo `json:"item"` + ApprovedBy primitive.ObjectID `json:"approvedBy,omitempty"` + RejectedBy primitive.ObjectID `json:"rejectedBy,omitempty"` + ApprovedAt string `json:"approvedAt,omitempty"` + RejectedAt string `json:"rejectedAt,omitempty"` + CompletedAt string `json:"completedAt,omitempty"` } // ResponseCampaignShortInfo ... @@ -41,3 +42,11 @@ type ResponseCampaignItemShortInfo struct { Name string `json:"name"` Status string `json:"status"` } + +// ResponseCampaignTransactionOptions ... +type ResponseCampaignTransactionOptions struct { + Link string `json:"link"` + SocialChannel string `json:"socialChannel"` + Milestone int64 `json:"milestone"` + MilestoneTitle string `json:"milestoneTitle"` +} -- 2.34.1