Compare commits
45 Commits
19e3f6f0ed
...
front-styl
| Author | SHA1 | Date | |
|---|---|---|---|
| 564656dcd6 | |||
| a75ed303b8 | |||
| 79f6278862 | |||
| 0382f228b2 | |||
| 527656bb7c | |||
| ec44200332 | |||
| 4027fa530e | |||
| c9d06c52e2 | |||
| 07cb7830ce | |||
| c91f420cbe | |||
| 25a04551e1 | |||
| 612e97e76e | |||
| 3479e5ed8a | |||
| 52d58d05eb | |||
| 931840c243 | |||
|
|
d73dad8975 | ||
|
|
7995177fe1 | ||
| 70e0e23ace | |||
| 9961d90fa7 | |||
| 16f92e53ff | |||
|
|
f435a8839b | ||
| 2d9e45b81c | |||
| 9b525f06cd | |||
| cf48624d7f | |||
| d115fec237 | |||
| 62aafdc11a | |||
| 5b6ee6d57a | |||
| 5a0765426a | |||
| 632e3afae3 | |||
| 574e241c8a | |||
| b13293572c | |||
| 7bce04e05a | |||
| 9a90de3f11 | |||
|
|
754bf2fe01 | ||
|
|
2ca07f03ce | ||
| 6efb39edf7 | |||
| e9af4bf311 | |||
| cc570cc6a8 | |||
| 1bf706dcd0 | |||
| be0687f4a9 | |||
| bfcfbb36c8 | |||
| e31ecda582 | |||
| 8e063978a8 | |||
| 31a2744131 | |||
| f55d59a0fd |
@@ -28,7 +28,7 @@ tmp_dir = "tmp"
|
|||||||
rerun = false
|
rerun = false
|
||||||
rerun_delay = 500
|
rerun_delay = 500
|
||||||
send_interrupt = false
|
send_interrupt = false
|
||||||
stop_on_error = true
|
stop_on_error = false
|
||||||
|
|
||||||
[color]
|
[color]
|
||||||
app = ""
|
app = ""
|
||||||
|
|||||||
3
.env
3
.env
@@ -64,3 +64,6 @@ IMAGE_PREFIX=https://www.naluconcept.com # remove prefix to serv them from same
|
|||||||
CORS_ORGIN=https://www.naluconcept.com
|
CORS_ORGIN=https://www.naluconcept.com
|
||||||
|
|
||||||
DSN=root:Maal12345678@tcp(localhost:3306)/nalu
|
DSN=root:Maal12345678@tcp(localhost:3306)/nalu
|
||||||
|
|
||||||
|
LOG_LEVEL=warn
|
||||||
|
LOG_COLORIZE=true
|
||||||
116
app/actions/orderStatusActions/examples.go
Normal file
116
app/actions/orderStatusActions/examples.go
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
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}
|
||||||
|
// })
|
||||||
21
app/actions/orderStatusActions/pending.go
Normal file
21
app/actions/orderStatusActions/pending.go
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
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,
|
||||||
|
})
|
||||||
|
}
|
||||||
88
app/actions/orderStatusActions/registry.go
Normal file
88
app/actions/orderStatusActions/registry.go
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
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}
|
||||||
|
}
|
||||||
@@ -4,8 +4,11 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"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"
|
||||||
|
|
||||||
"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"
|
||||||
)
|
)
|
||||||
@@ -21,6 +24,8 @@ var (
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.Init("b2b", nil, config.Get().Log.LogLevel, config.Get().Log.LogColorize)
|
||||||
|
|
||||||
// Create and setup the server
|
// Create and setup the server
|
||||||
server := web.New()
|
server := web.New()
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ type Config struct {
|
|||||||
Cors CorsConfig
|
Cors CorsConfig
|
||||||
MeiliSearch MeiliSearchConfig
|
MeiliSearch MeiliSearchConfig
|
||||||
Storage StorageConfig
|
Storage StorageConfig
|
||||||
|
Log LogConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
type I18n struct {
|
type I18n struct {
|
||||||
@@ -87,6 +88,11 @@ type AppConfig struct {
|
|||||||
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"`
|
||||||
|
LogColorize bool `env:"LOG_COLORIZE,true"`
|
||||||
|
}
|
||||||
|
|
||||||
type EmailConfig struct {
|
type EmailConfig struct {
|
||||||
SMTPHost string `env:"EMAIL_SMTP_HOST,localhost"`
|
SMTPHost string `env:"EMAIL_SMTP_HOST,localhost"`
|
||||||
SMTPPort int `env:"EMAIL_SMTP_PORT,587"`
|
SMTPPort int `env:"EMAIL_SMTP_PORT,587"`
|
||||||
@@ -209,6 +215,11 @@ 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
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package public
|
package public
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -11,6 +10,7 @@ import (
|
|||||||
"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"
|
||||||
@@ -178,7 +178,13 @@ func (h *AuthHandler) ForgotPassword(c fiber.Ctx) error {
|
|||||||
// Request password reset - always return success to prevent email enumeration
|
// Request password reset - always return success to prevent email enumeration
|
||||||
err := h.authService.RequestPasswordReset(req.Email)
|
err := h.authService.RequestPasswordReset(req.Email)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Password reset request error: %v", err)
|
|
||||||
|
logger.Warn("password reset request failed",
|
||||||
|
"handler", "AuthHandler.ForgotPassword",
|
||||||
|
|
||||||
|
"email", req.Email,
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.JSON(fiber.Map{
|
return c.JSON(fiber.Map{
|
||||||
@@ -307,7 +313,6 @@ 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 {
|
||||||
log.Printf("Register error: %v", err)
|
|
||||||
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),
|
||||||
})
|
})
|
||||||
@@ -447,7 +452,6 @@ 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 {
|
||||||
log.Printf("Google OAuth callback error: %v", err)
|
|
||||||
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),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"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"
|
||||||
@@ -45,6 +46,13 @@ func (h *AddressesHandler) GetTemplate(c fiber.Ctx) error {
|
|||||||
|
|
||||||
template, err := h.addressesService.GetTemplate(uint(country_id))
|
template, err := h.addressesService.GetTemplate(uint(country_id))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
|
logger.Error("failed to get address template",
|
||||||
|
"handler", "AddressesHandler.GetTemplate",
|
||||||
|
|
||||||
|
"country_id", country_id,
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
}
|
}
|
||||||
@@ -74,6 +82,13 @@ func (h *AddressesHandler) AddNewAddress(c fiber.Ctx) error {
|
|||||||
|
|
||||||
err = h.addressesService.AddNewAddress(userID, address_info, uint(country_id))
|
err = h.addressesService.AddNewAddress(userID, address_info, uint(country_id))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
|
logger.Error("failed to add new address",
|
||||||
|
"handler", "AddressesHandler.AddNewAddress",
|
||||||
|
|
||||||
|
"user_id", userID,
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
}
|
}
|
||||||
@@ -110,6 +125,14 @@ func (h *AddressesHandler) ModifyAddress(c fiber.Ctx) error {
|
|||||||
|
|
||||||
err = h.addressesService.ModifyAddress(userID, uint(address_id), address_info, uint(country_id))
|
err = h.addressesService.ModifyAddress(userID, uint(address_id), address_info, uint(country_id))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
|
logger.Error("failed to modify address",
|
||||||
|
"handler", "AddressesHandler.ModifyAddress",
|
||||||
|
|
||||||
|
"user_id", userID,
|
||||||
|
"address_id", address_id,
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
}
|
}
|
||||||
@@ -126,6 +149,13 @@ func (h *AddressesHandler) RetrieveAddressesInfo(c fiber.Ctx) error {
|
|||||||
|
|
||||||
addresses, err := h.addressesService.RetrieveAddresses(userID)
|
addresses, err := h.addressesService.RetrieveAddresses(userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
|
logger.Error("failed to retrieve addresses",
|
||||||
|
"handler", "AddressesHandler.RetrieveAddressesInfo",
|
||||||
|
|
||||||
|
"user_id", userID,
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
}
|
}
|
||||||
@@ -149,6 +179,14 @@ func (h *AddressesHandler) DeleteAddress(c fiber.Ctx) error {
|
|||||||
|
|
||||||
err = h.addressesService.DeleteAddress(userID, uint(address_id))
|
err = h.addressesService.DeleteAddress(userID, uint(address_id))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
|
logger.Error("failed to delete address",
|
||||||
|
"handler", "AddressesHandler.DeleteAddress",
|
||||||
|
|
||||||
|
"user_id", userID,
|
||||||
|
"address_id", address_id,
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"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"
|
||||||
@@ -28,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.Get("/add-new-cart", handler.AddNewCart)
|
r.Post("/add-new-cart", handler.AddNewCart)
|
||||||
r.Delete("/remove-cart", handler.RemoveCart)
|
r.Delete("/remove-cart", handler.RemoveCart)
|
||||||
r.Get("/change-cart-name", handler.ChangeCartName)
|
r.Patch("/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.Get("/add-product-to-cart", handler.AddProduct)
|
r.Post("/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
|
||||||
@@ -46,8 +47,16 @@ func (h *CartsHandler) AddNewCart(c fiber.Ctx) error {
|
|||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrInvalidBody)))
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrInvalidBody)))
|
||||||
}
|
}
|
||||||
|
|
||||||
new_cart, err := h.cartsService.CreateNewCart(userID)
|
name := c.Query("name")
|
||||||
|
new_cart, err := h.cartsService.CreateNewCart(userID, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
|
logger.Error("failed to create cart",
|
||||||
|
"handler", "CartsHandler.AddNewCart",
|
||||||
|
|
||||||
|
"user_id", userID,
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
}
|
}
|
||||||
@@ -71,6 +80,14 @@ func (h *CartsHandler) RemoveCart(c fiber.Ctx) error {
|
|||||||
|
|
||||||
err = h.cartsService.RemoveCart(userID, uint(cart_id))
|
err = h.cartsService.RemoveCart(userID, uint(cart_id))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
|
logger.Error("failed to remove cart",
|
||||||
|
"handler", "CartsHandler.RemoveCart",
|
||||||
|
|
||||||
|
"user_id", userID,
|
||||||
|
"cart_id", cart_id,
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
}
|
}
|
||||||
@@ -96,6 +113,14 @@ func (h *CartsHandler) ChangeCartName(c fiber.Ctx) error {
|
|||||||
|
|
||||||
err = h.cartsService.UpdateCartName(userID, uint(cart_id), new_name)
|
err = h.cartsService.UpdateCartName(userID, uint(cart_id), new_name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
|
logger.Error("failed to update cart name",
|
||||||
|
"handler", "CartsHandler.ChangeCartName",
|
||||||
|
|
||||||
|
"user_id", userID,
|
||||||
|
"cart_id", cart_id,
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
}
|
}
|
||||||
@@ -112,6 +137,13 @@ func (h *CartsHandler) RetrieveCartsInfo(c fiber.Ctx) error {
|
|||||||
|
|
||||||
carts_info, err := h.cartsService.RetrieveCartsInfo(userID)
|
carts_info, err := h.cartsService.RetrieveCartsInfo(userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
|
logger.Error("failed to retrieve carts info",
|
||||||
|
"handler", "CartsHandler.RetrieveCartsInfo",
|
||||||
|
|
||||||
|
"user_id", userID,
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
}
|
}
|
||||||
@@ -135,6 +167,14 @@ func (h *CartsHandler) RetrieveCart(c fiber.Ctx) error {
|
|||||||
|
|
||||||
cart, err := h.cartsService.RetrieveCart(userID, uint(cart_id))
|
cart, err := h.cartsService.RetrieveCart(userID, uint(cart_id))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
|
logger.Error("failed to retrieve cart",
|
||||||
|
"handler", "CartsHandler.RetrieveCart",
|
||||||
|
|
||||||
|
"user_id", userID,
|
||||||
|
"cart_id", cart_id,
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
}
|
}
|
||||||
@@ -194,6 +234,15 @@ func (h *CartsHandler) AddProduct(c fiber.Ctx) error {
|
|||||||
|
|
||||||
err = h.cartsService.AddProduct(userID, uint(cart_id), uint(product_id), product_attribute_id, amount, set_amount)
|
err = h.cartsService.AddProduct(userID, uint(cart_id), uint(product_id), product_attribute_id, amount, set_amount)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
|
logger.Error("failed to add product to cart",
|
||||||
|
"handler", "CartsHandler.AddProduct",
|
||||||
|
|
||||||
|
"user_id", userID,
|
||||||
|
"cart_id", cart_id,
|
||||||
|
"product_id", product_id,
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
}
|
}
|
||||||
@@ -239,6 +288,15 @@ func (h *CartsHandler) RemoveProduct(c fiber.Ctx) error {
|
|||||||
|
|
||||||
err = h.cartsService.RemoveProduct(userID, uint(cart_id), uint(product_id), product_attribute_id)
|
err = h.cartsService.RemoveProduct(userID, uint(cart_id), uint(product_id), product_attribute_id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
|
logger.Error("failed to remove product from cart",
|
||||||
|
"handler", "CartsHandler.RemoveProduct",
|
||||||
|
|
||||||
|
"user_id", userID,
|
||||||
|
"cart_id", cart_id,
|
||||||
|
"product_id", product_id,
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"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"
|
||||||
@@ -46,6 +47,12 @@ func (h *CurrencyHandler) PostCurrencyRate(c fiber.Ctx) error {
|
|||||||
|
|
||||||
err := h.CurrencyService.CreateCurrencyRate(¤cyRate)
|
err := h.CurrencyService.CreateCurrencyRate(¤cyRate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
|
logger.Error("failed to create currency rate",
|
||||||
|
"handler", "CurrencyHandler.PostCurrencyRate",
|
||||||
|
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
}
|
}
|
||||||
@@ -63,6 +70,13 @@ func (h *CurrencyHandler) GetCurrencyRate(c fiber.Ctx) error {
|
|||||||
|
|
||||||
currency, err := h.CurrencyService.GetCurrency(uint(id))
|
currency, err := h.CurrencyService.GetCurrency(uint(id))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
|
logger.Error("failed to get currency",
|
||||||
|
"handler", "CurrencyHandler.GetCurrencyRate",
|
||||||
|
|
||||||
|
"currency_id", id,
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
return c.Status(responseErrors.GetErrorStatus(err)).JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"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"
|
||||||
@@ -32,6 +33,7 @@ func CustomerHandlerRoutes(r fiber.Router) fiber.Router {
|
|||||||
|
|
||||||
r.Get("", handler.customerData)
|
r.Get("", handler.customerData)
|
||||||
r.Get("/list", middleware.Require(perms.UserReadAny), handler.listCustomers)
|
r.Get("/list", middleware.Require(perms.UserReadAny), handler.listCustomers)
|
||||||
|
r.Patch("/no-vat", middleware.Require(perms.UserWriteAny), handler.setCustomerNoVatStatus)
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,6 +65,13 @@ func (h *customerHandler) customerData(fc fiber.Ctx) error {
|
|||||||
|
|
||||||
customer, err := h.service.GetById(customerId)
|
customer, err := h.service.GetById(customerId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
|
logger.Error("failed to get customer",
|
||||||
|
"handler", "customerHandler.customerData",
|
||||||
|
|
||||||
|
"customer_id", customerId,
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
return fc.Status(responseErrors.GetErrorStatus(err)).
|
return fc.Status(responseErrors.GetErrorStatus(err)).
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(fc, err)))
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(fc, err)))
|
||||||
}
|
}
|
||||||
@@ -87,6 +96,12 @@ func (h *customerHandler) listCustomers(fc fiber.Ctx) error {
|
|||||||
|
|
||||||
customer, err := h.service.Find(user.LangID, p, filt, search)
|
customer, err := h.service.Find(user.LangID, p, filt, search)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
|
logger.Error("failed to list customers",
|
||||||
|
"handler", "customerHandler.listCustomers",
|
||||||
|
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
return fc.Status(responseErrors.GetErrorStatus(err)).
|
return fc.Status(responseErrors.GetErrorStatus(err)).
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(fc, err)))
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(fc, err)))
|
||||||
}
|
}
|
||||||
@@ -100,3 +115,35 @@ var columnMappingListUsers map[string]string = map[string]string{
|
|||||||
"first_name": "users.first_name",
|
"first_name": "users.first_name",
|
||||||
"last_name": "users.last_name",
|
"last_name": "users.last_name",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *customerHandler) setCustomerNoVatStatus(fc fiber.Ctx) error {
|
||||||
|
user, ok := localeExtractor.GetCustomer(fc)
|
||||||
|
if !ok || user == nil {
|
||||||
|
return fc.Status(responseErrors.GetErrorStatus(responseErrors.ErrInvalidBody)).
|
||||||
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(fc, responseErrors.ErrInvalidBody)))
|
||||||
|
}
|
||||||
|
|
||||||
|
var req struct {
|
||||||
|
CustomerID uint `json:"customer_id"`
|
||||||
|
IsNoVat bool `json:"is_no_vat"`
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := fc.Bind().Body(&req); err != nil {
|
||||||
|
return fc.Status(responseErrors.GetErrorStatus(responseErrors.ErrJSONBody)).
|
||||||
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(fc, responseErrors.ErrJSONBody)))
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := h.service.SetCustomerNoVatStatus(req.CustomerID, req.IsNoVat); err != nil {
|
||||||
|
|
||||||
|
logger.Error("failed to set customer no vat status",
|
||||||
|
"handler", "customerHandler.setCustomerNoVatStatus",
|
||||||
|
|
||||||
|
"customer_id", req.CustomerID,
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
|
return fc.Status(responseErrors.GetErrorStatus(err)).
|
||||||
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(fc, err)))
|
||||||
|
}
|
||||||
|
|
||||||
|
return fc.JSON(response.Make(nullable.GetNil(""), 0, i18n.T_(fc, response.Message_OK)))
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package restricted
|
|||||||
import (
|
import (
|
||||||
"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"
|
||||||
@@ -34,6 +35,12 @@ func LocaleSelectorHandlerRoutes(r fiber.Router) fiber.Router {
|
|||||||
func (h *LocaleSelectorHandler) GetLanguages(c fiber.Ctx) error {
|
func (h *LocaleSelectorHandler) GetLanguages(c fiber.Ctx) error {
|
||||||
languages, err := h.localeSelectorService.GetLanguages()
|
languages, err := h.localeSelectorService.GetLanguages()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
|
logger.Error("failed to get languages",
|
||||||
|
"handler", "LocaleSelectorHandler.GetLanguages",
|
||||||
|
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
}
|
}
|
||||||
@@ -44,6 +51,12 @@ func (h *LocaleSelectorHandler) GetLanguages(c fiber.Ctx) error {
|
|||||||
func (h *LocaleSelectorHandler) GetCountries(c fiber.Ctx) error {
|
func (h *LocaleSelectorHandler) GetCountries(c fiber.Ctx) error {
|
||||||
countries, err := h.localeSelectorService.GetCountriesAndCurrencies()
|
countries, err := h.localeSelectorService.GetCountriesAndCurrencies()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
|
logger.Error("failed to get countries",
|
||||||
|
"handler", "LocaleSelectorHandler.GetCountries",
|
||||||
|
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,12 @@ package restricted
|
|||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"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/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"
|
||||||
@@ -29,6 +32,7 @@ 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
|
||||||
}
|
}
|
||||||
@@ -49,6 +53,12 @@ func (h *MenuHandler) GetCategoryTree(c fiber.Ctx) error {
|
|||||||
|
|
||||||
category_tree, err := h.menuService.GetCategoryTree(uint(root_category_id), lang_id)
|
category_tree, err := h.menuService.GetCategoryTree(uint(root_category_id), lang_id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
|
logger.Error("failed to get category tree",
|
||||||
|
"handler", "MenuHandler.GetCategoryTree",
|
||||||
|
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
}
|
}
|
||||||
@@ -79,6 +89,12 @@ func (h *MenuHandler) GetBreadcrumb(c fiber.Ctx) error {
|
|||||||
|
|
||||||
breadcrumb, err := h.menuService.GetBreadcrumb(uint(root_category_id), uint(category_id), lang_id)
|
breadcrumb, err := h.menuService.GetBreadcrumb(uint(root_category_id), uint(category_id), lang_id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
|
logger.Error("failed to get breadcrumb",
|
||||||
|
"handler", "MenuHandler.GetBreadcrumb",
|
||||||
|
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
}
|
}
|
||||||
@@ -93,6 +109,27 @@ func (h *MenuHandler) GetTopMenu(c fiber.Ctx) error {
|
|||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrBadAttribute)))
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrBadAttribute)))
|
||||||
}
|
}
|
||||||
menu, err := h.menuService.GetTopMenu(customer.LangID, customer.RoleID)
|
menu, err := h.menuService.GetTopMenu(customer.LangID, customer.RoleID)
|
||||||
|
if err != nil {
|
||||||
|
|
||||||
|
logger.Error("failed to get top menu",
|
||||||
|
"handler", "MenuHandler.GetTopMenu",
|
||||||
|
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
|
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)))
|
||||||
|
}
|
||||||
|
|
||||||
|
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 {
|
if err != nil {
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
|
|||||||
@@ -2,11 +2,16 @@ 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/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"
|
||||||
@@ -31,7 +36,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.Get("/change-order-status", handler.ChangeOrderStatus)
|
r.Patch("/change-order-status", middleware.Require(perms.OrdersModifyAll), handler.ChangeOrderStatus)
|
||||||
|
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
@@ -53,6 +58,12 @@ func (h *OrdersHandler) ListOrders(c fiber.Ctx) error {
|
|||||||
|
|
||||||
list, err := h.ordersService.Find(user, paging, filters)
|
list, err := h.ordersService.Find(user, paging, filters)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
|
logger.Error("failed to list orders",
|
||||||
|
"handler", "OrdersHandler.ListOrders",
|
||||||
|
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
}
|
}
|
||||||
@@ -66,6 +77,11 @@ 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 {
|
||||||
@@ -97,8 +113,21 @@ func (h *OrdersHandler) PlaceNewOrder(c fiber.Ctx) error {
|
|||||||
|
|
||||||
name := c.Query("name")
|
name := c.Query("name")
|
||||||
|
|
||||||
err = h.ordersService.PlaceNewOrder(userID, uint(cart_id), name, uint(country_id), address_info)
|
originalUserId, ok := localeExtractor.GetOriginalUserID(c)
|
||||||
|
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",
|
||||||
|
"handler", "OrdersHandler.PlaceNewOrder",
|
||||||
|
|
||||||
|
"user_id", userID,
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
}
|
}
|
||||||
@@ -136,6 +165,13 @@ func (h *OrdersHandler) ChangeOrderAddress(c fiber.Ctx) error {
|
|||||||
|
|
||||||
err = h.ordersService.ChangeOrderAddress(user, uint(order_id), uint(country_id), address_info)
|
err = h.ordersService.ChangeOrderAddress(user, uint(order_id), uint(country_id), address_info)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
|
logger.Error("failed to change order address",
|
||||||
|
"handler", "OrdersHandler.ChangeOrderAddress",
|
||||||
|
|
||||||
|
"order_id", order_id,
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
}
|
}
|
||||||
@@ -146,23 +182,27 @@ 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 {
|
||||||
user, ok := localeExtractor.GetCustomer(c)
|
userId, ok := localeExtractor.GetUserID(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_attribute := c.Query("order_id")
|
order_id, err := strconv.Atoi(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)))
|
||||||
}
|
}
|
||||||
|
|
||||||
status := c.Query("status")
|
err = h.ordersService.ChangeOrderStatus(userId, uint(order_id), enums.OrderStatus(strings.ToUpper(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",
|
||||||
|
"handler", "OrdersHandler.ChangeOrderStatus",
|
||||||
|
|
||||||
|
"order_id", order_id,
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
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"
|
||||||
@@ -74,6 +75,15 @@ func (h *ProductsHandler) GetProductJson(c fiber.Ctx) error {
|
|||||||
}
|
}
|
||||||
productJson, err := h.productService.Get(uint(p_id_product), customer.LangID, customer.ID, uint(b2b_id_country), uint(p_quantity))
|
productJson, err := h.productService.Get(uint(p_id_product), customer.LangID, customer.ID, uint(b2b_id_country), uint(p_quantity))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
logger.Error("failed to get product",
|
||||||
|
"handler", "ProductsHandler.GetProductJson",
|
||||||
|
"product_id", p_id_product,
|
||||||
|
"lang_id", customer.LangID,
|
||||||
|
"customer_id", customer.ID,
|
||||||
|
"b2b_id_country", b2b_id_country,
|
||||||
|
"quantity", p_quantity,
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
}
|
}
|
||||||
@@ -96,6 +106,13 @@ func (h *ProductsHandler) ListProducts(c fiber.Ctx) error {
|
|||||||
|
|
||||||
list, err := h.productService.Find(customer.LangID, customer.ID, paging, filters, customer, constdata.DEFAULT_PRODUCT_QUANTITY, constdata.SHOP_ID)
|
list, err := h.productService.Find(customer.LangID, customer.ID, paging, filters, customer, constdata.DEFAULT_PRODUCT_QUANTITY, constdata.SHOP_ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
|
logger.Error("failed to list products",
|
||||||
|
"handler", "ProductsHandler.ListProducts",
|
||||||
|
"lang_id", customer.LangID,
|
||||||
|
"customer_id", customer.ID,
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
}
|
}
|
||||||
@@ -112,6 +129,7 @@ var columnMappingListProducts map[string]string = map[string]string{
|
|||||||
"quantity": "bp.quantity",
|
"quantity": "bp.quantity",
|
||||||
"is_favorite": "bp.is_favorite",
|
"is_favorite": "bp.is_favorite",
|
||||||
"is_new": "bp.is_new",
|
"is_new": "bp.is_new",
|
||||||
|
"is_oem": "bp.is_oem",
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *ProductsHandler) AddToFavorites(c fiber.Ctx) error {
|
func (h *ProductsHandler) AddToFavorites(c fiber.Ctx) error {
|
||||||
@@ -131,6 +149,13 @@ func (h *ProductsHandler) AddToFavorites(c fiber.Ctx) error {
|
|||||||
|
|
||||||
err = h.productService.AddToFavorites(userID, uint(productID))
|
err = h.productService.AddToFavorites(userID, uint(productID))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
|
logger.Error("failed to add to favorites",
|
||||||
|
"handler", "ProductsHandler.AddToFavorites",
|
||||||
|
"user_id", userID,
|
||||||
|
"product_id", productID,
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
}
|
}
|
||||||
@@ -155,6 +180,12 @@ func (h *ProductsHandler) RemoveFromFavorites(c fiber.Ctx) error {
|
|||||||
|
|
||||||
err = h.productService.RemoveFromFavorites(userID, uint(productID))
|
err = h.productService.RemoveFromFavorites(userID, uint(productID))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
logger.Error("failed to remove from favorites",
|
||||||
|
"handler", "ProductsHandler.RemoveFromFavorites",
|
||||||
|
"user_id", userID,
|
||||||
|
"product_id", productID,
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
}
|
}
|
||||||
@@ -179,6 +210,15 @@ func (h *ProductsHandler) ListProductVariants(c fiber.Ctx) error {
|
|||||||
|
|
||||||
list, err := h.productService.GetProductAttributes(customer.LangID, uint(productID), constdata.SHOP_ID, customer.ID, customer.CountryID, constdata.DEFAULT_PRODUCT_QUANTITY)
|
list, err := h.productService.GetProductAttributes(customer.LangID, uint(productID), constdata.SHOP_ID, customer.ID, customer.CountryID, constdata.DEFAULT_PRODUCT_QUANTITY)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
|
logger.Error("failed to list product variants",
|
||||||
|
"handler", "ProductsHandler.ListProductVariants",
|
||||||
|
"product_id", productID,
|
||||||
|
"customer_id", customer.ID,
|
||||||
|
"lang_id", customer.LangID,
|
||||||
|
"country_id", customer.CountryID,
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"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"
|
||||||
@@ -66,6 +67,13 @@ func (h *ProductTranslationHandler) GetProductDescription(c fiber.Ctx) error {
|
|||||||
|
|
||||||
description, err := h.productTranslationService.GetProductDescription(userID, uint(productID), uint(productLangID))
|
description, err := h.productTranslationService.GetProductDescription(userID, uint(productID), uint(productLangID))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
|
logger.Error("failed to get product description",
|
||||||
|
"handler", "ProductTranslationHandler.GetProductDescription",
|
||||||
|
|
||||||
|
"product_id", productID,
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
}
|
}
|
||||||
@@ -103,6 +111,13 @@ func (h *ProductTranslationHandler) SaveProductDescription(c fiber.Ctx) error {
|
|||||||
|
|
||||||
err = h.productTranslationService.SaveProductDescription(userID, uint(productID), uint(productLangID), updates)
|
err = h.productTranslationService.SaveProductDescription(userID, uint(productID), uint(productLangID), updates)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
|
logger.Error("failed to save product description",
|
||||||
|
"handler", "ProductTranslationHandler.SaveProductDescription",
|
||||||
|
|
||||||
|
"product_id", productID,
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
}
|
}
|
||||||
@@ -147,6 +162,13 @@ func (h *ProductTranslationHandler) TranslateProductDescription(c fiber.Ctx) err
|
|||||||
|
|
||||||
description, err := h.productTranslationService.TranslateProductDescription(userID, uint(productID), uint(productFromLangID), uint(productToLangID), aiModel)
|
description, err := h.productTranslationService.TranslateProductDescription(userID, uint(productID), uint(productFromLangID), uint(productToLangID), aiModel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
|
logger.Error("failed to translate product description",
|
||||||
|
"handler", "ProductTranslationHandler.TranslateProductDescription",
|
||||||
|
|
||||||
|
"product_id", productID,
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package restricted
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"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"
|
||||||
@@ -10,6 +9,7 @@ import (
|
|||||||
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"
|
||||||
@@ -47,7 +47,13 @@ func (h *MeiliSearchHandler) CreateIndex(c fiber.Ctx) error {
|
|||||||
|
|
||||||
err := h.meiliService.CreateIndex(id_lang)
|
err := h.meiliService.CreateIndex(id_lang)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("CreateIndex error: %v\n", err)
|
|
||||||
|
logger.Error("failed to create search index",
|
||||||
|
"handler", "MeiliSearchHandler.CreateIndex",
|
||||||
|
|
||||||
|
"lang_id", id_lang,
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
}
|
}
|
||||||
@@ -72,6 +78,13 @@ func (h *MeiliSearchHandler) Search(c fiber.Ctx) error {
|
|||||||
|
|
||||||
result, err := h.searchService.Search(index, c.Body(), id_lang)
|
result, err := h.searchService.Search(index, c.Body(), id_lang)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
|
logger.Error("failed to search",
|
||||||
|
"handler", "MeiliSearchHandler.Search",
|
||||||
|
|
||||||
|
"index", index,
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
}
|
}
|
||||||
@@ -80,6 +93,13 @@ func (h *MeiliSearchHandler) Search(c fiber.Ctx) error {
|
|||||||
if createErr := h.meiliService.CreateIndex(id_lang); createErr == nil {
|
if createErr := h.meiliService.CreateIndex(id_lang); createErr == nil {
|
||||||
result, err = h.searchService.Search(index, c.Body(), id_lang)
|
result, err = h.searchService.Search(index, c.Body(), id_lang)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
|
logger.Error("failed to search after index creation",
|
||||||
|
"handler", "MeiliSearchHandler.Search",
|
||||||
|
|
||||||
|
"index", index,
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
}
|
}
|
||||||
@@ -100,6 +120,13 @@ func (h *MeiliSearchHandler) GetSettings(c fiber.Ctx) error {
|
|||||||
|
|
||||||
result, err := h.searchService.GetIndexSettings(index)
|
result, err := h.searchService.GetIndexSettings(index)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
|
logger.Error("failed to get index settings",
|
||||||
|
"handler", "MeiliSearchHandler.GetSettings",
|
||||||
|
|
||||||
|
"index", index,
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"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"
|
||||||
@@ -51,6 +52,12 @@ func (h *SpecificPriceHandler) Create(c fiber.Ctx) error {
|
|||||||
|
|
||||||
result, err := h.SpecificPriceService.Create(c.Context(), &pr)
|
result, err := h.SpecificPriceService.Create(c.Context(), &pr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
|
logger.Error("failed to create specific price",
|
||||||
|
"handler", "SpecificPriceHandler.Create",
|
||||||
|
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
}
|
}
|
||||||
@@ -74,6 +81,13 @@ func (h *SpecificPriceHandler) Update(c fiber.Ctx) error {
|
|||||||
|
|
||||||
result, err := h.SpecificPriceService.Update(c.Context(), id, &pr)
|
result, err := h.SpecificPriceService.Update(c.Context(), id, &pr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
|
logger.Error("failed to update specific price",
|
||||||
|
"handler", "SpecificPriceHandler.Update",
|
||||||
|
|
||||||
|
"specific_price_id", id,
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
}
|
}
|
||||||
@@ -84,6 +98,12 @@ func (h *SpecificPriceHandler) Update(c fiber.Ctx) error {
|
|||||||
func (h *SpecificPriceHandler) List(c fiber.Ctx) error {
|
func (h *SpecificPriceHandler) List(c fiber.Ctx) error {
|
||||||
result, err := h.SpecificPriceService.List(c.Context())
|
result, err := h.SpecificPriceService.List(c.Context())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
|
logger.Error("failed to list specific prices",
|
||||||
|
"handler", "SpecificPriceHandler.List",
|
||||||
|
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
}
|
}
|
||||||
@@ -101,6 +121,13 @@ func (h *SpecificPriceHandler) GetByID(c fiber.Ctx) error {
|
|||||||
|
|
||||||
result, err := h.SpecificPriceService.GetByID(c.Context(), id)
|
result, err := h.SpecificPriceService.GetByID(c.Context(), id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
|
logger.Error("failed to get specific price",
|
||||||
|
"handler", "SpecificPriceHandler.GetByID",
|
||||||
|
|
||||||
|
"specific_price_id", id,
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
}
|
}
|
||||||
@@ -118,6 +145,13 @@ func (h *SpecificPriceHandler) Activate(c fiber.Ctx) error {
|
|||||||
|
|
||||||
err = h.SpecificPriceService.SetActive(c.Context(), id, true)
|
err = h.SpecificPriceService.SetActive(c.Context(), id, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
|
logger.Error("failed to activate specific price",
|
||||||
|
"handler", "SpecificPriceHandler.Activate",
|
||||||
|
|
||||||
|
"specific_price_id", id,
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
}
|
}
|
||||||
@@ -135,6 +169,13 @@ func (h *SpecificPriceHandler) Deactivate(c fiber.Ctx) error {
|
|||||||
|
|
||||||
err = h.SpecificPriceService.SetActive(c.Context(), id, false)
|
err = h.SpecificPriceService.SetActive(c.Context(), id, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
|
logger.Error("failed to deactivate specific price",
|
||||||
|
"handler", "SpecificPriceHandler.Deactivate",
|
||||||
|
|
||||||
|
"specific_price_id", id,
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
}
|
}
|
||||||
@@ -152,6 +193,13 @@ func (h *SpecificPriceHandler) Delete(c fiber.Ctx) error {
|
|||||||
|
|
||||||
err = h.SpecificPriceService.Delete(c.Context(), id)
|
err = h.SpecificPriceService.Delete(c.Context(), id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
|
logger.Error("failed to delete specific price",
|
||||||
|
"handler", "SpecificPriceHandler.Delete",
|
||||||
|
|
||||||
|
"specific_price_id", id,
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"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"
|
||||||
@@ -52,6 +53,12 @@ func (h *StorageHandler) ListContent(c fiber.Ctx) error {
|
|||||||
entries_in_list, err := h.storageService.ListContent(abs_path)
|
entries_in_list, err := h.storageService.ListContent(abs_path)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
|
logger.Error("failed to list storage content",
|
||||||
|
"handler", "StorageHandler.ListContent",
|
||||||
|
"path", abs_path,
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
}
|
}
|
||||||
@@ -68,6 +75,12 @@ func (h *StorageHandler) DownloadFile(c fiber.Ctx) error {
|
|||||||
|
|
||||||
f, filename, filesize, err := h.storageService.DownloadFilePrep(abs_path)
|
f, filename, filesize, err := h.storageService.DownloadFilePrep(abs_path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
|
logger.Error("failed to prepare file download",
|
||||||
|
"handler", "StorageHandler.DownloadFile",
|
||||||
|
"path", abs_path,
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
}
|
}
|
||||||
@@ -87,6 +100,12 @@ func (h *StorageHandler) CreateNewWebdavToken(c fiber.Ctx) error {
|
|||||||
|
|
||||||
new_token, err := h.storageService.NewWebdavToken(userID)
|
new_token, err := h.storageService.NewWebdavToken(userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
|
logger.Error("failed to create webdav token",
|
||||||
|
"handler", "StorageHandler.CreateNewWebdavToken",
|
||||||
|
"user_id", userID,
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ type Customer struct {
|
|||||||
CreatedAt time.Time `json:"created_at"`
|
CreatedAt time.Time `json:"created_at"`
|
||||||
UpdatedAt time.Time `json:"updated_at"`
|
UpdatedAt time.Time `json:"updated_at"`
|
||||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
||||||
|
IsNoVat bool `gorm:"default:false" json:"is_no_vat"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *Customer) HasPermission(permission perms.Permission) bool {
|
func (u *Customer) HasPermission(permission perms.Permission) bool {
|
||||||
|
|||||||
16
app/model/enums/orderStatus.go
Normal file
16
app/model/enums/orderStatus.go
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
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"
|
||||||
|
)
|
||||||
@@ -2,7 +2,7 @@ package model
|
|||||||
|
|
||||||
import "encoding/json"
|
import "encoding/json"
|
||||||
|
|
||||||
type B2BTopMenu struct {
|
type B2BMenu 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,10 +10,22 @@ type B2BTopMenu 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 *B2BTopMenu `gorm:"foreignKey:ParentID;references:MenuID;constraint:OnDelete:RESTRICT,OnUpdate:RESTRICT" json:"parent,omitempty"`
|
Parent *B2BMenu `gorm:"foreignKey:ParentID;references:MenuID;constraint:OnDelete:RESTRICT,OnUpdate:RESTRICT" json:"parent,omitempty"`
|
||||||
Children []*B2BTopMenu `gorm:"foreignKey:ParentID" json:"children,omitempty"`
|
Children []*B2BMenu `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,5 +1,11 @@
|
|||||||
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"`
|
||||||
@@ -7,7 +13,12 @@ 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 string `gorm:"column:status;size:50;not null" json:"status"`
|
Status enums.OrderStatus `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"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
20
app/model/orderStatusHistory.go
Normal file
20
app/model/orderStatusHistory.go
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
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"
|
||||||
|
}
|
||||||
@@ -12,7 +12,8 @@ type ProductInList struct {
|
|||||||
PriceTaxExcl float64 `gorm:"column:price_tax_excl" json:"price_tax_excl"`
|
PriceTaxExcl float64 `gorm:"column:price_tax_excl" json:"price_tax_excl"`
|
||||||
PriceTaxIncl float64 `gorm:"column:price_tax_incl" json:"price_tax_incl"`
|
PriceTaxIncl float64 `gorm:"column:price_tax_incl" json:"price_tax_incl"`
|
||||||
IsFavorite bool `gorm:"column:is_favorite" json:"is_favorite"`
|
IsFavorite bool `gorm:"column:is_favorite" json:"is_favorite"`
|
||||||
IsNew uint `gorm:"column:is_new" json:"is_new"`
|
IsNew bool `gorm:"column:is_new" json:"is_new"`
|
||||||
|
IsOEM bool `gorm:"column:is_oem" json:"is_oem"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ProductFilters struct {
|
type ProductFilters struct {
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import (
|
|||||||
|
|
||||||
type UICartsRepo interface {
|
type UICartsRepo interface {
|
||||||
CartsAmount(user_id uint) (uint, error)
|
CartsAmount(user_id uint) (uint, error)
|
||||||
CreateNewCart(user_id uint) (model.CustomerCart, error)
|
CreateNewCart(user_id uint, name string) (model.CustomerCart, error)
|
||||||
RemoveCart(user_id uint, cart_id uint) error
|
RemoveCart(user_id uint, cart_id uint) error
|
||||||
UserHasCart(user_id uint, cart_id uint) (bool, error)
|
UserHasCart(user_id uint, cart_id uint) (bool, error)
|
||||||
UpdateCartName(user_id uint, cart_id uint, new_name string) error
|
UpdateCartName(user_id uint, cart_id uint, new_name string) error
|
||||||
@@ -42,10 +42,7 @@ func (repo *CartsRepo) CartsAmount(user_id uint) (uint, error) {
|
|||||||
return amt, err
|
return amt, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repo *CartsRepo) CreateNewCart(user_id uint) (model.CustomerCart, error) {
|
func (repo *CartsRepo) CreateNewCart(user_id uint, name string) (model.CustomerCart, error) {
|
||||||
var name string
|
|
||||||
name = constdata.DEFAULT_NEW_CART_NAME
|
|
||||||
|
|
||||||
cart := model.CustomerCart{
|
cart := model.CustomerCart{
|
||||||
UserID: user_id,
|
UserID: user_id,
|
||||||
Name: &name,
|
Name: &name,
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ type UICustomerRepo interface {
|
|||||||
Find(langId uint, p find.Paging, filt *filters.FiltersList, search string) (*find.Found[model.UserInList], error)
|
Find(langId uint, p find.Paging, filt *filters.FiltersList, search string) (*find.Found[model.UserInList], error)
|
||||||
Save(customer *model.Customer) error
|
Save(customer *model.Customer) error
|
||||||
Create(customer *model.Customer) error
|
Create(customer *model.Customer) error
|
||||||
|
SetCustomerNoVatStatus(customerID uint, isNoVat bool) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type CustomerRepo struct{}
|
type CustomerRepo struct{}
|
||||||
@@ -114,3 +115,7 @@ func (repo *CustomerRepo) Save(customer *model.Customer) error {
|
|||||||
func (repo *CustomerRepo) Create(customer *model.Customer) error {
|
func (repo *CustomerRepo) Create(customer *model.Customer) error {
|
||||||
return db.DB.Create(customer).Error
|
return db.DB.Create(customer).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (repo *CustomerRepo) SetCustomerNoVatStatus(customerID uint, isNoVat bool) error {
|
||||||
|
return db.DB.Model(&model.Customer{}).Where("id = ?", customerID).Update("is_no_vat", isNoVat).Error
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,19 +1,23 @@
|
|||||||
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"
|
||||||
constdata "git.ma-al.com/goc_daniel/b2b/app/utils/const_data"
|
"git.ma-al.com/goc_daniel/b2b/app/model/enums"
|
||||||
"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) 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)
|
||||||
ChangeOrderAddress(order_id uint, country_id uint, address_info string) error
|
ChangeOrderAddress(order_id uint, country_id uint, address_info string) error
|
||||||
ChangeOrderStatus(order_id uint, status string) error
|
ChangeOrderStatus(orderId uint, newStatus enums.OrderStatus, userId uint) error
|
||||||
|
GetOrderStatus(orderID uint) (enums.OrderStatus, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type OrdersRepo struct{}
|
type OrdersRepo struct{}
|
||||||
@@ -35,6 +39,18 @@ 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
|
||||||
@@ -69,13 +85,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) error {
|
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) {
|
||||||
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: constdata.NEW_ORDER_STATUS,
|
Status: enums.OrderStatusPending,
|
||||||
Products: make([]model.OrderProduct, 0, len(cart.Products)),
|
Products: make([]model.OrderProduct, 0, len(cart.Products)),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,8 +102,35 @@ 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,
|
||||||
|
}
|
||||||
|
|
||||||
return db.DB.Create(&order).Error
|
err = tx.Create(&history).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 {
|
||||||
@@ -97,14 +140,53 @@ 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(order_id uint, status string) error {
|
func (repo *OrdersRepo) ChangeOrderStatus(orderID uint, newStatus enums.OrderStatus, userId uint) error {
|
||||||
return db.DB.
|
tx := db.Get().Begin()
|
||||||
Table("b2b_customer_orders").
|
|
||||||
Where("order_id = ?", order_id).
|
var currentStatus enums.OrderStatus
|
||||||
Update("status", status).
|
err := tx.Table("b2b_customer_orders").
|
||||||
Error
|
Select("status").
|
||||||
|
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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -122,6 +122,19 @@ func (repo *ProductsRepo) Find(langID uint, userID uint, p find.Paging, filt *fi
|
|||||||
Group("product_id"),
|
Group("product_id"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "oems",
|
||||||
|
Subquery: exclause.Subquery{
|
||||||
|
DB: db.DB.
|
||||||
|
Table("b2b_oems").
|
||||||
|
Select(`
|
||||||
|
product_id AS product_id,
|
||||||
|
COUNT(*) > 0 AS is_customers_oem
|
||||||
|
`).
|
||||||
|
Where("user_id = ?", userID).
|
||||||
|
Group("product_id"),
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Name: "new_product_days",
|
Name: "new_product_days",
|
||||||
Subquery: exclause.Subquery{
|
Subquery: exclause.Subquery{
|
||||||
@@ -150,6 +163,7 @@ func (repo *ProductsRepo) Find(langID uint, userID uint, p find.Paging, filt *fi
|
|||||||
pl.name AS name,
|
pl.name AS name,
|
||||||
ps.id_category_default AS category_id,
|
ps.id_category_default AS category_id,
|
||||||
p.reference AS reference,
|
p.reference AS reference,
|
||||||
|
p.is_oem AS is_oem,
|
||||||
sa.quantity AS quantity,
|
sa.quantity AS quantity,
|
||||||
COALESCE(f.is_favorite, 0) AS is_favorite,
|
COALESCE(f.is_favorite, 0) AS is_favorite,
|
||||||
CASE
|
CASE
|
||||||
@@ -166,7 +180,9 @@ func (repo *ProductsRepo) Find(langID uint, userID uint, p find.Paging, filt *fi
|
|||||||
Joins("LEFT JOIN favorites f ON f.product_id = ps.id_product").
|
Joins("LEFT JOIN favorites f ON f.product_id = ps.id_product").
|
||||||
Joins("LEFT JOIN ps_stock_available sa ON sa.id_product = ps.id_product AND sa.id_product_attribute = 0").
|
Joins("LEFT JOIN ps_stock_available sa ON sa.id_product = ps.id_product AND sa.id_product_attribute = 0").
|
||||||
Joins("LEFT JOIN new_product_days npd ON 1 = 1").
|
Joins("LEFT JOIN new_product_days npd ON 1 = 1").
|
||||||
|
Joins("LEFT JOIN oems ON oems.product_id = ps.id_product").
|
||||||
Where("ps.active = ?", 1).
|
Where("ps.active = ?", 1).
|
||||||
|
Where("(p.is_oem = 0 OR oems.is_customers_oem > 0)").
|
||||||
Group("ps.id_product"),
|
Group("ps.id_product"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -182,7 +198,8 @@ func (repo *ProductsRepo) Find(langID uint, userID uint, p find.Paging, filt *fi
|
|||||||
COALESCE(v.variants_number, 0) AS variants_number,
|
COALESCE(v.variants_number, 0) AS variants_number,
|
||||||
bp.quantity AS quantity,
|
bp.quantity AS quantity,
|
||||||
bp.is_favorite AS is_favorite,
|
bp.is_favorite AS is_favorite,
|
||||||
bp.is_new AS is_new
|
bp.is_new AS is_new,
|
||||||
|
bp.is_oem AS is_oem
|
||||||
`, config.Get().Image.ImagePrefix).
|
`, config.Get().Image.ImagePrefix).
|
||||||
Joins("JOIN ps_product_lang pl ON pl.id_product = bp.product_id AND pl.id_lang = ?", langID).
|
Joins("JOIN ps_product_lang pl ON pl.id_product = bp.product_id AND pl.id_lang = ?", langID).
|
||||||
Joins("JOIN ps_image_shop ims ON ims.id_product = bp.product_id AND ims.cover = 1").
|
Joins("JOIN ps_image_shop ims ON ims.id_product = bp.product_id AND ims.cover = 1").
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ 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{}
|
||||||
@@ -38,10 +39,23 @@ 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{Active: 1}).
|
Where(model.B2BTopMenu{B2BMenu: model.B2BMenu{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,6 +15,7 @@ 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"
|
||||||
@@ -68,22 +69,47 @@ 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
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,22 +120,38 @@ 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,6 +212,11 @@ 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,8 +228,11 @@ 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 {
|
||||||
// Log error but don't fail registration - user can request resend
|
logger.Warn("failed to send verification email",
|
||||||
_ = err
|
"service", "AuthService.Register",
|
||||||
|
"email", req.Email,
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -210,6 +260,7 @@ 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)
|
||||||
}
|
}
|
||||||
@@ -278,6 +329,7 @@ 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)
|
||||||
}
|
}
|
||||||
@@ -304,6 +356,10 @@ 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -328,7 +384,12 @@ 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -539,6 +600,7 @@ 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,10 +8,12 @@ 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"
|
||||||
@@ -77,12 +79,20 @@ 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)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"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"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -17,7 +18,7 @@ func New() *CartsService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *CartsService) CreateNewCart(user_id uint) (model.CustomerCart, error) {
|
func (s *CartsService) CreateNewCart(user_id uint, name string) (model.CustomerCart, error) {
|
||||||
var cart model.CustomerCart
|
var cart model.CustomerCart
|
||||||
|
|
||||||
customers_carts_amount, err := s.repo.CartsAmount(user_id)
|
customers_carts_amount, err := s.repo.CartsAmount(user_id)
|
||||||
@@ -28,8 +29,21 @@ func (s *CartsService) CreateNewCart(user_id uint) (model.CustomerCart, error) {
|
|||||||
return cart, responseErrors.ErrMaxAmtOfCartsReached
|
return cart, responseErrors.ErrMaxAmtOfCartsReached
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if name == "" {
|
||||||
|
name = constdata.DEFAULT_NEW_CART_NAME
|
||||||
|
}
|
||||||
|
|
||||||
// create new cart for customer
|
// create new cart for customer
|
||||||
cart, err = s.repo.CreateNewCart(user_id)
|
cart, err = s.repo.CreateNewCart(user_id, name)
|
||||||
|
if err != nil {
|
||||||
|
return cart, err
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.Info("cart created",
|
||||||
|
"service", "cartsService",
|
||||||
|
"user_id", user_id,
|
||||||
|
"cart_id", cart.CartID,
|
||||||
|
)
|
||||||
|
|
||||||
return cart, nil
|
return cart, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,3 +24,7 @@ func (s *CustomerService) GetById(id uint) (*model.Customer, error) {
|
|||||||
func (s *CustomerService) Find(langId uint, p find.Paging, filt *filters.FiltersList, search string) (*find.Found[model.UserInList], error) {
|
func (s *CustomerService) Find(langId uint, p find.Paging, filt *filters.FiltersList, search string) (*find.Found[model.UserInList], error) {
|
||||||
return s.repo.Find(langId, p, filt, search)
|
return s.repo.Find(langId, p, filt, search)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *CustomerService) SetCustomerNoVatStatus(customerID uint, isNoVat bool) error {
|
||||||
|
return s.repo.SetCustomerNoVatStatus(customerID, isNoVat)
|
||||||
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ 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"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -44,6 +45,11 @@ 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")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,6 +75,12 @@ 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,9 +132,12 @@ 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 == "" {
|
||||||
return nil // No admin email configured
|
logger.Warn("no admin email setup in the config",
|
||||||
|
"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,6 +10,7 @@ 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"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -193,18 +194,52 @@ 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.B2BTopMenu, error) {
|
func (s *MenuService) GetTopMenu(languageId uint, roleId uint) ([]*model.B2BMenu, 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
|
||||||
}
|
}
|
||||||
|
|
||||||
menuMap := make(map[int]*model.B2BTopMenu, len(items))
|
menus := make([]model.B2BMenu, len(items))
|
||||||
roots := make([]*model.B2BTopMenu, 0)
|
for i := range items {
|
||||||
|
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.B2BTopMenu, 0)
|
menu.Children = make([]*model.B2BMenu, 0)
|
||||||
menuMap[menu.MenuID] = menu
|
menuMap[menu.MenuID] = menu
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -226,26 +261,59 @@ func (s *MenuService) GetTopMenu(languageId uint, roleId uint) ([]*model.B2BTopM
|
|||||||
parent.Children = append(parent.Children, menu)
|
parent.Children = append(parent.Children, menu)
|
||||||
}
|
}
|
||||||
|
|
||||||
return roots, nil
|
return roots
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
for i := 0; i < len(*all_categories); i++ {
|
for i := 0; i < len(*all_categories); i++ {
|
||||||
(*all_categories)[i].Filter = "category_id_in=" + strconv.Itoa(int((*all_categories)[i].CategoryID))
|
(*all_categories)[i].Filter = "category_id_eq=" + strconv.Itoa(int((*all_categories)[i].CategoryID))
|
||||||
}
|
}
|
||||||
|
|
||||||
var additional model.ScannedCategory
|
// the new products category
|
||||||
additional.CategoryID = 10001
|
var new_products_category model.ScannedCategory
|
||||||
additional.Name = "New Products"
|
new_products_category.CategoryID = constdata.ADDITIONAL_CATEGORIES_INDEX + 1
|
||||||
additional.Active = 1
|
new_products_category.Name = "New Products"
|
||||||
additional.Position = 10
|
new_products_category.Active = 1
|
||||||
additional.ParentID = 2
|
new_products_category.Position = 10
|
||||||
additional.IsRoot = 0
|
new_products_category.ParentID = 2
|
||||||
additional.LinkRewrite = i18n.T___(id_lang, "category.new_products")
|
new_products_category.IsRoot = 0
|
||||||
additional.IsoCode = iso_code
|
new_products_category.LinkRewrite = i18n.T___(id_lang, "category.new_products")
|
||||||
|
new_products_category.IsoCode = iso_code
|
||||||
|
|
||||||
additional.Visited = false
|
new_products_category.Visited = false
|
||||||
additional.Filter = "is_new_in=true"
|
new_products_category.Filter = "is_new_eq=true"
|
||||||
|
|
||||||
*all_categories = append(*all_categories, additional)
|
*all_categories = append(*all_categories, new_products_category)
|
||||||
|
|
||||||
|
// the oem products category
|
||||||
|
var oem_products_category model.ScannedCategory
|
||||||
|
oem_products_category.CategoryID = constdata.ADDITIONAL_CATEGORIES_INDEX + 2
|
||||||
|
oem_products_category.Name = "OEM Products"
|
||||||
|
oem_products_category.Active = 1
|
||||||
|
oem_products_category.Position = 11
|
||||||
|
oem_products_category.ParentID = 2
|
||||||
|
oem_products_category.IsRoot = 0
|
||||||
|
oem_products_category.LinkRewrite = i18n.T___(id_lang, "category.oem_products")
|
||||||
|
oem_products_category.IsoCode = iso_code
|
||||||
|
|
||||||
|
oem_products_category.Visited = false
|
||||||
|
oem_products_category.Filter = "is_oem_eq=true"
|
||||||
|
|
||||||
|
*all_categories = append(*all_categories, oem_products_category)
|
||||||
|
|
||||||
|
// the favorite products category
|
||||||
|
var favorite_products_category model.ScannedCategory
|
||||||
|
favorite_products_category.CategoryID = constdata.ADDITIONAL_CATEGORIES_INDEX + 3
|
||||||
|
favorite_products_category.Name = "Favourite Products" // British English version.
|
||||||
|
favorite_products_category.Active = 1
|
||||||
|
favorite_products_category.Position = 12
|
||||||
|
favorite_products_category.ParentID = 2
|
||||||
|
favorite_products_category.IsRoot = 0
|
||||||
|
favorite_products_category.LinkRewrite = i18n.T___(id_lang, "category.favorite_products")
|
||||||
|
favorite_products_category.IsoCode = iso_code
|
||||||
|
|
||||||
|
favorite_products_category.Visited = false
|
||||||
|
favorite_products_category.Filter = "is_favorite_eq=true"
|
||||||
|
|
||||||
|
*all_categories = append(*all_categories, favorite_products_category)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,19 @@
|
|||||||
package orderService
|
package orderService
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"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/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"
|
||||||
@@ -18,19 +22,36 @@ 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
|
||||||
@@ -45,9 +66,12 @@ func (s *OrderService) Find(user *model.Customer, p find.Paging, filt *filters.F
|
|||||||
|
|
||||||
for i := 0; i < len(list.Items); i++ {
|
for i := 0; i < len(list.Items); i++ {
|
||||||
address_unparsed, err := s.addressesService.ValidateAddressJson(list.Items[i].AddressString, list.Items[i].CountryID)
|
address_unparsed, err := s.addressesService.ValidateAddressJson(list.Items[i].AddressString, list.Items[i].CountryID)
|
||||||
// log such errors
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("err: %v\n", err)
|
logger.Warn("failed to validate address",
|
||||||
|
"service", "orderService",
|
||||||
|
"order_id", list.Items[i].OrderID,
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
list.Items[i].AddressUnparsed = &address_unparsed
|
list.Items[i].AddressUnparsed = &address_unparsed
|
||||||
@@ -56,7 +80,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) error {
|
func (s *OrderService) PlaceNewOrder(user_id uint, cart_id uint, name string, country_id uint, address_info string, originalUserId uint) 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
|
||||||
@@ -82,8 +106,10 @@ 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
|
||||||
err = s.ordersRepo.PlaceNewOrder(cart, name, country_id, address_info)
|
order, err := s.ordersRepo.PlaceNewOrder(cart, name, country_id, address_info, originalUserId, base_price, tax_incl, tax_excl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -92,20 +118,16 @@ func (s *OrderService) PlaceNewOrder(user_id uint, cart_id uint, name string, co
|
|||||||
// if no error is returned, remove the cart. This should be smooth
|
// if no error is returned, remove the cart. This should be smooth
|
||||||
err = s.cartsRepo.RemoveCart(user_id, cart_id)
|
err = s.cartsRepo.RemoveCart(user_id, cart_id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Log error but don't fail placing order
|
logger.Warn("failed to remove cart after order placement",
|
||||||
_ = err
|
"service", "orderService",
|
||||||
|
"user_id", user_id,
|
||||||
|
"cart_id", cart_id,
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// send email to admin
|
return s.ChangeOrderStatus(user_id, order.OrderID, enums.OrderStatusPending)
|
||||||
go func(user_id uint) {
|
|
||||||
err := s.emailService.SendNewOrderPlacedNotification(user_id)
|
|
||||||
if err != nil {
|
|
||||||
// Log error but don't fail placing order
|
|
||||||
_ = err
|
|
||||||
}
|
|
||||||
}(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 {
|
||||||
@@ -128,18 +150,57 @@ 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is obiously just an initial version of this function
|
func (s *OrderService) ChangeOrderStatus(userId, orderId uint, newStatus enums.OrderStatus) error {
|
||||||
func (s *OrderService) ChangeOrderStatus(user *model.Customer, order_id uint, status string) error {
|
order, err := s.ordersRepo.Get(orderId)
|
||||||
if !user.HasPermission(perms.OrdersModifyAll) {
|
if err != nil {
|
||||||
exists, err := s.ordersRepo.UserHasOrder(user.ID, order_id)
|
return err
|
||||||
|
}
|
||||||
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
if !exists {
|
actionCtx := orderStatusActions.ActionContext{
|
||||||
return responseErrors.ErrUserHasNoSuchOrder
|
Order: order,
|
||||||
}
|
UserId: &userId,
|
||||||
|
EmailService: s.emailService,
|
||||||
}
|
}
|
||||||
|
|
||||||
return s.ordersRepo.ChangeOrderStatus(order_id, status)
|
go func() {
|
||||||
|
_ = 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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ const ADMIN_NOTIFICATION_LANGUAGE = 2
|
|||||||
|
|
||||||
// CATEGORY_TREE_ROOT_ID corresponds to id_category in ps_category which has is_root_category=1
|
// CATEGORY_TREE_ROOT_ID corresponds to id_category in ps_category which has is_root_category=1
|
||||||
const CATEGORY_TREE_ROOT_ID = 2
|
const CATEGORY_TREE_ROOT_ID = 2
|
||||||
|
const ADDITIONAL_CATEGORIES_INDEX = 10000
|
||||||
|
|
||||||
// since arrays can not be const
|
// since arrays can not be const
|
||||||
var CATEGORY_BLACKLIST = []uint{250}
|
var CATEGORY_BLACKLIST = []uint{250}
|
||||||
|
|||||||
@@ -14,6 +14,14 @@ 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 {
|
||||||
|
|||||||
151
app/utils/logger/logger.go
Normal file
151
app/utils/logger/logger.go
Normal file
@@ -0,0 +1,151 @@
|
|||||||
|
package logger
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"log/slog"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
var L *slog.Logger
|
||||||
|
|
||||||
|
const (
|
||||||
|
reset = "\033[0m"
|
||||||
|
red = "\033[31m"
|
||||||
|
yellow = "\033[33m"
|
||||||
|
green = "\033[32m"
|
||||||
|
blue = "\033[36m"
|
||||||
|
gray = "\033[90m"
|
||||||
|
)
|
||||||
|
|
||||||
|
type consoleHandler struct {
|
||||||
|
w io.Writer
|
||||||
|
colorize bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *consoleHandler) Enabled(ctx context.Context, level slog.Level) bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *consoleHandler) Handle(ctx context.Context, r slog.Record) error {
|
||||||
|
level := r.Level.String()
|
||||||
|
color := reset
|
||||||
|
|
||||||
|
switch r.Level {
|
||||||
|
case slog.LevelError:
|
||||||
|
color = red
|
||||||
|
case slog.LevelWarn:
|
||||||
|
color = yellow
|
||||||
|
case slog.LevelInfo:
|
||||||
|
color = blue
|
||||||
|
case slog.LevelDebug:
|
||||||
|
color = gray
|
||||||
|
}
|
||||||
|
|
||||||
|
var msg string
|
||||||
|
if h.colorize {
|
||||||
|
msg = fmt.Sprintf("%s%s%s %s%s%s %s%s%s",
|
||||||
|
reset, r.Time.Format("15:04:05"), reset,
|
||||||
|
color, level, reset,
|
||||||
|
reset, r.Message, reset)
|
||||||
|
} else {
|
||||||
|
msg = fmt.Sprintf("%s %s %s", r.Time.Format("15:04:05"), level, r.Message)
|
||||||
|
}
|
||||||
|
|
||||||
|
var pairs []string
|
||||||
|
r.Attrs(func(attr slog.Attr) bool {
|
||||||
|
if h.colorize {
|
||||||
|
pairs = append(pairs, fmt.Sprintf("%s%s=%s%v%s", green, attr.Key, reset, attr.Value, reset))
|
||||||
|
} else {
|
||||||
|
pairs = append(pairs, fmt.Sprintf("%s=%v", attr.Key, attr.Value))
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
|
||||||
|
if len(pairs) > 0 {
|
||||||
|
msg += " " + strings.Join(pairs, " ")
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Fprintln(h.w, msg)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *consoleHandler) WithAttrs(attrs []slog.Attr) slog.Handler {
|
||||||
|
return &consoleHandler{w: h.w, colorize: h.colorize}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *consoleHandler) WithGroup(name string) slog.Handler {
|
||||||
|
return &consoleHandler{w: h.w, colorize: h.colorize}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Init(service string, output io.Writer, level string, colorize bool) {
|
||||||
|
if output == nil {
|
||||||
|
output = os.Stderr
|
||||||
|
}
|
||||||
|
|
||||||
|
var lvl slog.Level
|
||||||
|
switch level {
|
||||||
|
case "debug":
|
||||||
|
lvl = slog.LevelDebug
|
||||||
|
case "warn":
|
||||||
|
lvl = slog.LevelWarn
|
||||||
|
case "error":
|
||||||
|
lvl = slog.LevelError
|
||||||
|
default:
|
||||||
|
lvl = slog.LevelInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
if colorize {
|
||||||
|
L = slog.New(&consoleHandler{w: output, colorize: true}).With("service", service, "level", lvl.String())
|
||||||
|
} else {
|
||||||
|
L = slog.New(slog.NewJSONHandler(output, &slog.HandlerOptions{
|
||||||
|
Level: lvl,
|
||||||
|
AddSource: false,
|
||||||
|
ReplaceAttr: func(groups []string, a slog.Attr) slog.Attr {
|
||||||
|
if a.Key == slog.TimeKey && groups == nil {
|
||||||
|
a.Key = "timestamp"
|
||||||
|
}
|
||||||
|
if a.Key == slog.LevelKey {
|
||||||
|
a.Key = "level"
|
||||||
|
}
|
||||||
|
if a.Key == slog.MessageKey {
|
||||||
|
a.Key = "message"
|
||||||
|
}
|
||||||
|
return a
|
||||||
|
},
|
||||||
|
})).With("service", service)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Info(msg string, args ...any) {
|
||||||
|
if L != nil {
|
||||||
|
L.Info(msg, args...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Warn(msg string, args ...any) {
|
||||||
|
if L != nil {
|
||||||
|
L.Warn(msg, args...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Error(msg string, args ...any) {
|
||||||
|
if L != nil {
|
||||||
|
L.Error(msg, args...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Debug(msg string, args ...any) {
|
||||||
|
if L != nil {
|
||||||
|
L.Debug(msg, args...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func With(args ...any) *slog.Logger {
|
||||||
|
if L == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return L.With(args...)
|
||||||
|
}
|
||||||
@@ -71,6 +71,8 @@ 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'")
|
||||||
@@ -314,7 +316,8 @@ 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
|
||||||
|
|||||||
@@ -95,4 +95,6 @@ type Product struct {
|
|||||||
Category string `gorm:"column:category" json:"category"`
|
Category string `gorm:"column:category" json:"category"`
|
||||||
|
|
||||||
IsFavorite bool `gorm:"column:is_favorite" json:"is_favorite"`
|
IsFavorite bool `gorm:"column:is_favorite" json:"is_favorite"`
|
||||||
|
IsOEM bool `gorm:"column:is_oem" json:"is_oem"`
|
||||||
|
IsNew bool `gorm:"column:is_new" json:"is_new"`
|
||||||
}
|
}
|
||||||
|
|||||||
15
bo/components.d.ts
vendored
15
bo/components.d.ts
vendored
@@ -11,6 +11,8 @@ export {}
|
|||||||
/* prettier-ignore */
|
/* prettier-ignore */
|
||||||
declare module 'vue' {
|
declare module 'vue' {
|
||||||
export interface GlobalComponents {
|
export interface GlobalComponents {
|
||||||
|
'>': typeof import('./src/components/admin/product/ <TabGeneralSkeleton v-if="addProductStore.loadingCategories" />.vue')['default']
|
||||||
|
AddProduct: typeof import('./src/components/admin/AddProduct.vue')['default']
|
||||||
CartDetails: typeof import('./src/components/customer/CartDetails.vue')['default']
|
CartDetails: typeof import('./src/components/customer/CartDetails.vue')['default']
|
||||||
CategoryMenu: typeof import('./src/components/inner/CategoryMenu.vue')['default']
|
CategoryMenu: typeof import('./src/components/inner/CategoryMenu.vue')['default']
|
||||||
copy: typeof import('./src/components/admin/ProductDetailView copy.vue')['default']
|
copy: typeof import('./src/components/admin/ProductDetailView copy.vue')['default']
|
||||||
@@ -21,6 +23,7 @@ declare module 'vue' {
|
|||||||
En_TermsAndConditionsView: typeof import('./src/components/terms/en_TermsAndConditionsView.vue')['default']
|
En_TermsAndConditionsView: typeof import('./src/components/terms/en_TermsAndConditionsView.vue')['default']
|
||||||
FavoriteProducts: typeof import('./src/components/admin/FavoriteProducts.vue')['default']
|
FavoriteProducts: typeof import('./src/components/admin/FavoriteProducts.vue')['default']
|
||||||
LangSwitch: typeof import('./src/components/inner/LangSwitch.vue')['default']
|
LangSwitch: typeof import('./src/components/inner/LangSwitch.vue')['default']
|
||||||
|
LayoutSkeleton: typeof import('./src/components/ui/LayoutSkeleton.vue')['default']
|
||||||
PageAddresses: typeof import('./src/components/customer/PageAddresses.vue')['default']
|
PageAddresses: typeof import('./src/components/customer/PageAddresses.vue')['default']
|
||||||
PageCart: typeof import('./src/components/customer/PageCart.vue')['default']
|
PageCart: typeof import('./src/components/customer/PageCart.vue')['default']
|
||||||
PageCarts: typeof import('./src/components/customer/PageCarts.vue')['default']
|
PageCarts: typeof import('./src/components/customer/PageCarts.vue')['default']
|
||||||
@@ -41,15 +44,26 @@ declare module 'vue' {
|
|||||||
ProductEditor: typeof import('./src/components/inner/ProductEditor.vue')['default']
|
ProductEditor: typeof import('./src/components/inner/ProductEditor.vue')['default']
|
||||||
ProductVariants: typeof import('./src/components/customer/components/ProductVariants.vue')['default']
|
ProductVariants: typeof import('./src/components/customer/components/ProductVariants.vue')['default']
|
||||||
Profile: typeof import('./src/components/customer-management/Profile.vue')['default']
|
Profile: typeof import('./src/components/customer-management/Profile.vue')['default']
|
||||||
|
RichEditor: typeof import('./src/components/ui/RichEditor.vue')['default']
|
||||||
RouterLink: typeof import('vue-router')['RouterLink']
|
RouterLink: typeof import('vue-router')['RouterLink']
|
||||||
RouterView: typeof import('vue-router')['RouterView']
|
RouterView: typeof import('vue-router')['RouterView']
|
||||||
StorageFileBrowser: typeof import('./src/components/customer/StorageFileBrowser.vue')['default']
|
StorageFileBrowser: typeof import('./src/components/customer/StorageFileBrowser.vue')['default']
|
||||||
|
TabGeneral: typeof import('./src/components/admin/product/TabGeneral.vue')['default']
|
||||||
|
TabGeneralSceleton: typeof import('./src/components/admin/product/TabGeneralSceleton.vue')['default']
|
||||||
|
TabGeneralSkeleton: typeof import('./src/components/admin/product/TabGeneralSkeleton.vue')['default']
|
||||||
|
TabOptions: typeof import('./src/components/admin/product/TabOptions.vue')['default']
|
||||||
|
TabPricing: typeof import('./src/components/admin/product/TabPricing.vue')['default']
|
||||||
|
TabQuantities: typeof import('./src/components/admin/product/TabQuantities.vue')['default']
|
||||||
|
TabSeo: typeof import('./src/components/admin/product/TabSeo.vue')['default']
|
||||||
|
TabShipping: typeof import('./src/components/admin/product/TabShipping.vue')['default']
|
||||||
|
TabVariants: typeof import('./src/components/admin/product/TabVariants.vue')['default']
|
||||||
ThemeSwitch: typeof import('./src/components/inner/ThemeSwitch.vue')['default']
|
ThemeSwitch: typeof import('./src/components/inner/ThemeSwitch.vue')['default']
|
||||||
TopBar: typeof import('./src/components/TopBar.vue')['default']
|
TopBar: typeof import('./src/components/TopBar.vue')['default']
|
||||||
TopBarLogin: typeof import('./src/components/TopBarLogin.vue')['default']
|
TopBarLogin: typeof import('./src/components/TopBarLogin.vue')['default']
|
||||||
UAlert: typeof import('./node_modules/@nuxt/ui/dist/runtime/components/Alert.vue')['default']
|
UAlert: typeof import('./node_modules/@nuxt/ui/dist/runtime/components/Alert.vue')['default']
|
||||||
UApp: typeof import('./node_modules/@nuxt/ui/dist/runtime/components/App.vue')['default']
|
UApp: typeof import('./node_modules/@nuxt/ui/dist/runtime/components/App.vue')['default']
|
||||||
UAvatar: typeof import('./node_modules/@nuxt/ui/dist/runtime/components/Avatar.vue')['default']
|
UAvatar: typeof import('./node_modules/@nuxt/ui/dist/runtime/components/Avatar.vue')['default']
|
||||||
|
UBadge: typeof import('./node_modules/@nuxt/ui/dist/runtime/components/Badge.vue')['default']
|
||||||
UButton: typeof import('./node_modules/@nuxt/ui/dist/runtime/components/Button.vue')['default']
|
UButton: typeof import('./node_modules/@nuxt/ui/dist/runtime/components/Button.vue')['default']
|
||||||
UCard: typeof import('./node_modules/@nuxt/ui/dist/runtime/components/Card.vue')['default']
|
UCard: typeof import('./node_modules/@nuxt/ui/dist/runtime/components/Card.vue')['default']
|
||||||
UCheckbox: typeof import('./node_modules/@nuxt/ui/dist/runtime/components/Checkbox.vue')['default']
|
UCheckbox: typeof import('./node_modules/@nuxt/ui/dist/runtime/components/Checkbox.vue')['default']
|
||||||
@@ -70,6 +84,7 @@ declare module 'vue' {
|
|||||||
UsersList: typeof import('./src/components/admin/UsersList.vue')['default']
|
UsersList: typeof import('./src/components/admin/UsersList.vue')['default']
|
||||||
UsersSearch: typeof import('./src/components/admin/UsersSearch.vue')['default']
|
UsersSearch: typeof import('./src/components/admin/UsersSearch.vue')['default']
|
||||||
USidebar: typeof import('./node_modules/@nuxt/ui/dist/runtime/components/Sidebar.vue')['default']
|
USidebar: typeof import('./node_modules/@nuxt/ui/dist/runtime/components/Sidebar.vue')['default']
|
||||||
|
USwitch: typeof import('./node_modules/@nuxt/ui/dist/runtime/components/Switch.vue')['default']
|
||||||
UTable: typeof import('./node_modules/@nuxt/ui/dist/runtime/components/Table.vue')['default']
|
UTable: typeof import('./node_modules/@nuxt/ui/dist/runtime/components/Table.vue')['default']
|
||||||
UTabs: typeof import('./node_modules/@nuxt/ui/dist/runtime/components/Tabs.vue')['default']
|
UTabs: typeof import('./node_modules/@nuxt/ui/dist/runtime/components/Tabs.vue')['default']
|
||||||
UTextarea: typeof import('./node_modules/@nuxt/ui/dist/runtime/components/Textarea.vue')['default']
|
UTextarea: typeof import('./node_modules/@nuxt/ui/dist/runtime/components/Textarea.vue')['default']
|
||||||
|
|||||||
6889
bo/package-lock.json
generated
Normal file
6889
bo/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -15,6 +15,9 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@nuxt/ui": "^4.6.0",
|
"@nuxt/ui": "^4.6.0",
|
||||||
"@tailwindcss/vite": "^4.2.2",
|
"@tailwindcss/vite": "^4.2.2",
|
||||||
|
"@tiptap/extension-placeholder": "^3.22.3",
|
||||||
|
"@tiptap/starter-kit": "^3.22.3",
|
||||||
|
"@tiptap/vue-3": "^3.22.3",
|
||||||
"chart.js": "^4.5.1",
|
"chart.js": "^4.5.1",
|
||||||
"pinia": "^3.0.4",
|
"pinia": "^3.0.4",
|
||||||
"reka-ui": "^2.9.3",
|
"reka-ui": "^2.9.3",
|
||||||
|
|||||||
118
bo/src/components/admin/AddProduct.vue
Normal file
118
bo/src/components/admin/AddProduct.vue
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
<template>
|
||||||
|
<div class="space-y-6">
|
||||||
|
|
||||||
|
<!-- Header bar -->
|
||||||
|
<div class="flex items-center justify-between flex-wrap gap-3">
|
||||||
|
<div class="flex items-center gap-3">
|
||||||
|
<UIcon name="i-lucide-arrow-left"
|
||||||
|
class="cursor-pointer text-(--text-sky-light) dark:text-(--text-sky-dark) text-xl"
|
||||||
|
@click="$router.back()" />
|
||||||
|
<h1 class="text-2xl font-bold text-black dark:text-white">
|
||||||
|
{{ isEditMode ? 'Edit Product' : 'Add Product' }}
|
||||||
|
</h1>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex items-center gap-3">
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<span class="text-sm text-gray-500 dark:text-gray-400">Active</span>
|
||||||
|
<USwitch v-model="store.form.active" color="success" />
|
||||||
|
</div>
|
||||||
|
<UButton variant="outline" color="neutral" @click="handleCancel">Cancel</UButton>
|
||||||
|
<UButton color="info" :loading="store.saving" @click="handleSave">
|
||||||
|
<UIcon name="i-lucide-save" class="text-base" />
|
||||||
|
Save
|
||||||
|
</UButton>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Alerts -->
|
||||||
|
<UAlert v-if="store.error" color="error" variant="subtle" :title="store.error" icon="i-lucide-alert-circle" />
|
||||||
|
<UAlert v-if="store.successMessage" color="success" variant="subtle" :title="store.successMessage"
|
||||||
|
icon="i-lucide-check-circle" />
|
||||||
|
|
||||||
|
<!-- Tabs -->
|
||||||
|
<UTabs :items="tabs" color="info" :ui="{ root: 'gap-6' }">
|
||||||
|
<template #general>
|
||||||
|
<ProductTabGeneral />
|
||||||
|
</template>
|
||||||
|
<template #pricing>
|
||||||
|
<ProductTabPricing />
|
||||||
|
</template>
|
||||||
|
<template #quantities>
|
||||||
|
<ProductTabQuantities />
|
||||||
|
</template>
|
||||||
|
<template #shipping>
|
||||||
|
<ProductTabShipping />
|
||||||
|
</template>
|
||||||
|
<template #seo>
|
||||||
|
<ProductTabSeo />
|
||||||
|
</template>
|
||||||
|
<template #options>
|
||||||
|
<ProductTabOptions />
|
||||||
|
</template>
|
||||||
|
<template #variants>
|
||||||
|
<ProductTabVariants :is-edit-mode="isEditMode" />
|
||||||
|
</template>
|
||||||
|
</UTabs>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { onMounted, computed } from 'vue'
|
||||||
|
import { useRouter } from 'vue-router'
|
||||||
|
import { useAddProductStore } from '@/stores/admin/addProduct'
|
||||||
|
import ProductTabGeneral from './product/TabGeneral.vue'
|
||||||
|
import ProductTabPricing from './product/TabPricing.vue'
|
||||||
|
import ProductTabQuantities from './product/TabQuantities.vue'
|
||||||
|
import ProductTabShipping from './product/TabShipping.vue'
|
||||||
|
import ProductTabSeo from './product/TabSeo.vue'
|
||||||
|
import ProductTabOptions from './product/TabOptions.vue'
|
||||||
|
import ProductTabVariants from './product/TabVariants.vue'
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
productId?: number
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const router = useRouter()
|
||||||
|
const store = useAddProductStore()
|
||||||
|
const isEditMode = computed(() => !!props.productId)
|
||||||
|
|
||||||
|
const tabs = computed(() => [
|
||||||
|
{ label: 'General', slot: 'general' },
|
||||||
|
{ label: 'Pricing', slot: 'pricing' },
|
||||||
|
{ label: 'Quantities', slot: 'quantities' },
|
||||||
|
{ label: 'Shipping', slot: 'shipping' },
|
||||||
|
{ label: 'SEO', slot: 'seo' },
|
||||||
|
{ label: 'Options', slot: 'options' },
|
||||||
|
...(isEditMode.value ? [{ label: 'Variants', slot: 'variants' }] : []),
|
||||||
|
])
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
store.resetForm()
|
||||||
|
if (isEditMode.value && props.productId) {
|
||||||
|
await store.loadProduct(props.productId)
|
||||||
|
await store.loadVariants(props.productId)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
async function handleSave() {
|
||||||
|
if (!store.form.name.trim()) {
|
||||||
|
store.error = 'Product name is required.'
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (isEditMode.value && props.productId) {
|
||||||
|
await store.updateProduct(props.productId)
|
||||||
|
} else {
|
||||||
|
const newId = await store.createProduct()
|
||||||
|
if (newId) {
|
||||||
|
router.push({ name: 'admin-product-edit', params: { product_id: newId } })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleCancel() {
|
||||||
|
store.resetForm()
|
||||||
|
router.push({ name: 'admin-products' })
|
||||||
|
}
|
||||||
|
</script>
|
||||||
268
bo/src/components/admin/product/TabGeneral.vue
Normal file
268
bo/src/components/admin/product/TabGeneral.vue
Normal file
@@ -0,0 +1,268 @@
|
|||||||
|
<template>
|
||||||
|
<TabGeneralSkeleton v-if="addProductStore.loadingCategories" />
|
||||||
|
|
||||||
|
<div v-else class="space-y-5">
|
||||||
|
<!-- {{ addProductStore.form }} -->
|
||||||
|
|
||||||
|
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||||
|
<UFormField label="Product name" name="productName">
|
||||||
|
<UInput v-model="addProductStore.form.product.name" placeholder="Enter product name" class="w-full" />
|
||||||
|
</UFormField>
|
||||||
|
<UFormField label="Reference (SKU)" name="productReference">
|
||||||
|
<UInput v-model="addProductStore.form.product.reference" placeholder="e.g. REF-001" class="w-full" />
|
||||||
|
</UFormField>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||||
|
<UFormField label="Podsumowanie">
|
||||||
|
<ProductEditor v-model="addProductStore.form.product.description_short" />
|
||||||
|
</UFormField>
|
||||||
|
<UFormField label="Description">
|
||||||
|
<ProductEditor v-model="addProductStore.form.product.description" />
|
||||||
|
</UFormField>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<fieldset
|
||||||
|
class="rounded-xl border border-(--border-light) dark:border-(--border-dark) p-4 space-y-3 bg-white dark:bg-neutral-900">
|
||||||
|
<legend class="px-1 block font-medium text-default text-[16px]">Images</legend>
|
||||||
|
|
||||||
|
<div class="flex items-start gap-3 flex-wrap">
|
||||||
|
<div v-for="(img, idx) in addProductStore.images" :key="idx" class="relative group shrink-0">
|
||||||
|
<div class="relative w-36 h-36 rounded-xl overflow-hidden border-2 transition-colors" :class="img.cover
|
||||||
|
? 'border-sky-500'
|
||||||
|
: 'border-(--border-light) dark:border-(--border-dark)'">
|
||||||
|
|
||||||
|
<img :src="img.previewUrl" @error="onImgError"
|
||||||
|
class="w-full h-full object-contain bg-white dark:bg-neutral-900" />
|
||||||
|
|
||||||
|
<div v-if="img.uploading" class="absolute inset-0 flex items-center justify-center bg-black/50">
|
||||||
|
<UIcon name="svg-spinners:ring-resize" class="text-2xl text-white" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-else-if="img.error"
|
||||||
|
class="absolute bottom-0 left-0 right-0 bg-red-500/80 text-white text-[10px] px-1 py-0.5 text-center truncate">
|
||||||
|
{{ img.error }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div v-if="img.cover"
|
||||||
|
class="absolute top-1.5 left-1.5 bg-sky-500 text-white text-[10px] font-semibold px-1.5 py-0.5 rounded-full leading-none">
|
||||||
|
★ Cover
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="!img.uploading"
|
||||||
|
class="absolute inset-0 flex flex-col items-center justify-center gap-2 opacity-0 group-hover:opacity-100 transition-opacity bg-black/50">
|
||||||
|
<button v-if="!img.cover" type="button"
|
||||||
|
class="flex items-center gap-1 px-2 py-1 rounded-md bg-white/20 hover:bg-sky-500 text-white text-xs font-medium transition-colors"
|
||||||
|
@click.stop="addProductStore.setCover(idx)">
|
||||||
|
<UIcon name="i-lucide-star" class="text-sm" />
|
||||||
|
Set cover
|
||||||
|
</button>
|
||||||
|
<button type="button"
|
||||||
|
class="flex items-center gap-1 px-2 py-1 rounded-md bg-white/20 hover:bg-red-500 text-white text-xs font-medium transition-colors"
|
||||||
|
@click.stop="addProductStore.removeImage(idx)">
|
||||||
|
<UIcon name="i-lucide-trash-2" class="text-sm" />
|
||||||
|
Remove
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<label
|
||||||
|
class="w-36 h-36 shrink-0 flex flex-col items-center justify-center gap-1 rounded-xl border-2 border-dashed border-(--border-light) dark:border-(--border-dark) cursor-pointer hover:border-sky-400 hover:text-sky-400 transition-colors text-gray-400"
|
||||||
|
@dragover.prevent @drop.prevent="onDrop">
|
||||||
|
<UIcon name="i-lucide-plus" class="text-2xl" />
|
||||||
|
<span class="text-xs">Add image</span>
|
||||||
|
<input type="file" accept="image/*" multiple class="hidden" @change="onFileChange" />
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</fieldset>
|
||||||
|
|
||||||
|
<div class="space-y-2">
|
||||||
|
<legend class="px-1 block font-medium text-default text-[16px]">Powiązany produkt</legend>
|
||||||
|
|
||||||
|
<UInput v-model="relatedSearch" placeholder="Search and add Powiązany produkt" icon="i-lucide-search"
|
||||||
|
class="w-full" />
|
||||||
|
<div v-if="addProductStore.relatedProducts.length > 0"
|
||||||
|
class="rounded-lg border border-(--border-light) dark:border-(--border-dark) overflow-hidden">
|
||||||
|
<div v-for="p in addProductStore.relatedProducts" :key="p.product_id"
|
||||||
|
class="flex items-center justify-between px-3 py-2 text-sm text-black dark:text-white border-b border-(--border-light) dark:border-(--border-dark) last:border-0 bg-white">
|
||||||
|
<span>{{ p.name }}</span>
|
||||||
|
<button type="button" @click="removeRelated(p.product_id)"
|
||||||
|
class="text-red-500 transition-colors ml-2 cursor-pointer hover:text-red-700">
|
||||||
|
<UIcon name="i-lucide-x" class="text-base" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="relatedResults.length > 0"
|
||||||
|
class="rounded-lg border border-(--border-light) dark:border-(--border-dark) bg-white dark:bg-neutral-900 max-h-80 overflow-auto">
|
||||||
|
<button v-for="p in relatedResults" :key="p.product_id" type="button"
|
||||||
|
class="w-full text-left px-3 py-2 text-sm text-black dark:text-white hover:bg-gray-50 dark:hover:bg-neutral-800 transition-colors border-b border-(--border-light) dark:border-(--border-dark) last:border-0"
|
||||||
|
@click="addRelated(p)">
|
||||||
|
{{ p.name }}
|
||||||
|
<span class="text-gray-400 ml-1">{{ p.reference }}</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<fieldset
|
||||||
|
class="rounded-xl border border-(--border-light) dark:border-(--border-dark) p-4 space-y-3 bg-white dark:bg-neutral-900">
|
||||||
|
<legend class="px-1 block font-medium text-default text-[16px]">Kategorie</legend>
|
||||||
|
|
||||||
|
<UInput v-model="categorySearch" placeholder="Search" class="w-52" icon="i-lucide-search" />
|
||||||
|
<div v-if="addProductStore.selectedCategories.length > 0"
|
||||||
|
class="rounded-lg border border-(--border-light) dark:border-(--border-dark) p-2 min-h-10 flex flex-wrap gap-2">
|
||||||
|
<span v-for="cat in addProductStore.selectedCategories" :key="cat.id_category"
|
||||||
|
class="inline-flex items-center gap-1 px-2.5 py-0.5 rounded-full text-xs font-medium bg-sky-100 dark:bg-sky-900 text-sky-700 dark:text-sky-300">
|
||||||
|
{{ cat.name }}
|
||||||
|
<button type="button" @click="removeCategory(cat.id_category)"
|
||||||
|
class="text-sky-500 hover:text-sky-700 dark:hover:text-sky-200 leading-none ml-0.5">
|
||||||
|
<UIcon name="i-lucide-x" />
|
||||||
|
</button>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="space-y-0.5 overflow-y-auto flex">
|
||||||
|
<UNavigationMenu orientation="vertical" type="multiple" :items="filteredCategories" :ui="{
|
||||||
|
root: 'w-auto max-h-80'
|
||||||
|
}">
|
||||||
|
<template #item="{ item }">
|
||||||
|
<div class="flex items-center gap-2.5 cursor-pointer rounded px-1.5 py-1 hover:bg-gray-50 dark:hover:bg-neutral-800 transition-colors"
|
||||||
|
@click.stop="toggleCategory({ id_category: item.params?.category_id, name: item.label as string })">
|
||||||
|
<UCheckbox :model-value="isCategorySelected(item.params?.category_id)" color="info" />
|
||||||
|
<span class="text-sm text-black dark:text-white">{{ item.label }}</span>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</UNavigationMenu>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<UButton size="xs" variant="outline" color="neutral" icon="i-lucide-plus">
|
||||||
|
Add new category
|
||||||
|
</UButton>
|
||||||
|
</fieldset>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ref, computed } from 'vue'
|
||||||
|
import { useAddProductStore } from '@/stores/admin/addProduct'
|
||||||
|
import type { ProductCategory, ProductRelated } from '@/types/product'
|
||||||
|
import errorImg from '@/assets/error.svg'
|
||||||
|
import { useFetchJson } from '@/composable/useFetchJson'
|
||||||
|
import { watch } from 'vue'
|
||||||
|
import type { NavigationMenuItem } from '@nuxt/ui'
|
||||||
|
import TabGeneralSkeleton from './TabGeneralSkeleton.vue'
|
||||||
|
|
||||||
|
const addProductStore = useAddProductStore()
|
||||||
|
|
||||||
|
const loading = ref(false)
|
||||||
|
|
||||||
|
function onImgError(e: Event) {
|
||||||
|
const target = e.target as HTMLImageElement
|
||||||
|
target.src = errorImg
|
||||||
|
}
|
||||||
|
|
||||||
|
function onFileChange(e: Event) {
|
||||||
|
const files = (e.target as HTMLInputElement).files
|
||||||
|
if (files && files.length > 0) addProductStore.addImageFiles(files)
|
||||||
|
; (e.target as HTMLInputElement).value = ''
|
||||||
|
}
|
||||||
|
|
||||||
|
function onDrop(e: DragEvent) {
|
||||||
|
const files = e.dataTransfer?.files
|
||||||
|
if (files && files.length > 0) addProductStore.addImageFiles(files)
|
||||||
|
}
|
||||||
|
|
||||||
|
// categories
|
||||||
|
const categorySearch = ref('')
|
||||||
|
const allCategories = computed(() => adaptCategory(addProductStore.categories))
|
||||||
|
function adaptCategory(menu: NavigationMenuItem[]) {
|
||||||
|
for (const item of menu) {
|
||||||
|
if (item.children && item.children.length > 0) {
|
||||||
|
item.open = true
|
||||||
|
adaptCategory(item.children);
|
||||||
|
} else {
|
||||||
|
item.icon = 'i-lucide-file-text'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return menu;
|
||||||
|
}
|
||||||
|
|
||||||
|
//filter category - return like parent => children
|
||||||
|
const filteredCategories = computed(() => {
|
||||||
|
const q = categorySearch.value.trim().toLowerCase()
|
||||||
|
if (!q) return allCategories.value
|
||||||
|
return allCategories.value.filter(c => c.name.toLowerCase().includes(q))
|
||||||
|
})
|
||||||
|
|
||||||
|
function isCategorySelected(id: number) {
|
||||||
|
return addProductStore.selectedCategories.some(c => c.id_category === id)
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleCategory(cat: ProductCategory) {
|
||||||
|
if (isCategorySelected(cat.id_category)) {
|
||||||
|
removeCategory(cat.id_category)
|
||||||
|
} else {
|
||||||
|
addProductStore.selectedCategories.push(cat)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeCategory(id: number) {
|
||||||
|
const idx = addProductStore.selectedCategories.findIndex(c => c.id_category === id)
|
||||||
|
if (idx !== -1) addProductStore.selectedCategories.splice(idx, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// related products
|
||||||
|
const relatedSearch = ref('')
|
||||||
|
const relatedResults = ref<ProductRelated[]>([])
|
||||||
|
|
||||||
|
let searchTimer: ReturnType<typeof setTimeout> | null = null
|
||||||
|
watch(relatedSearch, (q) => {
|
||||||
|
if (searchTimer) clearTimeout(searchTimer)
|
||||||
|
if (!q.trim()) { relatedResults.value = []; return }
|
||||||
|
searchTimer = setTimeout(async () => {
|
||||||
|
await fetchProducts(q)
|
||||||
|
}, 1000)
|
||||||
|
})
|
||||||
|
|
||||||
|
function addRelated(product: ProductRelated) {
|
||||||
|
if (!addProductStore.relatedProducts.some(p => p.product_id === product.product_id)) {
|
||||||
|
addProductStore.relatedProducts.push(product)
|
||||||
|
}
|
||||||
|
relatedSearch.value = ''
|
||||||
|
relatedResults.value = []
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeRelated(id: number) {
|
||||||
|
const idx = addProductStore.relatedProducts.findIndex(p => p.product_id === id)
|
||||||
|
if (idx !== -1) addProductStore.relatedProducts.splice(idx, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
const products = ref()
|
||||||
|
async function fetchProducts(q: string) {
|
||||||
|
if (!q.trim()) {
|
||||||
|
products.value = []
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
loading.value = true
|
||||||
|
relatedResults.value = []
|
||||||
|
try {
|
||||||
|
const query = `name=~${q.trim()}`
|
||||||
|
const result = await useFetchJson(
|
||||||
|
`/api/v1/restricted/product/list?${query}`
|
||||||
|
)
|
||||||
|
|
||||||
|
relatedResults.value = (result.items ?? result) as ProductRelated[]
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e);
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
addProductStore.loadCategories()
|
||||||
|
</script>
|
||||||
52
bo/src/components/admin/product/TabGeneralSkeleton.vue
Normal file
52
bo/src/components/admin/product/TabGeneralSkeleton.vue
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
<template>
|
||||||
|
<div class="space-y-5 animate-pulse">
|
||||||
|
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||||
|
<div class="space-y-1.5">
|
||||||
|
<div class="h-3.5 w-24 rounded bg-gray-200 dark:bg-neutral-700" />
|
||||||
|
<div class="h-9 rounded-lg bg-gray-200 dark:bg-neutral-700 w-full" />
|
||||||
|
</div>
|
||||||
|
<div class="space-y-1.5">
|
||||||
|
<div class="h-3.5 w-28 rounded bg-gray-200 dark:bg-neutral-700" />
|
||||||
|
<div class="h-9 rounded-lg bg-gray-200 dark:bg-neutral-700 w-full" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||||
|
<div class="space-y-1.5">
|
||||||
|
<div class="h-3.5 w-20 rounded bg-gray-200 dark:bg-neutral-700" />
|
||||||
|
<div class="h-32 rounded-lg bg-gray-200 dark:bg-neutral-700 w-full" />
|
||||||
|
</div>
|
||||||
|
<div class="space-y-1.5">
|
||||||
|
<div class="h-3.5 w-20 rounded bg-gray-200 dark:bg-neutral-700" />
|
||||||
|
<div class="h-32 rounded-lg bg-gray-200 dark:bg-neutral-700 w-full" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="rounded-xl border border-(--border-light) dark:border-(--border-dark) p-4 space-y-3">
|
||||||
|
<div class="h-4 w-16 rounded bg-gray-200 dark:bg-neutral-700" />
|
||||||
|
<div class="flex gap-3">
|
||||||
|
<div v-for="i in 3" :key="i" class="w-36 h-36 rounded-xl bg-gray-200 dark:bg-neutral-700 shrink-0" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="space-y-2">
|
||||||
|
<div class="h-3.5 w-32 rounded bg-gray-200 dark:bg-neutral-700" />
|
||||||
|
<div class="h-9 rounded-lg bg-gray-200 dark:bg-neutral-700 w-full" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="rounded-xl border border-(--border-light) dark:border-(--border-dark) p-4 space-y-3">
|
||||||
|
<div class="h-4 w-20 rounded bg-gray-200 dark:bg-neutral-700" />
|
||||||
|
<div class="h-9 w-52 rounded-lg bg-gray-200 dark:bg-neutral-700" />
|
||||||
|
<div class="space-y-2">
|
||||||
|
<div v-for="i in 5" :key="i" class="flex items-center gap-2.5 px-1.5 py-1">
|
||||||
|
<div class="h-4 w-4 rounded bg-gray-200 dark:bg-neutral-700 shrink-0" />
|
||||||
|
<div class="h-3.5 rounded bg-gray-200 dark:bg-neutral-700"
|
||||||
|
:class="['w-32', 'w-48', 'w-40', 'w-36', 'w-44'][i - 1]" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
</script>
|
||||||
47
bo/src/components/admin/product/TabOptions.vue
Normal file
47
bo/src/components/admin/product/TabOptions.vue
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
<template>
|
||||||
|
<div class="card-section space-y-6">
|
||||||
|
<div class="grid grid-cols-1 md:grid-cols-2 gap-5">
|
||||||
|
<UFormField label="Visibility">
|
||||||
|
<USelect v-model="store.form.visibility" :options="visibilityOptions" value-key="value"
|
||||||
|
label-key="label" class="w-full" />
|
||||||
|
</UFormField>
|
||||||
|
|
||||||
|
<UFormField label="Condition">
|
||||||
|
<USelect v-model="store.form.condition" :options="conditionOptions" value-key="value"
|
||||||
|
label-key="label" class="w-full" />
|
||||||
|
</UFormField>
|
||||||
|
|
||||||
|
<UFormField label="EAN-13 / JAN barcode">
|
||||||
|
<UInput v-model="store.form.ean13" placeholder="4006381333931" :maxlength="13" class="w-full" />
|
||||||
|
</UFormField>
|
||||||
|
|
||||||
|
<UFormField label="UPC barcode">
|
||||||
|
<UInput v-model="store.form.upc" placeholder="012345678905" :maxlength="12" class="w-full" />
|
||||||
|
</UFormField>
|
||||||
|
|
||||||
|
<UFormField label="ISBN">
|
||||||
|
<UInput v-model="store.form.isbn" placeholder="978-3-16-148410-0" :maxlength="32"
|
||||||
|
class="w-full" />
|
||||||
|
</UFormField>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { useAddProductStore } from '@/stores/admin/addProduct'
|
||||||
|
|
||||||
|
const store = useAddProductStore()
|
||||||
|
|
||||||
|
const visibilityOptions = [
|
||||||
|
{ value: 'both', label: 'Everywhere (catalog & search)' },
|
||||||
|
{ value: 'catalog', label: 'Catalog only' },
|
||||||
|
{ value: 'search', label: 'Search only' },
|
||||||
|
{ value: 'none', label: 'Hidden' },
|
||||||
|
]
|
||||||
|
|
||||||
|
const conditionOptions = [
|
||||||
|
{ value: 'new', label: 'New' },
|
||||||
|
{ value: 'used', label: 'Used' },
|
||||||
|
{ value: 'refurbished', label: 'Refurbished' },
|
||||||
|
]
|
||||||
|
</script>
|
||||||
26
bo/src/components/admin/product/TabPricing.vue
Normal file
26
bo/src/components/admin/product/TabPricing.vue
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<template>
|
||||||
|
<div class="card-section space-y-6">
|
||||||
|
<div class="grid grid-cols-1 md:grid-cols-2 gap-5">
|
||||||
|
<UFormField label="Price (net)">
|
||||||
|
<UInputNumber v-model="store.form.price" :min="0" :step="0.01"
|
||||||
|
:format-options="{ minimumFractionDigits: 2 }" class="w-full" />
|
||||||
|
</UFormField>
|
||||||
|
|
||||||
|
<UFormField label="Wholesale price (net)">
|
||||||
|
<UInputNumber v-model="store.form.wholesale_price" :min="0" :step="0.01"
|
||||||
|
:format-options="{ minimumFractionDigits: 2 }" class="w-full" />
|
||||||
|
</UFormField>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex items-center gap-3">
|
||||||
|
<USwitch v-model="store.form.on_sale" color="warning" />
|
||||||
|
<span class="text-sm text-black dark:text-white">Show "On Sale" badge on this product</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { useAddProductStore } from '@/stores/admin/addProduct'
|
||||||
|
|
||||||
|
const store = useAddProductStore()
|
||||||
|
</script>
|
||||||
30
bo/src/components/admin/product/TabQuantities.vue
Normal file
30
bo/src/components/admin/product/TabQuantities.vue
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<template>
|
||||||
|
<div class="card-section space-y-6">
|
||||||
|
<div class="grid grid-cols-1 md:grid-cols-2 gap-5">
|
||||||
|
<UFormField label="Stock quantity">
|
||||||
|
<UInputNumber v-model="store.form.quantity" :min="0" class="w-full" />
|
||||||
|
</UFormField>
|
||||||
|
|
||||||
|
<UFormField label="Minimum order quantity">
|
||||||
|
<UInputNumber v-model="store.form.minimal_quantity" :min="1" class="w-full" />
|
||||||
|
</UFormField>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<UFormField label="When out of stock">
|
||||||
|
<USelect v-model="store.form.out_of_stock" :options="outOfStockOptions" value-key="value"
|
||||||
|
label-key="label" class="w-72" />
|
||||||
|
</UFormField>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { useAddProductStore } from '@/stores/admin/addProduct'
|
||||||
|
|
||||||
|
const store = useAddProductStore()
|
||||||
|
|
||||||
|
const outOfStockOptions = [
|
||||||
|
{ value: 0, label: 'Deny orders' },
|
||||||
|
{ value: 1, label: 'Allow orders' },
|
||||||
|
{ value: 2, label: 'Use shop default' },
|
||||||
|
]
|
||||||
|
</script>
|
||||||
31
bo/src/components/admin/product/TabSeo.vue
Normal file
31
bo/src/components/admin/product/TabSeo.vue
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<template>
|
||||||
|
<div class="card-section space-y-6">
|
||||||
|
<p class="text-sm text-gray-400">
|
||||||
|
Leave blank to automatically use the product name. Helps search engines find your product.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<UFormField label="Meta title" hint="Recommended: max 70 characters">
|
||||||
|
<UInput v-model="store.form.meta_title" placeholder="Leave blank to use product name"
|
||||||
|
:maxlength="128" class="w-full" />
|
||||||
|
</UFormField>
|
||||||
|
|
||||||
|
<UFormField label="Meta description" hint="Recommended: max 160 characters">
|
||||||
|
<UTextarea v-model="store.form.meta_description"
|
||||||
|
placeholder="Brief description shown in search results" :rows="3" :maxlength="512"
|
||||||
|
class="w-full" />
|
||||||
|
</UFormField>
|
||||||
|
|
||||||
|
<UFormField label="URL slug">
|
||||||
|
<UInput v-model="store.form.link_rewrite" placeholder="auto-generated-from-name" class="w-full" />
|
||||||
|
<template #hint>
|
||||||
|
<span class="text-xs text-gray-400">Lowercase letters, numbers and hyphens only.</span>
|
||||||
|
</template>
|
||||||
|
</UFormField>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { useAddProductStore } from '@/stores/admin/addProduct'
|
||||||
|
|
||||||
|
const store = useAddProductStore()
|
||||||
|
</script>
|
||||||
32
bo/src/components/admin/product/TabShipping.vue
Normal file
32
bo/src/components/admin/product/TabShipping.vue
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
<template>
|
||||||
|
<div class="card-section space-y-6">
|
||||||
|
<p class="text-sm text-gray-400">
|
||||||
|
Package dimensions are used to calculate shipping costs.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div class="grid grid-cols-2 md:grid-cols-4 gap-5">
|
||||||
|
<UFormField label="Width (cm)">
|
||||||
|
<UInputNumber v-model="store.form.width" :min="0" :step="0.01" class="w-full" />
|
||||||
|
</UFormField>
|
||||||
|
<UFormField label="Height (cm)">
|
||||||
|
<UInputNumber v-model="store.form.height" :min="0" :step="0.01" class="w-full" />
|
||||||
|
</UFormField>
|
||||||
|
<UFormField label="Depth (cm)">
|
||||||
|
<UInputNumber v-model="store.form.depth" :min="0" :step="0.01" class="w-full" />
|
||||||
|
</UFormField>
|
||||||
|
<UFormField label="Weight (kg)">
|
||||||
|
<UInputNumber v-model="store.form.weight" :min="0" :step="0.001" class="w-full" />
|
||||||
|
</UFormField>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<UFormField label="Delivery days" hint="Days to ship from local warehouse to customer">
|
||||||
|
<UInputNumber v-model="store.form.delivery_days" :min="0" class="w-40" />
|
||||||
|
</UFormField>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { useAddProductStore } from '@/stores/admin/addProduct'
|
||||||
|
|
||||||
|
const store = useAddProductStore()
|
||||||
|
</script>
|
||||||
120
bo/src/components/admin/product/TabVariants.vue
Normal file
120
bo/src/components/admin/product/TabVariants.vue
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
<template>
|
||||||
|
<div class="card-section space-y-4">
|
||||||
|
|
||||||
|
<div v-if="store.loading" class="flex justify-center py-10">
|
||||||
|
<UIcon name="svg-spinners:ring-resize" class="text-3xl text-primary" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-else-if="store.variants.length === 0" class="flex flex-col items-center gap-3 py-10 text-gray-400">
|
||||||
|
<UIcon name="i-lucide-layers" class="text-4xl" />
|
||||||
|
<p class="text-sm text-center">
|
||||||
|
{{ isEditMode ? 'No variants found for this product.' : 'Save the product first, then variants will appear here.' }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<template v-else>
|
||||||
|
<p class="text-sm text-gray-400">
|
||||||
|
Each variant is a combination of attributes (e.g. Color: Red / Size: M).
|
||||||
|
Edit price offset, stock and other details per variant independently.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div v-for="variant in store.variants" :key="variant.id_product_attribute"
|
||||||
|
class="border border-(--border-light) dark:border-(--border-dark) rounded-xl p-4 space-y-4">
|
||||||
|
|
||||||
|
<!-- Variant header -->
|
||||||
|
<div class="flex items-center justify-between flex-wrap gap-2">
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<span class="font-semibold text-black dark:text-white text-sm">
|
||||||
|
{{ variant.attribute_label || `Variant #${variant.id_product_attribute}` }}
|
||||||
|
</span>
|
||||||
|
<UBadge v-if="variant.default_on" color="success" variant="subtle" size="sm">
|
||||||
|
Default
|
||||||
|
</UBadge>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<UButton size="sm" color="info"
|
||||||
|
:loading="!!store.variantSaving[variant.id_product_attribute!]"
|
||||||
|
@click="handleSaveVariant(variant)">
|
||||||
|
Save variant
|
||||||
|
</UButton>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<UAlert v-if="store.variantErrors[variant.id_product_attribute!]" color="error"
|
||||||
|
variant="subtle" :title="store.variantErrors[variant.id_product_attribute!]" />
|
||||||
|
|
||||||
|
<!-- Variant fields -->
|
||||||
|
<div class="grid grid-cols-2 md:grid-cols-4 gap-4">
|
||||||
|
<UFormField label="Reference">
|
||||||
|
<UInput v-model="variant.reference" placeholder="REF-001-A" class="w-full" />
|
||||||
|
</UFormField>
|
||||||
|
|
||||||
|
<UFormField label="EAN-13">
|
||||||
|
<UInput v-model="variant.ean13" placeholder="4006381333931" :maxlength="13"
|
||||||
|
class="w-full" />
|
||||||
|
</UFormField>
|
||||||
|
|
||||||
|
<UFormField label="Price offset">
|
||||||
|
<UInputNumber v-model="variant.price" :step="0.01"
|
||||||
|
:format-options="{ minimumFractionDigits: 2 }" class="w-full" />
|
||||||
|
</UFormField>
|
||||||
|
|
||||||
|
<UFormField label="Wholesale price">
|
||||||
|
<UInputNumber v-model="variant.wholesale_price" :min="0" :step="0.01"
|
||||||
|
:format-options="{ minimumFractionDigits: 2 }" class="w-full" />
|
||||||
|
</UFormField>
|
||||||
|
|
||||||
|
<UFormField label="Stock quantity">
|
||||||
|
<UInputNumber v-model="variant.quantity" :min="0" class="w-full" />
|
||||||
|
</UFormField>
|
||||||
|
|
||||||
|
<UFormField label="Min. quantity">
|
||||||
|
<UInputNumber v-model="variant.minimal_quantity" :min="1" class="w-full" />
|
||||||
|
</UFormField>
|
||||||
|
|
||||||
|
<UFormField label="Weight offset (kg)">
|
||||||
|
<UInputNumber v-model="variant.weight" :step="0.001" class="w-full" />
|
||||||
|
</UFormField>
|
||||||
|
|
||||||
|
<UFormField label="">
|
||||||
|
<div class="flex items-center gap-2 pt-6">
|
||||||
|
<USwitch v-model="variant.default_on" color="success"
|
||||||
|
@update:model-value="onSetDefault(variant)" />
|
||||||
|
<span class="text-sm text-black dark:text-white">Set as default</span>
|
||||||
|
</div>
|
||||||
|
</UFormField>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { useAddProductStore } from '@/stores/admin/addProduct'
|
||||||
|
import type { ProductVariantForm } from '@/types/product'
|
||||||
|
|
||||||
|
const props = defineProps<{ isEditMode: boolean }>()
|
||||||
|
|
||||||
|
const store = useAddProductStore()
|
||||||
|
|
||||||
|
async function handleSaveVariant(variant: ProductVariantForm) {
|
||||||
|
if (!variant.id_product_attribute) return
|
||||||
|
await store.saveVariant(variant.id_product_attribute, {
|
||||||
|
reference: variant.reference,
|
||||||
|
ean13: variant.ean13,
|
||||||
|
price: variant.price,
|
||||||
|
wholesale_price: variant.wholesale_price,
|
||||||
|
quantity: variant.quantity,
|
||||||
|
minimal_quantity: variant.minimal_quantity,
|
||||||
|
weight: variant.weight,
|
||||||
|
default_on: variant.default_on,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function onSetDefault(selected: ProductVariantForm) {
|
||||||
|
if (!selected.default_on) return
|
||||||
|
store.variants.forEach(v => {
|
||||||
|
if (v.id_product_attribute !== selected.id_product_attribute) v.default_on = false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
</script>
|
||||||
@@ -1,77 +1,89 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="">
|
<div class="flex flex-col gap-5">
|
||||||
<div class="flex flex-col gap-5 mb-6">
|
<div class="flex justify-between items-center">
|
||||||
<h1 class="text-2xl font-bold text-black dark:text-white">{{ t('Addresses') }}</h1>
|
<h1 class="text-2xl font-bold text-black dark:text-white">{{ t('Addresses') }}</h1>
|
||||||
<div class="flex md:flex-row flex-col justify-between items-start md:items-center gap-5 md:gap-0">
|
<UButton color="info" @click="openModal()">
|
||||||
<div class="flex gap-2 items-center">
|
|
||||||
<UInput v-model="searchQuery" type="text" :placeholder="t('Search address')"
|
|
||||||
class="bg-white dark:bg-gray-800 text-black dark:text-white absolute" />
|
|
||||||
<UIcon name="ic:baseline-search"
|
|
||||||
class="text-[20px] text-(--text-sky-light) dark:text-(--text-sky-dark) relative left-40" />
|
|
||||||
</div>
|
|
||||||
<UButton color="info" @click="openCreateModal">
|
|
||||||
<UIcon name="mdi:add-bold" />
|
<UIcon name="mdi:add-bold" />
|
||||||
{{ t('Add Address') }}
|
{{ t('Add Address') }}
|
||||||
</UButton>
|
</UButton>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div v-if="store.loading" class="text-center py-8 text-gray-500 dark:text-gray-400">
|
||||||
|
{{ t('Loading...') }}
|
||||||
</div>
|
</div>
|
||||||
<div v-if="cartStore.addressLoading" class="text-center py-8 text-gray-500 dark:text-gray-400">
|
<div v-else-if="store.error" class="text-center py-8 text-red-500">
|
||||||
{{ t('Loading addresses...') }}
|
{{ store.error }}
|
||||||
</div>
|
</div>
|
||||||
<div v-else-if="cartStore.addressError" class="text-center py-8 text-red-500 dark:text-red-400">
|
<div v-else-if="store.addresses.length" class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-6">
|
||||||
{{ cartStore.addressError }}
|
<div v-for="addr in store.addresses" :key="addr.id"
|
||||||
|
class="border border-(--border-light) dark:border-(--border-dark) rounded-md p-4 bg-(--second-light) dark:bg-(--main-dark) flex justify-between">
|
||||||
|
<div class="flex flex-col gap-1">
|
||||||
|
<p class="font-semibold text-black dark:text-white">{{ addr.address_unparsed.recipient }}</p>
|
||||||
|
<p class="text-sm text-black dark:text-white">
|
||||||
|
{{ addr.address_unparsed.street }} {{ addr.address_unparsed.building_no
|
||||||
|
}}{{ addr.address_unparsed.apartment_no ? '/' + addr.address_unparsed.apartment_no : '' }}
|
||||||
|
</p>
|
||||||
|
<p class="text-sm text-black dark:text-white">
|
||||||
|
{{ addr.address_unparsed.postal_code }}, {{ addr.address_unparsed.city }}
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div v-else-if="cartStore.paginatedAddresses.length"
|
<div class="flex flex-col items-end justify-between">
|
||||||
class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-6">
|
<UButton size="xs" color="error" variant="ghost" :title="t('Delete')"
|
||||||
<div v-for="address in cartStore.paginatedAddresses" :key="address.id"
|
@click="confirmDelete(addr.id)">
|
||||||
class="border border-(--border-light) dark:border-(--border-dark) rounded-md p-4 bg-(--second-light) dark:bg-(--main-dark) hover:shadow-md transition-shadow flex justify-between">
|
|
||||||
<div class="flex flex-col gap-2 items-start justify-end">
|
|
||||||
<p class="text-black dark:text-white font-semibold">{{ address.address_info.recipient }}</p>
|
|
||||||
<p class="text-black dark:text-white">{{ address.address_info.street }} {{
|
|
||||||
address.address_info.building_no }}{{ address.address_info.apartment_no ? '/' +
|
|
||||||
address.address_info.apartment_no : '' }}</p>
|
|
||||||
<p class="text-black dark:text-white">{{ address.address_info.postal_code }}, {{
|
|
||||||
address.address_info.city }}</p>
|
|
||||||
<p class="text-black dark:text-white">{{ address.address_info.voivodeship }}</p>
|
|
||||||
<p v-if="address.address_info.address_line2" class="text-black dark:text-white">{{
|
|
||||||
address.address_info.address_line2 }}</p>
|
|
||||||
</div>
|
|
||||||
<div class="flex flex-col items-end justify-between gap-2">
|
|
||||||
<button @click="confirmDelete(address.id)"
|
|
||||||
class="p-2 text-red-500 bg-red-100 dark:bg-(--main-dark) rounded transition-colors"
|
|
||||||
:title="t('Remove')">
|
|
||||||
<UIcon name="material-symbols:delete" class="text-[18px]" />
|
<UIcon name="material-symbols:delete" class="text-[18px]" />
|
||||||
</button>
|
</UButton>
|
||||||
<UButton size="sm" color="neutral" variant="outline" @click="openEditModal(address)"
|
<UButton size="sm" color="neutral" variant="outline" @click="openModal(addr)">
|
||||||
class="text-(--text-sky-light) dark:text-(--text-sky-dark) text-[13px]">
|
|
||||||
{{ t('edit') }}
|
{{ t('edit') }}
|
||||||
<UIcon name="ic:sharp-edit" class="text-[15px]" />
|
<UIcon name="ic:sharp-edit" class="text-[14px]" />
|
||||||
</UButton>
|
</UButton>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-else class="text-center py-8 text-gray-500 dark:text-gray-400">{{ t('No addresses found') }}</div>
|
<div v-else class="text-center py-8 text-gray-500 dark:text-gray-400">
|
||||||
<div class="mt-6 flex justify-center">
|
{{ t('No addresses found') }}
|
||||||
<UPagination v-model:page="page" :total="totalItems" :page-size="pageSize" />
|
|
||||||
</div>
|
</div>
|
||||||
<UModal v-model:open="showModal" :overlay="true" class="max-w-md mx-auto">
|
|
||||||
<template #content>
|
<UModal v-model:open="showModal">
|
||||||
<div class="p-6 flex flex-col gap-6">
|
<template #header>
|
||||||
<p class="text-[20px] text-black dark:text-white ">Address</p>
|
<h3 class="text-lg font-semibold text-black dark:text-white">
|
||||||
<UForm @submit="saveAddress" class="space-y-4" :validate="validate" :state="formData">
|
{{ editingId ? t('Edit Address') : t('Add Address') }}
|
||||||
<template v-for="field in formFieldKeys" :key="field">
|
</h3>
|
||||||
<UFormField :label="fieldLabel(field)" :name="field"
|
</template>
|
||||||
:required="field !== 'address_line2'">
|
<template #body>
|
||||||
|
<div class="flex flex-col gap-5">
|
||||||
|
<USelectMenu v-model="selectedCountry" :items="countries" class="w-full"
|
||||||
|
@update:model-value="onCountryChange" :searchInput="false">
|
||||||
|
<template #default>
|
||||||
|
<div class="flex flex-col items-start leading-tight">
|
||||||
|
<span class="text-xs text-gray-400">{{ t('Country') }}</span>
|
||||||
|
<span v-if="selectedCountry" class="font-medium text-black dark:text-white">
|
||||||
|
{{ selectedCountry.name }}
|
||||||
|
</span>
|
||||||
|
<span v-else class="text-gray-400">{{ t('Select country') }}</span>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<template #item-leading="{ item }">
|
||||||
|
<span class="text-lg mr-1">{{ item.flag }} {{ item.name }}</span>
|
||||||
|
</template>
|
||||||
|
</USelectMenu>
|
||||||
|
|
||||||
|
<div v-if="templateLoading" class="text-center py-4 text-gray-500 dark:text-gray-400">
|
||||||
|
{{ t('Loading...') }}
|
||||||
|
</div>
|
||||||
|
<p v-else-if="!selectedCountry" class="text-center text-sm text-gray-400 dark:text-gray-500">
|
||||||
|
{{ t('Select a country to continue') }}
|
||||||
|
</p>
|
||||||
|
<UForm v-else :validate="validate" :state="formData" @submit="save" class="space-y-4">
|
||||||
|
<UFormField v-for="field in templateKeys" :key="field" :label="fieldLabel(field)" :name="field"
|
||||||
|
:required="!optionalFields.has(field)">
|
||||||
<UInput v-model="formData[field]" :placeholder="fieldLabel(field)" class="w-full" />
|
<UInput v-model="formData[field]" :placeholder="fieldLabel(field)" class="w-full" />
|
||||||
</UFormField>
|
</UFormField>
|
||||||
</template>
|
|
||||||
|
|
||||||
<div class="flex justify-end gap-2">
|
<div class="flex justify-end gap-2 pt-2">
|
||||||
<UButton variant="outline" color="neutral" @click="closeModal">
|
<UButton variant="outline" color="neutral" @click="showModal = false">
|
||||||
{{ t('Cancel') }}
|
{{ t('Cancel') }}
|
||||||
</UButton>
|
</UButton>
|
||||||
|
<UButton type="submit" color="info">
|
||||||
<UButton type="submit" color="info" class="cursor-pointer">
|
|
||||||
{{ t('Save') }}
|
{{ t('Save') }}
|
||||||
</UButton>
|
</UButton>
|
||||||
</div>
|
</div>
|
||||||
@@ -79,24 +91,25 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</UModal>
|
</UModal>
|
||||||
<UModal v-model:open="showDeleteConfirm" :overlay="true" class="max-w-md mx-auto">
|
|
||||||
<template #content>
|
<UModal v-model:open="showDeleteConfirm">
|
||||||
<div class="p-6 flex flex-col gap-3">
|
<template #body>
|
||||||
<div class="flex flex-col gap-2 justify-center items-center">
|
<div class="flex flex-col items-center gap-3 py-2">
|
||||||
<p class="flex items-end gap-2 dark:text-white text-black">
|
<UIcon name="f7:exclamationmark-triangle" class="text-[40px] text-red-600" />
|
||||||
<UIcon name='f7:exclamationmark-triangle' class="text-[35px] text-red-700" />
|
<p class="font-semibold text-black dark:text-white">{{ t('Confirm Delete') }}</p>
|
||||||
Confirm Delete
|
<p class="text-sm text-gray-600 dark:text-gray-300">
|
||||||
|
{{ t('Are you sure you want to delete this address?') }}
|
||||||
</p>
|
</p>
|
||||||
<p class="text-gray-700 dark:text-gray-300">
|
|
||||||
{{ t('Are you sure you want to delete this address?') }}</p>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="flex justify-center gap-5">
|
</template>
|
||||||
<UButton variant="outline" color="neutral" @click="showDeleteConfirm = false"
|
<template #footer>
|
||||||
class="dark:text-white text-black">{{ t('Cancel') }}
|
<div class="flex justify-center gap-4">
|
||||||
|
<UButton variant="outline" color="neutral" @click="showDeleteConfirm = false">
|
||||||
|
{{ t('Cancel') }}
|
||||||
|
</UButton>
|
||||||
|
<UButton variant="outline" color="error" @click="deleteAddress">
|
||||||
|
{{ t('Delete') }}
|
||||||
</UButton>
|
</UButton>
|
||||||
<UButton variant="outline" color="neutral" @click="deleteAddress" class="text-red-700">
|
|
||||||
{{ t('Delete') }}</UButton>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</UModal>
|
</UModal>
|
||||||
@@ -104,53 +117,33 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, reactive, computed, watch, onMounted } from 'vue'
|
import { ref, reactive, computed } from 'vue'
|
||||||
import { useCartStore } from '@/stores/customer/cart'
|
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
import { currentCountry } from '@/router/langs'
|
import { countries } from '@/router/langs'
|
||||||
|
import { useAddressStore } from '@/stores/customer/address'
|
||||||
|
import type { Country } from '@/types'
|
||||||
|
import type { Address } from '@/stores/customer/address'
|
||||||
|
|
||||||
type AddressFormState = Record<string, string>
|
|
||||||
|
|
||||||
const cartStore = useCartStore()
|
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
const searchQuery = ref(cartStore.addressSearchQuery)
|
const store = useAddressStore()
|
||||||
|
|
||||||
|
// --- Modal state ---
|
||||||
const showModal = ref(false)
|
const showModal = ref(false)
|
||||||
const isEditing = ref(false)
|
const editingId = ref<number | null>(null)
|
||||||
const editingAddressId = ref<number | null>(null)
|
const selectedCountry = ref<Country | null>(null)
|
||||||
const addressTemplate = ref<AddressFormState | null>(null)
|
const templateLoading = ref(false)
|
||||||
const formData = reactive<AddressFormState>({})
|
const template = ref<Record<string, string>>({})
|
||||||
|
const formData = reactive<Record<string, string>>({})
|
||||||
|
|
||||||
|
const templateKeys = computed(() => Object.keys(template.value))
|
||||||
|
const optionalFields = new Set(['address_line2'])
|
||||||
|
|
||||||
|
// --- Delete state ---
|
||||||
const showDeleteConfirm = ref(false)
|
const showDeleteConfirm = ref(false)
|
||||||
const addressToDelete = ref<number | null>(null)
|
const deleteId = ref<number | null>(null)
|
||||||
|
|
||||||
const page = computed<number>({
|
const fieldLabels: Record<string, string> = {
|
||||||
get: () => cartStore.addressCurrentPage,
|
recipient: 'Recipient',
|
||||||
set: (value: number) => cartStore.setAddressPage(value)
|
|
||||||
})
|
|
||||||
const totalItems = computed(() => cartStore.totalAddressItems)
|
|
||||||
const pageSize = cartStore.addressPageSize
|
|
||||||
const formFieldKeys = computed(() => (addressTemplate.value ? Object.keys(addressTemplate.value) : []))
|
|
||||||
|
|
||||||
watch(searchQuery, (val) => {
|
|
||||||
cartStore.setAddressSearchQuery(val)
|
|
||||||
})
|
|
||||||
|
|
||||||
onMounted(() => {
|
|
||||||
cartStore.fetchAddresses()
|
|
||||||
})
|
|
||||||
|
|
||||||
function clearFormData() {
|
|
||||||
Object.keys(formData).forEach((key) => delete formData[key])
|
|
||||||
}
|
|
||||||
|
|
||||||
function fieldLabel(key: string) {
|
|
||||||
const labels: Record<string, string> = {
|
|
||||||
postal_code: 'Zip Code',
|
|
||||||
post_town: 'City',
|
|
||||||
city: 'City',
|
|
||||||
county: 'County',
|
|
||||||
region: 'Region',
|
|
||||||
voivodeship: 'Region / Voivodeship',
|
|
||||||
street: 'Street',
|
street: 'Street',
|
||||||
thoroughfare: 'Street',
|
thoroughfare: 'Street',
|
||||||
building_no: 'Building No',
|
building_no: 'Building No',
|
||||||
@@ -159,90 +152,88 @@ function fieldLabel(key: string) {
|
|||||||
orientation_number: 'Orientation Number',
|
orientation_number: 'Orientation Number',
|
||||||
apartment_no: 'Apartment No',
|
apartment_no: 'Apartment No',
|
||||||
sub_building: 'Sub Building',
|
sub_building: 'Sub Building',
|
||||||
address_line2: 'Address Line 2',
|
postal_code: 'Zip Code',
|
||||||
recipient: 'Recipient'
|
post_town: 'City',
|
||||||
|
city: 'City',
|
||||||
|
county: 'County',
|
||||||
|
region: 'Region',
|
||||||
|
voivodeship: 'Region / Voivodeship',
|
||||||
|
address_line2: 'Address Line 2'
|
||||||
}
|
}
|
||||||
|
|
||||||
return t(labels[key] ?? key.replace(/_/g, ' ').replace(/\b\w/g, (chr) => chr.toUpperCase()))
|
function fieldLabel(key: string) {
|
||||||
}
|
return t(fieldLabels[key] ?? key.replace(/_/g, ' ').replace(/\b\w/g, (c) => c.toUpperCase()))
|
||||||
|
|
||||||
async function openCreateModal() {
|
|
||||||
resetForm()
|
|
||||||
isEditing.value = false
|
|
||||||
|
|
||||||
const template = await cartStore.getAddressTemplate(Number(currentCountry.value?.id) | 2).catch(() => null)
|
|
||||||
if (template) {
|
|
||||||
addressTemplate.value = template
|
|
||||||
clearFormData()
|
|
||||||
Object.assign(formData, template)
|
|
||||||
}
|
|
||||||
|
|
||||||
showModal.value = true
|
|
||||||
}
|
|
||||||
|
|
||||||
async function openEditModal(address: any) {
|
|
||||||
currentCountry.value = address.country_id || 1
|
|
||||||
const template = await cartStore.getAddressTemplate(address.country_id | 2).catch(() => null)
|
|
||||||
|
|
||||||
if (template) {
|
|
||||||
addressTemplate.value = template
|
|
||||||
clearFormData()
|
|
||||||
Object.assign(formData, template)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (address.address_info) {
|
|
||||||
formFieldKeys.value.forEach((key) => {
|
|
||||||
formData[key] = address.address_info[key] ?? ''
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
isEditing.value = true
|
|
||||||
editingAddressId.value = address.id
|
|
||||||
showModal.value = true
|
|
||||||
}
|
|
||||||
|
|
||||||
function resetForm() {
|
|
||||||
clearFormData()
|
|
||||||
editingAddressId.value = null
|
|
||||||
}
|
|
||||||
|
|
||||||
function closeModal() {
|
|
||||||
showModal.value = false
|
|
||||||
resetForm()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function validate() {
|
function validate() {
|
||||||
const errors: Array<{ name: string; message: string }> = []
|
return templateKeys.value
|
||||||
const optionalFields = new Set(['address_line2'])
|
.filter((key) => !optionalFields.has(key) && !formData[key]?.trim())
|
||||||
|
.map((key) => ({ name: key, message: t(`${fieldLabel(key)} is required`) }))
|
||||||
formFieldKeys.value.forEach((key) => {
|
|
||||||
if (!optionalFields.has(key) && !formData[key]?.trim()) {
|
|
||||||
errors.push({ name: key, message: `${fieldLabel(key)} required` })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function applyTemplate(tpl: Record<string, string>, existing?: Record<string, string>) {
|
||||||
|
Object.keys(formData).forEach((k) => delete formData[k])
|
||||||
|
Object.keys(tpl).forEach((k) => {
|
||||||
|
formData[k] = existing?.[k] ?? ''
|
||||||
})
|
})
|
||||||
|
|
||||||
return errors
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function saveAddress() {
|
function openModal(addr?: Address) {
|
||||||
if (isEditing.value && editingAddressId.value) {
|
template.value = {}
|
||||||
await cartStore.updateAddress(editingAddressId.value, currentCountry.value?.id || 2, formData)
|
Object.keys(formData).forEach((k) => delete formData[k])
|
||||||
|
|
||||||
|
if (addr) {
|
||||||
|
editingId.value = addr.id
|
||||||
|
selectedCountry.value = countries.find((c) => c.id === addr.country_id) ?? null
|
||||||
|
loadTemplate(addr.country_id, addr.address_unparsed)
|
||||||
} else {
|
} else {
|
||||||
await cartStore.addAddress(currentCountry.value?.id || 2, formData)
|
editingId.value = null
|
||||||
|
selectedCountry.value = null
|
||||||
}
|
}
|
||||||
closeModal()
|
|
||||||
|
showModal.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
async function onCountryChange(country: Country | null) {
|
||||||
|
if (!country) {
|
||||||
|
template.value = {}
|
||||||
|
Object.keys(formData).forEach((k) => delete formData[k])
|
||||||
|
return
|
||||||
|
}
|
||||||
|
await loadTemplate(country.id)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadTemplate(countryId: number, existing?: Record<string, string>) {
|
||||||
|
templateLoading.value = true
|
||||||
|
try {
|
||||||
|
const tpl = await store.getTemplate(countryId)
|
||||||
|
template.value = tpl
|
||||||
|
applyTemplate(tpl, existing)
|
||||||
|
} finally {
|
||||||
|
templateLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function save() {
|
||||||
|
if (!selectedCountry.value) return
|
||||||
|
if (editingId.value) {
|
||||||
|
await store.updateAddress(editingId.value, selectedCountry.value.id, { ...formData })
|
||||||
|
} else {
|
||||||
|
await store.createAddress(selectedCountry.value.id, { ...formData })
|
||||||
|
}
|
||||||
|
showModal.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
function confirmDelete(id: number) {
|
function confirmDelete(id: number) {
|
||||||
addressToDelete.value = id
|
deleteId.value = id
|
||||||
showDeleteConfirm.value = true
|
showDeleteConfirm.value = true
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deleteAddress() {
|
async function deleteAddress() {
|
||||||
if (addressToDelete.value) {
|
if (deleteId.value) await store.deleteAddress(deleteId.value)
|
||||||
await cartStore.deleteAddress(addressToDelete.value)
|
|
||||||
}
|
|
||||||
showDeleteConfirm.value = false
|
showDeleteConfirm.value = false
|
||||||
addressToDelete.value = null
|
deleteId.value = null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
store.fetchAddresses()
|
||||||
</script>
|
</script>
|
||||||
@@ -1,15 +1,12 @@
|
|||||||
<template>
|
<template>
|
||||||
<component :is="Default || 'div'">
|
|
||||||
<div class="flex flex-col gap-5 md:gap-10">
|
<div class="flex flex-col gap-5 md:gap-10">
|
||||||
<h1 class="text-2xl font-bold text-black dark:text-white">
|
<h1 class="text-2xl font-bold text-black dark:text-white">
|
||||||
Shopping Cart
|
Shopping Cart
|
||||||
</h1>
|
</h1>
|
||||||
</div>
|
</div>
|
||||||
</component>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import Default from '@/layouts/default.vue';
|
|
||||||
import { useCartStore } from '@/stores/customer/cart';
|
import { useCartStore } from '@/stores/customer/cart';
|
||||||
|
|
||||||
const cartStore =useCartStore()
|
const cartStore =useCartStore()
|
||||||
|
|||||||
@@ -1,21 +1,13 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="flex flex-col gap-5 md:gap-10">
|
<div class="flex flex-col gap-5 md:gap-10">
|
||||||
<h1 class="text-2xl font-bold text-black dark:text-white">{{ t('Shopping Cart') }}</h1>
|
<div class="flex flex-col md:flex-row justify-between items-center gap-4">
|
||||||
<div class="flex flex-col lg:flex-row gap-5 md:gap-10">
|
<h1 class="text-2xl font-bold text-black dark:text-white">{{ t('Shopping Carts') }}</h1>
|
||||||
<div class="flex-1">
|
<div class="flex gap-3">
|
||||||
<div
|
<UButton color="primary" @click="showCreateModal = true" :disabled="cartStore.carts?.length >= 10"
|
||||||
class="bg-(--second-light) dark:bg-(--main-dark) rounded-lg border border-(--border-light) dark:border-(--border-dark) overflow-hidden">
|
class="bg-(--accent-blue-light) dark:bg-(--accent-blue-dark) text-white hover:bg-(--accent-blue-dark) dark:hover:bg-(--accent-blue-light)">
|
||||||
<h2
|
<UIcon name="mdi:plus" class="mr-1" />
|
||||||
class="text-lg font-semibold text-black dark:text-white p-4 border-b border-(--border-light) dark:border-(--border-dark)">
|
{{ t('New Cart') }}
|
||||||
{{ t('Selected Products') }}
|
</UButton>
|
||||||
</h2>
|
|
||||||
<div v-if="cartStore.items.length > 0">
|
|
||||||
<div v-for="item in cartStore.items" :key="item.id"
|
|
||||||
class="grid grid-cols-5 items-center p-4 border-b border-(--border-light) dark:border-(--border-dark) w-[100%]">
|
|
||||||
<div
|
|
||||||
class="bg-(--second-light) dark:bg-(--main-dark) rounded flex items-center justify-center overflow-hidden">
|
|
||||||
<img v-if="item.image" :src="item.image" :alt="item.name" class="w-full h-full object-cover" />
|
|
||||||
<UIcon v-else name="mdi:package-variant" class="text-2xl text-gray-400" />
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -35,17 +27,15 @@
|
|||||||
: 'hover:bg-gray-50 dark:hover:bg-gray-800 border-l-4 border-transparent'">
|
: 'hover:bg-gray-50 dark:hover:bg-gray-800 border-l-4 border-transparent'">
|
||||||
<div class="flex-1 min-w-0">
|
<div class="flex-1 min-w-0">
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
<p class="text-red-600 font-medium truncate">{{ cart.cart_id }}</p>
|
|
||||||
<p class="text-black dark:text-white font-medium truncate cursor-pointer"
|
<p class="text-black dark:text-white font-medium truncate cursor-pointer"
|
||||||
@click="openCart(cart)">{{
|
@click="openCart(cart)">{{ cart.name }}</p>
|
||||||
cart.name }}</p>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<input type="checkbox" :checked="cartStore.activeCartId === cart.cart_id"
|
<input type="checkbox" :checked="cartStore.activeCartId === cart.cart_id"
|
||||||
@change="toggleCart(cart.cart_id)" />
|
@change="toggleCart(cart.cart_id)" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-else class="p-8 text-center">
|
<div v-else class="p-8 text-center flex items-center justify-center">
|
||||||
<UIcon name="mdi:cart-outline" class="text-4xl text-gray-300 dark:text-gray-600 mb-2" />
|
<UIcon name="mdi:cart-outline" class="text-4xl text-gray-300 dark:text-gray-600 mb-2" />
|
||||||
<p class="text-gray-500 dark:text-gray-400">{{ t('No carts yet') }}</p>
|
<p class="text-gray-500 dark:text-gray-400">{{ t('No carts yet') }}</p>
|
||||||
</div>
|
</div>
|
||||||
@@ -73,12 +63,8 @@
|
|||||||
{{ t('Create') }}
|
{{ t('Create') }}
|
||||||
</UButton>
|
</UButton>
|
||||||
</div>
|
</div>
|
||||||
</label>
|
</template>
|
||||||
</div>
|
</UModal>
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
@@ -86,9 +72,7 @@ import { ref, onMounted } from 'vue'
|
|||||||
import { useCartStore } from '@/stores/customer/cart'
|
import { useCartStore } from '@/stores/customer/cart'
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
const cartStore = useCartStore()
|
|
||||||
const addressStore = useAddressStore()
|
|
||||||
const { t } = useI18n()
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
const cartStore = useCartStore()
|
const cartStore = useCartStore()
|
||||||
@@ -103,12 +87,10 @@ async function createCart() {
|
|||||||
showCreateModal.value = false
|
showCreateModal.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
cartStore.fetchCarts()
|
cartStore.fetchCarts()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
function openCart(cart) {
|
function openCart(cart) {
|
||||||
router.push({ name: 'customer-cart', params: { id: cart.cart_id } });
|
router.push({ name: 'customer-cart', params: { id: cart.cart_id } });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,47 +1,60 @@
|
|||||||
<template>
|
<template>
|
||||||
<component :is="Default">
|
|
||||||
<div class="pt-70! flex flex-col items-center justify-center bg-gray-50 dark:bg-(--main-dark)">
|
<div class="pt-70! flex flex-col items-center justify-center bg-gray-50 dark:bg-(--main-dark)">
|
||||||
<h1 class="text-6xl font-bold text-black dark:text-white mb-14">Search Products</h1>
|
<h1 class="text-6xl font-bold text-black dark:text-white mb-14">
|
||||||
|
Search Products
|
||||||
|
</h1>
|
||||||
|
|
||||||
<div class="w-full max-w-4xl">
|
<div class="w-full max-w-4xl">
|
||||||
<UInput icon="i-lucide-search" type="text" placeholder="Type product name or ID..."
|
<UInput icon="i-lucide-search" type="text" placeholder="Type product name or ID..."
|
||||||
v-model="searchQuery" class="w-full!" :ui="{ base: 'py-4! rounded-full!' }" />
|
v-model="searchQuery" class="w-full!" :ui="{ base: 'py-4! rounded-full!' }" />
|
||||||
</div>
|
</div>
|
||||||
<div v-if="products.length" class="mt-6">
|
|
||||||
<UTable :data="products" :columns="columns" class="flex-1 w-full" :ui="{
|
<div v-if="loading" class="mt-6">
|
||||||
root: 'max-w-100wv overflow-auto!'
|
Loading...
|
||||||
}" />
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p v-else-if="searchQuery">
|
<div v-else-if="products.length" class="mt-6 w-full">
|
||||||
|
<UTable :data="products" :columns="columns" class="flex-1 w-full"
|
||||||
|
:ui="{ root: 'max-w-100wv overflow-auto!' }" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p v-else-if="searchQuery" class="mt-6">
|
||||||
No products found
|
No products found
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</component>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { useFetchJson } from '@/composable/useFetchJson';
|
import { useFetchJson } from '@/composable/useFetchJson'
|
||||||
import Default from '@/layouts/default.vue';
|
import { ref, watch, computed, resolveComponent } from 'vue'
|
||||||
import { watch } from 'vue';
|
import { useRoute, useRouter } from 'vue-router'
|
||||||
import { ref } from 'vue';
|
import { debounce } from 'chart.js/helpers'
|
||||||
|
import { h } from 'vue'
|
||||||
|
|
||||||
|
import type { TableColumn } from '@nuxt/ui'
|
||||||
|
import type { Product } from '@/types/product'
|
||||||
|
import errorImg from '@/assets/error.svg'
|
||||||
|
|
||||||
const searchQuery = ref('')
|
const searchQuery = ref('')
|
||||||
const products = ref([])
|
const products = ref<Product[]>([])
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
const error = ref<string | null>(null)
|
const error = ref<string | null>(null)
|
||||||
|
|
||||||
|
|
||||||
async function fetchProducts() {
|
async function fetchProducts() {
|
||||||
|
if (!searchQuery.value.trim()) {
|
||||||
|
products.value = []
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
loading.value = true
|
loading.value = true
|
||||||
error.value = null
|
error.value = null
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const query = searchQuery.value
|
const query = `name=~${searchQuery.value.trim()}`
|
||||||
? `name=~${searchQuery.value}`
|
|
||||||
: ''
|
|
||||||
|
|
||||||
const result = await useFetchJson(
|
const result = await useFetchJson(
|
||||||
`/api/v1/restricted/list-products/get-listing?${query}`
|
`/api/v1/restricted/product/list?${query}`
|
||||||
)
|
)
|
||||||
|
|
||||||
products.value = result.items || result
|
products.value = result.items || result
|
||||||
@@ -52,125 +65,90 @@ async function fetchProducts() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const debouncedFetch = debounce(fetchProducts, 400)
|
||||||
|
|
||||||
watch(searchQuery, () => {
|
watch(searchQuery, () => {
|
||||||
fetchProducts()
|
debouncedFetch()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const route = useRoute()
|
||||||
|
const router = useRouter()
|
||||||
|
|
||||||
import errorImg from '@/assets/error.svg'
|
const sortField = computed({
|
||||||
import type { TableColumn } from '@nuxt/ui';
|
get: () => [
|
||||||
import type { Product } from '@/types/product';
|
route.query.sort as string | undefined,
|
||||||
// const columns: TableColumn<Product>[] = [
|
route.query.direction as 'asc' | 'desc' | undefined
|
||||||
// {
|
],
|
||||||
// accessorKey: 'product_id',
|
set: ([sort]: [string, 'asc' | 'desc']) => {
|
||||||
// header: ({ column }) => {
|
const query = { ...route.query, sort, direction: 'asc' }
|
||||||
// return h('div', { class: 'flex flex-col gap-1' }, [
|
router.push({ query })
|
||||||
// h('div', {
|
}
|
||||||
// class: 'flex items-center gap-2 cursor-pointer',
|
})
|
||||||
// onClick: () => {
|
|
||||||
// sortField.value = ['product_id', 'asc']
|
|
||||||
// }
|
|
||||||
// }, [
|
|
||||||
// h('span', 'ID'),
|
|
||||||
// h(UIcon, {
|
|
||||||
// name: getIcon('product_id')
|
|
||||||
// })
|
|
||||||
// ]),
|
|
||||||
|
|
||||||
// h(UInput, {
|
function getIcon(name: string) {
|
||||||
// placeholder: 'Search...',
|
if (sortField.value[0] === name) {
|
||||||
// modelValue: filters.value[column.id] ?? '',
|
return sortField.value[1] === 'asc'
|
||||||
// 'onUpdate:modelValue': (val: string) => {
|
? 'i-lucide-arrow-up-narrow-wide'
|
||||||
// updateFilter(column.id, val)
|
: 'i-lucide-arrow-down-wide-narrow'
|
||||||
// },
|
}
|
||||||
// size: 'xs'
|
return 'i-lucide-arrow-up-down'
|
||||||
// })
|
}
|
||||||
// ])
|
|
||||||
// },
|
|
||||||
// // header: '#',
|
|
||||||
// cell: ({ row }) => `#${row.getValue('product_id') as number}`
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// accessorKey: 'image_link',
|
|
||||||
// header: 'Image',
|
|
||||||
// cell: ({ row }) => {
|
|
||||||
// return h('img', {
|
|
||||||
// src: row.getValue('image_link') as string,
|
|
||||||
// style: 'width:40px;height:40px;object-fit:cover;',
|
|
||||||
// onError: (e: Event) => {
|
|
||||||
// const target = e.target as HTMLImageElement
|
|
||||||
// target.src = errorImg
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
// },
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// accessorKey: 'name',
|
|
||||||
// header: ({ column }) => {
|
|
||||||
// return h('div', { class: 'flex flex-col gap-1' }, [
|
|
||||||
// h('div', {
|
|
||||||
// class: 'flex items-center gap-2 cursor-pointer',
|
|
||||||
// onClick: () => {
|
|
||||||
// sortField.value = ['name', 'asc']
|
|
||||||
// }
|
|
||||||
// }, [
|
|
||||||
// h('span', 'Name'),
|
|
||||||
// h(UIcon, {
|
|
||||||
// name: getIcon('name')
|
|
||||||
// })
|
|
||||||
// ]),
|
|
||||||
|
|
||||||
// h(UInput, {
|
|
||||||
// placeholder: 'Search...',
|
const UInput = resolveComponent('UInput')
|
||||||
// modelValue: filters.value[column.id] ?? '',
|
const UButton = resolveComponent('UButton')
|
||||||
// 'onUpdate:modelValue': (val: string) => {
|
const UIcon = resolveComponent('UIcon')
|
||||||
// updateFilter(column.id, val)
|
|
||||||
// },
|
const columns: TableColumn<Product>[] = [
|
||||||
// size: 'xs'
|
{
|
||||||
// })
|
accessorKey: 'product_id',
|
||||||
// ])
|
header: 'ID',
|
||||||
// },
|
cell: ({ row }) => `#${row.getValue('product_id')}`
|
||||||
// cell: ({ row }) => row.getValue('name') as string,
|
},
|
||||||
// filterFn: (row, columnId, value) => {
|
{
|
||||||
// const name = row.getValue(columnId) as string
|
accessorKey: 'image_link',
|
||||||
// return name.toLowerCase().includes(value.toLowerCase())
|
header: 'Image',
|
||||||
// }
|
cell: ({ row }) =>
|
||||||
// },
|
h('img', {
|
||||||
// {
|
src: row.getValue('image_link'),
|
||||||
// accessorKey: 'quantity',
|
style: 'width:40px;height:40px;object-fit:cover;',
|
||||||
// header: ({ }) => {
|
onError: (e: Event) => {
|
||||||
// return h('div', { class: 'flex flex-col gap-1' }, [
|
(e.target as HTMLImageElement).src = errorImg
|
||||||
// h('div', {
|
}
|
||||||
// class: 'flex items-center gap-2 cursor-pointer',
|
})
|
||||||
// onClick: () => {
|
},
|
||||||
// sortField.value = ['quantity', 'asc']
|
{
|
||||||
// }
|
accessorKey: 'name',
|
||||||
// }, [
|
header: 'Name',
|
||||||
// h('span', 'In stock'),
|
cell: ({ row }) => row.getValue('name')
|
||||||
// h(UIcon, {
|
},
|
||||||
// name: getIcon('quantity')
|
{
|
||||||
// })
|
accessorKey: 'quantity',
|
||||||
// ]),
|
header: 'In stock',
|
||||||
// ])
|
cell: ({ row }) => row.getValue('quantity')
|
||||||
// },
|
},
|
||||||
// cell: ({ row }) => row.getValue('quantity') as number
|
{
|
||||||
// },
|
accessorKey: 'action',
|
||||||
// {
|
header: '',
|
||||||
// accessorKey: 'count',
|
cell: ({ row }) =>
|
||||||
// header: '',
|
h(
|
||||||
// cell: ({ row }) => {
|
UButton,
|
||||||
// return h(UButton, {
|
{
|
||||||
// onClick: () => {
|
onClick: () =>
|
||||||
// goToProduct(row.original.product_id, row.original.link_rewrite)
|
router.push({
|
||||||
// },
|
name: 'admin-product-details',
|
||||||
// class: 'cursor-pointer',
|
params: {
|
||||||
// color: 'info',
|
product_id: row.original.product_id,
|
||||||
// variant: 'soft'
|
link_rewrite: row.original.link_rewrite
|
||||||
// }, () => 'Show product')
|
}
|
||||||
// },
|
}),
|
||||||
// }
|
color: 'info',
|
||||||
// ]
|
variant: 'soft'
|
||||||
|
},
|
||||||
|
() => 'Show product'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
]
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|||||||
@@ -39,9 +39,10 @@ function adaptMenu(menu: NavigationMenuItem[]) {
|
|||||||
if (item.children && item.children.length > 0) {
|
if (item.children && item.children.length > 0) {
|
||||||
item.open = path && path.includes(item.category_id) ? true : openAll.value
|
item.open = path && path.includes(item.category_id) ? true : openAll.value
|
||||||
adaptMenu(item.children);
|
adaptMenu(item.children);
|
||||||
|
|
||||||
item.children.unshift({
|
item.children.unshift({
|
||||||
label: item.label, icon: 'i-lucide-book-open', popover: item.label, to: {
|
label: item.label, icon: 'i-lucide-book-open', popover: item.label, to: {
|
||||||
name: 'admin-products-category', params: {
|
name: item.params.to, params: {
|
||||||
category_id: item.params.category_id,
|
category_id: item.params.category_id,
|
||||||
link_rewrite: item.params.link_rewrite
|
link_rewrite: item.params.link_rewrite
|
||||||
}
|
}
|
||||||
@@ -49,7 +50,7 @@ function adaptMenu(menu: NavigationMenuItem[]) {
|
|||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
item.to = {
|
item.to = {
|
||||||
name: 'admin-products-category', params: {
|
name: item.params.to, params: {
|
||||||
category_id: item.params.category_id,
|
category_id: item.params.category_id,
|
||||||
link_rewrite: item.params.link_rewrite
|
link_rewrite: item.params.link_rewrite
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,7 +54,6 @@ const locale = computed({
|
|||||||
const pathParts = currentPath.split('/').filter(Boolean)
|
const pathParts = currentPath.split('/').filter(Boolean)
|
||||||
|
|
||||||
cookie.setCookie('lang_id', `${langs.find((x) => x.iso_code == value)?.id}`, { days: 60, secure: true, sameSite: 'Lax' })
|
cookie.setCookie('lang_id', `${langs.find((x) => x.iso_code == value)?.id}`, { days: 60, secure: true, sameSite: 'Lax' })
|
||||||
|
|
||||||
if (pathParts.length > 0) {
|
if (pathParts.length > 0) {
|
||||||
const isLocale = langs.some((l) => l.lang_code === pathParts[0])
|
const isLocale = langs.some((l) => l.lang_code === pathParts[0])
|
||||||
if (isLocale) {
|
if (isLocale) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<UEditor v-slot="{ editor }" v-model="localValue" content-type="html"
|
<UEditor v-slot="{ editor }" v-model="localValue" content-type="html"
|
||||||
:ui="{ base: 'p-8 sm:px-16', root: 'p-2' }"
|
:ui="{ base: 'p-8', root: 'p-2' }"
|
||||||
class="min-w-full border rounded-md bg-white! border-(--border-light)" placeholder="Write there ...">
|
class="min-w-full border rounded-md bg-white! border-(--border-light)" placeholder="Write there ...">
|
||||||
<UEditorToolbar :editor="editor" :items="toolbarItems" class="sm:px-8 flex-wrap!">
|
<UEditorToolbar :editor="editor" :items="toolbarItems" class="sm:px-8 flex-wrap!">
|
||||||
<template #link>
|
<template #link>
|
||||||
|
|||||||
52
bo/src/components/ui/LayoutSkeleton.vue
Normal file
52
bo/src/components/ui/LayoutSkeleton.vue
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
<template>
|
||||||
|
<div class="flex flex-1 overflow-x-hidden h-svh animate-pulse">
|
||||||
|
<!-- Sidebar -->
|
||||||
|
<div class="flex flex-col shrink-0 w-52 bg-elevated/25 border-r border-default h-full">
|
||||||
|
<!-- Sidebar header -->
|
||||||
|
<div class="flex items-center gap-2 p-3 border-b border-default h-(--ui-header-height)">
|
||||||
|
<div class="h-8 w-8 rounded-lg bg-gray-200 dark:bg-neutral-700 shrink-0" />
|
||||||
|
<div class="h-4 flex-1 rounded bg-gray-200 dark:bg-neutral-700" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Sidebar nav items -->
|
||||||
|
<div class="flex flex-col gap-1 p-2 flex-1">
|
||||||
|
<div v-for="i in 7" :key="i" class="flex items-center gap-2.5 px-1.5 py-1.5">
|
||||||
|
<div class="h-5 w-5 rounded bg-gray-200 dark:bg-neutral-700 shrink-0" />
|
||||||
|
<div class="h-3.5 rounded bg-gray-200 dark:bg-neutral-700" :class="['w-20','w-28','w-24','w-16','w-28','w-20','w-24'][i-1]" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Sidebar footer -->
|
||||||
|
<div class="p-3 border-t border-default">
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<div class="h-8 w-8 rounded-lg bg-gray-200 dark:bg-neutral-700 shrink-0" />
|
||||||
|
<div class="h-3.5 flex-1 rounded bg-gray-200 dark:bg-neutral-700" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Main area -->
|
||||||
|
<div class="flex-1 flex flex-col overflow-hidden">
|
||||||
|
<!-- Header -->
|
||||||
|
<div class="flex h-(--ui-header-height) shrink-0 items-center justify-between px-4 border-b border-default">
|
||||||
|
<!-- Left: toggle + title -->
|
||||||
|
<div class="flex items-center gap-4">
|
||||||
|
<div class="h-8 w-8 rounded-lg bg-gray-200 dark:bg-neutral-700" />
|
||||||
|
<div class="h-5 w-36 rounded bg-gray-200 dark:bg-neutral-700" />
|
||||||
|
</div>
|
||||||
|
<!-- Right: controls -->
|
||||||
|
<div class="hidden md:flex items-center gap-3">
|
||||||
|
<div class="h-8 w-20 rounded-lg bg-gray-200 dark:bg-neutral-700" />
|
||||||
|
<div class="h-8 w-20 rounded-lg bg-gray-200 dark:bg-neutral-700" />
|
||||||
|
<div class="h-8 w-8 rounded-lg bg-gray-200 dark:bg-neutral-700" />
|
||||||
|
<div class="h-8 w-24 rounded-lg bg-gray-200 dark:bg-neutral-700" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Page content placeholder -->
|
||||||
|
<div class="flex-1 p-4 bg-slate-50 dark:bg-(--main-dark)">
|
||||||
|
<slot />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
99
bo/src/components/ui/RichEditor.vue
Normal file
99
bo/src/components/ui/RichEditor.vue
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
<template>
|
||||||
|
<div class="rich-editor rounded-lg border border-(--border-light) dark:border-(--border-dark) overflow-hidden focus-within:ring-1 focus-within:ring-sky-500 focus-within:border-sky-500 transition-colors">
|
||||||
|
<!-- Toolbar -->
|
||||||
|
<div class="flex items-center gap-0.5 px-2 py-1.5 border-b border-(--border-light) dark:border-(--border-dark) bg-gray-50 dark:bg-neutral-800 flex-wrap">
|
||||||
|
<button type="button" @click="editor?.chain().focus().toggleBold().run()"
|
||||||
|
:class="{ 'bg-sky-100 dark:bg-sky-900 text-sky-600 dark:text-sky-300': editor?.isActive('bold') }"
|
||||||
|
class="toolbar-btn font-bold">B</button>
|
||||||
|
<button type="button" @click="editor?.chain().focus().toggleItalic().run()"
|
||||||
|
:class="{ 'bg-sky-100 dark:bg-sky-900 text-sky-600 dark:text-sky-300': editor?.isActive('italic') }"
|
||||||
|
class="toolbar-btn italic">I</button>
|
||||||
|
<button type="button" @click="editor?.chain().focus().toggleStrike().run()"
|
||||||
|
:class="{ 'bg-sky-100 dark:bg-sky-900 text-sky-600 dark:text-sky-300': editor?.isActive('strike') }"
|
||||||
|
class="toolbar-btn line-through">S</button>
|
||||||
|
<div class="w-px h-4 bg-gray-300 dark:bg-neutral-600 mx-1" />
|
||||||
|
<button type="button" @click="editor?.chain().focus().toggleHeading({ level: 2 }).run()"
|
||||||
|
:class="{ 'bg-sky-100 dark:bg-sky-900 text-sky-600 dark:text-sky-300': editor?.isActive('heading', { level: 2 }) }"
|
||||||
|
class="toolbar-btn text-xs font-semibold">H2</button>
|
||||||
|
<button type="button" @click="editor?.chain().focus().toggleHeading({ level: 3 }).run()"
|
||||||
|
:class="{ 'bg-sky-100 dark:bg-sky-900 text-sky-600 dark:text-sky-300': editor?.isActive('heading', { level: 3 }) }"
|
||||||
|
class="toolbar-btn text-xs font-semibold">H3</button>
|
||||||
|
<div class="w-px h-4 bg-gray-300 dark:bg-neutral-600 mx-1" />
|
||||||
|
<button type="button" @click="editor?.chain().focus().toggleBulletList().run()"
|
||||||
|
:class="{ 'bg-sky-100 dark:bg-sky-900 text-sky-600 dark:text-sky-300': editor?.isActive('bulletList') }"
|
||||||
|
class="toolbar-btn">
|
||||||
|
<UIcon name="i-lucide-list" class="text-sm" />
|
||||||
|
</button>
|
||||||
|
<button type="button" @click="editor?.chain().focus().toggleOrderedList().run()"
|
||||||
|
:class="{ 'bg-sky-100 dark:bg-sky-900 text-sky-600 dark:text-sky-300': editor?.isActive('orderedList') }"
|
||||||
|
class="toolbar-btn">
|
||||||
|
<UIcon name="i-lucide-list-ordered" class="text-sm" />
|
||||||
|
</button>
|
||||||
|
<div class="w-px h-4 bg-gray-300 dark:bg-neutral-600 mx-1" />
|
||||||
|
<button type="button" @click="editor?.chain().focus().undo().run()" class="toolbar-btn">
|
||||||
|
<UIcon name="i-lucide-undo-2" class="text-sm" />
|
||||||
|
</button>
|
||||||
|
<button type="button" @click="editor?.chain().focus().redo().run()" class="toolbar-btn">
|
||||||
|
<UIcon name="i-lucide-redo-2" class="text-sm" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Editor area -->
|
||||||
|
<EditorContent :editor="editor"
|
||||||
|
class="min-h-32 px-3 py-2.5 text-sm text-black dark:text-white bg-white dark:bg-neutral-900 prose prose-sm dark:prose-invert max-w-none focus:outline-none" />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { watch, onBeforeUnmount } from 'vue'
|
||||||
|
import { useEditor, EditorContent } from '@tiptap/vue-3'
|
||||||
|
import StarterKit from '@tiptap/starter-kit'
|
||||||
|
import Placeholder from '@tiptap/extension-placeholder'
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
modelValue: string
|
||||||
|
placeholder?: string
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
'update:modelValue': [value: string]
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const editor = useEditor({
|
||||||
|
content: props.modelValue,
|
||||||
|
extensions: [
|
||||||
|
StarterKit,
|
||||||
|
Placeholder.configure({ placeholder: props.placeholder ?? '' }),
|
||||||
|
],
|
||||||
|
editorProps: {
|
||||||
|
attributes: { class: 'focus:outline-none' },
|
||||||
|
},
|
||||||
|
onUpdate({ editor }) {
|
||||||
|
emit('update:modelValue', editor.getHTML())
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
// Sync external changes (e.g. store reset)
|
||||||
|
watch(() => props.modelValue, (val) => {
|
||||||
|
if (editor.value && editor.value.getHTML() !== val) {
|
||||||
|
editor.value.commands.setContent(val, false)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
onBeforeUnmount(() => editor.value?.destroy())
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
/* .toolbar-btn {
|
||||||
|
@apply flex items-center justify-center w-7 h-7 rounded text-gray-600 dark:text-gray-300 hover:bg-gray-200 dark:hover:bg-neutral-700 transition-colors text-sm;
|
||||||
|
} */
|
||||||
|
|
||||||
|
/* Tiptap placeholder */
|
||||||
|
.tiptap p.is-editor-empty:first-child::before {
|
||||||
|
content: attr(data-placeholder);
|
||||||
|
float: left;
|
||||||
|
/* color: theme('colors.gray.400'); */
|
||||||
|
pointer-events: none;
|
||||||
|
height: 0;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="flex flex-1 overflow-x-hidden h-svh">
|
<LayoutSkeleton v-if="loadingLayout" />
|
||||||
|
|
||||||
|
<div v-else class="flex flex-1 overflow-x-hidden h-svh">
|
||||||
<USidebar v-model:open="open" collapsible="icon" rail :ui="{
|
<USidebar v-model:open="open" collapsible="icon" rail :ui="{
|
||||||
container: 'h-full z-80',
|
container: 'h-full z-80',
|
||||||
inner: 'bg-elevated/25 divide-transparent',
|
inner: 'bg-elevated/25 divide-transparent',
|
||||||
@@ -88,6 +90,7 @@
|
|||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, computed, onMounted } from 'vue'
|
import { ref, computed, onMounted } from 'vue'
|
||||||
|
import LayoutSkeleton from '@/components/ui/LayoutSkeleton.vue'
|
||||||
import { useColorMode } from '@vueuse/core'
|
import { useColorMode } from '@vueuse/core'
|
||||||
import type { DropdownMenuItem, NavigationMenuItem } from '@nuxt/ui'
|
import type { DropdownMenuItem, NavigationMenuItem } from '@nuxt/ui'
|
||||||
import { defineShortcuts, extractShortcuts } from '@nuxt/ui/runtime/composables/defineShortcuts.js'
|
import { defineShortcuts, extractShortcuts } from '@nuxt/ui/runtime/composables/defineShortcuts.js'
|
||||||
@@ -98,7 +101,9 @@ const userStore = useUserStore()
|
|||||||
|
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const pageTitle = computed(() => route.meta.name ?? 'Default Page')
|
const pageTitle = computed(() => route.meta.name ?? 'Default Page')
|
||||||
await userStore.getUser()
|
|
||||||
|
const loadingLayout = ref(true)
|
||||||
|
userStore.getUser().finally(() => { loadingLayout.value = false })
|
||||||
|
|
||||||
const open = ref(true)
|
const open = ref(true)
|
||||||
const colorMode = useColorMode()
|
const colorMode = useColorMode()
|
||||||
@@ -205,8 +210,7 @@ const menu = ref<TopMenuItem[] | null>(null)
|
|||||||
async function getTopMenu() {
|
async function getTopMenu() {
|
||||||
try {
|
try {
|
||||||
const { items } = await useFetchJson<TopMenuItem[]>('/api/v1/restricted/menu/get-top-menu')
|
const { items } = await useFetchJson<TopMenuItem[]>('/api/v1/restricted/menu/get-top-menu')
|
||||||
|
menu.value = items[0]?.children || []
|
||||||
menu.value = items
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err)
|
console.log(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -182,7 +182,7 @@ const menu = ref<TopMenuItem[] | null>(null)
|
|||||||
const Id = Number(route.params.user_id)
|
const Id = Number(route.params.user_id)
|
||||||
async function cmGetTopMenu() {
|
async function cmGetTopMenu() {
|
||||||
try {
|
try {
|
||||||
const { items } = await useFetchJson<TopMenuItem[]>(`/api/v1/restricted/menu/get-top-menu?target_user_id=${Id}`)
|
const { items } = await useFetchJson<TopMenuItem[]>(`/api/v1/restricted/menu/get-customer-management-menu`)
|
||||||
|
|
||||||
menu.value = items
|
menu.value = items
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
@@ -103,8 +103,6 @@ async function setRoutes() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(router);
|
|
||||||
// await router.replace(router.currentRoute.value.fullPath)
|
// await router.replace(router.currentRoute.value.fullPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,10 +12,7 @@ export const currentCountry = ref<Country>()
|
|||||||
const defLang = ref<Language>()
|
const defLang = ref<Language>()
|
||||||
const defCountry = ref<Country>()
|
const defCountry = ref<Country>()
|
||||||
const cookie = useCookie()
|
const cookie = useCookie()
|
||||||
// Get available language codes for route matching
|
|
||||||
// export const availableLocales = computed(() => langs.map((l) => l.lang_code))
|
|
||||||
|
|
||||||
// Initialize languages from API
|
|
||||||
export async function initLangs() {
|
export async function initLangs() {
|
||||||
try {
|
try {
|
||||||
const { items } = await useFetchJson<Language[]>('/api/v1/langs')
|
const { items } = await useFetchJson<Language[]>('/api/v1/langs')
|
||||||
@@ -33,8 +30,6 @@ export async function initLangs() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize country/currency from API
|
|
||||||
|
|
||||||
export async function initCountryCurrency() {
|
export async function initCountryCurrency() {
|
||||||
try {
|
try {
|
||||||
const { items } = await useFetchJson<Country[]>('/api/v1/restricted/langs-and-countries/get-countries')
|
const { items } = await useFetchJson<Country[]>('/api/v1/restricted/langs-and-countries/get-countries')
|
||||||
@@ -43,13 +38,10 @@ export async function initCountryCurrency() {
|
|||||||
let idfromcookie = null
|
let idfromcookie = null
|
||||||
const cc = cookie.getCookie('country_id')
|
const cc = cookie.getCookie('country_id')
|
||||||
if (cc) {
|
if (cc) {
|
||||||
idfromcookie = langs.find((x) => x.id == parseInt(cc))
|
idfromcookie = countries.find((x) => x.id == parseInt(cc))
|
||||||
}
|
}
|
||||||
defCountry.value = items.find((x) => x.id === defLang.value?.id)
|
defCountry.value = items.find((x) => x.id === defLang.value?.id)
|
||||||
currentCountry.value = idfromcookie ?? defCountry.value
|
currentCountry.value = idfromcookie ?? defCountry.value
|
||||||
console.log(defCountry.value);
|
|
||||||
console.log(currentCountry.value);
|
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to fetch languages:', error)
|
console.error('Failed to fetch languages:', error)
|
||||||
}
|
}
|
||||||
@@ -60,7 +52,6 @@ export async function switchLocalization() {
|
|||||||
await useFetchJson('/api/v1/public/auth/update-choice', {
|
await useFetchJson('/api/v1/public/auth/update-choice', {
|
||||||
method: 'POST'
|
method: 'POST'
|
||||||
})
|
})
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error)
|
console.log(error)
|
||||||
}
|
}
|
||||||
|
|||||||
168
bo/src/stores/admin/addProduct.ts
Normal file
168
bo/src/stores/admin/addProduct.ts
Normal file
@@ -0,0 +1,168 @@
|
|||||||
|
import { defineStore } from 'pinia'
|
||||||
|
import { ref, reactive } from 'vue'
|
||||||
|
import { useFetchJson } from '@/composable/useFetchJson'
|
||||||
|
import type {
|
||||||
|
ProductCategory,
|
||||||
|
ProductRelated,
|
||||||
|
ProductForm,
|
||||||
|
ProductFormProduct,
|
||||||
|
ProductFormPrice,
|
||||||
|
ProductFormVariant,
|
||||||
|
ProductVariantForm,
|
||||||
|
ProductImage,
|
||||||
|
} from '@/types/product'
|
||||||
|
import type { MenuItem } from '@/types'
|
||||||
|
import { settings } from '@/router/settings'
|
||||||
|
|
||||||
|
// ── Default values ────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
function emptyForm(): ProductForm {
|
||||||
|
return {
|
||||||
|
product: {
|
||||||
|
reference: '',
|
||||||
|
base_price: 0,
|
||||||
|
quantity: 0,
|
||||||
|
minimal_quantity: 1,
|
||||||
|
available_for_order: true,
|
||||||
|
available_date: '',
|
||||||
|
out_of_stock_behavior: 2,
|
||||||
|
on_sale: false,
|
||||||
|
show_price: true,
|
||||||
|
condition: 'new',
|
||||||
|
is_virtual: false,
|
||||||
|
weight: 0,
|
||||||
|
width: 0,
|
||||||
|
height: 0,
|
||||||
|
depth: 0,
|
||||||
|
delivery_days: null,
|
||||||
|
active: true,
|
||||||
|
visibility: 'both',
|
||||||
|
indexed: true,
|
||||||
|
date_add: '',
|
||||||
|
date_upd: '',
|
||||||
|
name: '',
|
||||||
|
description: '',
|
||||||
|
description_short: '',
|
||||||
|
manufacturer: '',
|
||||||
|
category: '',
|
||||||
|
is_favorite: false,
|
||||||
|
is_oem: false,
|
||||||
|
is_new: false,
|
||||||
|
},
|
||||||
|
price: {
|
||||||
|
base: 0,
|
||||||
|
final_tax_excl: 0,
|
||||||
|
final_tax_incl: 0,
|
||||||
|
tax_rate: 0,
|
||||||
|
priority: 0,
|
||||||
|
},
|
||||||
|
variants: [],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Store ─────────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export const useAddProductStore = defineStore('addProduct', () => {
|
||||||
|
const loading = ref(false)
|
||||||
|
const saving = ref(false)
|
||||||
|
const error = ref<string | null>(null)
|
||||||
|
const successMessage = ref<string | null>(null)
|
||||||
|
|
||||||
|
// Form data for creating / editing a product
|
||||||
|
const form = reactive<ProductForm>(emptyForm())
|
||||||
|
|
||||||
|
// Variants loaded when editing an existing product
|
||||||
|
const variants = ref<ProductVariantForm[]>([])
|
||||||
|
const variantSaving = ref<Record<number, boolean>>({})
|
||||||
|
const variantErrors = ref<Record<number, string>>({})
|
||||||
|
|
||||||
|
// Images
|
||||||
|
const images = ref<ProductImage[]>([])
|
||||||
|
|
||||||
|
// Categories & related products
|
||||||
|
const selectedCategories = ref<ProductCategory[]>([])
|
||||||
|
const relatedProducts = ref<ProductRelated[]>([])
|
||||||
|
|
||||||
|
// ── Product ─────────────────────────────────────────────────────────
|
||||||
|
async function loadProduct(productId: number) {
|
||||||
|
loading.value = true
|
||||||
|
error.value = null
|
||||||
|
try {
|
||||||
|
// const resp = await useFetchJson<ProductForm>(`/api/v1/restricted/admin/product/${productId}`)
|
||||||
|
// Object.assign(form, resp.items)
|
||||||
|
console.log('[addProduct] loadProduct – API not connected yet', productId)
|
||||||
|
} catch (e: unknown) {
|
||||||
|
error.value = e instanceof Error ? e.message : 'Failed to load product'
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Images ────────────────────────────────────────────────────────────────
|
||||||
|
function addImageFiles(files: FileList | File[]) {
|
||||||
|
const incoming = Array.from(files)
|
||||||
|
for (const file of incoming) {
|
||||||
|
const previewUrl = URL.createObjectURL(file)
|
||||||
|
images.value.push({ previewUrl, file, cover: false, uploading: false })
|
||||||
|
}
|
||||||
|
if (!images.value.some(i => i.cover) && images.value.length > 0) {
|
||||||
|
images.value[0]!.cover = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeImage(index: number) {
|
||||||
|
const img = images.value[index]!
|
||||||
|
if (img.previewUrl.startsWith('blob:')) URL.revokeObjectURL(img.previewUrl)
|
||||||
|
const wasCover = img.cover
|
||||||
|
images.value.splice(index, 1)
|
||||||
|
if (wasCover && images.value.length > 0) {
|
||||||
|
images.value[0]!.cover = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function setCover(index: number) {
|
||||||
|
images.value.forEach((img, i) => { img.cover = i === index })
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function resetForm() {
|
||||||
|
Object.assign(form, emptyForm())
|
||||||
|
variants.value = []
|
||||||
|
images.value = []
|
||||||
|
selectedCategories.value = []
|
||||||
|
relatedProducts.value = []
|
||||||
|
error.value = null
|
||||||
|
successMessage.value = null
|
||||||
|
}
|
||||||
|
|
||||||
|
const categories = ref<MenuItem[]>([])
|
||||||
|
const loadingCategories = ref(true)
|
||||||
|
async function loadCategories() {
|
||||||
|
loadingCategories.value = true
|
||||||
|
const resp = await useFetchJson<MenuItem>(`/api/v1/restricted/menu/get-category-tree?root_category_id=${settings['app'].category_tree_root_id}`);
|
||||||
|
categories.value = resp.items.children
|
||||||
|
loadingCategories.value = false
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
loading,
|
||||||
|
saving,
|
||||||
|
error,
|
||||||
|
successMessage,
|
||||||
|
form,
|
||||||
|
images,
|
||||||
|
selectedCategories,
|
||||||
|
relatedProducts,
|
||||||
|
variants,
|
||||||
|
variantSaving,
|
||||||
|
variantErrors,
|
||||||
|
categories,
|
||||||
|
loadingCategories,
|
||||||
|
loadProduct,
|
||||||
|
addImageFiles,
|
||||||
|
removeImage,
|
||||||
|
setCover,
|
||||||
|
resetForm,
|
||||||
|
loadCategories
|
||||||
|
}
|
||||||
|
})
|
||||||
@@ -1,19 +1,11 @@
|
|||||||
|
import { useFetchJson } from '@/composable/useFetchJson'
|
||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
import { ref, computed } from 'vue'
|
import { ref } from 'vue'
|
||||||
|
|
||||||
export interface AddressFormData {
|
|
||||||
street: string
|
|
||||||
zipCode: string
|
|
||||||
city: string
|
|
||||||
country: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Address {
|
export interface Address {
|
||||||
id: number
|
id: number
|
||||||
street: string
|
country_id: number
|
||||||
zipCode: string
|
address_unparsed: Record<string, string>
|
||||||
city: string
|
|
||||||
country: string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useAddressStore = defineStore('address', () => {
|
export const useAddressStore = defineStore('address', () => {
|
||||||
@@ -21,124 +13,46 @@ export const useAddressStore = defineStore('address', () => {
|
|||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
const error = ref<string | null>(null)
|
const error = ref<string | null>(null)
|
||||||
|
|
||||||
const currentPage = ref(1)
|
async function fetchAddresses() {
|
||||||
const pageSize = 20
|
loading.value = true
|
||||||
|
error.value = null
|
||||||
const searchQuery = ref('')
|
try {
|
||||||
|
const res = await useFetchJson<Address[]>('/api/v1/restricted/addresses/retrieve-addresses')
|
||||||
function initMockData() {
|
addresses.value = res.items ?? []
|
||||||
addresses.value = [
|
} catch (e: unknown) {
|
||||||
{ id: 1, street: 'Main Street 123', zipCode: '10-001', city: 'New York', country: 'United States' },
|
error.value = e instanceof Error ? e.message : 'Failed to load addresses'
|
||||||
{ id: 2, street: 'Oak Avenue 123', zipCode: '90-001', city: 'Los Angeles', country: 'United States' },
|
} finally {
|
||||||
{ id: 3, street: 'Pine Road 123', zipCode: '60-601', city: 'Chicago', country: 'United States' }
|
loading.value = false
|
||||||
]
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const filteredAddresses = computed(() => {
|
async function deleteAddress(id: number) {
|
||||||
if (!searchQuery.value) return addresses.value
|
await useFetchJson(`/api/v1/restricted/addresses/delete-address?address_id=${id}`, { method: 'DELETE' })
|
||||||
|
addresses.value = addresses.value.filter((a) => a.id !== id)
|
||||||
|
}
|
||||||
|
|
||||||
const query = searchQuery.value.toLowerCase()
|
async function getTemplate(countryId: number): Promise<Record<string, string>> {
|
||||||
|
const res = await useFetchJson<Record<string, string>>(
|
||||||
return addresses.value.filter(addr =>
|
`/api/v1/restricted/addresses/get-template?country_id=${countryId}`
|
||||||
addr.street.toLowerCase().includes(query) ||
|
|
||||||
addr.city.toLowerCase().includes(query) ||
|
|
||||||
addr.country.toLowerCase().includes(query) ||
|
|
||||||
addr.zipCode.toLowerCase().includes(query)
|
|
||||||
)
|
)
|
||||||
|
return res.items ?? {}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function createAddress(countryId: number, data: Record<string, string>) {
|
||||||
|
await useFetchJson(`/api/v1/restricted/addresses/add-new-address?country_id=${countryId}`, {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify(data)
|
||||||
})
|
})
|
||||||
|
await fetchAddresses()
|
||||||
|
}
|
||||||
|
|
||||||
const totalItems = computed(() => filteredAddresses.value.length)
|
async function updateAddress(id: number, countryId: number, data: Record<string, string>) {
|
||||||
const totalPages = computed(() => Math.ceil(totalItems.value / pageSize))
|
await useFetchJson(`/api/v1/restricted/addresses/modify-address?country_id=${countryId}&address_id=${id}`, {
|
||||||
|
method: 'POST',
|
||||||
const paginatedAddresses = computed(() => {
|
body: JSON.stringify(data)
|
||||||
const start = (currentPage.value - 1) * pageSize
|
|
||||||
return filteredAddresses.value.slice(start, start + pageSize)
|
|
||||||
})
|
})
|
||||||
|
await fetchAddresses()
|
||||||
function getAddressById(id: number) {
|
|
||||||
return addresses.value.find(addr => addr.id === id)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function normalize(data: AddressFormData): AddressFormData {
|
return { addresses, loading, error, fetchAddresses, deleteAddress, getTemplate, createAddress, updateAddress }
|
||||||
return {
|
|
||||||
street: data.street.trim(),
|
|
||||||
zipCode: data.zipCode.trim(),
|
|
||||||
city: data.city.trim(),
|
|
||||||
country: data.country.trim()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function generateId(): number {
|
|
||||||
return Math.max(0, ...addresses.value.map(a => a.id)) + 1
|
|
||||||
}
|
|
||||||
|
|
||||||
function addAddress(formData: AddressFormData): Address {
|
|
||||||
const newAddress: Address = {
|
|
||||||
id: generateId(),
|
|
||||||
...normalize(formData)
|
|
||||||
}
|
|
||||||
|
|
||||||
addresses.value.unshift(newAddress)
|
|
||||||
resetPagination()
|
|
||||||
|
|
||||||
return newAddress
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateAddress(id: number, formData: AddressFormData): boolean {
|
|
||||||
const index = addresses.value.findIndex(a => a.id === id)
|
|
||||||
if (index === -1) return false
|
|
||||||
|
|
||||||
const existing = addresses.value[index]
|
|
||||||
if (!existing) return false
|
|
||||||
|
|
||||||
addresses.value[index] = {
|
|
||||||
id: existing.id,
|
|
||||||
...normalize(formData)
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
function deleteAddress(id: number): boolean {
|
|
||||||
const index = addresses.value.findIndex(a => a.id === id)
|
|
||||||
if (index === -1) return false
|
|
||||||
|
|
||||||
addresses.value.splice(index, 1)
|
|
||||||
resetPagination()
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
function setPage(page: number) {
|
|
||||||
currentPage.value = page
|
|
||||||
}
|
|
||||||
|
|
||||||
function setSearchQuery(query: string) {
|
|
||||||
searchQuery.value = query
|
|
||||||
currentPage.value = 1
|
|
||||||
}
|
|
||||||
|
|
||||||
function resetPagination() {
|
|
||||||
currentPage.value = 1
|
|
||||||
}
|
|
||||||
|
|
||||||
initMockData()
|
|
||||||
|
|
||||||
return {
|
|
||||||
addresses,
|
|
||||||
loading,
|
|
||||||
error,
|
|
||||||
currentPage,
|
|
||||||
pageSize,
|
|
||||||
totalItems,
|
|
||||||
totalPages,
|
|
||||||
searchQuery,
|
|
||||||
filteredAddresses,
|
|
||||||
paginatedAddresses,
|
|
||||||
getAddressById,
|
|
||||||
addAddress,
|
|
||||||
updateAddress,
|
|
||||||
deleteAddress,
|
|
||||||
setPage,
|
|
||||||
setSearchQuery,
|
|
||||||
resetPagination
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
import { ref, computed } from 'vue'
|
import { computed, ref } from 'vue'
|
||||||
import { useFetchJson } from '@/composable/useFetchJson'
|
import { useFetchJson } from '@/composable/useFetchJson'
|
||||||
|
import type { ApiResponse } from '@/types'
|
||||||
|
import { useRoute } from 'vue-router'
|
||||||
|
|
||||||
export interface Cart {
|
export interface Cart {
|
||||||
id: number
|
id: number
|
||||||
@@ -22,135 +24,28 @@ export const useCartStore = defineStore('cart', () => {
|
|||||||
const activeCartId = ref<number | null>(null)
|
const activeCartId = ref<number | null>(null)
|
||||||
const error = ref<string | null>(null)
|
const error = ref<string | null>(null)
|
||||||
|
|
||||||
const addresses = ref<Address[]>([])
|
async function fetchCarts() {
|
||||||
const addressLoading = ref(false)
|
|
||||||
const addressError = ref<string | null>(null)
|
|
||||||
const addressSearchQuery = ref('')
|
|
||||||
const addressCurrentPage = ref(1)
|
|
||||||
const addressPageSize = 20
|
|
||||||
const addressTotalCount = ref(0)
|
|
||||||
|
|
||||||
function transformAddressResponse(address: any): Address {
|
|
||||||
const info = address.address_info || address.addressInfo || {}
|
|
||||||
|
|
||||||
return {
|
|
||||||
id: address.id ?? 0,
|
|
||||||
country_id: address.country_id ?? address.countryId ?? 1,
|
|
||||||
customer_id: address.customer_id ?? address.customerId ?? 0,
|
|
||||||
address_info: info as Record<string, string>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function fetchAddresses() {
|
|
||||||
addressLoading.value = true
|
|
||||||
addressError.value = null
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const queryParam = addressSearchQuery.value ? `&query=${encodeURIComponent(addressSearchQuery.value)}` : ''
|
const res = await useFetchJson<ApiResponse>(
|
||||||
const response = await useFetchJson<Address[]>(`/api/v1/restricted/addresses/retrieve-addresses?page=${addressCurrentPage.value}&elems=${addressPageSize}${queryParam}`)
|
`/api/v1/restricted/carts/retrieve-carts-info`
|
||||||
addresses.value = response.items || []
|
)
|
||||||
addressTotalCount.value = response.count ?? addresses.value.length
|
|
||||||
} catch (error: unknown) {
|
carts.value = res.items
|
||||||
addressError.value = error instanceof Error ? error.message : 'Failed to load addresses'
|
} catch (e: any) {
|
||||||
} finally {
|
error.value = e?.message ?? 'Error loading carts'
|
||||||
addressLoading.value = false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function addAddress(countryId: number, formData: AddressTemplate): Promise<Address | null> {
|
|
||||||
addressLoading.value = true
|
|
||||||
addressError.value = null
|
|
||||||
|
|
||||||
try {
|
|
||||||
const response = await useFetchJson<any>(`/api/v1/restricted/addresses/add-new-address?country_id=${countryId}`, {
|
|
||||||
method: 'POST',
|
|
||||||
body: JSON.stringify(formData)
|
|
||||||
})
|
|
||||||
|
|
||||||
await fetchAddresses()
|
|
||||||
return transformAddressResponse(response.items ?? response)
|
|
||||||
} catch (error: unknown) {
|
|
||||||
addressError.value = error instanceof Error ? error.message : 'Failed to create address'
|
|
||||||
return null
|
|
||||||
} finally {
|
|
||||||
addressLoading.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getAddressTemplate(countryId: number): Promise<AddressTemplate> {
|
|
||||||
const response = await useFetchJson<any>(`/api/v1/restricted/addresses/get-template?country_id=${countryId}`)
|
|
||||||
return response.items ?? {}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function updateAddress(id: number, countryId: number, formData: AddressTemplate): Promise<boolean> {
|
|
||||||
addressLoading.value = true
|
|
||||||
addressError.value = null
|
|
||||||
|
|
||||||
try {
|
|
||||||
await useFetchJson<any>(`/api/v1/restricted/addresses/modify-address?country_id=${countryId}&address_id=${id}`, {
|
|
||||||
method: 'POST',
|
|
||||||
body: JSON.stringify(formData)
|
|
||||||
})
|
|
||||||
|
|
||||||
await fetchAddresses()
|
|
||||||
return true
|
|
||||||
} catch (error: unknown) {
|
|
||||||
addressError.value = error instanceof Error ? error.message : 'Failed to update address'
|
|
||||||
return false
|
|
||||||
} finally {
|
|
||||||
addressLoading.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function deleteAddress(id: number): Promise<boolean> {
|
|
||||||
addressLoading.value = true
|
|
||||||
addressError.value = null
|
|
||||||
|
|
||||||
try {
|
|
||||||
await useFetchJson<any>(`/api/v1/restricted/addresses/delete-address?address_id=${id}`, {
|
|
||||||
method: 'DELETE'
|
|
||||||
})
|
|
||||||
|
|
||||||
await fetchAddresses()
|
|
||||||
return true
|
|
||||||
} catch (error: unknown) {
|
|
||||||
addressError.value = error instanceof Error ? error.message : 'Failed to delete address'
|
|
||||||
return false
|
|
||||||
} finally {
|
|
||||||
addressLoading.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const totalAddressItems = computed(() => addressTotalCount.value || addresses.value.length)
|
|
||||||
const totalAddressPages = computed(() => Math.ceil(totalAddressItems.value / addressPageSize))
|
|
||||||
|
|
||||||
const paginatedAddresses = computed(() => addresses.value)
|
|
||||||
|
|
||||||
function setAddressPage(page: number) {
|
|
||||||
addressCurrentPage.value = page
|
|
||||||
return fetchAddresses()
|
|
||||||
}
|
|
||||||
|
|
||||||
function setAddressSearchQuery(query: string) {
|
|
||||||
addressSearchQuery.value = query
|
|
||||||
addressCurrentPage.value = 1
|
|
||||||
return fetchAddresses()
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function initMockData() {
|
|
||||||
items.value = [
|
|
||||||
{ id: 1, productId: 101, name: 'Premium Widget Pro', product_number: 'NC209/7000', image: '/img/product-1.jpg', price: 129.99, quantity: 2 },
|
|
||||||
{ id: 2, productId: 102, name: 'Ultra Gadget X', product_number: 'NC234/6453', image: '/img/product-2.jpg', price: 89.50, quantity: 1 },
|
|
||||||
{ id: 3, productId: 103, name: 'Mega Tool Set', product_number: 'NC324/9030', image: '/img/product-3.jpg', price: 249.00, quantity: 3 }
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
async function addNewCart(name: string) {
|
async function addNewCart(name: string) {
|
||||||
|
if (!name.trim()) {
|
||||||
|
error.value = 'Cart name is required'
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
error.value = null
|
error.value = null
|
||||||
|
|
||||||
const url = `/api/v1/restricted/carts/add-new-cart`
|
const url = `/api/v1/restricted/carts/add-new-cart?name=${name}`
|
||||||
const response = await useFetchJson<ApiResponse>(url)
|
const response = await useFetchJson<ApiResponse>(url)
|
||||||
|
|
||||||
const newCart: Cart = {
|
const newCart: Cart = {
|
||||||
@@ -212,37 +107,15 @@ export const useCartStore = defineStore('cart', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
items,
|
carts,
|
||||||
selectedAddressId,
|
activeCartId,
|
||||||
selectedDeliveryMethodId,
|
error,
|
||||||
shippingCost,
|
errorMessage,
|
||||||
vatRate,
|
activeCart,
|
||||||
deliveryMethods,
|
setActiveCart,
|
||||||
productsTotal,
|
addProduct,
|
||||||
vatAmount,
|
fetchCarts,
|
||||||
orderTotal,
|
addNewCart,
|
||||||
itemCount,
|
initCart,
|
||||||
deleteProduct,
|
|
||||||
updateQuantity,
|
|
||||||
removeItem,
|
|
||||||
clearCart,
|
|
||||||
setSelectedAddress,
|
|
||||||
setDeliveryMethod,
|
|
||||||
addresses,
|
|
||||||
addressLoading,
|
|
||||||
addressError,
|
|
||||||
addressSearchQuery,
|
|
||||||
addressCurrentPage,
|
|
||||||
addressPageSize,
|
|
||||||
paginatedAddresses,
|
|
||||||
totalAddressItems,
|
|
||||||
totalAddressPages,
|
|
||||||
fetchAddresses,
|
|
||||||
addAddress,
|
|
||||||
updateAddress,
|
|
||||||
deleteAddress,
|
|
||||||
setAddressPage,
|
|
||||||
setAddressSearchQuery,
|
|
||||||
getAddressTemplate
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -11,12 +11,8 @@ export const useUserStore = defineStore('user', () => {
|
|||||||
error.value = null
|
error.value = null
|
||||||
try {
|
try {
|
||||||
const data = await useFetchJson<User>(`/api/v1/restricted/customer`)
|
const data = await useFetchJson<User>(`/api/v1/restricted/customer`)
|
||||||
console.log('getUser API response:', data)
|
|
||||||
|
|
||||||
const response: User = (data as any).items ?? data
|
const response: User = (data as any).items ?? data
|
||||||
console.log('User response:', response)
|
|
||||||
user.value = response
|
user.value = response
|
||||||
|
|
||||||
return response
|
return response
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
error.value = err?.message ?? 'Unknown error'
|
error.value = err?.message ?? 'Unknown error'
|
||||||
|
|||||||
90
bo/src/types/product.d.ts
vendored
90
bo/src/types/product.d.ts
vendored
@@ -18,3 +18,93 @@ export interface Product {
|
|||||||
image_link: string
|
image_link: string
|
||||||
link_rewrite: string
|
link_rewrite: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ProductCategory {
|
||||||
|
id_category: number
|
||||||
|
name: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ProductRelated {
|
||||||
|
product_id: number
|
||||||
|
name: string
|
||||||
|
reference: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ProductFormProduct {
|
||||||
|
id?: number
|
||||||
|
reference: string
|
||||||
|
base_price: number
|
||||||
|
quantity: number
|
||||||
|
minimal_quantity: number
|
||||||
|
available_for_order: boolean
|
||||||
|
available_date: string
|
||||||
|
out_of_stock_behavior: number // 0=deny, 1=allow, 2=default
|
||||||
|
on_sale: boolean
|
||||||
|
show_price: boolean
|
||||||
|
condition: 'new' | 'used' | 'refurbished'
|
||||||
|
is_virtual: boolean
|
||||||
|
weight: number
|
||||||
|
width: number
|
||||||
|
height: number
|
||||||
|
depth: number
|
||||||
|
delivery_days: number | null
|
||||||
|
active: boolean
|
||||||
|
visibility: 'both' | 'catalog' | 'search' | 'none'
|
||||||
|
indexed: boolean
|
||||||
|
date_add: string
|
||||||
|
date_upd: string
|
||||||
|
name: string
|
||||||
|
description: string
|
||||||
|
description_short: string
|
||||||
|
manufacturer: string
|
||||||
|
category: string
|
||||||
|
is_favorite: boolean
|
||||||
|
is_oem: boolean
|
||||||
|
is_new: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ProductFormPrice {
|
||||||
|
base: number
|
||||||
|
final_tax_excl: number
|
||||||
|
final_tax_incl: number
|
||||||
|
tax_rate: number
|
||||||
|
priority: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ProductFormVariantAttribute {
|
||||||
|
group: string
|
||||||
|
attribute: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ProductFormVariant {
|
||||||
|
id_product_attribute: number
|
||||||
|
reference: string
|
||||||
|
base_price: number
|
||||||
|
price_tax_excl: number
|
||||||
|
price_tax_incl: number
|
||||||
|
quantity: number
|
||||||
|
attributes: ProductFormVariantAttribute[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ProductVariantForm = ProductFormVariant
|
||||||
|
|
||||||
|
export interface ProductForm {
|
||||||
|
product: ProductFormProduct
|
||||||
|
price: ProductFormPrice
|
||||||
|
variants: ProductFormVariant[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ProductImage {
|
||||||
|
/** Temporary local URL for preview before upload */
|
||||||
|
previewUrl: string
|
||||||
|
/** File object – present only before upload */
|
||||||
|
file?: File
|
||||||
|
/** Server-side image id after upload */
|
||||||
|
id_image?: number
|
||||||
|
/** Whether this is the cover image */
|
||||||
|
cover: boolean
|
||||||
|
/** Upload in progress */
|
||||||
|
uploading?: boolean
|
||||||
|
/** Upload error */
|
||||||
|
error?: string
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
info:
|
info:
|
||||||
name: Delete Index - MeiliSearch
|
name: Delete Index - MeiliSearch
|
||||||
type: http
|
type: http
|
||||||
seq: 7
|
seq: 8
|
||||||
|
|
||||||
http:
|
http:
|
||||||
method: DELETE
|
method: DELETE
|
||||||
|
|||||||
19
bruno/api_v1/cart/Add new cart.yml
Normal file
19
bruno/api_v1/cart/Add new cart.yml
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
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
|
||||||
31
bruno/api_v1/cart/Add product to cart.yml
Normal file
31
bruno/api_v1/cart/Add product to cart.yml
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
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
|
||||||
22
bruno/api_v1/cart/Change cart name.yml
Normal file
22
bruno/api_v1/cart/Change cart name.yml
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
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
|
||||||
19
bruno/api_v1/cart/Remove cart.yml
Normal file
19
bruno/api_v1/cart/Remove cart.yml
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
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
|
||||||
25
bruno/api_v1/cart/Remove product from cart.yml
Normal file
25
bruno/api_v1/cart/Remove product from cart.yml
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
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
|
||||||
19
bruno/api_v1/cart/Retrieve cart.yml
Normal file
19
bruno/api_v1/cart/Retrieve cart.yml
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
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
|
||||||
15
bruno/api_v1/cart/Retrieve carts info.yml
Normal file
15
bruno/api_v1/cart/Retrieve carts info.yml
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
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 +1,7 @@
|
|||||||
info:
|
info:
|
||||||
name: list
|
name: cart
|
||||||
type: folder
|
type: folder
|
||||||
seq: 3
|
seq: 7
|
||||||
|
|
||||||
request:
|
request:
|
||||||
auth: inherit
|
auth: inherit
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
info:
|
info:
|
||||||
name: currency
|
name: currency
|
||||||
type: folder
|
type: folder
|
||||||
seq: 9
|
seq: 10
|
||||||
|
|
||||||
request:
|
request:
|
||||||
auth: inherit
|
auth: inherit
|
||||||
|
|||||||
22
bruno/api_v1/customer/Set is_no_vat.yml
Normal file
22
bruno/api_v1/customer/Set is_no_vat.yml
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
info:
|
||||||
|
name: Set is_no_vat
|
||||||
|
type: http
|
||||||
|
seq: 4
|
||||||
|
|
||||||
|
http:
|
||||||
|
method: PATCH
|
||||||
|
url: "{{bas_url}}/restricted/customer/no-vat"
|
||||||
|
body:
|
||||||
|
type: json
|
||||||
|
data: |-
|
||||||
|
{
|
||||||
|
"customer_id":1,
|
||||||
|
"is_no_vat": false
|
||||||
|
}
|
||||||
|
auth: inherit
|
||||||
|
|
||||||
|
settings:
|
||||||
|
encodeUrl: true
|
||||||
|
timeout: 0
|
||||||
|
followRedirects: true
|
||||||
|
maxRedirects: 5
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
info:
|
info:
|
||||||
name: customer
|
name: customer
|
||||||
type: folder
|
type: folder
|
||||||
seq: 10
|
seq: 11
|
||||||
|
|
||||||
request:
|
request:
|
||||||
auth: inherit
|
auth: inherit
|
||||||
|
|||||||
22
bruno/api_v1/menu/Breadcrumb.yml
Normal file
22
bruno/api_v1/menu/Breadcrumb.yml
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
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
|
||||||
19
bruno/api_v1/menu/Category tree.yml
Normal file
19
bruno/api_v1/menu/Category tree.yml
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
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
|
||||||
15
bruno/api_v1/menu/Top Customer Management Menu.yml
Normal file
15
bruno/api_v1/menu/Top Customer Management Menu.yml
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
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
|
||||||
15
bruno/api_v1/menu/Top Menu.yml
Normal file
15
bruno/api_v1/menu/Top Menu.yml
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
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
|
||||||
7
bruno/api_v1/menu/folder.yml
Normal file
7
bruno/api_v1/menu/folder.yml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
info:
|
||||||
|
name: menu
|
||||||
|
type: folder
|
||||||
|
seq: 12
|
||||||
|
|
||||||
|
request:
|
||||||
|
auth: inherit
|
||||||
33
bruno/api_v1/order/Change order address.yml
Normal file
33
bruno/api_v1/order/Change order address.yml
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
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
|
||||||
22
bruno/api_v1/order/Change order status.yml
Normal file
22
bruno/api_v1/order/Change order status.yml
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
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,21 +1,22 @@
|
|||||||
info:
|
info:
|
||||||
name: list-products
|
name: List
|
||||||
type: http
|
type: http
|
||||||
seq: 1
|
seq: 1
|
||||||
|
|
||||||
http:
|
http:
|
||||||
method: GET
|
method: GET
|
||||||
url: http://localhost:3000/api/v1/restricted/list/list-products?p=1&elems=10&target_user_id=2
|
url: "{{bas_url}}/restricted/orders/list?p=1&elems=30&sort=order_id,desc"
|
||||||
params:
|
params:
|
||||||
- name: p
|
- name: p
|
||||||
value: "1"
|
value: "1"
|
||||||
type: query
|
type: query
|
||||||
- name: elems
|
- name: elems
|
||||||
value: "10"
|
value: "30"
|
||||||
type: query
|
type: query
|
||||||
- name: target_user_id
|
- name: sort
|
||||||
value: "2"
|
value: order_id,desc
|
||||||
type: query
|
type: query
|
||||||
|
auth: inherit
|
||||||
|
|
||||||
settings:
|
settings:
|
||||||
encodeUrl: true
|
encodeUrl: true
|
||||||
37
bruno/api_v1/order/Place new order.yml
Normal file
37
bruno/api_v1/order/Place new order.yml
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
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
|
||||||
7
bruno/api_v1/order/folder.yml
Normal file
7
bruno/api_v1/order/folder.yml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
info:
|
||||||
|
name: order
|
||||||
|
type: folder
|
||||||
|
seq: 13
|
||||||
|
|
||||||
|
request:
|
||||||
|
auth: inherit
|
||||||
@@ -5,7 +5,7 @@ info:
|
|||||||
|
|
||||||
http:
|
http:
|
||||||
method: GET
|
method: GET
|
||||||
url: "{{bas_url}}/restricted/product/list?p=1&elems=30&reference=~NC100"
|
url: "{{bas_url}}/restricted/product/list?p=1&elems=30&reference=~NC100&is_new_eq=0&is_favorite_eq=false&is_oem_eq=FALSE"
|
||||||
params:
|
params:
|
||||||
- name: p
|
- name: p
|
||||||
value: "1"
|
value: "1"
|
||||||
@@ -27,11 +27,12 @@ http:
|
|||||||
- name: is_new_eq
|
- name: is_new_eq
|
||||||
value: "0"
|
value: "0"
|
||||||
type: query
|
type: query
|
||||||
disabled: true
|
|
||||||
- name: is_favorite_eq
|
- name: is_favorite_eq
|
||||||
value: "false"
|
value: "false"
|
||||||
type: query
|
type: query
|
||||||
disabled: true
|
- name: is_oem_eq
|
||||||
|
value: "FALSE"
|
||||||
|
type: query
|
||||||
body:
|
body:
|
||||||
type: json
|
type: json
|
||||||
data: ""
|
data: ""
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
info:
|
info:
|
||||||
name: product
|
name: product
|
||||||
type: folder
|
type: folder
|
||||||
seq: 8
|
seq: 9
|
||||||
|
|
||||||
request:
|
request:
|
||||||
auth: inherit
|
auth: inherit
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
info:
|
info:
|
||||||
name: routes
|
name: routes
|
||||||
type: folder
|
type: folder
|
||||||
seq: 10
|
seq: 12
|
||||||
|
|
||||||
request:
|
request:
|
||||||
auth: inherit
|
auth: inherit
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
info:
|
info:
|
||||||
name: addresses
|
name: addresses
|
||||||
type: folder
|
type: folder
|
||||||
seq: 10
|
seq: 9
|
||||||
|
|
||||||
request:
|
request:
|
||||||
auth: inherit
|
auth: inherit
|
||||||
|
|||||||
@@ -5,15 +5,14 @@ info:
|
|||||||
|
|
||||||
http:
|
http:
|
||||||
method: POST
|
method: POST
|
||||||
url: http://localhost:3000/api/v1/public/auth/update-choice?lang_id=0&country_id=1
|
url: http://localhost:3000/api/v1/public/auth/update-choice?lang_id=1&country_id=1
|
||||||
params:
|
params:
|
||||||
- name: lang_id
|
- name: lang_id
|
||||||
value: "0"
|
value: "1"
|
||||||
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
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user