From 67b99f7774427e7bdfe393c53e2f31ff040ce78a Mon Sep 17 00:00:00 2001 From: Nguyen Minh Date: Wed, 11 Jan 2023 09:27:49 +0700 Subject: [PATCH 1/2] campaign-get-seller-statistic --- client/campaign.go | 22 ++++++++++++++++++++++ model/campaign_request.go | 10 +++++++++- model/campaign_response.go | 29 +++++++++++++++++++++++++++++ subject/campaign.go | 2 ++ 4 files changed, 62 insertions(+), 1 deletion(-) diff --git a/client/campaign.go b/client/campaign.go index 82649d3..16fa6e4 100644 --- a/client/campaign.go +++ b/client/campaign.go @@ -34,3 +34,25 @@ func (c Campaign) GetCampaignTransaction(p model.GetCampaignTransactionsRequest) } return r.Data, nil } + +// GetCampaignSellerStatistic .... +func (c Campaign) GetCampaignSellerStatistic(req model.GetCampaignSellerStatisticBySellerIDs) (*model.ResponseCampaignSellerStatistic, error) { + msg, err := natsio.GetServer().Request(subject.Campaign.GetCampaignSellerStatisticBySellerIDs, toBytes(req)) + if err != nil { + return nil, err + } + + var r struct { + Data *model.ResponseCampaignSellerStatistic `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 index 71227e4..8033196 100644 --- a/model/campaign_request.go +++ b/model/campaign_request.go @@ -1,6 +1,9 @@ package model -import "time" +import ( + "go.mongodb.org/mongo-driver/bson/primitive" + "time" +) // GetCampaignTransactionsRequest ... type GetCampaignTransactionsRequest struct { @@ -12,3 +15,8 @@ type GetCampaignTransactionsRequest struct { Page int64 `json:"page"` Limit int64 `json:"limit"` } + +// GetCampaignSellerStatisticBySellerIDs ... +type GetCampaignSellerStatisticBySellerIDs struct { + SellerIDs []primitive.ObjectID +} diff --git a/model/campaign_response.go b/model/campaign_response.go index 9619035..65199e9 100644 --- a/model/campaign_response.go +++ b/model/campaign_response.go @@ -57,3 +57,32 @@ type ResponseCampaignTransactionOptions struct { type ResponseCampaignTransactionAdminConfirmData struct { FriendPublicTotal int64 `json:"friendPublicTotal"` } + +// ResponseCampaignSellerStatisticList ... +type ResponseCampaignSellerStatisticList struct { + List []ResponseCampaignSellerStatistic `json:"list"` +} + +// ResponseCampaignSellerStatistic ... +type ResponseCampaignSellerStatistic struct { + SellerID primitive.ObjectID `json:"sellerId"` + Statistic CampaignSellerStatistic `json:"Statistic"` +} + +// CampaignSellerStatistic ... +type CampaignSellerStatistic struct { + TotalNotRejected int64 `bson:"totalNotRejected" json:"totalNotRejected"` + CashTotalNotRejected float64 `bson:"cashTotalNotRejected" json:"cashTotalNotRejected"` + + TotalCompleted int64 `bson:"totalCompleted" json:"totalCompleted"` + CashTotalCompleted float64 `bson:"cashTotalCompleted" json:"cashTotalCompleted"` + + TotalPending int64 `bson:"totalPending" json:"totalPending"` + CashTotalPending float64 `bson:"cashTotalPending" json:"cashTotalPending"` + + TotalApproved int64 `bson:"totalApproved" json:"totalApproved"` + CashTotalApproved float64 `bson:"cashTotalApproved" json:"cashTotalApproved"` + + TotalRejected int64 `bson:"totalRejected" json:"totalRejected"` + CashTotalRejected float64 `bson:"cashTotalRejected" json:"cashTotalRejected"` +} diff --git a/subject/campaign.go b/subject/campaign.go index 8c7ddac..a986f69 100644 --- a/subject/campaign.go +++ b/subject/campaign.go @@ -10,6 +10,8 @@ func getCampaignValue(val string) string { // Campaign ... var Campaign = struct { GetListCampaignTransactionAdminInfoByIDs string + GetCampaignSellerStatisticBySellerIDs string }{ GetListCampaignTransactionAdminInfoByIDs: getCampaignValue("get_list_campaign_transaction_admin_info_by_ids"), + GetCampaignSellerStatisticBySellerIDs: getCampaignValue("get_campaign_seller_statistic_by_seller_ids"), } -- 2.34.1 From 2003cb4e4946341696196f71fc9d6acc3d25a10e Mon Sep 17 00:00:00 2001 From: Nguyen Minh Date: Wed, 11 Jan 2023 10:21:02 +0700 Subject: [PATCH 2/2] update --- client/campaign.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/campaign.go b/client/campaign.go index 16fa6e4..8368230 100644 --- a/client/campaign.go +++ b/client/campaign.go @@ -36,15 +36,15 @@ func (c Campaign) GetCampaignTransaction(p model.GetCampaignTransactionsRequest) } // GetCampaignSellerStatistic .... -func (c Campaign) GetCampaignSellerStatistic(req model.GetCampaignSellerStatisticBySellerIDs) (*model.ResponseCampaignSellerStatistic, error) { +func (c Campaign) GetCampaignSellerStatistic(req model.GetCampaignSellerStatisticBySellerIDs) (*model.ResponseCampaignSellerStatisticList, error) { msg, err := natsio.GetServer().Request(subject.Campaign.GetCampaignSellerStatisticBySellerIDs, toBytes(req)) if err != nil { return nil, err } var r struct { - Data *model.ResponseCampaignSellerStatistic `json:"data"` - Error string `json:"error"` + Data *model.ResponseCampaignSellerStatisticList `json:"data"` + Error string `json:"error"` } if err = json.Unmarshal(msg.Data, &r); err != nil { -- 2.34.1