Add void print
This commit is contained in:
@@ -5,7 +5,7 @@ import (
|
||||
)
|
||||
|
||||
type TransactionDB struct {
|
||||
ID string `gorm:"primaryKey;column:id"`
|
||||
ID string `gorm:"type:uuid;default:gen_random_uuid();primaryKey;column:id"`
|
||||
OrderID int64 `gorm:"column:order_id"`
|
||||
Amount float64 `gorm:"column:amount"`
|
||||
PaymentMethod string `gorm:"column:payment_method"`
|
||||
|
||||
@@ -41,6 +41,8 @@ type OrderRepository interface {
|
||||
GetOrderHistoryByUserID(ctx mycontext.Context, userID int64, req entity.SearchRequest) ([]*entity.Order, int64, error)
|
||||
FindByIDAndCustomerID(ctx mycontext.Context, id int64, customerID int64) (*entity.Order, error)
|
||||
UpdateOrder(ctx mycontext.Context, id int64, status string, description string) error
|
||||
UpdateOrderItem(ctx mycontext.Context, orderItemID int64, quantity int) error
|
||||
UpdateOrderTotals(ctx mycontext.Context, orderID int64, amount, tax, total float64) error
|
||||
}
|
||||
|
||||
type orderRepository struct {
|
||||
@@ -979,3 +981,47 @@ func (r *orderRepository) FindByIDAndCustomerID(ctx mycontext.Context, id int64,
|
||||
|
||||
return order, nil
|
||||
}
|
||||
|
||||
func (r *orderRepository) UpdateOrderItem(ctx mycontext.Context, orderItemID int64, quantity int) error {
|
||||
now := time.Now()
|
||||
|
||||
result := r.db.Model(&models.OrderItemDB{}).
|
||||
Where("order_item_id = ?", orderItemID).
|
||||
Updates(map[string]interface{}{
|
||||
"quantity": quantity,
|
||||
"updated_at": now,
|
||||
})
|
||||
|
||||
if result.Error != nil {
|
||||
return errors.Wrap(result.Error, "failed to update order item")
|
||||
}
|
||||
|
||||
if result.RowsAffected == 0 {
|
||||
logger.ContextLogger(ctx).Warn("no order item updated")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *orderRepository) UpdateOrderTotals(ctx mycontext.Context, orderID int64, amount, tax, total float64) error {
|
||||
now := time.Now()
|
||||
|
||||
result := r.db.Model(&models.OrderDB{}).
|
||||
Where("id = ?", orderID).
|
||||
Updates(map[string]interface{}{
|
||||
"amount": amount,
|
||||
"tax": tax,
|
||||
"total": total,
|
||||
"updated_at": now,
|
||||
})
|
||||
|
||||
if result.Error != nil {
|
||||
return errors.Wrap(result.Error, "failed to update order totals")
|
||||
}
|
||||
|
||||
if result.RowsAffected == 0 {
|
||||
logger.ContextLogger(ctx).Warn("no order updated")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"enaklo-pos-be/internal/common/mycontext"
|
||||
"enaklo-pos-be/internal/entity"
|
||||
"enaklo-pos-be/internal/repository/models"
|
||||
"github.com/google/uuid"
|
||||
"github.com/pkg/errors"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
@@ -51,7 +52,7 @@ func (r *transactionRepository) FindByOrderID(ctx mycontext.Context, orderID int
|
||||
|
||||
func (r *transactionRepository) toTransactionDBModel(transaction *entity.Transaction) models.TransactionDB {
|
||||
return models.TransactionDB{
|
||||
ID: transaction.ID,
|
||||
ID: uuid.New().String(),
|
||||
OrderID: transaction.OrderID,
|
||||
Amount: transaction.Amount,
|
||||
PaymentMethod: transaction.PaymentMethod,
|
||||
|
||||
Reference in New Issue
Block a user