chore: apply new logger to order actions
This commit is contained in:
@@ -1,122 +1,116 @@
|
||||
package orderStatusActions
|
||||
|
||||
import (
|
||||
"log"
|
||||
// func init() {
|
||||
// GlobalRegistry.Register(enums.OrderStatusConfirmed, ActionChain{
|
||||
// SendOrderConfirmationEmail,
|
||||
// NotifyInventorySystem,
|
||||
// })
|
||||
|
||||
"git.ma-al.com/goc_daniel/b2b/app/model/enums"
|
||||
)
|
||||
// GlobalRegistry.Register(enums.OrderStatusProcessing, ActionChain{
|
||||
// NotifyWarehouse,
|
||||
// ReserveInventory,
|
||||
// })
|
||||
|
||||
func init() {
|
||||
GlobalRegistry.Register(enums.OrderStatusConfirmed, ActionChain{
|
||||
SendOrderConfirmationEmail,
|
||||
NotifyInventorySystem,
|
||||
})
|
||||
// GlobalRegistry.Register(enums.OrderStatusShipped, ActionChain{
|
||||
// NotifyWarehouseShipped,
|
||||
// GenerateTrackingNumber,
|
||||
// SendShippingNotificationEmail,
|
||||
// })
|
||||
|
||||
GlobalRegistry.Register(enums.OrderStatusProcessing, ActionChain{
|
||||
NotifyWarehouse,
|
||||
ReserveInventory,
|
||||
})
|
||||
// GlobalRegistry.Register(enums.OrderStatusDelivered, ActionChain{
|
||||
// SendDeliveryConfirmationEmail,
|
||||
// NotifyFulfillmentComplete,
|
||||
// })
|
||||
|
||||
GlobalRegistry.Register(enums.OrderStatusShipped, ActionChain{
|
||||
NotifyWarehouseShipped,
|
||||
GenerateTrackingNumber,
|
||||
SendShippingNotificationEmail,
|
||||
})
|
||||
// GlobalRegistry.Register(enums.OrderStatusCancelled, ActionChain{
|
||||
// SendCancellationEmail,
|
||||
// ReleaseInventory,
|
||||
// ProcessRefund,
|
||||
// })
|
||||
|
||||
GlobalRegistry.Register(enums.OrderStatusDelivered, ActionChain{
|
||||
SendDeliveryConfirmationEmail,
|
||||
NotifyFulfillmentComplete,
|
||||
})
|
||||
// GlobalRegistry.Register(enums.OrderStatusReturned, ActionChain{
|
||||
// SendReturnConfirmationEmail,
|
||||
// NotifyReturnsDepartment,
|
||||
// })
|
||||
|
||||
GlobalRegistry.Register(enums.OrderStatusCancelled, ActionChain{
|
||||
SendCancellationEmail,
|
||||
ReleaseInventory,
|
||||
ProcessRefund,
|
||||
})
|
||||
// GlobalRegistry.Register(enums.OrderStatusRefunded, ActionChain{
|
||||
// NotifyRefundProcessed,
|
||||
// })
|
||||
|
||||
GlobalRegistry.Register(enums.OrderStatusReturned, ActionChain{
|
||||
SendReturnConfirmationEmail,
|
||||
NotifyReturnsDepartment,
|
||||
})
|
||||
// GlobalRegistry.Register(enums.OrderStatusPending, ActionChain{})
|
||||
// }
|
||||
|
||||
GlobalRegistry.Register(enums.OrderStatusRefunded, ActionChain{
|
||||
NotifyRefundProcessed,
|
||||
})
|
||||
// var SendOrderConfirmationEmail = WithID("send_order_confirmation_email", func(actionCtx ActionContext) ActionResult {
|
||||
// log.Printf("Sending order confirmation email for order %d", actionCtx.OrderId)
|
||||
// return ActionResult{Err: nil}
|
||||
// })
|
||||
|
||||
GlobalRegistry.Register(enums.OrderStatusPending, ActionChain{})
|
||||
}
|
||||
// var NotifyInventorySystem = WithID("notify_inventory_system", func(actionCtx ActionContext) ActionResult {
|
||||
// log.Printf("Notifying inventory system for order %d", actionCtx.OrderId)
|
||||
// return ActionResult{Err: nil}
|
||||
// })
|
||||
|
||||
var SendOrderConfirmationEmail = WithID("send_order_confirmation_email", func(actionCtx ActionContext) ActionResult {
|
||||
log.Printf("Sending order confirmation email for order %d", actionCtx.OrderId)
|
||||
return ActionResult{Err: nil}
|
||||
})
|
||||
// var NotifyWarehouse = WithID("notify_warehouse", func(actionCtx ActionContext) ActionResult {
|
||||
// log.Printf("Notifying warehouse for order %d", actionCtx.OrderId)
|
||||
// return ActionResult{Err: nil}
|
||||
// })
|
||||
|
||||
var NotifyInventorySystem = WithID("notify_inventory_system", func(actionCtx ActionContext) ActionResult {
|
||||
log.Printf("Notifying inventory system for order %d", actionCtx.OrderId)
|
||||
return ActionResult{Err: nil}
|
||||
})
|
||||
// var ReserveInventory = WithID("reserve_inventory", func(actionCtx ActionContext) ActionResult {
|
||||
// log.Printf("Reserving inventory for order %d", actionCtx.OrderId)
|
||||
// return ActionResult{Err: nil}
|
||||
// })
|
||||
|
||||
var NotifyWarehouse = WithID("notify_warehouse", func(actionCtx ActionContext) ActionResult {
|
||||
log.Printf("Notifying warehouse for order %d", actionCtx.OrderId)
|
||||
return ActionResult{Err: nil}
|
||||
})
|
||||
// var NotifyWarehouseShipped = WithID("notify_warehouse_shipped", func(actionCtx ActionContext) ActionResult {
|
||||
// log.Printf("Notifying warehouse of shipment for order %d", actionCtx.OrderId)
|
||||
// return ActionResult{Err: nil}
|
||||
// })
|
||||
|
||||
var ReserveInventory = WithID("reserve_inventory", func(actionCtx ActionContext) ActionResult {
|
||||
log.Printf("Reserving inventory for order %d", actionCtx.OrderId)
|
||||
return ActionResult{Err: nil}
|
||||
})
|
||||
// var GenerateTrackingNumber = WithID("generate_tracking_number", func(actionCtx ActionContext) ActionResult {
|
||||
// log.Printf("Generating tracking number for order %d", actionCtx.OrderId)
|
||||
// return ActionResult{Err: nil}
|
||||
// })
|
||||
|
||||
var NotifyWarehouseShipped = WithID("notify_warehouse_shipped", func(actionCtx ActionContext) ActionResult {
|
||||
log.Printf("Notifying warehouse of shipment for order %d", actionCtx.OrderId)
|
||||
return ActionResult{Err: nil}
|
||||
})
|
||||
// var SendShippingNotificationEmail = WithID("send_shipping_notification_email", func(actionCtx ActionContext) ActionResult {
|
||||
// log.Printf("Sending shipping notification email for order %d", actionCtx.OrderId)
|
||||
// return ActionResult{Err: nil}
|
||||
// })
|
||||
|
||||
var GenerateTrackingNumber = WithID("generate_tracking_number", func(actionCtx ActionContext) ActionResult {
|
||||
log.Printf("Generating tracking number for order %d", actionCtx.OrderId)
|
||||
return ActionResult{Err: nil}
|
||||
})
|
||||
// var SendDeliveryConfirmationEmail = WithID("send_delivery_confirmation_email", func(actionCtx ActionContext) ActionResult {
|
||||
// log.Printf("Sending delivery confirmation email for order %d", actionCtx.OrderId)
|
||||
// return ActionResult{Err: nil}
|
||||
// })
|
||||
|
||||
var SendShippingNotificationEmail = WithID("send_shipping_notification_email", func(actionCtx ActionContext) ActionResult {
|
||||
log.Printf("Sending shipping notification email for order %d", actionCtx.OrderId)
|
||||
return ActionResult{Err: nil}
|
||||
})
|
||||
// var NotifyFulfillmentComplete = WithID("notify_fulfillment_complete", func(actionCtx ActionContext) ActionResult {
|
||||
// log.Printf("Notifying fulfillment complete for order %d", actionCtx.OrderId)
|
||||
// return ActionResult{Err: nil}
|
||||
// })
|
||||
|
||||
var SendDeliveryConfirmationEmail = WithID("send_delivery_confirmation_email", func(actionCtx ActionContext) ActionResult {
|
||||
log.Printf("Sending delivery confirmation email for order %d", actionCtx.OrderId)
|
||||
return ActionResult{Err: nil}
|
||||
})
|
||||
// var SendCancellationEmail = WithID("send_cancellation_email", func(actionCtx ActionContext) ActionResult {
|
||||
// log.Printf("Sending cancellation email for order %d", actionCtx.OrderId)
|
||||
// return ActionResult{Err: nil}
|
||||
// })
|
||||
|
||||
var NotifyFulfillmentComplete = WithID("notify_fulfillment_complete", func(actionCtx ActionContext) ActionResult {
|
||||
log.Printf("Notifying fulfillment complete for order %d", actionCtx.OrderId)
|
||||
return ActionResult{Err: nil}
|
||||
})
|
||||
// var ReleaseInventory = WithID("release_inventory", func(actionCtx ActionContext) ActionResult {
|
||||
// log.Printf("Releasing inventory for order %d", actionCtx.OrderId)
|
||||
// return ActionResult{Err: nil}
|
||||
// })
|
||||
|
||||
var SendCancellationEmail = WithID("send_cancellation_email", func(actionCtx ActionContext) ActionResult {
|
||||
log.Printf("Sending cancellation email for order %d", actionCtx.OrderId)
|
||||
return ActionResult{Err: nil}
|
||||
})
|
||||
// var ProcessRefund = WithID("process_refund", func(actionCtx ActionContext) ActionResult {
|
||||
// log.Printf("Processing refund for order %d", actionCtx.OrderId)
|
||||
// return ActionResult{Err: nil}
|
||||
// })
|
||||
|
||||
var ReleaseInventory = WithID("release_inventory", func(actionCtx ActionContext) ActionResult {
|
||||
log.Printf("Releasing inventory for order %d", actionCtx.OrderId)
|
||||
return ActionResult{Err: nil}
|
||||
})
|
||||
// var SendReturnConfirmationEmail = WithID("send_return_confirmation_email", func(actionCtx ActionContext) ActionResult {
|
||||
// log.Printf("Sending return confirmation email for order %d", actionCtx.OrderId)
|
||||
// return ActionResult{Err: nil}
|
||||
// })
|
||||
|
||||
var ProcessRefund = WithID("process_refund", func(actionCtx ActionContext) ActionResult {
|
||||
log.Printf("Processing refund for order %d", actionCtx.OrderId)
|
||||
return ActionResult{Err: nil}
|
||||
})
|
||||
// var NotifyReturnsDepartment = WithID("notify_returns_department", func(actionCtx ActionContext) ActionResult {
|
||||
// log.Printf("Notifying returns department for order %d", actionCtx.OrderId)
|
||||
// return ActionResult{Err: nil}
|
||||
// })
|
||||
|
||||
var SendReturnConfirmationEmail = WithID("send_return_confirmation_email", func(actionCtx ActionContext) ActionResult {
|
||||
log.Printf("Sending return confirmation email for order %d", actionCtx.OrderId)
|
||||
return ActionResult{Err: nil}
|
||||
})
|
||||
|
||||
var NotifyReturnsDepartment = WithID("notify_returns_department", func(actionCtx ActionContext) ActionResult {
|
||||
log.Printf("Notifying returns department for order %d", actionCtx.OrderId)
|
||||
return ActionResult{Err: nil}
|
||||
})
|
||||
|
||||
var NotifyRefundProcessed = WithID("notify_refund_processed", func(actionCtx ActionContext) ActionResult {
|
||||
log.Printf("Notifying refund processed for order %d", actionCtx.OrderId)
|
||||
return ActionResult{Err: nil}
|
||||
})
|
||||
// var NotifyRefundProcessed = WithID("notify_refund_processed", func(actionCtx ActionContext) ActionResult {
|
||||
// log.Printf("Notifying refund processed for order %d", actionCtx.OrderId)
|
||||
// return ActionResult{Err: nil}
|
||||
// })
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
package orderStatusActions
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"git.ma-al.com/goc_daniel/b2b/app/model"
|
||||
"git.ma-al.com/goc_daniel/b2b/app/model/enums"
|
||||
"git.ma-al.com/goc_daniel/b2b/app/service/emailService"
|
||||
"git.ma-al.com/goc_daniel/b2b/app/utils/logger"
|
||||
)
|
||||
|
||||
var GlobalRegistry = make(ActionRegistry)
|
||||
@@ -13,7 +12,6 @@ var GlobalRegistry = make(ActionRegistry)
|
||||
type ActionID string
|
||||
|
||||
type ActionContext struct {
|
||||
OrderId uint
|
||||
Order *model.CustomerOrder
|
||||
UserId *uint
|
||||
EmailService *emailService.EmailService
|
||||
@@ -37,7 +35,12 @@ func (c ActionChain) Execute(actionCtx ActionContext) []ActionResult {
|
||||
result := action.Execute(actionCtx)
|
||||
results = append(results, result)
|
||||
if result.Err != nil {
|
||||
log.Printf("action %s failed for order %d: %v", action.ID(), actionCtx.OrderId, result.Err)
|
||||
logger.Debug("action failed",
|
||||
"action_id", action.ID(),
|
||||
"order", actionCtx.Order,
|
||||
"user_id", actionCtx.UserId,
|
||||
"error", result.Err,
|
||||
)
|
||||
}
|
||||
}
|
||||
return results
|
||||
|
||||
Reference in New Issue
Block a user