Merge pull request 'add nasts campaign transaction' (#81) from feature/export-data-campaign-transaction into feature/campaign-completed

Reviewed-on: #81
This commit is contained in:
Minh Nguyen 2022-11-24 02:41:01 +00:00
commit 436a713725
5 changed files with 101 additions and 0 deletions

31
client/campaign.go Normal file
View File

@ -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
}

14
model/campaign_request.go Normal file
View File

@ -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"`
}

View File

@ -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"`
}

15
subject/campaign.go Normal file
View File

@ -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"),
}

View File

@ -13,6 +13,7 @@ var prefixes = struct {
SupplierRole string SupplierRole string
SocialPost string SocialPost string
Staff string Staff string
Campaign string
}{ }{
Communication: "communication", Communication: "communication",
Order: "order", Order: "order",
@ -26,4 +27,5 @@ var prefixes = struct {
SupplierRole: "supplier_role", SupplierRole: "supplier_role",
SocialPost: "social_post", SocialPost: "social_post",
Staff: "staff", Staff: "staff",
Campaign: "campaign",
} }