generate_voucher_promotion #181

Merged
minhnguyen merged 1 commits from feature/generate_voucher_promotion into master 2025-01-21 07:50:15 +00:00
2 changed files with 57 additions and 0 deletions

37
client/promotion.go Normal file
View File

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

View File

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