update cart
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-05-30 03:54:12 +07:00
parent 323f50fb43
commit 073a7e6d8c
10 changed files with 207 additions and 163 deletions
+3 -5
View File
@@ -13,12 +13,11 @@ func NewService() *Service {
return &Service{}
}
func (s *Service) CreateOrderText(req *proto.OrderReq, items []*proto.CardItem) (string, error) {
func (s *Service) CreateOrderText(req *proto.OrderReq, cart *proto.CartRsp) (string, error) {
buffer := bytes.Buffer{}
var orderAmount int64
buffer.WriteString(fmt.Sprintf("Заказ от:\n%s\n%s\n", req.Order.Name, req.Order.Phone))
buffer.WriteString("\n")
for _, item := range items {
for _, item := range cart.Items {
buffer.WriteString(item.Name)
buffer.WriteString("\n")
unit, err := unitToText(item.Unit)
@@ -26,12 +25,11 @@ func (s *Service) CreateOrderText(req *proto.OrderReq, items []*proto.CardItem)
return "", err
}
buffer.WriteString(fmt.Sprintf("Количество: %d%s\n", item.Count, unit))
orderAmount += item.Amount
buffer.WriteString(fmt.Sprintf("Сумма: %.00fр\n", float64(item.Amount)/100))
buffer.WriteString("\n")
}
buffer.WriteString("\n")
buffer.WriteString(fmt.Sprintf("ИТОГО: %.00fр\n", float64(orderAmount)/100))
buffer.WriteString(fmt.Sprintf("ИТОГО: %.00fр\n", float64(cart.Amount)/100))
return buffer.String(), nil
}