generate_voucher_promotion #181
			
				
			
		
		
		
	| 
						 | 
				
			
			@ -0,0 +1,37 @@
 | 
			
		|||
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"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type Promotion struct{}
 | 
			
		||||
 | 
			
		||||
func GetPromotion() Promotion {
 | 
			
		||||
	return Promotion{}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (s Promotion) GenerateVoucherPromotion(p model.GenerateVoucherPromotionRequest) (*model.ResponseGenerateVoucherPromotion, error) {
 | 
			
		||||
	msg, err := natsio.GetServer().Request(subject.Promotion.GenerateVoucherPromotion, toBytes(p))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var r struct {
 | 
			
		||||
		Data  *model.ResponseGenerateVoucherPromotion `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
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,20 @@
 | 
			
		|||
package model
 | 
			
		||||
 | 
			
		||||
import "go.mongodb.org/mongo-driver/bson/primitive"
 | 
			
		||||
 | 
			
		||||
type GenerateVoucherPromotionRequest struct {
 | 
			
		||||
	Cash       float64                         `json:"cash"`
 | 
			
		||||
	TargetID   primitive.ObjectID              `json:"targetId"`
 | 
			
		||||
	TargetType string                          `json:"targetType"`
 | 
			
		||||
	Options    GenerateVoucherPromotionOptions `json:"options"`
 | 
			
		||||
	Seller     primitive.ObjectID              `json:"seller"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type GenerateVoucherPromotionOptions struct {
 | 
			
		||||
	Title string `json:"title"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type ResponseGenerateVoucherPromotion struct {
 | 
			
		||||
	Success bool   `json:"success"`
 | 
			
		||||
	Error   string `json:"error"`
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
		Reference in New Issue