Compare commits
1 Commits
main
...
609f1bebff
| Author | SHA1 | Date | |
|---|---|---|---|
| 609f1bebff |
@@ -1,116 +0,0 @@
|
|||||||
package orderStatusActions
|
|
||||||
|
|
||||||
// func init() {
|
|
||||||
// GlobalRegistry.Register(enums.OrderStatusConfirmed, ActionChain{
|
|
||||||
// SendOrderConfirmationEmail,
|
|
||||||
// NotifyInventorySystem,
|
|
||||||
// })
|
|
||||||
|
|
||||||
// GlobalRegistry.Register(enums.OrderStatusProcessing, ActionChain{
|
|
||||||
// NotifyWarehouse,
|
|
||||||
// ReserveInventory,
|
|
||||||
// })
|
|
||||||
|
|
||||||
// GlobalRegistry.Register(enums.OrderStatusShipped, ActionChain{
|
|
||||||
// NotifyWarehouseShipped,
|
|
||||||
// GenerateTrackingNumber,
|
|
||||||
// SendShippingNotificationEmail,
|
|
||||||
// })
|
|
||||||
|
|
||||||
// GlobalRegistry.Register(enums.OrderStatusDelivered, ActionChain{
|
|
||||||
// SendDeliveryConfirmationEmail,
|
|
||||||
// NotifyFulfillmentComplete,
|
|
||||||
// })
|
|
||||||
|
|
||||||
// GlobalRegistry.Register(enums.OrderStatusCancelled, ActionChain{
|
|
||||||
// SendCancellationEmail,
|
|
||||||
// ReleaseInventory,
|
|
||||||
// ProcessRefund,
|
|
||||||
// })
|
|
||||||
|
|
||||||
// GlobalRegistry.Register(enums.OrderStatusReturned, ActionChain{
|
|
||||||
// SendReturnConfirmationEmail,
|
|
||||||
// NotifyReturnsDepartment,
|
|
||||||
// })
|
|
||||||
|
|
||||||
// GlobalRegistry.Register(enums.OrderStatusRefunded, ActionChain{
|
|
||||||
// NotifyRefundProcessed,
|
|
||||||
// })
|
|
||||||
|
|
||||||
// GlobalRegistry.Register(enums.OrderStatusPending, ActionChain{})
|
|
||||||
// }
|
|
||||||
|
|
||||||
// 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 NotifyInventorySystem = WithID("notify_inventory_system", func(actionCtx ActionContext) ActionResult {
|
|
||||||
// log.Printf("Notifying inventory system 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 ReserveInventory = WithID("reserve_inventory", func(actionCtx ActionContext) ActionResult {
|
|
||||||
// log.Printf("Reserving inventory 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 GenerateTrackingNumber = WithID("generate_tracking_number", func(actionCtx ActionContext) ActionResult {
|
|
||||||
// log.Printf("Generating tracking number 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 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 NotifyFulfillmentComplete = WithID("notify_fulfillment_complete", func(actionCtx ActionContext) ActionResult {
|
|
||||||
// log.Printf("Notifying fulfillment complete 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 ReleaseInventory = WithID("release_inventory", func(actionCtx ActionContext) ActionResult {
|
|
||||||
// log.Printf("Releasing inventory 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 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}
|
|
||||||
// })
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
package orderStatusActions
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/model/enums"
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
var sendNewOrderEmail = WithID("send_new_order_email", func(actionCtx ActionContext) ActionResult {
|
|
||||||
|
|
||||||
if actionCtx.EmailService == nil {
|
|
||||||
return ActionResult{Err: fmt.Errorf("emailService not provided")}
|
|
||||||
}
|
|
||||||
return ActionResult{Err: actionCtx.EmailService.SendNewOrderPlacedNotification(*actionCtx.UserId)}
|
|
||||||
})
|
|
||||||
|
|
||||||
GlobalRegistry.Register(enums.OrderStatusPending, ActionChain{
|
|
||||||
sendNewOrderEmail,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -1,88 +0,0 @@
|
|||||||
package orderStatusActions
|
|
||||||
|
|
||||||
import (
|
|
||||||
"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)
|
|
||||||
|
|
||||||
type ActionID string
|
|
||||||
|
|
||||||
type ActionContext struct {
|
|
||||||
Order *model.CustomerOrder
|
|
||||||
UserId *uint
|
|
||||||
EmailService *emailService.EmailService
|
|
||||||
}
|
|
||||||
|
|
||||||
type ActionResult struct {
|
|
||||||
Err error
|
|
||||||
Metadata map[string]any
|
|
||||||
}
|
|
||||||
|
|
||||||
type OrderAction interface {
|
|
||||||
ID() ActionID
|
|
||||||
Execute(actionCtx ActionContext) ActionResult
|
|
||||||
}
|
|
||||||
|
|
||||||
type ActionChain []OrderAction
|
|
||||||
|
|
||||||
func (c ActionChain) Execute(actionCtx ActionContext) []ActionResult {
|
|
||||||
results := make([]ActionResult, 0, len(c))
|
|
||||||
for _, action := range c {
|
|
||||||
result := action.Execute(actionCtx)
|
|
||||||
results = append(results, result)
|
|
||||||
if result.Err != nil {
|
|
||||||
logger.Debug("action failed",
|
|
||||||
"action_id", action.ID(),
|
|
||||||
"order", actionCtx.Order,
|
|
||||||
"user_id", actionCtx.UserId,
|
|
||||||
"error", result.Err,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return results
|
|
||||||
}
|
|
||||||
|
|
||||||
type ActionRegistry map[enums.OrderStatus]ActionChain
|
|
||||||
|
|
||||||
func (r ActionRegistry) Register(status enums.OrderStatus, chain ActionChain) {
|
|
||||||
r[status] = chain
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r ActionRegistry) ExecuteForStatus(status enums.OrderStatus, actionCtx ActionContext) []ActionResult {
|
|
||||||
chain, exists := r[status]
|
|
||||||
if !exists {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return chain.Execute(actionCtx)
|
|
||||||
}
|
|
||||||
|
|
||||||
type ActionFunc func(actionCtx ActionContext) ActionResult
|
|
||||||
|
|
||||||
func (f ActionFunc) ID() ActionID {
|
|
||||||
return "anonymous"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f ActionFunc) Execute(actionCtx ActionContext) ActionResult {
|
|
||||||
return f(actionCtx)
|
|
||||||
}
|
|
||||||
|
|
||||||
type actionAdapter struct {
|
|
||||||
id ActionID
|
|
||||||
fn ActionFunc
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *actionAdapter) ID() ActionID {
|
|
||||||
return a.id
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *actionAdapter) Execute(actionCtx ActionContext) ActionResult {
|
|
||||||
return a.fn(actionCtx)
|
|
||||||
}
|
|
||||||
|
|
||||||
func WithID(id ActionID, fn ActionFunc) OrderAction {
|
|
||||||
return &actionAdapter{id: id, fn: fn}
|
|
||||||
}
|
|
||||||
@@ -6,9 +6,8 @@ import (
|
|||||||
|
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/config"
|
"git.ma-al.com/goc_daniel/b2b/app/config"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/delivery/web"
|
"git.ma-al.com/goc_daniel/b2b/app/delivery/web"
|
||||||
|
logger "git.ma-al.com/goc_daniel/b2b/app/internal/logger"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/service/langsService"
|
"git.ma-al.com/goc_daniel/b2b/app/service/langsService"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/logger"
|
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/version"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/version"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
@@ -24,7 +23,7 @@ var (
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Init("b2b", nil, config.Get().Log.LogLevel, config.Get().Log.LogColorize)
|
logger.Init("b2b", nil, config.Get().App.LogLevel, config.Get().App.LogColorize)
|
||||||
|
|
||||||
// Create and setup the server
|
// Create and setup the server
|
||||||
server := web.New()
|
server := web.New()
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ type Config struct {
|
|||||||
Cors CorsConfig
|
Cors CorsConfig
|
||||||
MeiliSearch MeiliSearchConfig
|
MeiliSearch MeiliSearchConfig
|
||||||
Storage StorageConfig
|
Storage StorageConfig
|
||||||
Log LogConfig
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type I18n struct {
|
type I18n struct {
|
||||||
@@ -86,9 +85,6 @@ type AppConfig struct {
|
|||||||
Version string `env:"APP_VERSION,1.0.0"`
|
Version string `env:"APP_VERSION,1.0.0"`
|
||||||
Environment string `env:"APP_ENVIRONMENT,development"`
|
Environment string `env:"APP_ENVIRONMENT,development"`
|
||||||
BaseURL string `env:"APP_BASE_URL,http://localhost:5173"`
|
BaseURL string `env:"APP_BASE_URL,http://localhost:5173"`
|
||||||
}
|
|
||||||
|
|
||||||
type LogConfig struct {
|
|
||||||
LogLevel string `env:"LOG_LEVEL,warn"`
|
LogLevel string `env:"LOG_LEVEL,warn"`
|
||||||
LogColorize bool `env:"LOG_COLORIZE,true"`
|
LogColorize bool `env:"LOG_COLORIZE,true"`
|
||||||
}
|
}
|
||||||
@@ -215,11 +211,6 @@ func load() *Config {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error("not possible to load env variables for storage : ", err.Error(), "")
|
slog.Error("not possible to load env variables for storage : ", err.Error(), "")
|
||||||
}
|
}
|
||||||
|
|
||||||
err = loadEnv(&cfg.Log)
|
|
||||||
if err != nil {
|
|
||||||
slog.Error("not possible to load env variables for logger : ", err.Error(), "")
|
|
||||||
}
|
|
||||||
cfg.Storage.RootFolder = ResolveRelativePath(cfg.Storage.RootFolder)
|
cfg.Storage.RootFolder = ResolveRelativePath(cfg.Storage.RootFolder)
|
||||||
|
|
||||||
return cfg
|
return cfg
|
||||||
|
|||||||
@@ -6,11 +6,11 @@ import (
|
|||||||
|
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/config"
|
"git.ma-al.com/goc_daniel/b2b/app/config"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/delivery/middleware"
|
"git.ma-al.com/goc_daniel/b2b/app/delivery/middleware"
|
||||||
|
"git.ma-al.com/goc_daniel/b2b/app/internal/logger"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/model"
|
"git.ma-al.com/goc_daniel/b2b/app/model"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/service/authService"
|
"git.ma-al.com/goc_daniel/b2b/app/service/authService"
|
||||||
constdata "git.ma-al.com/goc_daniel/b2b/app/utils/const_data"
|
constdata "git.ma-al.com/goc_daniel/b2b/app/utils/const_data"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/i18n"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/i18n"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/logger"
|
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/nullable"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/nullable"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/response"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/response"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/responseErrors"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/responseErrors"
|
||||||
@@ -75,6 +75,13 @@ func (h *AuthHandler) Login(c fiber.Ctx) error {
|
|||||||
// Attempt login
|
// Attempt login
|
||||||
response, rawRefreshToken, err := h.authService.Login(&req)
|
response, rawRefreshToken, err := h.authService.Login(&req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
|
logger.Error("login failed",
|
||||||
|
"handler", "AuthHandler.Login",
|
||||||
|
|
||||||
|
"email", req.Email,
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).JSON(fiber.Map{
|
return c.Status(responseErrors.GetErrorStatus(err)).JSON(fiber.Map{
|
||||||
"error": responseErrors.GetErrorCode(c, err),
|
"error": responseErrors.GetErrorCode(c, err),
|
||||||
})
|
})
|
||||||
@@ -212,6 +219,12 @@ func (h *AuthHandler) ResetPassword(c fiber.Ctx) error {
|
|||||||
// Reset password (also revokes all refresh tokens for the user)
|
// Reset password (also revokes all refresh tokens for the user)
|
||||||
err := h.authService.ResetPassword(req.Token, req.Password)
|
err := h.authService.ResetPassword(req.Token, req.Password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
|
logger.Error("password reset failed",
|
||||||
|
"handler", "AuthHandler.ResetPassword",
|
||||||
|
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).JSON(fiber.Map{
|
return c.Status(responseErrors.GetErrorStatus(err)).JSON(fiber.Map{
|
||||||
"error": responseErrors.GetErrorCode(c, err),
|
"error": responseErrors.GetErrorCode(c, err),
|
||||||
})
|
})
|
||||||
@@ -313,6 +326,13 @@ func (h *AuthHandler) Register(c fiber.Ctx) error {
|
|||||||
// Attempt registration
|
// Attempt registration
|
||||||
err := h.authService.Register(&req)
|
err := h.authService.Register(&req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
|
logger.Error("registration failed",
|
||||||
|
"handler", "AuthHandler.Register",
|
||||||
|
|
||||||
|
"email", req.Email,
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).JSON(fiber.Map{
|
return c.Status(responseErrors.GetErrorStatus(err)).JSON(fiber.Map{
|
||||||
"error": responseErrors.GetErrorCode(c, err),
|
"error": responseErrors.GetErrorCode(c, err),
|
||||||
})
|
})
|
||||||
@@ -452,6 +472,12 @@ func (h *AuthHandler) GoogleCallback(c fiber.Ctx) error {
|
|||||||
|
|
||||||
response, rawRefreshToken, err := h.authService.HandleGoogleCallback(code)
|
response, rawRefreshToken, err := h.authService.HandleGoogleCallback(code)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
|
logger.Error("google oauth callback failed",
|
||||||
|
"handler", "AuthHandler.GoogleCallback",
|
||||||
|
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).JSON(fiber.Map{
|
return c.Status(responseErrors.GetErrorStatus(err)).JSON(fiber.Map{
|
||||||
"error": responseErrors.GetErrorCode(c, err),
|
"error": responseErrors.GetErrorCode(c, err),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ package restricted
|
|||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"git.ma-al.com/goc_daniel/b2b/app/internal/logger"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/service/addressesService"
|
"git.ma-al.com/goc_daniel/b2b/app/service/addressesService"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/i18n"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/i18n"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/localeExtractor"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/localeExtractor"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/logger"
|
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/nullable"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/nullable"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/response"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/response"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/responseErrors"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/responseErrors"
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ package restricted
|
|||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"git.ma-al.com/goc_daniel/b2b/app/internal/logger"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/service/cartsService"
|
"git.ma-al.com/goc_daniel/b2b/app/service/cartsService"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/i18n"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/i18n"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/localeExtractor"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/localeExtractor"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/logger"
|
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/nullable"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/nullable"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/response"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/response"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/responseErrors"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/responseErrors"
|
||||||
@@ -29,12 +29,12 @@ func NewCartsHandler() *CartsHandler {
|
|||||||
func CartsHandlerRoutes(r fiber.Router) fiber.Router {
|
func CartsHandlerRoutes(r fiber.Router) fiber.Router {
|
||||||
handler := NewCartsHandler()
|
handler := NewCartsHandler()
|
||||||
|
|
||||||
r.Post("/add-new-cart", handler.AddNewCart)
|
r.Get("/add-new-cart", handler.AddNewCart)
|
||||||
r.Delete("/remove-cart", handler.RemoveCart)
|
r.Delete("/remove-cart", handler.RemoveCart)
|
||||||
r.Patch("/change-cart-name", handler.ChangeCartName)
|
r.Get("/change-cart-name", handler.ChangeCartName)
|
||||||
r.Get("/retrieve-carts-info", handler.RetrieveCartsInfo)
|
r.Get("/retrieve-carts-info", handler.RetrieveCartsInfo)
|
||||||
r.Get("/retrieve-cart", handler.RetrieveCart)
|
r.Get("/retrieve-cart", handler.RetrieveCart)
|
||||||
r.Post("/add-product-to-cart", handler.AddProduct)
|
r.Get("/add-product-to-cart", handler.AddProduct)
|
||||||
r.Delete("/remove-product-from-cart", handler.RemoveProduct)
|
r.Delete("/remove-product-from-cart", handler.RemoveProduct)
|
||||||
|
|
||||||
return r
|
return r
|
||||||
|
|||||||
@@ -6,10 +6,10 @@ import (
|
|||||||
"git.ma-al.com/goc_daniel/b2b/app/config"
|
"git.ma-al.com/goc_daniel/b2b/app/config"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/delivery/middleware"
|
"git.ma-al.com/goc_daniel/b2b/app/delivery/middleware"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/delivery/middleware/perms"
|
"git.ma-al.com/goc_daniel/b2b/app/delivery/middleware/perms"
|
||||||
|
"git.ma-al.com/goc_daniel/b2b/app/internal/logger"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/model"
|
"git.ma-al.com/goc_daniel/b2b/app/model"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/service/currencyService"
|
"git.ma-al.com/goc_daniel/b2b/app/service/currencyService"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/i18n"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/i18n"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/logger"
|
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/nullable"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/nullable"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/response"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/response"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/responseErrors"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/responseErrors"
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ import (
|
|||||||
|
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/delivery/middleware"
|
"git.ma-al.com/goc_daniel/b2b/app/delivery/middleware"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/delivery/middleware/perms"
|
"git.ma-al.com/goc_daniel/b2b/app/delivery/middleware/perms"
|
||||||
|
"git.ma-al.com/goc_daniel/b2b/app/internal/logger"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/model"
|
"git.ma-al.com/goc_daniel/b2b/app/model"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/service/customerService"
|
"git.ma-al.com/goc_daniel/b2b/app/service/customerService"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/i18n"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/i18n"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/localeExtractor"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/localeExtractor"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/logger"
|
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/nullable"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/nullable"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/query/query_params"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/query/query_params"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/response"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/response"
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package restricted
|
package restricted
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"git.ma-al.com/goc_daniel/b2b/app/internal/logger"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/service/localeSelectorService"
|
"git.ma-al.com/goc_daniel/b2b/app/service/localeSelectorService"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/i18n"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/i18n"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/logger"
|
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/nullable"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/nullable"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/response"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/response"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/responseErrors"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/responseErrors"
|
||||||
|
|||||||
@@ -3,12 +3,10 @@ package restricted
|
|||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/delivery/middleware"
|
"git.ma-al.com/goc_daniel/b2b/app/internal/logger"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/delivery/middleware/perms"
|
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/service/menuService"
|
"git.ma-al.com/goc_daniel/b2b/app/service/menuService"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/i18n"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/i18n"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/localeExtractor"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/localeExtractor"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/logger"
|
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/nullable"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/nullable"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/response"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/response"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/responseErrors"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/responseErrors"
|
||||||
@@ -32,7 +30,6 @@ func MenuHandlerRoutes(r fiber.Router) fiber.Router {
|
|||||||
r.Get("/get-category-tree", handler.GetCategoryTree)
|
r.Get("/get-category-tree", handler.GetCategoryTree)
|
||||||
r.Get("/get-breadcrumb", handler.GetBreadcrumb)
|
r.Get("/get-breadcrumb", handler.GetBreadcrumb)
|
||||||
r.Get("/get-top-menu", handler.GetTopMenu)
|
r.Get("/get-top-menu", handler.GetTopMenu)
|
||||||
r.Get("/get-customer-management-menu", middleware.Require(perms.UserReadAny), handler.GetCustomerManagementMenu)
|
|
||||||
|
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
@@ -122,18 +119,3 @@ func (h *MenuHandler) GetTopMenu(c fiber.Ctx) error {
|
|||||||
|
|
||||||
return c.JSON(response.Make(&menu, len(menu), i18n.T_(c, response.Message_OK)))
|
return c.JSON(response.Make(&menu, len(menu), i18n.T_(c, response.Message_OK)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *MenuHandler) GetCustomerManagementMenu(c fiber.Ctx) error {
|
|
||||||
langId, ok := localeExtractor.GetLangID(c)
|
|
||||||
if !ok {
|
|
||||||
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrBadAttribute)).
|
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrBadAttribute)))
|
|
||||||
}
|
|
||||||
menu, err := h.menuService.GetCustomerManagementMenu(langId)
|
|
||||||
if err != nil {
|
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).
|
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
|
||||||
}
|
|
||||||
|
|
||||||
return c.JSON(response.Make(&menu, len(menu), i18n.T_(c, response.Message_OK)))
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -2,16 +2,12 @@ package restricted
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/delivery/middleware"
|
"git.ma-al.com/goc_daniel/b2b/app/internal/logger"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/delivery/middleware/perms"
|
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/model"
|
"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/orderService"
|
"git.ma-al.com/goc_daniel/b2b/app/service/orderService"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/i18n"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/i18n"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/localeExtractor"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/localeExtractor"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/logger"
|
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/nullable"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/nullable"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/query/query_params"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/query/query_params"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/response"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/response"
|
||||||
@@ -36,7 +32,7 @@ func OrdersHandlerRoutes(r fiber.Router) fiber.Router {
|
|||||||
r.Get("/list", handler.ListOrders)
|
r.Get("/list", handler.ListOrders)
|
||||||
r.Post("/place-new-order", handler.PlaceNewOrder)
|
r.Post("/place-new-order", handler.PlaceNewOrder)
|
||||||
r.Post("/change-order-address", handler.ChangeOrderAddress)
|
r.Post("/change-order-address", handler.ChangeOrderAddress)
|
||||||
r.Patch("/change-order-status", middleware.Require(perms.OrdersModifyAll), handler.ChangeOrderStatus)
|
r.Get("/change-order-status", handler.ChangeOrderStatus)
|
||||||
|
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
@@ -77,11 +73,6 @@ var columnMappingListOrders map[string]string = map[string]string{
|
|||||||
"name": "b2b_customer_orders.name",
|
"name": "b2b_customer_orders.name",
|
||||||
"country_id": "b2b_customer_orders.country_id",
|
"country_id": "b2b_customer_orders.country_id",
|
||||||
"status": "b2b_customer_orders.status",
|
"status": "b2b_customer_orders.status",
|
||||||
"base_price": "b2b_customer_orders.base_price",
|
|
||||||
"tax_incl": "b2b_customer_orders.tax_incl",
|
|
||||||
"tax_excl": "b2b_customer_orders.tax_excl",
|
|
||||||
"created_at": "b2b_customer_orders.created_at",
|
|
||||||
"updated_at": "b2b_customer_orders.updated_at",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *OrdersHandler) PlaceNewOrder(c fiber.Ctx) error {
|
func (h *OrdersHandler) PlaceNewOrder(c fiber.Ctx) error {
|
||||||
@@ -113,13 +104,7 @@ func (h *OrdersHandler) PlaceNewOrder(c fiber.Ctx) error {
|
|||||||
|
|
||||||
name := c.Query("name")
|
name := c.Query("name")
|
||||||
|
|
||||||
originalUserId, ok := localeExtractor.GetOriginalUserID(c)
|
err = h.ordersService.PlaceNewOrder(userID, uint(cart_id), name, uint(country_id), address_info)
|
||||||
if !ok {
|
|
||||||
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrInvalidBody)).
|
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrInvalidBody)))
|
|
||||||
}
|
|
||||||
|
|
||||||
err = h.ordersService.PlaceNewOrder(userID, uint(cart_id), name, uint(country_id), address_info, originalUserId)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
logger.Error("failed to place order",
|
logger.Error("failed to place order",
|
||||||
@@ -182,19 +167,22 @@ func (h *OrdersHandler) ChangeOrderAddress(c fiber.Ctx) error {
|
|||||||
// we base permissions and user based on target user only.
|
// we base permissions and user based on target user only.
|
||||||
// TODO: well, permissions and all that.
|
// TODO: well, permissions and all that.
|
||||||
func (h *OrdersHandler) ChangeOrderStatus(c fiber.Ctx) error {
|
func (h *OrdersHandler) ChangeOrderStatus(c fiber.Ctx) error {
|
||||||
userId, ok := localeExtractor.GetUserID(c)
|
user, ok := localeExtractor.GetCustomer(c)
|
||||||
if !ok {
|
if !ok {
|
||||||
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrInvalidBody)).
|
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrInvalidBody)).
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrInvalidBody)))
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrInvalidBody)))
|
||||||
}
|
}
|
||||||
|
|
||||||
order_id, err := strconv.Atoi(c.Query("order_id"))
|
order_id_attribute := c.Query("order_id")
|
||||||
|
order_id, err := strconv.Atoi(order_id_attribute)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrBadAttribute)).
|
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrBadAttribute)).
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrBadAttribute)))
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrBadAttribute)))
|
||||||
}
|
}
|
||||||
|
|
||||||
err = h.ordersService.ChangeOrderStatus(userId, uint(order_id), enums.OrderStatus(strings.ToUpper(c.Query("status"))))
|
status := c.Query("status")
|
||||||
|
|
||||||
|
err = h.ordersService.ChangeOrderStatus(user, uint(order_id), status)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
logger.Error("failed to change order status",
|
logger.Error("failed to change order status",
|
||||||
|
|||||||
@@ -4,12 +4,12 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/config"
|
"git.ma-al.com/goc_daniel/b2b/app/config"
|
||||||
|
"git.ma-al.com/goc_daniel/b2b/app/internal/logger"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/model/dbmodel"
|
"git.ma-al.com/goc_daniel/b2b/app/model/dbmodel"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/service/productService"
|
"git.ma-al.com/goc_daniel/b2b/app/service/productService"
|
||||||
constdata "git.ma-al.com/goc_daniel/b2b/app/utils/const_data"
|
constdata "git.ma-al.com/goc_daniel/b2b/app/utils/const_data"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/i18n"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/i18n"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/localeExtractor"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/localeExtractor"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/logger"
|
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/nullable"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/nullable"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/query/query_params"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/query/query_params"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/response"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/response"
|
||||||
|
|||||||
@@ -6,10 +6,10 @@ import (
|
|||||||
"git.ma-al.com/goc_daniel/b2b/app/config"
|
"git.ma-al.com/goc_daniel/b2b/app/config"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/delivery/middleware"
|
"git.ma-al.com/goc_daniel/b2b/app/delivery/middleware"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/delivery/middleware/perms"
|
"git.ma-al.com/goc_daniel/b2b/app/delivery/middleware/perms"
|
||||||
|
"git.ma-al.com/goc_daniel/b2b/app/internal/logger"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/service/productTranslationService"
|
"git.ma-al.com/goc_daniel/b2b/app/service/productTranslationService"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/i18n"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/i18n"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/localeExtractor"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/localeExtractor"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/logger"
|
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/nullable"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/nullable"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/response"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/response"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/responseErrors"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/responseErrors"
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ import (
|
|||||||
|
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/delivery/middleware"
|
"git.ma-al.com/goc_daniel/b2b/app/delivery/middleware"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/delivery/middleware/perms"
|
"git.ma-al.com/goc_daniel/b2b/app/delivery/middleware/perms"
|
||||||
|
"git.ma-al.com/goc_daniel/b2b/app/internal/logger"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/service/meiliService"
|
"git.ma-al.com/goc_daniel/b2b/app/service/meiliService"
|
||||||
searchservice "git.ma-al.com/goc_daniel/b2b/app/service/searchService"
|
searchservice "git.ma-al.com/goc_daniel/b2b/app/service/searchService"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/i18n"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/i18n"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/localeExtractor"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/localeExtractor"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/logger"
|
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/nullable"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/nullable"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/response"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/response"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/responseErrors"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/responseErrors"
|
||||||
|
|||||||
@@ -6,10 +6,10 @@ import (
|
|||||||
"git.ma-al.com/goc_daniel/b2b/app/config"
|
"git.ma-al.com/goc_daniel/b2b/app/config"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/delivery/middleware"
|
"git.ma-al.com/goc_daniel/b2b/app/delivery/middleware"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/delivery/middleware/perms"
|
"git.ma-al.com/goc_daniel/b2b/app/delivery/middleware/perms"
|
||||||
|
"git.ma-al.com/goc_daniel/b2b/app/internal/logger"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/model"
|
"git.ma-al.com/goc_daniel/b2b/app/model"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/service/specificPriceService"
|
"git.ma-al.com/goc_daniel/b2b/app/service/specificPriceService"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/i18n"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/i18n"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/logger"
|
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/nullable"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/nullable"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/response"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/response"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/responseErrors"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/responseErrors"
|
||||||
|
|||||||
@@ -6,10 +6,10 @@ import (
|
|||||||
"git.ma-al.com/goc_daniel/b2b/app/config"
|
"git.ma-al.com/goc_daniel/b2b/app/config"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/delivery/middleware"
|
"git.ma-al.com/goc_daniel/b2b/app/delivery/middleware"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/delivery/middleware/perms"
|
"git.ma-al.com/goc_daniel/b2b/app/delivery/middleware/perms"
|
||||||
|
"git.ma-al.com/goc_daniel/b2b/app/internal/logger"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/service/storageService"
|
"git.ma-al.com/goc_daniel/b2b/app/service/storageService"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/i18n"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/i18n"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/localeExtractor"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/localeExtractor"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/logger"
|
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/nullable"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/nullable"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/response"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/response"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/responseErrors"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/responseErrors"
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ func (h *consoleHandler) Handle(ctx context.Context, r slog.Record) error {
|
|||||||
case slog.LevelWarn:
|
case slog.LevelWarn:
|
||||||
color = yellow
|
color = yellow
|
||||||
case slog.LevelInfo:
|
case slog.LevelInfo:
|
||||||
color = blue
|
color = green
|
||||||
case slog.LevelDebug:
|
case slog.LevelDebug:
|
||||||
color = gray
|
color = gray
|
||||||
}
|
}
|
||||||
@@ -47,9 +47,9 @@ func (h *consoleHandler) Handle(ctx context.Context, r slog.Record) error {
|
|||||||
var msg string
|
var msg string
|
||||||
if h.colorize {
|
if h.colorize {
|
||||||
msg = fmt.Sprintf("%s%s%s %s%s%s %s%s%s",
|
msg = fmt.Sprintf("%s%s%s %s%s%s %s%s%s",
|
||||||
reset, r.Time.Format("15:04:05"), reset,
|
gray, r.Time.Format("15:04:05"), reset,
|
||||||
color, level, reset,
|
color, level, reset,
|
||||||
reset, r.Message, reset)
|
blue, r.Message, reset)
|
||||||
} else {
|
} else {
|
||||||
msg = fmt.Sprintf("%s %s %s", r.Time.Format("15:04:05"), level, r.Message)
|
msg = fmt.Sprintf("%s %s %s", r.Time.Format("15:04:05"), level, r.Message)
|
||||||
}
|
}
|
||||||
@@ -57,7 +57,7 @@ func (h *consoleHandler) Handle(ctx context.Context, r slog.Record) error {
|
|||||||
var pairs []string
|
var pairs []string
|
||||||
r.Attrs(func(attr slog.Attr) bool {
|
r.Attrs(func(attr slog.Attr) bool {
|
||||||
if h.colorize {
|
if h.colorize {
|
||||||
pairs = append(pairs, fmt.Sprintf("%s%s=%s%v%s", green, attr.Key, reset, attr.Value, reset))
|
pairs = append(pairs, fmt.Sprintf("%s=%v%s", blue, attr.Value, reset))
|
||||||
} else {
|
} else {
|
||||||
pairs = append(pairs, fmt.Sprintf("%s=%v", attr.Key, attr.Value))
|
pairs = append(pairs, fmt.Sprintf("%s=%v", attr.Key, attr.Value))
|
||||||
}
|
}
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
package enums
|
|
||||||
|
|
||||||
type OrderStatus string
|
|
||||||
|
|
||||||
const (
|
|
||||||
OrderStatusPending OrderStatus = "PENDING"
|
|
||||||
OrderStatusConfirmed OrderStatus = "CONFIRMED"
|
|
||||||
OrderStatusProcessing OrderStatus = "PROCESSING"
|
|
||||||
OrderStatusShipped OrderStatus = "SHIPPED"
|
|
||||||
OrderStatusOutForDelivery OrderStatus = "OUT_FOR_DELIVERY"
|
|
||||||
OrderStatusDelivered OrderStatus = "DELIVERED"
|
|
||||||
OrderStatusCancelled OrderStatus = "CANCELLED"
|
|
||||||
OrderStatusReturned OrderStatus = "RETURNED"
|
|
||||||
OrderStatusRefunded OrderStatus = "REFUNDED"
|
|
||||||
OrderStatusFailed OrderStatus = "FAILED"
|
|
||||||
)
|
|
||||||
@@ -1,11 +1,5 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
import (
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/model/enums"
|
|
||||||
)
|
|
||||||
|
|
||||||
type CustomerOrder struct {
|
type CustomerOrder struct {
|
||||||
OrderID uint `gorm:"column:order_id;primaryKey;autoIncrement" json:"order_id"`
|
OrderID uint `gorm:"column:order_id;primaryKey;autoIncrement" json:"order_id"`
|
||||||
UserID uint `gorm:"column:user_id;not null;index" json:"user_id"`
|
UserID uint `gorm:"column:user_id;not null;index" json:"user_id"`
|
||||||
@@ -13,12 +7,7 @@ type CustomerOrder struct {
|
|||||||
CountryID uint `gorm:"column:country_id;not null" json:"country_id"`
|
CountryID uint `gorm:"column:country_id;not null" json:"country_id"`
|
||||||
AddressString string `gorm:"column:address_string;not null" json:"address_string"`
|
AddressString string `gorm:"column:address_string;not null" json:"address_string"`
|
||||||
AddressUnparsed *AddressUnparsed `gorm:"-" json:"address_unparsed"`
|
AddressUnparsed *AddressUnparsed `gorm:"-" json:"address_unparsed"`
|
||||||
Status enums.OrderStatus `gorm:"column:status;size:50;not null" json:"status"`
|
Status string `gorm:"column:status;size:50;not null" json:"status"`
|
||||||
BasePrice float64 `gorm:"column:base_price;type:decimal(10,2);not null" json:"base_price"`
|
|
||||||
TaxIncl float64 `gorm:"column:tax_incl;type:decimal(10,2);not null" json:"tax_incl"`
|
|
||||||
TaxExcl float64 `gorm:"column:tax_excl;type:decimal(10,2);not null" json:"tax_excl"`
|
|
||||||
CreatedAt time.Time `gorm:"column:created_at;not null" json:"created_at"`
|
|
||||||
UpdatedAt time.Time `gorm:"column:updated_at;not null" json:"updated_at"`
|
|
||||||
Products []OrderProduct `gorm:"foreignKey:OrderID;references:OrderID" json:"products"`
|
Products []OrderProduct `gorm:"foreignKey:OrderID;references:OrderID" json:"products"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,20 +0,0 @@
|
|||||||
package model
|
|
||||||
|
|
||||||
import (
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/model/enums"
|
|
||||||
)
|
|
||||||
|
|
||||||
type OrderStatusHistory struct {
|
|
||||||
Id uint `gorm:"column:id;primaryKey;autoIncrement"`
|
|
||||||
OrderId uint `gorm:"column:order_id;not null;index:idx_order_status_history_order"`
|
|
||||||
OldStatus *enums.OrderStatus `gorm:"column:old_status;type:varchar(50)"`
|
|
||||||
NewStatus enums.OrderStatus `gorm:"column:new_status;type:varchar(50);not null"`
|
|
||||||
CreatedAt time.Time `gorm:"column:created_at;not null;autoCreateTime"`
|
|
||||||
UserId uint `gorm:"column:user_id;index:idx_order_status_history_user;not null"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (OrderStatusHistory) TableName() string {
|
|
||||||
return "b2b_order_status_history"
|
|
||||||
}
|
|
||||||
@@ -2,7 +2,7 @@ package model
|
|||||||
|
|
||||||
import "encoding/json"
|
import "encoding/json"
|
||||||
|
|
||||||
type B2BMenu struct {
|
type B2BTopMenu struct {
|
||||||
MenuID int `gorm:"column:menu_id;primaryKey;autoIncrement" json:"menu_id"`
|
MenuID int `gorm:"column:menu_id;primaryKey;autoIncrement" json:"menu_id"`
|
||||||
Label json.RawMessage `gorm:"column:label;type:longtext;not null;default:'{}'" json:"label"`
|
Label json.RawMessage `gorm:"column:label;type:longtext;not null;default:'{}'" json:"label"`
|
||||||
ParentID *int `gorm:"column:parent_id;index:FK_b2b_top_menu_parent_id" json:"parent_id,omitempty"`
|
ParentID *int `gorm:"column:parent_id;index:FK_b2b_top_menu_parent_id" json:"parent_id,omitempty"`
|
||||||
@@ -10,22 +10,10 @@ type B2BMenu struct {
|
|||||||
Active int8 `gorm:"column:active;type:tinyint;not null;default:1" json:"active"`
|
Active int8 `gorm:"column:active;type:tinyint;not null;default:1" json:"active"`
|
||||||
Position int `gorm:"column:position;not null;default:1" json:"position"`
|
Position int `gorm:"column:position;not null;default:1" json:"position"`
|
||||||
|
|
||||||
Parent *B2BMenu `gorm:"foreignKey:ParentID;references:MenuID;constraint:OnDelete:RESTRICT,OnUpdate:RESTRICT" json:"parent,omitempty"`
|
Parent *B2BTopMenu `gorm:"foreignKey:ParentID;references:MenuID;constraint:OnDelete:RESTRICT,OnUpdate:RESTRICT" json:"parent,omitempty"`
|
||||||
Children []*B2BMenu `gorm:"foreignKey:ParentID" json:"children,omitempty"`
|
Children []*B2BTopMenu `gorm:"foreignKey:ParentID" json:"children,omitempty"`
|
||||||
}
|
|
||||||
|
|
||||||
type B2BTopMenu struct {
|
|
||||||
B2BMenu
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (B2BTopMenu) TableName() string {
|
func (B2BTopMenu) TableName() string {
|
||||||
return "b2b_top_menu"
|
return "b2b_top_menu"
|
||||||
}
|
}
|
||||||
|
|
||||||
type B2BCustomerManagementMenu struct {
|
|
||||||
B2BMenu
|
|
||||||
}
|
|
||||||
|
|
||||||
func (B2BCustomerManagementMenu) TableName() string {
|
|
||||||
return "b2b_customer_management_menu"
|
|
||||||
}
|
|
||||||
@@ -1,23 +1,19 @@
|
|||||||
package ordersRepo
|
package ordersRepo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
|
||||||
|
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/db"
|
"git.ma-al.com/goc_daniel/b2b/app/db"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/model"
|
"git.ma-al.com/goc_daniel/b2b/app/model"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/model/enums"
|
constdata "git.ma-al.com/goc_daniel/b2b/app/utils/const_data"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/query/filters"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/query/filters"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/query/find"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/query/find"
|
||||||
)
|
)
|
||||||
|
|
||||||
type UIOrdersRepo interface {
|
type UIOrdersRepo interface {
|
||||||
UserHasOrder(user_id uint, order_id uint) (bool, error)
|
UserHasOrder(user_id uint, order_id uint) (bool, error)
|
||||||
Get(orderId uint) (*model.CustomerOrder, error)
|
|
||||||
Find(user_id uint, p find.Paging, filt *filters.FiltersList) (*find.Found[model.CustomerOrder], error)
|
Find(user_id uint, p find.Paging, filt *filters.FiltersList) (*find.Found[model.CustomerOrder], error)
|
||||||
PlaceNewOrder(cart *model.CustomerCart, name string, country_id uint, address_info string, originalUserId uint, base_price float64, tax_incl float64, tax_excl float64) (*model.CustomerOrder, error)
|
PlaceNewOrder(cart *model.CustomerCart, name string, country_id uint, address_info string) error
|
||||||
ChangeOrderAddress(order_id uint, country_id uint, address_info string) error
|
ChangeOrderAddress(order_id uint, country_id uint, address_info string) error
|
||||||
ChangeOrderStatus(orderId uint, newStatus enums.OrderStatus, userId uint) error
|
ChangeOrderStatus(order_id uint, status string) error
|
||||||
GetOrderStatus(orderID uint) (enums.OrderStatus, error)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type OrdersRepo struct{}
|
type OrdersRepo struct{}
|
||||||
@@ -39,18 +35,6 @@ func (repo *OrdersRepo) UserHasOrder(user_id uint, order_id uint) (bool, error)
|
|||||||
return amt >= 1, err
|
return amt >= 1, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repo *OrdersRepo) Get(orderId uint) (*model.CustomerOrder, error) {
|
|
||||||
var order model.CustomerOrder
|
|
||||||
|
|
||||||
err := db.Get().
|
|
||||||
Model(&model.CustomerOrder{}).
|
|
||||||
Preload("Products").
|
|
||||||
Where("order_id = ?", orderId).
|
|
||||||
First(&order).Error
|
|
||||||
|
|
||||||
return &order, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (repo *OrdersRepo) Find(user_id uint, p find.Paging, filt *filters.FiltersList) (*find.Found[model.CustomerOrder], error) {
|
func (repo *OrdersRepo) Find(user_id uint, p find.Paging, filt *filters.FiltersList) (*find.Found[model.CustomerOrder], error) {
|
||||||
var list []model.CustomerOrder
|
var list []model.CustomerOrder
|
||||||
var total int64
|
var total int64
|
||||||
@@ -85,13 +69,13 @@ func (repo *OrdersRepo) Find(user_id uint, p find.Paging, filt *filters.FiltersL
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repo *OrdersRepo) PlaceNewOrder(cart *model.CustomerCart, name string, country_id uint, address_info string, originalUserId uint, base_price float64, tax_incl float64, tax_excl float64) (*model.CustomerOrder, error) {
|
func (repo *OrdersRepo) PlaceNewOrder(cart *model.CustomerCart, name string, country_id uint, address_info string) error {
|
||||||
order := model.CustomerOrder{
|
order := model.CustomerOrder{
|
||||||
UserID: cart.UserID,
|
UserID: cart.UserID,
|
||||||
Name: name,
|
Name: name,
|
||||||
CountryID: country_id,
|
CountryID: country_id,
|
||||||
AddressString: address_info,
|
AddressString: address_info,
|
||||||
Status: enums.OrderStatusPending,
|
Status: constdata.NEW_ORDER_STATUS,
|
||||||
Products: make([]model.OrderProduct, 0, len(cart.Products)),
|
Products: make([]model.OrderProduct, 0, len(cart.Products)),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,35 +86,8 @@ func (repo *OrdersRepo) PlaceNewOrder(cart *model.CustomerCart, name string, cou
|
|||||||
Amount: product.Amount,
|
Amount: product.Amount,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
order.CreatedAt = time.Now()
|
|
||||||
order.UpdatedAt = time.Now()
|
|
||||||
order.BasePrice = base_price
|
|
||||||
order.TaxIncl = tax_incl
|
|
||||||
order.TaxExcl = tax_excl
|
|
||||||
tx := db.Get().Begin()
|
|
||||||
err := tx.Create(&order).Error
|
|
||||||
if err != nil {
|
|
||||||
tx.Rollback()
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
history := model.OrderStatusHistory{
|
|
||||||
OrderId: order.OrderID,
|
|
||||||
OldStatus: nil,
|
|
||||||
NewStatus: enums.OrderStatusPending,
|
|
||||||
UserId: originalUserId,
|
|
||||||
}
|
|
||||||
|
|
||||||
err = tx.Create(&history).Error
|
return db.DB.Create(&order).Error
|
||||||
if err != nil {
|
|
||||||
tx.Rollback()
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
err = tx.Commit().Error
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &order, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repo *OrdersRepo) ChangeOrderAddress(order_id uint, country_id uint, address_info string) error {
|
func (repo *OrdersRepo) ChangeOrderAddress(order_id uint, country_id uint, address_info string) error {
|
||||||
@@ -140,53 +97,14 @@ func (repo *OrdersRepo) ChangeOrderAddress(order_id uint, country_id uint, addre
|
|||||||
Updates(map[string]interface{}{
|
Updates(map[string]interface{}{
|
||||||
"country_id": country_id,
|
"country_id": country_id,
|
||||||
"address_string": address_info,
|
"address_string": address_info,
|
||||||
"updated_at": time.Now(),
|
|
||||||
}).
|
}).
|
||||||
Error
|
Error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repo *OrdersRepo) ChangeOrderStatus(orderID uint, newStatus enums.OrderStatus, userId uint) error {
|
func (repo *OrdersRepo) ChangeOrderStatus(order_id uint, status string) error {
|
||||||
tx := db.Get().Begin()
|
return db.DB.
|
||||||
|
Table("b2b_customer_orders").
|
||||||
var currentStatus enums.OrderStatus
|
Where("order_id = ?", order_id).
|
||||||
err := tx.Table("b2b_customer_orders").
|
Update("status", status).
|
||||||
Select("status").
|
Error
|
||||||
Where("order_id = ?", orderID).
|
|
||||||
Scan(¤tStatus).Error
|
|
||||||
if err != nil {
|
|
||||||
tx.Rollback()
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = tx.Table("b2b_customer_orders").
|
|
||||||
Where("order_id = ?", orderID).
|
|
||||||
Update("status", string(newStatus)).Error
|
|
||||||
if err != nil {
|
|
||||||
tx.Rollback()
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
history := model.OrderStatusHistory{
|
|
||||||
OrderId: orderID,
|
|
||||||
OldStatus: ¤tStatus,
|
|
||||||
NewStatus: newStatus,
|
|
||||||
UserId: userId,
|
|
||||||
}
|
|
||||||
|
|
||||||
err = tx.Create(&history).Error
|
|
||||||
if err != nil {
|
|
||||||
tx.Rollback()
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return tx.Commit().Error
|
|
||||||
}
|
|
||||||
|
|
||||||
func (repo *OrdersRepo) GetOrderStatus(orderID uint) (enums.OrderStatus, error) {
|
|
||||||
var status enums.OrderStatus
|
|
||||||
err := db.DB.Table("b2b_customer_orders").
|
|
||||||
Select("status").
|
|
||||||
Where("order_id = ?", orderID).
|
|
||||||
Scan(&status).Error
|
|
||||||
return status, err
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import (
|
|||||||
type UIRoutesRepo interface {
|
type UIRoutesRepo interface {
|
||||||
GetRoutes(langId uint, roleId uint) ([]model.Route, error)
|
GetRoutes(langId uint, roleId uint) ([]model.Route, error)
|
||||||
GetTopMenu(id uint, roleId uint) ([]model.B2BTopMenu, error)
|
GetTopMenu(id uint, roleId uint) ([]model.B2BTopMenu, error)
|
||||||
GetCustomerManagementMenu(langId uint) ([]model.B2BCustomerManagementMenu, error)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type RoutesRepo struct{}
|
type RoutesRepo struct{}
|
||||||
@@ -39,23 +38,10 @@ func (p *RoutesRepo) GetTopMenu(langId uint, roleId uint) ([]model.B2BTopMenu, e
|
|||||||
Get().
|
Get().
|
||||||
Model(model.B2BTopMenu{}).
|
Model(model.B2BTopMenu{}).
|
||||||
Joins("JOIN b2b_top_menu_roles tmr ON tmr.top_menu_id = b2b_top_menu.menu_id").
|
Joins("JOIN b2b_top_menu_roles tmr ON tmr.top_menu_id = b2b_top_menu.menu_id").
|
||||||
Where(model.B2BTopMenu{B2BMenu: model.B2BMenu{Active: 1}}).
|
Where(model.B2BTopMenu{Active: 1}).
|
||||||
Where("tmr.role_id = ?", roleId).
|
Where("tmr.role_id = ?", roleId).
|
||||||
Order("b2b_top_menu.parent_id ASC, b2b_top_menu.position ASC").
|
Order("b2b_top_menu.parent_id ASC, b2b_top_menu.position ASC").
|
||||||
Find(&menus).Error
|
Find(&menus).Error
|
||||||
|
|
||||||
return menus, err
|
return menus, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *RoutesRepo) GetCustomerManagementMenu(langId uint) ([]model.B2BCustomerManagementMenu, error) {
|
|
||||||
var menus []model.B2BCustomerManagementMenu
|
|
||||||
|
|
||||||
err := db.
|
|
||||||
Get().
|
|
||||||
Model(model.B2BCustomerManagementMenu{}).
|
|
||||||
Where(model.B2BCustomerManagementMenu{B2BMenu: model.B2BMenu{Active: 1}}).
|
|
||||||
Order("b2b_customer_management_menu.parent_id ASC, b2b_customer_management_menu.position ASC").
|
|
||||||
Find(&menus).Error
|
|
||||||
|
|
||||||
return menus, err
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import (
|
|||||||
roleRepo "git.ma-al.com/goc_daniel/b2b/app/repos/rolesRepo"
|
roleRepo "git.ma-al.com/goc_daniel/b2b/app/repos/rolesRepo"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/service/emailService"
|
"git.ma-al.com/goc_daniel/b2b/app/service/emailService"
|
||||||
constdata "git.ma-al.com/goc_daniel/b2b/app/utils/const_data"
|
constdata "git.ma-al.com/goc_daniel/b2b/app/utils/const_data"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/logger"
|
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/responseErrors"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/responseErrors"
|
||||||
|
|
||||||
"github.com/dlclark/regexp2"
|
"github.com/dlclark/regexp2"
|
||||||
@@ -69,47 +68,22 @@ func (s *AuthService) Login(req *model.LoginRequest) (*model.AuthResponse, strin
|
|||||||
// Find user by email
|
// Find user by email
|
||||||
if err := s.db.Preload("Role.Permissions").Where("email = ?", req.Email).First(&user).Error; err != nil {
|
if err := s.db.Preload("Role.Permissions").Where("email = ?", req.Email).First(&user).Error; err != nil {
|
||||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
logger.Info("login failed - invalid credentials",
|
|
||||||
"service", "AuthService.Login",
|
|
||||||
"email", req.Email,
|
|
||||||
"reason", "user not found",
|
|
||||||
)
|
|
||||||
return nil, "", responseErrors.ErrInvalidCredentials
|
return nil, "", responseErrors.ErrInvalidCredentials
|
||||||
}
|
}
|
||||||
logger.Error("login failed - database error",
|
|
||||||
"service", "AuthService.Login",
|
|
||||||
"email", req.Email,
|
|
||||||
"error", err.Error(),
|
|
||||||
)
|
|
||||||
return nil, "", fmt.Errorf("database error: %w", err)
|
return nil, "", fmt.Errorf("database error: %w", err)
|
||||||
}
|
}
|
||||||
// Check if user is active
|
// Check if user is active
|
||||||
if !user.IsActive {
|
if !user.IsActive {
|
||||||
logger.Info("login failed - user inactive",
|
|
||||||
"service", "AuthService.Login",
|
|
||||||
"email", req.Email,
|
|
||||||
"reason", "user account is inactive",
|
|
||||||
)
|
|
||||||
return nil, "", responseErrors.ErrUserInactive
|
return nil, "", responseErrors.ErrUserInactive
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if email is verified
|
// Check if email is verified
|
||||||
if !user.EmailVerified {
|
if !user.EmailVerified {
|
||||||
logger.Info("login failed - email not verified",
|
|
||||||
"service", "AuthService.Login",
|
|
||||||
"email", req.Email,
|
|
||||||
"reason", "email not verified",
|
|
||||||
)
|
|
||||||
return nil, "", responseErrors.ErrEmailNotVerified
|
return nil, "", responseErrors.ErrEmailNotVerified
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify password
|
// Verify password
|
||||||
if err := bcrypt.CompareHashAndPassword([]byte(user.Password), []byte(req.Password)); err != nil {
|
if err := bcrypt.CompareHashAndPassword([]byte(user.Password), []byte(req.Password)); err != nil {
|
||||||
logger.Info("login failed - invalid credentials",
|
|
||||||
"service", "AuthService.Login",
|
|
||||||
"email", req.Email,
|
|
||||||
"reason", "wrong password",
|
|
||||||
)
|
|
||||||
return nil, "", responseErrors.ErrInvalidCredentials
|
return nil, "", responseErrors.ErrInvalidCredentials
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,38 +94,22 @@ func (s *AuthService) Login(req *model.LoginRequest) (*model.AuthResponse, strin
|
|||||||
if req.LangID != nil {
|
if req.LangID != nil {
|
||||||
_, err := s.GetLangISOCode(*req.LangID)
|
_, err := s.GetLangISOCode(*req.LangID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Warn("login failed - invalid language ID",
|
|
||||||
"service", "AuthService.Login",
|
|
||||||
"email", req.Email,
|
|
||||||
"reason", "invalid language ID",
|
|
||||||
)
|
|
||||||
return nil, "", responseErrors.ErrBadLangID
|
return nil, "", responseErrors.ErrBadLangID
|
||||||
}
|
}
|
||||||
user.LangID = *req.LangID
|
user.LangID = *req.LangID
|
||||||
}
|
}
|
||||||
|
|
||||||
user.Country = nil
|
|
||||||
s.db.Save(&user)
|
s.db.Save(&user)
|
||||||
|
|
||||||
// Generate access token (JWT)
|
// Generate access token (JWT)
|
||||||
accessToken, err := s.generateAccessToken(&user)
|
accessToken, err := s.generateAccessToken(&user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("login failed - token generation error",
|
|
||||||
"service", "AuthService.Login",
|
|
||||||
"email", req.Email,
|
|
||||||
"error", err.Error(),
|
|
||||||
)
|
|
||||||
return nil, "", fmt.Errorf("failed to generate access token: %w", err)
|
return nil, "", fmt.Errorf("failed to generate access token: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate opaque refresh token and store in DB
|
// Generate opaque refresh token and store in DB
|
||||||
rawRefreshToken, err := s.createRefreshToken(user.ID)
|
rawRefreshToken, err := s.createRefreshToken(user.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("login failed - refresh token creation error",
|
|
||||||
"service", "AuthService.Login",
|
|
||||||
"email", req.Email,
|
|
||||||
"error", err.Error(),
|
|
||||||
)
|
|
||||||
return nil, "", fmt.Errorf("failed to create refresh token: %w", err)
|
return nil, "", fmt.Errorf("failed to create refresh token: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,11 +170,6 @@ func (s *AuthService) Register(req *model.RegisterRequest) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := s.db.Create(&user).Error; err != nil {
|
if err := s.db.Create(&user).Error; err != nil {
|
||||||
logger.Error("registration failed - database error",
|
|
||||||
"service", "AuthService.Register",
|
|
||||||
"email", req.Email,
|
|
||||||
"error", err.Error(),
|
|
||||||
)
|
|
||||||
return fmt.Errorf("failed to create user: %w", err)
|
return fmt.Errorf("failed to create user: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -228,11 +181,8 @@ func (s *AuthService) Register(req *model.RegisterRequest) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := s.email.SendVerificationEmail(user.Email, user.EmailVerificationToken, baseURL, lang); err != nil {
|
if err := s.email.SendVerificationEmail(user.Email, user.EmailVerificationToken, baseURL, lang); err != nil {
|
||||||
logger.Warn("failed to send verification email",
|
// Log error but don't fail registration - user can request resend
|
||||||
"service", "AuthService.Register",
|
_ = err
|
||||||
"email", req.Email,
|
|
||||||
"error", err.Error(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -260,7 +210,6 @@ func (s *AuthService) CompleteRegistration(req *model.CompleteRegistrationReques
|
|||||||
user.EmailVerificationToken = ""
|
user.EmailVerificationToken = ""
|
||||||
user.EmailVerificationExpires = nil
|
user.EmailVerificationExpires = nil
|
||||||
|
|
||||||
user.Country = nil
|
|
||||||
if err := s.db.Save(&user).Error; err != nil {
|
if err := s.db.Save(&user).Error; err != nil {
|
||||||
return nil, "", fmt.Errorf("failed to update user: %w", err)
|
return nil, "", fmt.Errorf("failed to update user: %w", err)
|
||||||
}
|
}
|
||||||
@@ -329,7 +278,6 @@ func (s *AuthService) RequestPasswordReset(emailAddr string) error {
|
|||||||
user.PasswordResetToken = token
|
user.PasswordResetToken = token
|
||||||
user.PasswordResetExpires = &expiresAt
|
user.PasswordResetExpires = &expiresAt
|
||||||
user.LastPasswordResetRequest = &now
|
user.LastPasswordResetRequest = &now
|
||||||
user.Country = nil
|
|
||||||
if err := s.db.Save(&user).Error; err != nil {
|
if err := s.db.Save(&user).Error; err != nil {
|
||||||
return fmt.Errorf("failed to save reset token: %w", err)
|
return fmt.Errorf("failed to save reset token: %w", err)
|
||||||
}
|
}
|
||||||
@@ -356,10 +304,6 @@ func (s *AuthService) ResetPassword(token, newPassword string) error {
|
|||||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
return responseErrors.ErrInvalidResetToken
|
return responseErrors.ErrInvalidResetToken
|
||||||
}
|
}
|
||||||
logger.Error("password reset failed - database error",
|
|
||||||
"service", "AuthService.ResetPassword",
|
|
||||||
"error", err.Error(),
|
|
||||||
)
|
|
||||||
return fmt.Errorf("database error: %w", err)
|
return fmt.Errorf("database error: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -384,12 +328,7 @@ func (s *AuthService) ResetPassword(token, newPassword string) error {
|
|||||||
user.PasswordResetToken = ""
|
user.PasswordResetToken = ""
|
||||||
user.PasswordResetExpires = nil
|
user.PasswordResetExpires = nil
|
||||||
|
|
||||||
user.Country = nil
|
|
||||||
if err := s.db.Save(&user).Error; err != nil {
|
if err := s.db.Save(&user).Error; err != nil {
|
||||||
logger.Error("password reset failed - database error",
|
|
||||||
"service", "AuthService.ResetPassword",
|
|
||||||
"error", err.Error(),
|
|
||||||
)
|
|
||||||
return fmt.Errorf("failed to update password: %w", err)
|
return fmt.Errorf("failed to update password: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -600,7 +539,6 @@ func (s *AuthService) UpdateJWTToken(user *model.Customer) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Save the updated user
|
// Save the updated user
|
||||||
user.Country = nil
|
|
||||||
if err := s.db.Save(user).Error; err != nil {
|
if err := s.db.Save(user).Error; err != nil {
|
||||||
return "", fmt.Errorf("database error: %w", err)
|
return "", fmt.Errorf("database error: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,12 +8,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/config"
|
"git.ma-al.com/goc_daniel/b2b/app/config"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/model"
|
"git.ma-al.com/goc_daniel/b2b/app/model"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/logger"
|
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/responseErrors"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/responseErrors"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/view"
|
"git.ma-al.com/goc_daniel/b2b/app/view"
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
@@ -79,20 +77,12 @@ func (s *AuthService) HandleGoogleCallback(code string) (*model.AuthResponse, st
|
|||||||
// Find or create user
|
// Find or create user
|
||||||
user, err := s.findOrCreateGoogleUser(userInfo)
|
user, err := s.findOrCreateGoogleUser(userInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if strings.Contains(err.Error(), "database") {
|
|
||||||
logger.Error("google oauth callback failed - database error",
|
|
||||||
"service", "AuthService.HandleGoogleCallback",
|
|
||||||
"email", userInfo.Email,
|
|
||||||
"error", err.Error(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
return nil, "", err
|
return nil, "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update last login
|
// Update last login
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
user.LastLoginAt = &now
|
user.LastLoginAt = &now
|
||||||
user.Country = nil
|
|
||||||
s.db.Save(user)
|
s.db.Save(user)
|
||||||
|
|
||||||
// Generate access token (JWT)
|
// Generate access token (JWT)
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package cartsService
|
package cartsService
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"git.ma-al.com/goc_daniel/b2b/app/internal/logger"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/model"
|
"git.ma-al.com/goc_daniel/b2b/app/model"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/repos/cartsRepo"
|
"git.ma-al.com/goc_daniel/b2b/app/repos/cartsRepo"
|
||||||
constdata "git.ma-al.com/goc_daniel/b2b/app/utils/const_data"
|
constdata "git.ma-al.com/goc_daniel/b2b/app/utils/const_data"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/logger"
|
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/responseErrors"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/responseErrors"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import (
|
|||||||
"git.ma-al.com/goc_daniel/b2b/app/templ/emails"
|
"git.ma-al.com/goc_daniel/b2b/app/templ/emails"
|
||||||
constdata "git.ma-al.com/goc_daniel/b2b/app/utils/const_data"
|
constdata "git.ma-al.com/goc_daniel/b2b/app/utils/const_data"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/i18n"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/i18n"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/logger"
|
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/view"
|
"git.ma-al.com/goc_daniel/b2b/app/view"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -45,11 +44,6 @@ func getLangID(isoCode string) uint {
|
|||||||
// SendEmail sends an email to the specified recipient
|
// SendEmail sends an email to the specified recipient
|
||||||
func (s *EmailService) SendEmail(to, subject, body string) error {
|
func (s *EmailService) SendEmail(to, subject, body string) error {
|
||||||
if !s.config.Enabled {
|
if !s.config.Enabled {
|
||||||
logger.Debug("email service is disabled",
|
|
||||||
"service", "EmailService.SendEmail",
|
|
||||||
"to", to,
|
|
||||||
"subject", subject,
|
|
||||||
)
|
|
||||||
return fmt.Errorf("email service is disabled")
|
return fmt.Errorf("email service is disabled")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,12 +69,6 @@ func (s *EmailService) SendEmail(to, subject, body string) error {
|
|||||||
// Send email
|
// Send email
|
||||||
addr := fmt.Sprintf("%s:%d", s.config.SMTPHost, s.config.SMTPPort)
|
addr := fmt.Sprintf("%s:%d", s.config.SMTPHost, s.config.SMTPPort)
|
||||||
if err := smtp.SendMail(addr, auth, s.config.FromEmail, []string{to}, []byte(msg.String())); err != nil {
|
if err := smtp.SendMail(addr, auth, s.config.FromEmail, []string{to}, []byte(msg.String())); err != nil {
|
||||||
logger.Error("failed to send email",
|
|
||||||
"service", "EmailService.SendEmail",
|
|
||||||
"to", to,
|
|
||||||
"subject", subject,
|
|
||||||
"error", err.Error(),
|
|
||||||
)
|
|
||||||
return fmt.Errorf("failed to send email: %w", err)
|
return fmt.Errorf("failed to send email: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,12 +120,9 @@ func (s *EmailService) SendNewUserAdminNotification(userEmail, userName, baseURL
|
|||||||
// SendNewOrderPlacedNotification sends an email to admin when new order is placed
|
// SendNewOrderPlacedNotification sends an email to admin when new order is placed
|
||||||
func (s *EmailService) SendNewOrderPlacedNotification(userID uint) error {
|
func (s *EmailService) SendNewOrderPlacedNotification(userID uint) error {
|
||||||
if s.config.AdminEmail == "" {
|
if s.config.AdminEmail == "" {
|
||||||
logger.Warn("no admin email setup in the config",
|
return nil // No admin email configured
|
||||||
"service", "EmailService.SendNewOrderPlacedNotification",
|
|
||||||
"user_id", userID,
|
|
||||||
)
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
subject := "New Order Created"
|
subject := "New Order Created"
|
||||||
body := s.newOrderPlacedTemplate(userID)
|
body := s.newOrderPlacedTemplate(userID)
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import (
|
|||||||
routesRepo "git.ma-al.com/goc_daniel/b2b/app/repos/routesRepo"
|
routesRepo "git.ma-al.com/goc_daniel/b2b/app/repos/routesRepo"
|
||||||
constdata "git.ma-al.com/goc_daniel/b2b/app/utils/const_data"
|
constdata "git.ma-al.com/goc_daniel/b2b/app/utils/const_data"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/i18n"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/i18n"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/logger"
|
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/responseErrors"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/responseErrors"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -194,52 +193,18 @@ func (s *MenuService) GetBreadcrumb(root_category_id uint, start_category_id uin
|
|||||||
return breadcrumb, nil
|
return breadcrumb, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MenuService) GetTopMenu(languageId uint, roleId uint) ([]*model.B2BMenu, error) {
|
func (s *MenuService) GetTopMenu(languageId uint, roleId uint) ([]*model.B2BTopMenu, error) {
|
||||||
items, err := s.routesRepo.GetTopMenu(languageId, roleId)
|
items, err := s.routesRepo.GetTopMenu(languageId, roleId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("failed to get top menu",
|
|
||||||
"handler", "ManuService.GetTopMenu",
|
|
||||||
"language_id", languageId,
|
|
||||||
"role_id", roleId,
|
|
||||||
"error", err.Error(),
|
|
||||||
)
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
menus := make([]model.B2BMenu, len(items))
|
menuMap := make(map[int]*model.B2BTopMenu, len(items))
|
||||||
for i := range items {
|
roots := make([]*model.B2BTopMenu, 0)
|
||||||
menus[i] = items[i].B2BMenu
|
|
||||||
}
|
|
||||||
|
|
||||||
return buildMenu(menus), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *MenuService) GetCustomerManagementMenu(languageId uint) ([]*model.B2BMenu, error) {
|
|
||||||
items, err := s.routesRepo.GetCustomerManagementMenu(languageId)
|
|
||||||
if err != nil {
|
|
||||||
logger.Error("failed to get customer management menu",
|
|
||||||
"handler", "ManuService.GetCustomerManagementMenu",
|
|
||||||
"language_id", languageId,
|
|
||||||
"error", err.Error(),
|
|
||||||
)
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
menus := make([]model.B2BMenu, len(items))
|
|
||||||
for i := range items {
|
|
||||||
menus[i] = items[i].B2BMenu
|
|
||||||
}
|
|
||||||
|
|
||||||
return buildMenu(menus), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func buildMenu(items []model.B2BMenu) []*model.B2BMenu {
|
|
||||||
menuMap := make(map[int]*model.B2BMenu, len(items))
|
|
||||||
roots := make([]*model.B2BMenu, 0)
|
|
||||||
|
|
||||||
for i := range items {
|
for i := range items {
|
||||||
menu := &items[i]
|
menu := &items[i]
|
||||||
menu.Children = make([]*model.B2BMenu, 0)
|
menu.Children = make([]*model.B2BTopMenu, 0)
|
||||||
menuMap[menu.MenuID] = menu
|
menuMap[menu.MenuID] = menu
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -261,7 +226,7 @@ func buildMenu(items []model.B2BMenu) []*model.B2BMenu {
|
|||||||
parent.Children = append(parent.Children, menu)
|
parent.Children = append(parent.Children, menu)
|
||||||
}
|
}
|
||||||
|
|
||||||
return roots
|
return roots, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MenuService) appendAdditional(all_categories *[]model.ScannedCategory, id_lang uint, iso_code string) {
|
func (s *MenuService) appendAdditional(all_categories *[]model.ScannedCategory, id_lang uint, iso_code string) {
|
||||||
|
|||||||
@@ -3,17 +3,13 @@ package orderService
|
|||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/actions/orderStatusActions"
|
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/delivery/middleware/perms"
|
"git.ma-al.com/goc_daniel/b2b/app/delivery/middleware/perms"
|
||||||
|
"git.ma-al.com/goc_daniel/b2b/app/internal/logger"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/model"
|
"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/repos/cartsRepo"
|
"git.ma-al.com/goc_daniel/b2b/app/repos/cartsRepo"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/repos/ordersRepo"
|
"git.ma-al.com/goc_daniel/b2b/app/repos/ordersRepo"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/repos/productsRepo"
|
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/service/addressesService"
|
"git.ma-al.com/goc_daniel/b2b/app/service/addressesService"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/service/emailService"
|
"git.ma-al.com/goc_daniel/b2b/app/service/emailService"
|
||||||
constdata "git.ma-al.com/goc_daniel/b2b/app/utils/const_data"
|
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/logger"
|
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/query/filters"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/query/filters"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/query/find"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/query/find"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/responseErrors"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/responseErrors"
|
||||||
@@ -22,36 +18,19 @@ import (
|
|||||||
type OrderService struct {
|
type OrderService struct {
|
||||||
ordersRepo ordersRepo.UIOrdersRepo
|
ordersRepo ordersRepo.UIOrdersRepo
|
||||||
cartsRepo cartsRepo.UICartsRepo
|
cartsRepo cartsRepo.UICartsRepo
|
||||||
productsRepo productsRepo.UIProductsRepo
|
|
||||||
addressesService *addressesService.AddressesService
|
addressesService *addressesService.AddressesService
|
||||||
emailService *emailService.EmailService
|
emailService *emailService.EmailService
|
||||||
actionRegistry *orderStatusActions.ActionRegistry
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func New() *OrderService {
|
func New() *OrderService {
|
||||||
return &OrderService{
|
return &OrderService{
|
||||||
ordersRepo: ordersRepo.New(),
|
ordersRepo: ordersRepo.New(),
|
||||||
cartsRepo: cartsRepo.New(),
|
cartsRepo: cartsRepo.New(),
|
||||||
productsRepo: productsRepo.New(),
|
|
||||||
addressesService: addressesService.New(),
|
addressesService: addressesService.New(),
|
||||||
emailService: emailService.NewEmailService(),
|
emailService: emailService.NewEmailService(),
|
||||||
actionRegistry: &orderStatusActions.GlobalRegistry,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var ValidStatuses = map[enums.OrderStatus]bool{
|
|
||||||
enums.OrderStatusPending: true,
|
|
||||||
enums.OrderStatusConfirmed: true,
|
|
||||||
enums.OrderStatusProcessing: true,
|
|
||||||
enums.OrderStatusShipped: true,
|
|
||||||
enums.OrderStatusOutForDelivery: true,
|
|
||||||
enums.OrderStatusDelivered: true,
|
|
||||||
enums.OrderStatusCancelled: true,
|
|
||||||
enums.OrderStatusReturned: true,
|
|
||||||
enums.OrderStatusRefunded: true,
|
|
||||||
enums.OrderStatusFailed: true,
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *OrderService) Find(user *model.Customer, p find.Paging, filt *filters.FiltersList) (*find.Found[model.CustomerOrder], error) {
|
func (s *OrderService) Find(user *model.Customer, p find.Paging, filt *filters.FiltersList) (*find.Found[model.CustomerOrder], error) {
|
||||||
if !user.HasPermission(perms.OrdersViewAll) {
|
if !user.HasPermission(perms.OrdersViewAll) {
|
||||||
// append filter to view only this user's orders
|
// append filter to view only this user's orders
|
||||||
@@ -80,7 +59,7 @@ func (s *OrderService) Find(user *model.Customer, p find.Paging, filt *filters.F
|
|||||||
return list, nil
|
return list, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *OrderService) PlaceNewOrder(user_id uint, cart_id uint, name string, country_id uint, address_info string, originalUserId uint) error {
|
func (s *OrderService) PlaceNewOrder(user_id uint, cart_id uint, name string, country_id uint, address_info string) error {
|
||||||
_, err := s.addressesService.ValidateAddressJson(address_info, country_id)
|
_, err := s.addressesService.ValidateAddressJson(address_info, country_id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -106,10 +85,8 @@ func (s *OrderService) PlaceNewOrder(user_id uint, cart_id uint, name string, co
|
|||||||
name = *cart.Name
|
name = *cart.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
base_price, tax_incl, tax_excl, err := s.getOrderTotalPrice(user_id, cart_id, country_id)
|
|
||||||
|
|
||||||
// all checks passed
|
// all checks passed
|
||||||
order, err := s.ordersRepo.PlaceNewOrder(cart, name, country_id, address_info, originalUserId, base_price, tax_incl, tax_excl)
|
err = s.ordersRepo.PlaceNewOrder(cart, name, country_id, address_info)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -126,8 +103,19 @@ func (s *OrderService) PlaceNewOrder(user_id uint, cart_id uint, name string, co
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return s.ChangeOrderStatus(user_id, order.OrderID, enums.OrderStatusPending)
|
// send email to admin
|
||||||
|
go func(user_id uint) {
|
||||||
|
err := s.emailService.SendNewOrderPlacedNotification(user_id)
|
||||||
|
if err != nil {
|
||||||
|
logger.Warn("failed to send new order notification",
|
||||||
|
"service", "orderService",
|
||||||
|
"user_id", user_id,
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}(user_id)
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *OrderService) ChangeOrderAddress(user *model.Customer, order_id uint, country_id uint, address_info string) error {
|
func (s *OrderService) ChangeOrderAddress(user *model.Customer, order_id uint, country_id uint, address_info string) error {
|
||||||
@@ -150,57 +138,18 @@ func (s *OrderService) ChangeOrderAddress(user *model.Customer, order_id uint, c
|
|||||||
return s.ordersRepo.ChangeOrderAddress(order_id, country_id, address_info)
|
return s.ordersRepo.ChangeOrderAddress(order_id, country_id, address_info)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *OrderService) ChangeOrderStatus(userId, orderId uint, newStatus enums.OrderStatus) error {
|
// This is obiously just an initial version of this function
|
||||||
order, err := s.ordersRepo.Get(orderId)
|
func (s *OrderService) ChangeOrderStatus(user *model.Customer, order_id uint, status string) error {
|
||||||
if err != nil {
|
if !user.HasPermission(perms.OrdersModifyAll) {
|
||||||
return err
|
exists, err := s.ordersRepo.UserHasOrder(user.ID, order_id)
|
||||||
}
|
|
||||||
if order == nil {
|
|
||||||
return responseErrors.ErrOrderNotFound
|
|
||||||
}
|
|
||||||
|
|
||||||
if !ValidStatuses[newStatus] {
|
|
||||||
return responseErrors.ErrInvalidStatus
|
|
||||||
}
|
|
||||||
|
|
||||||
err = s.ordersRepo.ChangeOrderStatus(order.OrderID, newStatus, userId)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
actionCtx := orderStatusActions.ActionContext{
|
if !exists {
|
||||||
Order: order,
|
return responseErrors.ErrUserHasNoSuchOrder
|
||||||
UserId: &userId,
|
}
|
||||||
EmailService: s.emailService,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
return s.ordersRepo.ChangeOrderStatus(order_id, status)
|
||||||
_ = s.actionRegistry.ExecuteForStatus(newStatus, actionCtx)
|
|
||||||
}()
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *OrderService) getOrderTotalPrice(user_id uint, cart_id uint, country_id uint) (float64, float64, float64, error) {
|
|
||||||
cart, err := s.cartsRepo.RetrieveCart(user_id, cart_id)
|
|
||||||
if err != nil {
|
|
||||||
return 0.0, 0.0, 0.0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
base_price := 0.0
|
|
||||||
tax_incl := 0.0
|
|
||||||
tax_excl := 0.0
|
|
||||||
|
|
||||||
for _, product := range cart.Products {
|
|
||||||
prices, err := s.productsRepo.GetPrice(product.ProductID, product.ProductAttributeID, constdata.SHOP_ID, user_id, country_id, product.Amount)
|
|
||||||
if err != nil {
|
|
||||||
return 0.0, 0.0, 0.0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
base_price += prices.Base
|
|
||||||
tax_incl += prices.FinalTaxIncl
|
|
||||||
tax_excl += prices.FinalTaxExcl
|
|
||||||
}
|
|
||||||
|
|
||||||
return base_price, tax_incl, tax_excl, nil
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,14 +14,6 @@ func GetLangID(c fiber.Ctx) (uint, bool) {
|
|||||||
return user_locale.OriginalUser.LangID, true
|
return user_locale.OriginalUser.LangID, true
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetOriginalUserID(c fiber.Ctx) (uint, bool) {
|
|
||||||
user_locale, ok := c.Locals(constdata.USER_LOCALE).(*model.UserLocale)
|
|
||||||
if !ok || user_locale.OriginalUser == nil {
|
|
||||||
return 0, false
|
|
||||||
}
|
|
||||||
return user_locale.OriginalUser.ID, true
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetUserID(c fiber.Ctx) (uint, bool) {
|
func GetUserID(c fiber.Ctx) (uint, bool) {
|
||||||
user_locale, ok := c.Locals(constdata.USER_LOCALE).(*model.UserLocale)
|
user_locale, ok := c.Locals(constdata.USER_LOCALE).(*model.UserLocale)
|
||||||
if !ok || user_locale.User == nil {
|
if !ok || user_locale.User == nil {
|
||||||
|
|||||||
@@ -71,8 +71,6 @@ var (
|
|||||||
// Typed errors for orders handler
|
// Typed errors for orders handler
|
||||||
ErrEmptyCart = errors.New("the cart is empty")
|
ErrEmptyCart = errors.New("the cart is empty")
|
||||||
ErrUserHasNoSuchOrder = errors.New("user does not have order with given id")
|
ErrUserHasNoSuchOrder = errors.New("user does not have order with given id")
|
||||||
ErrInvalidStatus = errors.New("invalid order status")
|
|
||||||
ErrOrderNotFound = errors.New("order not found")
|
|
||||||
|
|
||||||
// Typed errors for price reduction handler
|
// Typed errors for price reduction handler
|
||||||
ErrInvalidReductionType = errors.New("invalid reduction type: must be 'amount' or 'percentage'")
|
ErrInvalidReductionType = errors.New("invalid reduction type: must be 'amount' or 'percentage'")
|
||||||
@@ -316,8 +314,7 @@ func GetErrorStatus(err error) int {
|
|||||||
errors.Is(err, ErrMaxAmtOfAddressesReached),
|
errors.Is(err, ErrMaxAmtOfAddressesReached),
|
||||||
errors.Is(err, ErrUserHasNoSuchAddress),
|
errors.Is(err, ErrUserHasNoSuchAddress),
|
||||||
errors.Is(err, ErrInvalidCountryID),
|
errors.Is(err, ErrInvalidCountryID),
|
||||||
errors.Is(err, ErrInvalidAddressJSON),
|
errors.Is(err, ErrInvalidAddressJSON):
|
||||||
errors.Is(err, ErrInvalidStatus):
|
|
||||||
return fiber.StatusBadRequest
|
return fiber.StatusBadRequest
|
||||||
case errors.Is(err, ErrSpecificPriceNotFound):
|
case errors.Is(err, ErrSpecificPriceNotFound):
|
||||||
return fiber.StatusNotFound
|
return fiber.StatusNotFound
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
info:
|
info:
|
||||||
name: Delete Index - MeiliSearch
|
name: Delete Index - MeiliSearch
|
||||||
type: http
|
type: http
|
||||||
seq: 8
|
seq: 7
|
||||||
|
|
||||||
http:
|
http:
|
||||||
method: DELETE
|
method: DELETE
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
info:
|
|
||||||
name: Add new cart
|
|
||||||
type: http
|
|
||||||
seq: 1
|
|
||||||
|
|
||||||
http:
|
|
||||||
method: POST
|
|
||||||
url: "{{bas_url}}/restricted/carts/add-new-cart?name=TestCart"
|
|
||||||
params:
|
|
||||||
- name: name
|
|
||||||
value: TestCart
|
|
||||||
type: query
|
|
||||||
auth: inherit
|
|
||||||
|
|
||||||
settings:
|
|
||||||
encodeUrl: true
|
|
||||||
timeout: 0
|
|
||||||
followRedirects: true
|
|
||||||
maxRedirects: 5
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
info:
|
|
||||||
name: Add product to cart
|
|
||||||
type: http
|
|
||||||
seq: 6
|
|
||||||
|
|
||||||
http:
|
|
||||||
method: POST
|
|
||||||
url: "{{bas_url}}/restricted/carts/add-product-to-cart?cart_id=1&product_id=51&product_attribute_id=1115&amount=1&set_amount=true"
|
|
||||||
params:
|
|
||||||
- name: cart_id
|
|
||||||
value: "1"
|
|
||||||
type: query
|
|
||||||
- name: product_id
|
|
||||||
value: "51"
|
|
||||||
type: query
|
|
||||||
- name: product_attribute_id
|
|
||||||
value: "1115"
|
|
||||||
type: query
|
|
||||||
- name: amount
|
|
||||||
value: "1"
|
|
||||||
type: query
|
|
||||||
- name: set_amount
|
|
||||||
value: "true"
|
|
||||||
type: query
|
|
||||||
auth: inherit
|
|
||||||
|
|
||||||
settings:
|
|
||||||
encodeUrl: true
|
|
||||||
timeout: 0
|
|
||||||
followRedirects: true
|
|
||||||
maxRedirects: 5
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
info:
|
|
||||||
name: Change cart name
|
|
||||||
type: http
|
|
||||||
seq: 3
|
|
||||||
|
|
||||||
http:
|
|
||||||
method: PATCH
|
|
||||||
url: "{{bas_url}}/restricted/carts/change-cart-name?cart_id=1&new_name=UpdatedCart"
|
|
||||||
params:
|
|
||||||
- name: cart_id
|
|
||||||
value: "1"
|
|
||||||
type: query
|
|
||||||
- name: new_name
|
|
||||||
value: UpdatedCart
|
|
||||||
type: query
|
|
||||||
auth: inherit
|
|
||||||
|
|
||||||
settings:
|
|
||||||
encodeUrl: true
|
|
||||||
timeout: 0
|
|
||||||
followRedirects: true
|
|
||||||
maxRedirects: 5
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
info:
|
|
||||||
name: Remove cart
|
|
||||||
type: http
|
|
||||||
seq: 2
|
|
||||||
|
|
||||||
http:
|
|
||||||
method: DELETE
|
|
||||||
url: "{{bas_url}}/restricted/carts/remove-cart?cart_id=1"
|
|
||||||
params:
|
|
||||||
- name: cart_id
|
|
||||||
value: "1"
|
|
||||||
type: query
|
|
||||||
auth: inherit
|
|
||||||
|
|
||||||
settings:
|
|
||||||
encodeUrl: true
|
|
||||||
timeout: 0
|
|
||||||
followRedirects: true
|
|
||||||
maxRedirects: 5
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
info:
|
|
||||||
name: Remove product from cart
|
|
||||||
type: http
|
|
||||||
seq: 7
|
|
||||||
|
|
||||||
http:
|
|
||||||
method: DELETE
|
|
||||||
url: "{{bas_url}}/restricted/carts/remove-product-from-cart?cart_id=1&product_id=51&product_attribute_id=1115"
|
|
||||||
params:
|
|
||||||
- name: cart_id
|
|
||||||
value: "1"
|
|
||||||
type: query
|
|
||||||
- name: product_id
|
|
||||||
value: "51"
|
|
||||||
type: query
|
|
||||||
- name: product_attribute_id
|
|
||||||
value: "1115"
|
|
||||||
type: query
|
|
||||||
auth: inherit
|
|
||||||
|
|
||||||
settings:
|
|
||||||
encodeUrl: true
|
|
||||||
timeout: 0
|
|
||||||
followRedirects: true
|
|
||||||
maxRedirects: 5
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
info:
|
|
||||||
name: Retrieve cart
|
|
||||||
type: http
|
|
||||||
seq: 5
|
|
||||||
|
|
||||||
http:
|
|
||||||
method: GET
|
|
||||||
url: "{{bas_url}}/restricted/carts/retrieve-cart?cart_id=1"
|
|
||||||
params:
|
|
||||||
- name: cart_id
|
|
||||||
value: "1"
|
|
||||||
type: query
|
|
||||||
auth: inherit
|
|
||||||
|
|
||||||
settings:
|
|
||||||
encodeUrl: true
|
|
||||||
timeout: 0
|
|
||||||
followRedirects: true
|
|
||||||
maxRedirects: 5
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
info:
|
|
||||||
name: Retrieve carts info
|
|
||||||
type: http
|
|
||||||
seq: 4
|
|
||||||
|
|
||||||
http:
|
|
||||||
method: GET
|
|
||||||
url: "{{bas_url}}/restricted/carts/retrieve-carts-info"
|
|
||||||
auth: inherit
|
|
||||||
|
|
||||||
settings:
|
|
||||||
encodeUrl: true
|
|
||||||
timeout: 0
|
|
||||||
followRedirects: true
|
|
||||||
maxRedirects: 5
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
info:
|
|
||||||
name: cart
|
|
||||||
type: folder
|
|
||||||
seq: 7
|
|
||||||
|
|
||||||
request:
|
|
||||||
auth: inherit
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
info:
|
info:
|
||||||
name: currency
|
name: currency
|
||||||
type: folder
|
type: folder
|
||||||
seq: 10
|
seq: 9
|
||||||
|
|
||||||
request:
|
request:
|
||||||
auth: inherit
|
auth: inherit
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
info:
|
info:
|
||||||
name: customer
|
name: customer
|
||||||
type: folder
|
type: folder
|
||||||
seq: 11
|
seq: 10
|
||||||
|
|
||||||
request:
|
request:
|
||||||
auth: inherit
|
auth: inherit
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
info:
|
|
||||||
name: Breadcrumb
|
|
||||||
type: http
|
|
||||||
seq: 1
|
|
||||||
|
|
||||||
http:
|
|
||||||
method: GET
|
|
||||||
url: http://localhost:3000/api/v1/restricted/menu/get-breadcrumb?root_category_id=2&category_id=13
|
|
||||||
params:
|
|
||||||
- name: root_category_id
|
|
||||||
value: "2"
|
|
||||||
type: query
|
|
||||||
- name: category_id
|
|
||||||
value: "13"
|
|
||||||
type: query
|
|
||||||
auth: inherit
|
|
||||||
|
|
||||||
settings:
|
|
||||||
encodeUrl: true
|
|
||||||
timeout: 0
|
|
||||||
followRedirects: true
|
|
||||||
maxRedirects: 5
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
info:
|
|
||||||
name: Category tree
|
|
||||||
type: http
|
|
||||||
seq: 2
|
|
||||||
|
|
||||||
http:
|
|
||||||
method: GET
|
|
||||||
url: http://localhost:3000/api/v1/restricted/menu/get-category-tree?root_category_id=2
|
|
||||||
params:
|
|
||||||
- name: root_category_id
|
|
||||||
value: "2"
|
|
||||||
type: query
|
|
||||||
auth: inherit
|
|
||||||
|
|
||||||
settings:
|
|
||||||
encodeUrl: true
|
|
||||||
timeout: 0
|
|
||||||
followRedirects: true
|
|
||||||
maxRedirects: 5
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
info:
|
|
||||||
name: Top Customer Management Menu
|
|
||||||
type: http
|
|
||||||
seq: 4
|
|
||||||
|
|
||||||
http:
|
|
||||||
method: GET
|
|
||||||
url: "{{bas_url}}/restricted/menu/get-customer-management-menu"
|
|
||||||
auth: inherit
|
|
||||||
|
|
||||||
settings:
|
|
||||||
encodeUrl: true
|
|
||||||
timeout: 0
|
|
||||||
followRedirects: true
|
|
||||||
maxRedirects: 5
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
info:
|
|
||||||
name: Top Menu
|
|
||||||
type: http
|
|
||||||
seq: 3
|
|
||||||
|
|
||||||
http:
|
|
||||||
method: GET
|
|
||||||
url: "{{bas_url}}/restricted/menu/get-top-menu"
|
|
||||||
auth: inherit
|
|
||||||
|
|
||||||
settings:
|
|
||||||
encodeUrl: true
|
|
||||||
timeout: 0
|
|
||||||
followRedirects: true
|
|
||||||
maxRedirects: 5
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
info:
|
|
||||||
name: menu
|
|
||||||
type: folder
|
|
||||||
seq: 12
|
|
||||||
|
|
||||||
request:
|
|
||||||
auth: inherit
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
info:
|
|
||||||
name: Change order address
|
|
||||||
type: http
|
|
||||||
seq: 3
|
|
||||||
|
|
||||||
http:
|
|
||||||
method: POST
|
|
||||||
url: "{{bas_url}}/restricted/orders/change-order-address?order_id=1&country_id=1"
|
|
||||||
params:
|
|
||||||
- name: order_id
|
|
||||||
value: "1"
|
|
||||||
type: query
|
|
||||||
- name: country_id
|
|
||||||
value: "1"
|
|
||||||
type: query
|
|
||||||
body:
|
|
||||||
type: json
|
|
||||||
data: |-
|
|
||||||
{
|
|
||||||
"postal_code": "31-154",
|
|
||||||
"city": "Kraków",
|
|
||||||
"voivodeship": "śląskie",
|
|
||||||
"street": "Długa",
|
|
||||||
"building_no": "5",
|
|
||||||
"recipient": "Adam Adamowicz"
|
|
||||||
}
|
|
||||||
auth: inherit
|
|
||||||
|
|
||||||
settings:
|
|
||||||
encodeUrl: true
|
|
||||||
timeout: 0
|
|
||||||
followRedirects: true
|
|
||||||
maxRedirects: 5
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
info:
|
|
||||||
name: Change order status
|
|
||||||
type: http
|
|
||||||
seq: 1
|
|
||||||
|
|
||||||
http:
|
|
||||||
method: PATCH
|
|
||||||
url: "{{bas_url}}/restricted/orders/change-order-status?order_id=2&status=PENDING"
|
|
||||||
params:
|
|
||||||
- name: order_id
|
|
||||||
value: "2"
|
|
||||||
type: query
|
|
||||||
- name: status
|
|
||||||
value: PENDING
|
|
||||||
type: query
|
|
||||||
auth: inherit
|
|
||||||
|
|
||||||
settings:
|
|
||||||
encodeUrl: true
|
|
||||||
timeout: 0
|
|
||||||
followRedirects: true
|
|
||||||
maxRedirects: 5
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
info:
|
|
||||||
name: List
|
|
||||||
type: http
|
|
||||||
seq: 1
|
|
||||||
|
|
||||||
http:
|
|
||||||
method: GET
|
|
||||||
url: "{{bas_url}}/restricted/orders/list?p=1&elems=30&sort=order_id,desc"
|
|
||||||
params:
|
|
||||||
- name: p
|
|
||||||
value: "1"
|
|
||||||
type: query
|
|
||||||
- name: elems
|
|
||||||
value: "30"
|
|
||||||
type: query
|
|
||||||
- name: sort
|
|
||||||
value: order_id,desc
|
|
||||||
type: query
|
|
||||||
auth: inherit
|
|
||||||
|
|
||||||
settings:
|
|
||||||
encodeUrl: true
|
|
||||||
timeout: 0
|
|
||||||
followRedirects: true
|
|
||||||
maxRedirects: 5
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
info:
|
|
||||||
name: Place new order
|
|
||||||
type: http
|
|
||||||
seq: 2
|
|
||||||
|
|
||||||
http:
|
|
||||||
method: POST
|
|
||||||
url: "{{bas_url}}/restricted/orders/place-new-order?cart_id=1&name=Test+Order&country_id=1"
|
|
||||||
params:
|
|
||||||
- name: cart_id
|
|
||||||
value: "1"
|
|
||||||
type: query
|
|
||||||
- name: name
|
|
||||||
value: Test Order
|
|
||||||
type: query
|
|
||||||
- name: country_id
|
|
||||||
value: "1"
|
|
||||||
type: query
|
|
||||||
body:
|
|
||||||
type: json
|
|
||||||
data: |-
|
|
||||||
{
|
|
||||||
"postal_code": "31-154",
|
|
||||||
"city": "Kraków",
|
|
||||||
"voivodeship": "małopolskie",
|
|
||||||
"street": "Długa",
|
|
||||||
"building_no": "5",
|
|
||||||
"apartment_no": "7",
|
|
||||||
"recipient": "Jan Kowalski"
|
|
||||||
}
|
|
||||||
auth: inherit
|
|
||||||
|
|
||||||
settings:
|
|
||||||
encodeUrl: true
|
|
||||||
timeout: 0
|
|
||||||
followRedirects: true
|
|
||||||
maxRedirects: 5
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
info:
|
|
||||||
name: order
|
|
||||||
type: folder
|
|
||||||
seq: 13
|
|
||||||
|
|
||||||
request:
|
|
||||||
auth: inherit
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
info:
|
info:
|
||||||
name: product
|
name: product
|
||||||
type: folder
|
type: folder
|
||||||
seq: 9
|
seq: 8
|
||||||
|
|
||||||
request:
|
request:
|
||||||
auth: inherit
|
auth: inherit
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
info:
|
info:
|
||||||
name: routes
|
name: routes
|
||||||
type: folder
|
type: folder
|
||||||
seq: 12
|
seq: 10
|
||||||
|
|
||||||
request:
|
request:
|
||||||
auth: inherit
|
auth: inherit
|
||||||
|
|||||||
@@ -5,14 +5,15 @@ info:
|
|||||||
|
|
||||||
http:
|
http:
|
||||||
method: POST
|
method: POST
|
||||||
url: http://localhost:3000/api/v1/public/auth/update-choice?lang_id=1&country_id=1
|
url: http://localhost:3000/api/v1/public/auth/update-choice?lang_id=0&country_id=1
|
||||||
params:
|
params:
|
||||||
- name: lang_id
|
- name: lang_id
|
||||||
value: "1"
|
value: "0"
|
||||||
type: query
|
type: query
|
||||||
- name: country_id
|
- name: country_id
|
||||||
value: "1"
|
value: "1"
|
||||||
type: query
|
type: query
|
||||||
|
auth: inherit
|
||||||
|
|
||||||
settings:
|
settings:
|
||||||
encodeUrl: true
|
encodeUrl: true
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ info:
|
|||||||
|
|
||||||
http:
|
http:
|
||||||
method: GET
|
method: GET
|
||||||
url: http://localhost:3000/api/v1/restricted/carts/add-product-to-cart?cart_id=1&product_id=51&product_attribute_id=1115&amount=2&set_amount=true
|
url: http://localhost:3000/api/v1/restricted/carts/add-product-to-cart?cart_id=1&product_id=51&product_attribute_id=1115&amount=1&set_amount=true
|
||||||
params:
|
params:
|
||||||
- name: cart_id
|
- name: cart_id
|
||||||
value: "1"
|
value: "1"
|
||||||
@@ -17,7 +17,7 @@ http:
|
|||||||
value: "1115"
|
value: "1115"
|
||||||
type: query
|
type: query
|
||||||
- name: amount
|
- name: amount
|
||||||
value: "2"
|
value: "1"
|
||||||
type: query
|
type: query
|
||||||
- name: set_amount
|
- name: set_amount
|
||||||
value: "true"
|
value: "true"
|
||||||
|
|||||||
@@ -42,32 +42,9 @@ INSERT IGNORE INTO `b2b_top_menu` (`menu_id`, `label`, `parent_id`, `params`, `a
|
|||||||
(3, JSON_COMPACT('{"name":"admin-products","trans":{"pl":{"label":"admin-products"},"en":{"label":"admin-products"},"de":{"label":"admin-products"}}}'),1,JSON_COMPACT('{}'),1,1),
|
(3, JSON_COMPACT('{"name":"admin-products","trans":{"pl":{"label":"admin-products"},"en":{"label":"admin-products"},"de":{"label":"admin-products"}}}'),1,JSON_COMPACT('{}'),1,1),
|
||||||
(9, JSON_COMPACT('{"name":"carts","trans":{"pl":{"label":"Koszyki"},"en":{"label":"Carts"},"de":{"label":"Warenkörbe"}}}'),3,JSON_COMPACT('{"route": {"name": "home", "params":{"locale": ""}}}'),1,1);
|
(9, JSON_COMPACT('{"name":"carts","trans":{"pl":{"label":"Koszyki"},"en":{"label":"Carts"},"de":{"label":"Warenkörbe"}}}'),3,JSON_COMPACT('{"route": {"name": "home", "params":{"locale": ""}}}'),1,1);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS b2b_customer_management_menu (
|
|
||||||
menu_id INT AUTO_INCREMENT NOT NULL,
|
|
||||||
label LONGTEXT NOT NULL DEFAULT '{}',
|
|
||||||
parent_id INT NULL DEFAULT NULL,
|
|
||||||
params LONGTEXT NOT NULL DEFAULT '{}',
|
|
||||||
active TINYINT NOT NULL DEFAULT 1,
|
|
||||||
position INT NOT NULL DEFAULT 1,
|
|
||||||
PRIMARY KEY (menu_id),
|
|
||||||
CONSTRAINT FK_b2b_customer_management_menu_parent_id FOREIGN KEY (parent_id)
|
|
||||||
REFERENCES b2b_customer_management_menu (menu_id)
|
|
||||||
ON DELETE RESTRICT ON UPDATE RESTRICT,
|
|
||||||
INDEX FK_b2b_customer_management_menu_parent_id_idx (parent_id ASC)
|
|
||||||
) ENGINE = InnoDB;
|
|
||||||
|
|
||||||
INSERT IGNORE INTO `b2b_customer_management_menu` (`menu_id`, `label`, `parent_id`, `params`, `active`, `position`) VALUES
|
|
||||||
(1, JSON_COMPACT('{"name":"root","trans":{"pl":{"label":"Menu główne"},"en":{"label":"Main Menu"},"de":{"label":"Hauptmenü"}}}'),NULL,JSON_COMPACT('{}'),1,1),
|
|
||||||
(3, JSON_COMPACT('{"name":"admin-products","trans":{"pl":{"label":"admin-products"},"en":{"label":"admin-products"},"de":{"label":"admin-products"}}}'),1,JSON_COMPACT('{}'),1,1),
|
|
||||||
(9, JSON_COMPACT('{"name":"carts","trans":{"pl":{"label":"Koszyki"},"en":{"label":"Carts"},"de":{"label":"Warenkörbe"}}}'),3,JSON_COMPACT('{"route": {"name": "home", "params":{"locale": ""}}}'),1,1);
|
|
||||||
|
|
||||||
INSERT INTO `b2b_customer_management_menu` (`menu_id`, `label`, `parent_id`, `params`, `active`, `position`) VALUES (1, '{"name":"root","trans":{"pl":{"label":"Menu główne"},"en":{"label":"Main Menu"},"de":{"label":"Hauptmenü"}}}', NULL, '{}', 1, 1);
|
|
||||||
INSERT INTO `b2b_customer_management_menu` (`menu_id`, `label`, `parent_id`, `params`, `active`, `position`) VALUES (3, '{"name":"admin-products","trans":{"pl":{"label":"admin-products"},"en":{"label":"admin-products"},"de":{"label":"admin-products"}}}', 1, '{}', 1, 1);
|
|
||||||
INSERT INTO `b2b_customer_management_menu` (`menu_id`, `label`, `parent_id`, `params`, `active`, `position`) VALUES (9, '{"name":"carts","trans":{"pl":{"label":"Koszyki"},"en":{"label":"Carts"},"de":{"label":"Warenkörbe"}}}', 3, '{"route":{"name":"home","params":{"locale":""}}}', 1, 1);
|
|
||||||
|
|
||||||
-- +goose Down
|
-- +goose Down
|
||||||
|
|
||||||
DROP TABLE IF EXISTS b2b_routes;
|
DROP TABLE IF EXISTS b2b_routes;
|
||||||
DROP TABLE IF EXISTS b2b_top_menu;
|
DROP TABLE IF EXISTS b2b_top_menu;
|
||||||
DROP TABLE IF EXISTS b2b_customer_management_menu;
|
|
||||||
DROP FUNCTION IF EXISTS `slugify_eu`;
|
DROP FUNCTION IF EXISTS `slugify_eu`;
|
||||||
|
|||||||
@@ -251,11 +251,6 @@ CREATE TABLE IF NOT EXISTS b2b_customer_orders (
|
|||||||
country_id BIGINT UNSIGNED NOT NULL,
|
country_id BIGINT UNSIGNED NOT NULL,
|
||||||
address_string TEXT NOT NULL,
|
address_string TEXT NOT NULL,
|
||||||
status VARCHAR(50) NOT NULL,
|
status VARCHAR(50) NOT NULL,
|
||||||
created_at DATETIME NOT NULL,
|
|
||||||
updated_at DATETIME NOT NULL,
|
|
||||||
base_price DECIMAL(10, 2) NOT NULL,
|
|
||||||
tax_incl DECIMAL(10, 2) NOT NULL,
|
|
||||||
tax_excl DECIMAL(10, 2) NOT NULL,
|
|
||||||
CONSTRAINT fk_customer_orders_customers FOREIGN KEY (user_id) REFERENCES b2b_customers(id) ON DELETE NO ACTION ON UPDATE CASCADE,
|
CONSTRAINT fk_customer_orders_customers FOREIGN KEY (user_id) REFERENCES b2b_customers(id) ON DELETE NO ACTION ON UPDATE CASCADE,
|
||||||
CONSTRAINT fk_customer_orders_countries FOREIGN KEY (country_id) REFERENCES b2b_countries(id) ON DELETE NO ACTION ON UPDATE CASCADE
|
CONSTRAINT fk_customer_orders_countries FOREIGN KEY (country_id) REFERENCES b2b_countries(id) ON DELETE NO ACTION ON UPDATE CASCADE
|
||||||
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
|
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
|
||||||
@@ -462,30 +457,6 @@ END$$
|
|||||||
|
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
||||||
CREATE TABLE b2b_order_status_history (
|
|
||||||
id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
|
||||||
order_id BIGINT UNSIGNED NOT NULL,
|
|
||||||
old_status VARCHAR(50) NULL,
|
|
||||||
new_status VARCHAR(50) NOT NULL,
|
|
||||||
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
|
|
||||||
user_id BIGINT UNSIGNED NULL
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE INDEX idx_order_status_history_order
|
|
||||||
ON b2b_order_status_history(order_id);
|
|
||||||
|
|
||||||
CREATE INDEX idx_order_status_history_user
|
|
||||||
ON b2b_order_status_history(user_id);
|
|
||||||
|
|
||||||
ALTER TABLE b2b_order_status_history
|
|
||||||
ADD CONSTRAINT fk_order
|
|
||||||
FOREIGN KEY (order_id) REFERENCES b2b_customer_orders(order_id);
|
|
||||||
|
|
||||||
ALTER TABLE b2b_order_status_history
|
|
||||||
ADD CONSTRAINT fk_user
|
|
||||||
FOREIGN KEY (user_id) REFERENCES b2b_customers(id);
|
|
||||||
|
|
||||||
|
|
||||||
-- +goose Down
|
-- +goose Down
|
||||||
|
|
||||||
DROP TABLE IF EXISTS b2b_addresses;
|
DROP TABLE IF EXISTS b2b_addresses;
|
||||||
|
|||||||
@@ -12,19 +12,6 @@ INSERT INTO `b2b_roles` (`name`, `id`) VALUES ('admin','2');
|
|||||||
INSERT INTO `b2b_roles` (`name`, `id`) VALUES ('super_admin','3');
|
INSERT INTO `b2b_roles` (`name`, `id`) VALUES ('super_admin','3');
|
||||||
INSERT INTO `b2b_roles` (`name`, `id`) VALUES ('unlogged','4');
|
INSERT INTO `b2b_roles` (`name`, `id`) VALUES ('unlogged','4');
|
||||||
|
|
||||||
INSERT INTO `b2b_top_menu_roles` (`top_menu_id`, `role_id`) VALUES (1, '1');
|
|
||||||
INSERT INTO `b2b_top_menu_roles` (`top_menu_id`, `role_id`) VALUES (3, '1');
|
|
||||||
INSERT INTO `b2b_top_menu_roles` (`top_menu_id`, `role_id`) VALUES (9, '1');
|
|
||||||
INSERT INTO `b2b_top_menu_roles` (`top_menu_id`, `role_id`) VALUES (1, '2');
|
|
||||||
INSERT INTO `b2b_top_menu_roles` (`top_menu_id`, `role_id`) VALUES (3, '2');
|
|
||||||
INSERT INTO `b2b_top_menu_roles` (`top_menu_id`, `role_id`) VALUES (9, '2');
|
|
||||||
INSERT INTO `b2b_top_menu_roles` (`top_menu_id`, `role_id`) VALUES (1, '3');
|
|
||||||
INSERT INTO `b2b_top_menu_roles` (`top_menu_id`, `role_id`) VALUES (3, '3');
|
|
||||||
INSERT INTO `b2b_top_menu_roles` (`top_menu_id`, `role_id`) VALUES (9, '3');
|
|
||||||
INSERT INTO `b2b_top_menu_roles` (`top_menu_id`, `role_id`) VALUES (1, '4');
|
|
||||||
INSERT INTO `b2b_top_menu_roles` (`top_menu_id`, `role_id`) VALUES (3, '4');
|
|
||||||
INSERT INTO `b2b_top_menu_roles` (`top_menu_id`, `role_id`) VALUES (9, '4');
|
|
||||||
|
|
||||||
|
|
||||||
-- insert sample admin user admin@ma-al.com/Maal12345678
|
-- insert sample admin user admin@ma-al.com/Maal12345678
|
||||||
INSERT IGNORE INTO b2b_customers (id, email, password, first_name, last_name, role_id, provider, provider_id, avatar_url, is_active, email_verified, email_verification_token, email_verification_expires, password_reset_token, password_reset_expires, last_password_reset_request, last_login_at, lang_id, country_id, created_at, updated_at, deleted_at)
|
INSERT IGNORE INTO b2b_customers (id, email, password, first_name, last_name, role_id, provider, provider_id, avatar_url, is_active, email_verified, email_verification_token, email_verification_expires, password_reset_token, password_reset_expires, last_password_reset_request, last_login_at, lang_id, country_id, created_at, updated_at, deleted_at)
|
||||||
|
|||||||
@@ -415,7 +415,7 @@ BEGIN
|
|||||||
LEFT JOIN ps_manufacturer m
|
LEFT JOIN ps_manufacturer m
|
||||||
ON m.id_manufacturer = p.id_manufacturer
|
ON m.id_manufacturer = p.id_manufacturer
|
||||||
LEFT JOIN ps_configuration
|
LEFT JOIN ps_configuration
|
||||||
ON ps_configuration.name = 'PS_NB_DAYS_NEW_PRODUCT'
|
ON ps_configuration.name = PS_NB_DAYS_NEW_PRODUCT
|
||||||
|
|
||||||
WHERE p.id_product = p_id_product
|
WHERE p.id_product = p_id_product
|
||||||
LIMIT 1;
|
LIMIT 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user