add description all the way
Some checks failed
Build and Publish / Metadata (push) Successful in 11s
Build and Publish / BuildAndDeployAmd64 (push) Has been cancelled
Build and Publish / BuildAndDeployArm64 (push) Has started running

This commit is contained in:
matst80
2025-10-18 15:50:38 +02:00
parent 662b381a34
commit 0c127e9d38
4 changed files with 29 additions and 13 deletions

View File

@@ -92,10 +92,12 @@ type CartGrain struct {
}
type Voucher struct {
Code string `json:"code"`
Rules []string `json:"rules"`
Id uint32 `json:"id"`
Value int64 `json:"value"`
Code string `json:"code"`
Applied bool `json:"applied"`
Rules []string `json:"rules"`
Description string `json:"description,omitempty"`
Id uint32 `json:"id"`
Value int64 `json:"value"`
}
func (v *Voucher) AppliesTo(cart *CartGrain) ([]*CartItem, bool) {
@@ -270,13 +272,15 @@ func (c *CartGrain) UpdateTotals() {
c.TotalPrice.Add(delivery.Price)
}
for _, voucher := range c.Vouchers {
if _, ok := voucher.AppliesTo(c); ok {
_, ok := voucher.AppliesTo(c)
voucher.Applied = false
if ok {
value := NewPriceFromIncVat(voucher.Value, 25)
if c.TotalPrice.IncVat <= value.IncVat {
// don't apply discounts to more than the total price
continue
}
voucher.Applied = true
c.TotalDiscount.Add(*value)
c.TotalPrice.Subtract(*value)
}

View File

@@ -931,6 +931,7 @@ type AddVoucher struct {
Code string `protobuf:"bytes,1,opt,name=code,proto3" json:"code,omitempty"`
Value int64 `protobuf:"varint,2,opt,name=value,proto3" json:"value,omitempty"`
VoucherRules []string `protobuf:"bytes,3,rep,name=voucherRules,proto3" json:"voucherRules,omitempty"`
Description string `protobuf:"bytes,4,opt,name=description,proto3" json:"description,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
@@ -986,6 +987,13 @@ func (x *AddVoucher) GetVoucherRules() []string {
return nil
}
func (x *AddVoucher) GetDescription() string {
if x != nil {
return x.Description
}
return ""
}
type RemoveVoucher struct {
state protoimpl.MessageState `protogen:"open.v1"`
Id uint32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
@@ -1267,12 +1275,13 @@ const file_messages_proto_rawDesc = "" +
"\x12InitializeCheckout\x12\x18\n" +
"\aorderId\x18\x01 \x01(\tR\aorderId\x12\x16\n" +
"\x06status\x18\x02 \x01(\tR\x06status\x12,\n" +
"\x11paymentInProgress\x18\x03 \x01(\bR\x11paymentInProgress\"Z\n" +
"\x11paymentInProgress\x18\x03 \x01(\bR\x11paymentInProgress\"|\n" +
"\n" +
"AddVoucher\x12\x12\n" +
"\x04code\x18\x01 \x01(\tR\x04code\x12\x14\n" +
"\x05value\x18\x02 \x01(\x03R\x05value\x12\"\n" +
"\fvoucherRules\x18\x03 \x03(\tR\fvoucherRules\"\x1f\n" +
"\fvoucherRules\x18\x03 \x03(\tR\fvoucherRules\x12 \n" +
"\vdescription\x18\x04 \x01(\tR\vdescription\"\x1f\n" +
"\rRemoveVoucher\x12\x0e\n" +
"\x02id\x18\x01 \x01(\rR\x02id\"\xa7\x01\n" +
"\x19UpsertSubscriptionDetails\x12\x13\n" +

View File

@@ -15,9 +15,10 @@ type Rule struct {
}
type Voucher struct {
Code string `json:"code"`
Value int64 `json:"value"`
Rules string `json:"rules"`
Code string `json:"code"`
Value int64 `json:"value"`
Rules string `json:"rules"`
Description string `json:"description,omitempty"`
}
type Service struct {
@@ -40,8 +41,9 @@ func (s *Service) GetVoucher(code string) (*messages.AddVoucher, error) {
}
return &messages.AddVoucher{
Code: code,
Value: v.Value,
Code: code,
Value: v.Value,
Description: v.Description,
VoucherRules: []string{
v.Rules,
},

View File

@@ -99,6 +99,7 @@ message AddVoucher {
string code = 1;
int64 value = 2;
repeated string voucherRules = 3;
string description = 4;
}
message RemoveVoucher { uint32 id = 1; }