Merge pull request #38 from Selly-Modules/feature/seller-by-id

Feature/seller by
This commit is contained in:
trunglt251292 2022-10-03 10:48:13 +07:00 committed by GitHub
commit 89f4e1a11d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 319 additions and 0 deletions

88
client/seller.go Normal file
View File

@ -0,0 +1,88 @@
package client
import (
"encoding/json"
"errors"
"github.com/Selly-Modules/natsio"
"github.com/Selly-Modules/natsio/model"
"github.com/Selly-Modules/natsio/subject"
)
// Seller ...
type Seller struct{}
// GetSeller ...
func GetSeller() Seller {
return Seller{}
}
// GetSellerInfoByID ...
func (s Seller) GetSellerInfoByID(p model.GetSellerByIDRequest) (*model.ResponseSellerInfo, error) {
msg, err := natsio.GetServer().Request(subject.Seller.GetSellerInfoByID, toBytes(p))
if err != nil {
return nil, err
}
var r struct {
Data *model.ResponseSellerInfo `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
}
// GetListSellerInfoByIDs ...
func (s Seller) GetListSellerInfoByIDs(p model.GetListSellerByIDsRequest) (*model.ResponseListSellerInfo, error) {
msg, err := natsio.GetServer().Request(subject.Seller.GetListSellerInfoByIDs, toBytes(p))
if err != nil {
return nil, err
}
var r struct {
Data *model.ResponseListSellerInfo `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
}
// GetListSellerInfoSupportChatByIDs ...
func (s Seller) GetListSellerInfoSupportChatByIDs(p model.GetListSellerSupportChatByIDsRequest) (*model.ResponseListSellerInfoSupportChat, error) {
msg, err := natsio.GetServer().Request(subject.SupportChat.GetListSellerInfoSupportChatByIDs, toBytes(p))
if err != nil {
return nil, err
}
var r struct {
Data *model.ResponseListSellerInfoSupportChat `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
}

4
jestream_name.go Normal file
View File

@ -0,0 +1,4 @@
package natsio
// StreamNameSelly ...
const StreamNameSelly = "selly"

12
js/consumer/selly.go Normal file
View File

@ -0,0 +1,12 @@
package jsconsumer
// Selly ...
var Selly = struct {
PushNotification string
UpdateSellerAffiliateStatistic string
CheckAnDInsertCashflowBySeller string
}{
PushNotification: "PULL_PUSH_NOTIFICATION",
UpdateSellerAffiliateStatistic: "PULL_UPDATE_SELLER_AFFILIATE_STATISTIC",
CheckAnDInsertCashflowBySeller: "PULL_CHECK_AND_INSERT_CASHFLOW_BY_SELLER",
}

60
js/model/selly.go Normal file
View File

@ -0,0 +1,60 @@
package jsmodel
// PushNotification ...
type PushNotification struct {
User string `json:"user"`
Type string `json:"type"`
TargetID string `json:"targetId"`
IsFromAdmin bool `json:"isFromAdmin"`
Category string `json:"category"`
Options NotificationOptions `json:"options"`
}
// NotificationOptions ...
type NotificationOptions struct {
Title string `json:"title"`
Content string `json:"content"`
}
// PayloadUpdateSellerAffiliateStatistic ...
type PayloadUpdateSellerAffiliateStatistic struct {
SellerID string `json:"sellerId"`
Statistic SellerAffiliateStatistic `json:"statistic"`
}
// SellerAffiliateStatistic ...
type SellerAffiliateStatistic struct {
TransactionTotal int `json:"transactionTotal"`
TransactionCashback int `json:"transactionCashback"`
TransactionPending int `json:"transactionPending"`
TransactionApproved int `json:"transactionApproved"`
TransactionRejected int `json:"transactionRejected"`
CommissionTransactionTotal float64 `json:"commissionTransactionTotal"`
CommissionTransactionCashback float64 `json:"commissionTransactionCashback"`
CommissionTransactionApproved float64 `json:"commissionTransactionApproved"`
CommissionTransactionPending float64 `json:"commissionTransactionPending"`
CommissionTransactionRejected float64 `json:"commissionTransactionRejected"`
}
// PayloadCashflowsBySeller ...
type PayloadCashflowsBySeller struct {
SellerID string `json:"sellerId"`
List []CashflowSeller `json:"list"`
}
// CashflowSeller ...
type CashflowSeller struct {
Value float64 `json:"value"`
Action string `json:"action"`
Category string `json:"category"`
TargetID string `json:"targetId"`
TargetType string `json:"targetType"`
Options *CashFlowOptions `json:"options"`
}
// CashFlowOptions ...
type CashFlowOptions struct {
AffiliateTransactionCode string `json:"affiliateTransactionCode,omitempty"`
AffiliateCampaignID string `json:"affiliateCampaignId,omitempty"`
AffiliateCampaignName string `json:"affiliateCampaignName,omitempty"`
}

10
js/subject/config.go Normal file
View File

@ -0,0 +1,10 @@
package jssubject
var root = "js"
// prefixes ...
var prefixes = struct {
Selly string
}{
Selly: "selly",
}

21
js/subject/selly.go Normal file
View File

@ -0,0 +1,21 @@
package jssubject
import (
"fmt"
)
// getSellyValue ...
func getSellyValue(val string) string {
return fmt.Sprintf("%s.%s.%s", root, prefixes.Selly, val)
}
// Selly ...
var Selly = struct {
PushNotification string
UpdateSellerAffiliateStatistic string
CheckAnDInsertCashflowBySeller string
}{
PushNotification: getSellyValue("push_notifications"),
UpdateSellerAffiliateStatistic: getSellyValue("update_seller_affiliate_statistic"),
CheckAnDInsertCashflowBySeller: getSellyValue("check_and_insert_cashflow_statistic"),
}

18
model/seller_request.go Normal file
View File

@ -0,0 +1,18 @@
package model
import "go.mongodb.org/mongo-driver/bson/primitive"
// GetSellerByIDRequest ...
type GetSellerByIDRequest struct {
SellerID primitive.ObjectID `json:"sellerId"`
}
// GetListSellerByIDsRequest ...
type GetListSellerByIDsRequest struct {
SellerIDs []primitive.ObjectID `json:"sellerIds"`
}
// GetListSellerSupportChatByIDsRequest ...
type GetListSellerSupportChatByIDsRequest struct {
SellerIDs []primitive.ObjectID `json:"sellerIds"`
}

81
model/seller_response.go Normal file
View File

@ -0,0 +1,81 @@
package model
import "time"
// ResponseSellerInfo ...
type ResponseSellerInfo struct {
ID string `json:"_id"`
Name string `json:"name"`
Code string `json:"code"`
}
// ResponseListSellerInfo ...
type ResponseListSellerInfo struct {
Sellers []ResponseSellerInfo `json:"sellers"`
}
// ResponseListSellerInfoSupportChat ...
type ResponseListSellerInfoSupportChat struct {
Sellers []ResponseSellerInfoSupportChat `json:"sellers"`
}
// ResponseSellerInfoSupportChat ...
type ResponseSellerInfoSupportChat struct {
ID string `json:"_id"`
Name string `json:"name"`
Code string `json:"code"`
Membership SellerMembershipInfo `json:"membership"`
Info SellerContactInfo `json:"info"`
Team *TeamInfo `json:"team,omitempty"`
Statistic SellerStatistic `json:"statistic"`
TrackingTime *SellerTrackingTime `json:"trackingTime"`
Invitee *InviteeInfo `json:"invitee"`
CreatedAt time.Time `json:"createdAt"`
}
// SellerTrackingTime ...
type SellerTrackingTime struct {
FirstOrderDeliveredAt time.Time `json:"firstOrderDeliveredAt,omitempty"`
ThirdOrderDeliveredAt time.Time `json:"thirdOrderDeliveredAt,omitempty"`
}
// SellerStatistic ...
type SellerStatistic struct {
ThisMonthSale float64 `bson:"thisMonthSale" json:"thisMonthSale"`
LastMonthSale float64 `bson:"lastMonthSale" json:"lastMonthSale"`
Sale float64 `bson:"sale" json:"sale"`
TransactionTotal int `json:"transactionTotal"`
TransactionPaymentProcessing int `json:"transactionPaymentProcessing"`
TransactionWaitingApprove int `json:"transactionWaitingApprove"`
TransactionPending int `json:"transactionPending"`
TransactionSuccess int `json:"transactionSuccess"`
TransactionRejected int `json:"transactionRejected"`
TransactionDelivering int `json:"transactionDelivering"`
TransactionDelivered int `json:"transactionDelivered"`
}
// TeamInfo ...
type TeamInfo struct {
ID string `json:"_id"`
Name string `json:"name"`
Role string `json:"role"`
}
// InviteeInfo ...
type InviteeInfo struct {
ID string `json:"_id"`
Name string `json:"name"`
}
// SellerContactInfo ...
type SellerContactInfo struct {
City int `json:"cityCode"`
CityName string `json:"cityName"`
Gender string `json:"gender"`
}
// SellerMembershipInfo ...
type SellerMembershipInfo struct {
Level int `json:"level"`
Name string `json:"name"`
}

View File

@ -7,6 +7,7 @@ var prefixes = struct {
Warehouse string
Location string
Supplier string
Seller string
}{
Communication: "communication",
Order: "order",
@ -14,4 +15,5 @@ var prefixes = struct {
Warehouse: "warehouse",
Location: "location",
Supplier: "supplier",
Seller: "seller",
}

23
subject/seller.go Normal file
View File

@ -0,0 +1,23 @@
package subject
import "fmt"
func getSellerValue(val string) string {
return fmt.Sprintf("%s.%s", prefixes.Seller, val)
}
// Seller ...
var Seller = struct {
GetSellerInfoByID string
GetListSellerInfoByIDs string
}{
GetSellerInfoByID: getSellerValue("get_seller_info_by_id"),
GetListSellerInfoByIDs: getSellerValue("get_list_seller_info_by_ids"),
}
// SupportChat ...
var SupportChat = struct {
GetListSellerInfoSupportChatByIDs string
}{
GetListSellerInfoSupportChatByIDs: "SELLY_CHAT.REQUEST.SELLER_INFO",
}