Merge branch 'develop' of git.selly.red:Selly-Modules/natsio into develop

This commit is contained in:
Sinh 2022-11-24 09:46:01 +07:00
commit 3307ae3abd
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

@ -19,6 +19,7 @@ var prefixes = struct {
Segment string Segment string
SupplierUser string SupplierUser string
SupplierRole string SupplierRole string
Campaign string
}{ }{
Communication: "communication", Communication: "communication",
Order: "order", Order: "order",
@ -38,4 +39,5 @@ var prefixes = struct {
SocialPost: "social_post", SocialPost: "social_post",
Staff: "staff", Staff: "staff",
Segment: "segment", Segment: "segment",
Campaign: "campaign",
} }