Compare commits
96 Commits
059808665f
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| ce3d82f101 | |||
| 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 | |||
| 19e3f6f0ed | |||
| 46f4618301 | |||
| e335c3aa6f | |||
| 5ebf21c559 | |||
| 84b4c70ffb | |||
|
|
2fd9472db1 | ||
| 66df535317 | |||
| e31ecda582 | |||
| c97251c15b | |||
| 5663c4e126 | |||
| fa85c34794 | |||
|
|
e0a86febc4 | ||
| 1d257d82d3 | |||
|
|
40154ec861 | ||
|
|
bb507036db | ||
| 80a1314dc0 | |||
|
|
100a9f57d4 | ||
| 773e7d3c20 | |||
| 8e063978a8 | |||
| 03a0e5ea64 | |||
| ce8c19f715 | |||
| 31a2744131 | |||
| 4edcb0a852 | |||
| a4120dafa2 | |||
| 5e1a8e898c | |||
|
|
c610ce38cc | ||
| 8e3e41d6fe | |||
| b33da9d072 | |||
|
|
604247b7c8 | ||
| f55d59a0fd | |||
| e5988a85f3 | |||
|
|
0cb5cc47bb | ||
|
|
1efc5417be | ||
|
|
a0c3dd8ec8 | ||
| ab783b599d | |||
| d173af29fe | |||
| f14d60d67b | |||
| 967b101f9b | |||
| c59428adaa | |||
| 97ca510b99 | |||
|
|
ce4cadaa16 | ||
|
|
7f05d39b38 | ||
| 83b7cd49dd | |||
|
|
88255776f3 | ||
|
|
1f6d5ecb72 | ||
|
|
d4d55e2757 | ||
|
|
80d26bba12 | ||
|
|
33e9d016e9 | ||
|
|
a03a2b461f | ||
|
|
134bc4ea53 | ||
|
|
8595969c6e | ||
|
|
a6aa06faa0 | ||
|
|
4f4b32b131 | ||
|
|
dfdf8b4db9 | ||
|
|
438a13c04c |
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
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"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/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/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"
|
||||||
@@ -16,9 +17,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// AuthMiddleware creates authentication middleware
|
// AuthMiddleware creates authentication middleware
|
||||||
func AuthMiddleware() fiber.Handler {
|
func Authenticate() fiber.Handler {
|
||||||
authService := authService.NewAuthService()
|
authService := authService.NewAuthService()
|
||||||
|
|
||||||
return func(c fiber.Ctx) error {
|
return func(c fiber.Ctx) error {
|
||||||
// Get token from Authorization header
|
// Get token from Authorization header
|
||||||
authHeader := c.Get("Authorization")
|
authHeader := c.Get("Authorization")
|
||||||
@@ -26,17 +26,13 @@ func AuthMiddleware() fiber.Handler {
|
|||||||
// Try to get from cookie
|
// Try to get from cookie
|
||||||
authHeader = c.Cookies("access_token")
|
authHeader = c.Cookies("access_token")
|
||||||
if authHeader == "" {
|
if authHeader == "" {
|
||||||
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
|
return c.Next()
|
||||||
"error": "authorization token required",
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Extract token from "Bearer <token>"
|
// Extract token from "Bearer <token>"
|
||||||
parts := strings.Split(authHeader, " ")
|
parts := strings.Split(authHeader, " ")
|
||||||
if len(parts) != 2 || parts[0] != "Bearer" {
|
if len(parts) != 2 || parts[0] != "Bearer" {
|
||||||
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
|
return c.Next()
|
||||||
"error": "invalid authorization header format",
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
authHeader = parts[1]
|
authHeader = parts[1]
|
||||||
}
|
}
|
||||||
@@ -44,24 +40,18 @@ func AuthMiddleware() fiber.Handler {
|
|||||||
// Validate token
|
// Validate token
|
||||||
claims, err := authService.ValidateToken(authHeader)
|
claims, err := authService.ValidateToken(authHeader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
|
return c.Next()
|
||||||
"error": "invalid or expired token",
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get user from database
|
// Get user from database
|
||||||
user, err := authService.GetUserByID(claims.UserID)
|
user, err := authService.GetUserByID(claims.UserID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
|
return c.Next()
|
||||||
"error": "user not found",
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if user is active
|
// Check if user is active
|
||||||
if !user.IsActive {
|
if !user.IsActive {
|
||||||
return c.Status(fiber.StatusForbidden).JSON(fiber.Map{
|
return c.Next()
|
||||||
"error": "user account is inactive",
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create locale. LangID is overwritten by auth Token
|
// Create locale. LangID is overwritten by auth Token
|
||||||
@@ -79,10 +69,8 @@ func AuthMiddleware() fiber.Handler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// We now populate the target user
|
// We now populate the target user
|
||||||
if model.CustomerRole(user.Role.Name) != model.RoleAdmin {
|
if !userLocale.OriginalUser.HasPermission(perms.Teleport) {
|
||||||
return c.Status(fiber.StatusForbidden).JSON(fiber.Map{
|
return c.Next()
|
||||||
"error": "admin access required",
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
targetUserID, err := strconv.Atoi(targetUserIDAttribute)
|
targetUserID, err := strconv.Atoi(targetUserIDAttribute)
|
||||||
@@ -115,22 +103,14 @@ func AuthMiddleware() fiber.Handler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// RequireAdmin creates admin-only middleware
|
func Authorize() fiber.Handler {
|
||||||
func RequireAdmin() fiber.Handler {
|
|
||||||
return func(c fiber.Ctx) error {
|
return func(c fiber.Ctx) error {
|
||||||
originalUserRole, ok := localeExtractor.GetOriginalUserRole(c)
|
_, ok := localeExtractor.GetUserID(c)
|
||||||
if !ok {
|
if !ok {
|
||||||
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
|
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
|
||||||
"error": "not authenticated",
|
"error": "not authenticated",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if model.CustomerRole(originalUserRole.Name) != model.RoleAdmin {
|
|
||||||
return c.Status(fiber.StatusForbidden).JSON(fiber.Map{
|
|
||||||
"error": "admin access required",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
return c.Next()
|
return c.Next()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,16 @@ package perms
|
|||||||
type Permission string
|
type Permission string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
UserReadAny Permission = "user.read.any"
|
UserReadAny Permission = "user.read.any"
|
||||||
UserWriteAny Permission = "user.write.any"
|
UserWriteAny Permission = "user.write.any"
|
||||||
UserDeleteAny Permission = "user.delete.any"
|
UserDeleteAny Permission = "user.delete.any"
|
||||||
CurrencyWrite Permission = "currency.write"
|
CurrencyWrite Permission = "currency.write"
|
||||||
SpecificPriceManage Permission = "specific_price.manage"
|
SpecificPriceManage Permission = "specific_price.manage"
|
||||||
|
WebdavCreateToken Permission = "webdav.create_token"
|
||||||
|
ProductTranslationSave Permission = "product_translation.save"
|
||||||
|
ProductTranslationTranslate Permission = "product_translation.translate"
|
||||||
|
SearchCreateIndex Permission = "search.create_index"
|
||||||
|
OrdersViewAll Permission = "orders.view_all"
|
||||||
|
OrdersModifyAll Permission = "orders.modify_all"
|
||||||
|
Teleport Permission = "teleport"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -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"
|
||||||
@@ -49,7 +49,7 @@ func AuthHandlerRoutes(r fiber.Router) fiber.Router {
|
|||||||
r.Get("/google", handler.GoogleLogin)
|
r.Get("/google", handler.GoogleLogin)
|
||||||
r.Get("/google/callback", handler.GoogleCallback)
|
r.Get("/google/callback", handler.GoogleCallback)
|
||||||
|
|
||||||
authProtected := r.Group("", middleware.AuthMiddleware())
|
authProtected := r.Group("", middleware.Authorize())
|
||||||
authProtected.Get("/me", handler.Me)
|
authProtected.Get("/me", handler.Me)
|
||||||
authProtected.Post("/update-choice", handler.UpdateJWTToken)
|
authProtected.Post("/update-choice", handler.UpdateJWTToken)
|
||||||
|
|
||||||
@@ -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),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package public
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/service/menuService"
|
"git.ma-al.com/goc_daniel/b2b/app/service/menuService"
|
||||||
|
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/nullable"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/nullable"
|
||||||
@@ -31,12 +32,21 @@ func RoutingHandlerRoutes(r fiber.Router) fiber.Router {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *RoutingHandler) GetRouting(c fiber.Ctx) error {
|
func (h *RoutingHandler) GetRouting(c fiber.Ctx) error {
|
||||||
lang_id, ok := localeExtractor.GetLangID(c)
|
langId, ok := localeExtractor.GetLangID(c)
|
||||||
if !ok {
|
if !ok {
|
||||||
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrBadAttribute)).
|
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrInvalidBody)).
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrBadAttribute)))
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrInvalidBody)))
|
||||||
}
|
}
|
||||||
menu, err := h.menuService.GetRoutes(lang_id)
|
|
||||||
|
var roleId uint
|
||||||
|
customer, ok := localeExtractor.GetCustomer(c)
|
||||||
|
if !ok {
|
||||||
|
roleId = constdata.UNLOGGED_USER_ROLE_ID
|
||||||
|
} else {
|
||||||
|
roleId = customer.RoleID
|
||||||
|
}
|
||||||
|
|
||||||
|
menu, err := h.menuService.GetRoutes(langId, roleId)
|
||||||
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)))
|
||||||
|
|||||||
@@ -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)))
|
||||||
}
|
}
|
||||||
@@ -124,13 +147,20 @@ func (h *AddressesHandler) RetrieveAddressesInfo(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)))
|
||||||
}
|
}
|
||||||
|
|
||||||
addresses_info, err := h.addressesService.RetrieveAddressesInfo(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)))
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.JSON(response.Make(&addresses_info, 0, i18n.T_(c, response.Message_OK)))
|
return c.JSON(response.Make(addresses, 0, i18n.T_(c, response.Message_OK)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *AddressesHandler) DeleteAddress(c fiber.Ctx) error {
|
func (h *AddressesHandler) DeleteAddress(c fiber.Ctx) error {
|
||||||
@@ -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,11 +29,13 @@ 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.Get("/change-cart-name", handler.ChangeCartName)
|
r.Delete("/remove-cart", handler.RemoveCart)
|
||||||
|
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)
|
||||||
|
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
@@ -44,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)))
|
||||||
}
|
}
|
||||||
@@ -53,6 +64,37 @@ func (h *CartsHandler) AddNewCart(c fiber.Ctx) error {
|
|||||||
return c.JSON(response.Make(&new_cart, 0, i18n.T_(c, response.Message_OK)))
|
return c.JSON(response.Make(&new_cart, 0, i18n.T_(c, response.Message_OK)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *CartsHandler) RemoveCart(c fiber.Ctx) error {
|
||||||
|
userID, ok := localeExtractor.GetUserID(c)
|
||||||
|
if !ok {
|
||||||
|
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrInvalidBody)).
|
||||||
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrInvalidBody)))
|
||||||
|
}
|
||||||
|
|
||||||
|
cart_id_attribute := c.Query("cart_id")
|
||||||
|
cart_id, err := strconv.Atoi(cart_id_attribute)
|
||||||
|
if err != nil {
|
||||||
|
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrBadAttribute)).
|
||||||
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrBadAttribute)))
|
||||||
|
}
|
||||||
|
|
||||||
|
err = h.cartsService.RemoveCart(userID, uint(cart_id))
|
||||||
|
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)).
|
||||||
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.JSON(response.Make(nullable.GetNil(""), 0, i18n.T_(c, response.Message_OK)))
|
||||||
|
}
|
||||||
|
|
||||||
func (h *CartsHandler) ChangeCartName(c fiber.Ctx) error {
|
func (h *CartsHandler) ChangeCartName(c fiber.Ctx) error {
|
||||||
userID, ok := localeExtractor.GetUserID(c)
|
userID, ok := localeExtractor.GetUserID(c)
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -71,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)))
|
||||||
}
|
}
|
||||||
@@ -87,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)))
|
||||||
}
|
}
|
||||||
@@ -110,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)))
|
||||||
}
|
}
|
||||||
@@ -117,6 +182,7 @@ func (h *CartsHandler) RetrieveCart(c fiber.Ctx) error {
|
|||||||
return c.JSON(response.Make(cart, 0, i18n.T_(c, response.Message_OK)))
|
return c.JSON(response.Make(cart, 0, i18n.T_(c, response.Message_OK)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// adds or sets given amount of products to the cart
|
||||||
func (h *CartsHandler) AddProduct(c fiber.Ctx) error {
|
func (h *CartsHandler) AddProduct(c fiber.Ctx) error {
|
||||||
userID, ok := localeExtractor.GetUserID(c)
|
userID, ok := localeExtractor.GetUserID(c)
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -159,8 +225,78 @@ func (h *CartsHandler) AddProduct(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)))
|
||||||
}
|
}
|
||||||
|
|
||||||
err = h.cartsService.AddProduct(userID, uint(cart_id), uint(product_id), product_attribute_id, uint(amount))
|
set_amount_attribute := c.Query("set_amount")
|
||||||
|
set_amount, err := strconv.ParseBool(set_amount_attribute)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrBadAttribute)).
|
||||||
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrBadAttribute)))
|
||||||
|
}
|
||||||
|
|
||||||
|
err = h.cartsService.AddProduct(userID, uint(cart_id), uint(product_id), product_attribute_id, amount, set_amount)
|
||||||
|
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)).
|
||||||
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.JSON(response.Make(nullable.GetNil(""), 0, i18n.T_(c, response.Message_OK)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// removes product from the cart.
|
||||||
|
func (h *CartsHandler) RemoveProduct(c fiber.Ctx) error {
|
||||||
|
userID, ok := localeExtractor.GetUserID(c)
|
||||||
|
if !ok {
|
||||||
|
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrInvalidBody)).
|
||||||
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrInvalidBody)))
|
||||||
|
}
|
||||||
|
|
||||||
|
cart_id_attribute := c.Query("cart_id")
|
||||||
|
cart_id, err := strconv.Atoi(cart_id_attribute)
|
||||||
|
if err != nil {
|
||||||
|
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrBadAttribute)).
|
||||||
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrBadAttribute)))
|
||||||
|
}
|
||||||
|
|
||||||
|
product_id_attribute := c.Query("product_id")
|
||||||
|
product_id, err := strconv.Atoi(product_id_attribute)
|
||||||
|
if err != nil {
|
||||||
|
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrBadAttribute)).
|
||||||
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrBadAttribute)))
|
||||||
|
}
|
||||||
|
|
||||||
|
product_attribute_id_attribute := c.Query("product_attribute_id")
|
||||||
|
var product_attribute_id *uint
|
||||||
|
if product_attribute_id_attribute == "" {
|
||||||
|
product_attribute_id = nil
|
||||||
|
} else {
|
||||||
|
val, err := strconv.Atoi(product_attribute_id_attribute)
|
||||||
|
if err != nil {
|
||||||
|
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrBadAttribute)).
|
||||||
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrBadAttribute)))
|
||||||
|
}
|
||||||
|
uval := uint(val)
|
||||||
|
product_attribute_id = &uval
|
||||||
|
}
|
||||||
|
|
||||||
|
err = h.cartsService.RemoveProduct(userID, uint(cart_id), uint(product_id), product_attribute_id)
|
||||||
|
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)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,11 +3,13 @@ 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/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/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"
|
||||||
@@ -30,7 +32,8 @@ func CustomerHandlerRoutes(r fiber.Router) fiber.Router {
|
|||||||
handler := NewCustomerHandler()
|
handler := NewCustomerHandler()
|
||||||
|
|
||||||
r.Get("", handler.customerData)
|
r.Get("", handler.customerData)
|
||||||
r.Get("/list", 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
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,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)))
|
||||||
}
|
}
|
||||||
@@ -75,10 +85,6 @@ func (h *customerHandler) listCustomers(fc fiber.Ctx) error {
|
|||||||
return fc.Status(responseErrors.GetErrorStatus(responseErrors.ErrBadAttribute)).
|
return fc.Status(responseErrors.GetErrorStatus(responseErrors.ErrBadAttribute)).
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(fc, responseErrors.ErrBadAttribute)))
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(fc, responseErrors.ErrBadAttribute)))
|
||||||
}
|
}
|
||||||
if !user.HasPermission(perms.UserReadAny) {
|
|
||||||
return fc.Status(fiber.StatusForbidden).
|
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(fc, responseErrors.ErrForbidden)))
|
|
||||||
}
|
|
||||||
|
|
||||||
p, filt, err := query_params.ParseFilters[model.Customer](fc, columnMappingListUsers)
|
p, filt, err := query_params.ParseFilters[model.Customer](fc, columnMappingListUsers)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -87,15 +93,15 @@ func (h *customerHandler) listCustomers(fc fiber.Ctx) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
search := fc.Query("search")
|
search := fc.Query("search")
|
||||||
if search != "" {
|
|
||||||
if !user.HasPermission(perms.UserReadAny) {
|
|
||||||
return fc.Status(fiber.StatusForbidden).
|
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(fc, responseErrors.ErrForbidden)))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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)))
|
||||||
}
|
}
|
||||||
@@ -109,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)))
|
||||||
|
|||||||
211
app/delivery/web/api/restricted/orders.go
Normal file
211
app/delivery/web/api/restricted/orders.go
Normal file
@@ -0,0 +1,211 @@
|
|||||||
|
package restricted
|
||||||
|
|
||||||
|
import (
|
||||||
|
"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/enums"
|
||||||
|
"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/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/query/query_params"
|
||||||
|
"git.ma-al.com/goc_daniel/b2b/app/utils/response"
|
||||||
|
"git.ma-al.com/goc_daniel/b2b/app/utils/responseErrors"
|
||||||
|
"github.com/gofiber/fiber/v3"
|
||||||
|
)
|
||||||
|
|
||||||
|
type OrdersHandler struct {
|
||||||
|
ordersService *orderService.OrderService
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewOrdersHandler() *OrdersHandler {
|
||||||
|
ordersService := orderService.New()
|
||||||
|
return &OrdersHandler{
|
||||||
|
ordersService: ordersService,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func OrdersHandlerRoutes(r fiber.Router) fiber.Router {
|
||||||
|
handler := NewOrdersHandler()
|
||||||
|
|
||||||
|
r.Get("/list", handler.ListOrders)
|
||||||
|
r.Post("/place-new-order", handler.PlaceNewOrder)
|
||||||
|
r.Post("/change-order-address", handler.ChangeOrderAddress)
|
||||||
|
r.Patch("/change-order-status", middleware.Require(perms.OrdersModifyAll), handler.ChangeOrderStatus)
|
||||||
|
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
|
||||||
|
// when a user (not admin) wants to list orders, we automatically append filter to only view his orders.
|
||||||
|
// we base permissions and user based on target user only.
|
||||||
|
func (h *OrdersHandler) ListOrders(c fiber.Ctx) error {
|
||||||
|
user, ok := localeExtractor.GetCustomer(c)
|
||||||
|
if !ok {
|
||||||
|
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrInvalidBody)).
|
||||||
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrInvalidBody)))
|
||||||
|
}
|
||||||
|
|
||||||
|
paging, filters, err := query_params.ParseFilters[model.CustomerOrder](c, columnMappingListOrders)
|
||||||
|
if err != nil {
|
||||||
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
|
}
|
||||||
|
|
||||||
|
list, err := h.ordersService.Find(user, paging, filters)
|
||||||
|
if err != nil {
|
||||||
|
|
||||||
|
logger.Error("failed to list orders",
|
||||||
|
"handler", "OrdersHandler.ListOrders",
|
||||||
|
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.JSON(response.Make(&list.Items, int(list.Count), i18n.T_(c, response.Message_OK)))
|
||||||
|
}
|
||||||
|
|
||||||
|
var columnMappingListOrders map[string]string = map[string]string{
|
||||||
|
"order_id": "b2b_customer_orders.order_id",
|
||||||
|
"user_id": "b2b_customer_orders.user_id",
|
||||||
|
"name": "b2b_customer_orders.name",
|
||||||
|
"country_id": "b2b_customer_orders.country_id",
|
||||||
|
"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 {
|
||||||
|
userID, ok := localeExtractor.GetUserID(c)
|
||||||
|
if !ok {
|
||||||
|
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrInvalidBody)).
|
||||||
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrInvalidBody)))
|
||||||
|
}
|
||||||
|
|
||||||
|
cart_id_attribute := c.Query("cart_id")
|
||||||
|
cart_id, err := strconv.Atoi(cart_id_attribute)
|
||||||
|
if err != nil {
|
||||||
|
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrBadAttribute)).
|
||||||
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrBadAttribute)))
|
||||||
|
}
|
||||||
|
|
||||||
|
country_id_attribute := c.Query("country_id")
|
||||||
|
country_id, err := strconv.Atoi(country_id_attribute)
|
||||||
|
if err != nil {
|
||||||
|
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrBadAttribute)).
|
||||||
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrBadAttribute)))
|
||||||
|
}
|
||||||
|
|
||||||
|
address_info := string(c.Body())
|
||||||
|
if address_info == "" {
|
||||||
|
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrInvalidBody)).
|
||||||
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrInvalidBody)))
|
||||||
|
}
|
||||||
|
|
||||||
|
name := c.Query("name")
|
||||||
|
|
||||||
|
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 {
|
||||||
|
|
||||||
|
logger.Error("failed to place order",
|
||||||
|
"handler", "OrdersHandler.PlaceNewOrder",
|
||||||
|
|
||||||
|
"user_id", userID,
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.JSON(response.Make(nullable.GetNil(""), 0, i18n.T_(c, response.Message_OK)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// we base permissions and user based on target user only.
|
||||||
|
func (h *OrdersHandler) ChangeOrderAddress(c fiber.Ctx) error {
|
||||||
|
user, ok := localeExtractor.GetCustomer(c)
|
||||||
|
if !ok {
|
||||||
|
return c.Status(responseErrors.GetErrorStatus(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(order_id_attribute)
|
||||||
|
if err != nil {
|
||||||
|
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrBadAttribute)).
|
||||||
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrBadAttribute)))
|
||||||
|
}
|
||||||
|
|
||||||
|
country_id_attribute := c.Query("country_id")
|
||||||
|
country_id, err := strconv.Atoi(country_id_attribute)
|
||||||
|
if err != nil {
|
||||||
|
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrBadAttribute)).
|
||||||
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrBadAttribute)))
|
||||||
|
}
|
||||||
|
|
||||||
|
address_info := string(c.Body())
|
||||||
|
if address_info == "" {
|
||||||
|
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrInvalidBody)).
|
||||||
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrInvalidBody)))
|
||||||
|
}
|
||||||
|
|
||||||
|
err = h.ordersService.ChangeOrderAddress(user, uint(order_id), uint(country_id), address_info)
|
||||||
|
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)).
|
||||||
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.JSON(response.Make(nullable.GetNil(""), 0, i18n.T_(c, response.Message_OK)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// we base permissions and user based on target user only.
|
||||||
|
// TODO: well, permissions and all that.
|
||||||
|
func (h *OrdersHandler) ChangeOrderStatus(c fiber.Ctx) error {
|
||||||
|
userId, ok := localeExtractor.GetUserID(c)
|
||||||
|
if !ok {
|
||||||
|
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrInvalidBody)).
|
||||||
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrInvalidBody)))
|
||||||
|
}
|
||||||
|
|
||||||
|
order_id, err := strconv.Atoi(c.Query("order_id"))
|
||||||
|
if err != nil {
|
||||||
|
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrBadAttribute)).
|
||||||
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrBadAttribute)))
|
||||||
|
}
|
||||||
|
|
||||||
|
err = h.ordersService.ChangeOrderStatus(userId, uint(order_id), enums.OrderStatus(strings.ToUpper(c.Query("status"))))
|
||||||
|
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)).
|
||||||
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.JSON(response.Make(nullable.GetNil(""), 0, i18n.T_(c, response.Message_OK)))
|
||||||
|
}
|
||||||
@@ -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)))
|
||||||
}
|
}
|
||||||
@@ -103,14 +120,16 @@ func (h *ProductsHandler) ListProducts(c fiber.Ctx) error {
|
|||||||
return c.JSON(response.Make(&list.Items, int(list.Count), i18n.T_(c, response.Message_OK)))
|
return c.JSON(response.Make(&list.Items, int(list.Count), i18n.T_(c, response.Message_OK)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// These are all the filterable fields
|
||||||
var columnMappingListProducts map[string]string = map[string]string{
|
var columnMappingListProducts map[string]string = map[string]string{
|
||||||
"product_id": "ps.id_product",
|
"product_id": "bp.product_id",
|
||||||
"name": "pl.name",
|
"name": "bp.name",
|
||||||
"reference": "p.reference",
|
"reference": "bp.reference",
|
||||||
"category_name": "cl.name",
|
"category_id": "bp.category_id",
|
||||||
"category_id": "cp.id_category",
|
"quantity": "bp.quantity",
|
||||||
"quantity": "sa.quantity",
|
"is_favorite": "bp.is_favorite",
|
||||||
"is_favorite": "ps.is_favorite",
|
"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 {
|
||||||
@@ -130,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)))
|
||||||
}
|
}
|
||||||
@@ -154,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)))
|
||||||
}
|
}
|
||||||
@@ -178,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)))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,10 +4,12 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/config"
|
"git.ma-al.com/goc_daniel/b2b/app/config"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/model"
|
"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/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"
|
||||||
@@ -35,8 +37,8 @@ func ProductTranslationHandlerRoutes(r fiber.Router) fiber.Router {
|
|||||||
handler := NewProductTranslationHandler()
|
handler := NewProductTranslationHandler()
|
||||||
|
|
||||||
r.Get("/get-product-description", handler.GetProductDescription)
|
r.Get("/get-product-description", handler.GetProductDescription)
|
||||||
r.Post("/save-product-description", handler.SaveProductDescription)
|
r.Post("/save-product-description", middleware.Require(perms.ProductTranslationSave), handler.SaveProductDescription)
|
||||||
r.Get("/translate-product-description", handler.TranslateProductDescription)
|
r.Get("/translate-product-description", middleware.Require(perms.ProductTranslationTranslate), handler.TranslateProductDescription)
|
||||||
|
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
@@ -65,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)))
|
||||||
}
|
}
|
||||||
@@ -80,12 +89,6 @@ func (h *ProductTranslationHandler) SaveProductDescription(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)))
|
||||||
}
|
}
|
||||||
|
|
||||||
userRole, ok := localeExtractor.GetOriginalUserRole(c)
|
|
||||||
if !ok || model.CustomerRole(userRole.Name) != model.RoleAdmin {
|
|
||||||
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrAdminAccessRequired)).
|
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrAdminAccessRequired)))
|
|
||||||
}
|
|
||||||
|
|
||||||
productID_attribute := c.Query("productID")
|
productID_attribute := c.Query("productID")
|
||||||
productID, err := strconv.Atoi(productID_attribute)
|
productID, err := strconv.Atoi(productID_attribute)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -108,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)))
|
||||||
}
|
}
|
||||||
@@ -123,12 +133,6 @@ func (h *ProductTranslationHandler) TranslateProductDescription(c fiber.Ctx) err
|
|||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrInvalidBody)))
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrInvalidBody)))
|
||||||
}
|
}
|
||||||
|
|
||||||
userRole, ok := localeExtractor.GetOriginalUserRole(c)
|
|
||||||
if !ok || model.CustomerRole(userRole.Name) != model.RoleAdmin {
|
|
||||||
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrAdminAccessRequired)).
|
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrAdminAccessRequired)))
|
|
||||||
}
|
|
||||||
|
|
||||||
productID_attribute := c.Query("productID")
|
productID_attribute := c.Query("productID")
|
||||||
productID, err := strconv.Atoi(productID_attribute)
|
productID, err := strconv.Atoi(productID_attribute)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -158,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,13 +2,14 @@ package restricted
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/model"
|
"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/meiliService"
|
"git.ma-al.com/goc_daniel/b2b/app/service/meiliService"
|
||||||
searchservice "git.ma-al.com/goc_daniel/b2b/app/service/searchService"
|
searchservice "git.ma-al.com/goc_daniel/b2b/app/service/searchService"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/i18n"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/i18n"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/localeExtractor"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/localeExtractor"
|
||||||
|
"git.ma-al.com/goc_daniel/b2b/app/utils/logger"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/nullable"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/nullable"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/response"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/response"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/responseErrors"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/responseErrors"
|
||||||
@@ -30,7 +31,7 @@ func NewMeiliSearchHandler() *MeiliSearchHandler {
|
|||||||
func MeiliSearchHandlerRoutes(r fiber.Router) fiber.Router {
|
func MeiliSearchHandlerRoutes(r fiber.Router) fiber.Router {
|
||||||
handler := NewMeiliSearchHandler()
|
handler := NewMeiliSearchHandler()
|
||||||
|
|
||||||
r.Get("/create-index", handler.CreateIndex)
|
r.Get("/create-index", middleware.Require(perms.SearchCreateIndex), handler.CreateIndex)
|
||||||
r.Post("/search", handler.Search)
|
r.Post("/search", handler.Search)
|
||||||
r.Post("/settings", handler.GetSettings)
|
r.Post("/settings", handler.GetSettings)
|
||||||
|
|
||||||
@@ -44,15 +45,15 @@ func (h *MeiliSearchHandler) CreateIndex(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)))
|
||||||
}
|
}
|
||||||
|
|
||||||
userRole, ok := localeExtractor.GetOriginalUserRole(c)
|
|
||||||
if !ok || model.CustomerRole(userRole.Name) != model.RoleAdmin {
|
|
||||||
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrAdminAccessRequired)).
|
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrAdminAccessRequired)))
|
|
||||||
}
|
|
||||||
|
|
||||||
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)))
|
||||||
}
|
}
|
||||||
@@ -77,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)))
|
||||||
}
|
}
|
||||||
@@ -85,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)))
|
||||||
}
|
}
|
||||||
@@ -105,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)))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,9 +5,11 @@ import (
|
|||||||
|
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/config"
|
"git.ma-al.com/goc_daniel/b2b/app/config"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/delivery/middleware"
|
"git.ma-al.com/goc_daniel/b2b/app/delivery/middleware"
|
||||||
|
"git.ma-al.com/goc_daniel/b2b/app/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/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"
|
||||||
@@ -30,13 +32,13 @@ func NewSpecificPriceHandler() *SpecificPriceHandler {
|
|||||||
func SpecificPriceHandlerRoutes(r fiber.Router) fiber.Router {
|
func SpecificPriceHandlerRoutes(r fiber.Router) fiber.Router {
|
||||||
handler := NewSpecificPriceHandler()
|
handler := NewSpecificPriceHandler()
|
||||||
|
|
||||||
r.Post("/", middleware.Require("specific_price.manage"), handler.Create)
|
r.Post("/", middleware.Require(perms.SpecificPriceManage), handler.Create)
|
||||||
r.Put("/:id", middleware.Require("specific_price.manage"), handler.Update)
|
r.Put("/:id", middleware.Require(perms.SpecificPriceManage), handler.Update)
|
||||||
r.Delete("/:id", middleware.Require("specific_price.manage"), handler.Delete)
|
r.Delete("/:id", middleware.Require(perms.SpecificPriceManage), handler.Delete)
|
||||||
r.Get("/", middleware.Require("specific_price.manage"), handler.List)
|
r.Get("/", middleware.Require(perms.SpecificPriceManage), handler.List)
|
||||||
r.Get("/:id", middleware.Require("specific_price.manage"), handler.GetByID)
|
r.Get("/:id", middleware.Require(perms.SpecificPriceManage), handler.GetByID)
|
||||||
r.Patch("/:id/activate", middleware.Require("specific_price.manage"), handler.Activate)
|
r.Patch("/:id/activate", middleware.Require(perms.SpecificPriceManage), handler.Activate)
|
||||||
r.Patch("/:id/deactivate", middleware.Require("specific_price.manage"), handler.Deactivate)
|
r.Patch("/:id/deactivate", middleware.Require(perms.SpecificPriceManage), handler.Deactivate)
|
||||||
|
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
@@ -50,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)))
|
||||||
}
|
}
|
||||||
@@ -73,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)))
|
||||||
}
|
}
|
||||||
@@ -83,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)))
|
||||||
}
|
}
|
||||||
@@ -100,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)))
|
||||||
}
|
}
|
||||||
@@ -117,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)))
|
||||||
}
|
}
|
||||||
@@ -134,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)))
|
||||||
}
|
}
|
||||||
@@ -151,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)))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,10 +4,12 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/config"
|
"git.ma-al.com/goc_daniel/b2b/app/config"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/model"
|
"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/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"
|
||||||
@@ -34,7 +36,7 @@ func StorageHandlerRoutes(r fiber.Router) fiber.Router {
|
|||||||
r.Get("/download-file/*", handler.DownloadFile)
|
r.Get("/download-file/*", handler.DownloadFile)
|
||||||
|
|
||||||
// for admins only
|
// for admins only
|
||||||
r.Get("/create-new-webdav-token", handler.CreateNewWebdavToken)
|
r.Get("/create-new-webdav-token", middleware.Require(perms.WebdavCreateToken), handler.CreateNewWebdavToken)
|
||||||
|
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
@@ -51,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)))
|
||||||
}
|
}
|
||||||
@@ -67,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)))
|
||||||
}
|
}
|
||||||
@@ -84,14 +98,14 @@ func (h *StorageHandler) CreateNewWebdavToken(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)))
|
||||||
}
|
}
|
||||||
|
|
||||||
userRole, ok := localeExtractor.GetOriginalUserRole(c)
|
|
||||||
if !ok || model.CustomerRole(userRole.Name) != model.RoleAdmin {
|
|
||||||
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrAdminAccessRequired)).
|
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrAdminAccessRequired)))
|
|
||||||
}
|
|
||||||
|
|
||||||
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)))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,9 +86,10 @@ func (s *Server) Setup() error {
|
|||||||
|
|
||||||
// API routes
|
// API routes
|
||||||
s.api = s.app.Group("/api/v1")
|
s.api = s.app.Group("/api/v1")
|
||||||
|
s.api.Use(middleware.Authenticate())
|
||||||
s.public = s.api.Group("/public")
|
s.public = s.api.Group("/public")
|
||||||
s.restricted = s.api.Group("/restricted")
|
s.restricted = s.api.Group("/restricted")
|
||||||
s.restricted.Use(middleware.AuthMiddleware())
|
s.restricted.Use(middleware.Authorize())
|
||||||
s.webdav = s.api.Group("/webdav")
|
s.webdav = s.api.Group("/webdav")
|
||||||
s.webdav.Use(middleware.Webdav())
|
s.webdav.Use(middleware.Webdav())
|
||||||
|
|
||||||
@@ -132,8 +133,13 @@ func (s *Server) Setup() error {
|
|||||||
carts := s.restricted.Group("/carts")
|
carts := s.restricted.Group("/carts")
|
||||||
restricted.CartsHandlerRoutes(carts)
|
restricted.CartsHandlerRoutes(carts)
|
||||||
|
|
||||||
|
// orders (restricted)
|
||||||
|
orders := s.restricted.Group("/orders")
|
||||||
|
restricted.OrdersHandlerRoutes(orders)
|
||||||
|
|
||||||
specificPrice := s.restricted.Group("/specific-price")
|
specificPrice := s.restricted.Group("/specific-price")
|
||||||
restricted.SpecificPriceHandlerRoutes(specificPrice)
|
restricted.SpecificPriceHandlerRoutes(specificPrice)
|
||||||
|
|
||||||
// addresses (restricted)
|
// addresses (restricted)
|
||||||
addresses := s.restricted.Group("/addresses")
|
addresses := s.restricted.Group("/addresses")
|
||||||
restricted.AddressesHandlerRoutes(addresses)
|
restricted.AddressesHandlerRoutes(addresses)
|
||||||
@@ -161,16 +167,6 @@ func (s *Server) Setup() error {
|
|||||||
// })
|
// })
|
||||||
// })
|
// })
|
||||||
|
|
||||||
// // Admin routes example
|
|
||||||
// admin := s.api.Group("/admin")
|
|
||||||
// admin.Use(middleware.AuthMiddleware())
|
|
||||||
// admin.Use(middleware.RequireAdmin())
|
|
||||||
// admin.Get("/users", func(c fiber.Ctx) error {
|
|
||||||
// return c.JSON(fiber.Map{
|
|
||||||
// "message": "Admin area - user management",
|
|
||||||
// })
|
|
||||||
// })
|
|
||||||
|
|
||||||
// keep this at the end because its wilderange
|
// keep this at the end because its wilderange
|
||||||
general.InitBo(s.App())
|
general.InitBo(s.App())
|
||||||
|
|
||||||
|
|||||||
@@ -1,25 +1,18 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
type Address struct {
|
type Address struct {
|
||||||
ID uint `gorm:"column:id;primaryKey;autoIncrement" json:"id"`
|
ID uint `gorm:"column:id;primaryKey;autoIncrement" json:"id"`
|
||||||
CustomerID uint `gorm:"column:b2b_customer_id;not null;index" json:"customer_id"`
|
CustomerID uint `gorm:"column:b2b_customer_id;not null;index" json:"customer_id"`
|
||||||
AddressInfo string `gorm:"column:address_info;not null" json:"address_info"`
|
AddressString string `gorm:"column:address_string;not null" json:"address_string"`
|
||||||
CountryID uint `gorm:"column:b2b_country_id;not null" json:"country_id"`
|
AddressUnparsed *AddressUnparsed `gorm:"-" json:"address_unparsed"`
|
||||||
|
CountryID uint `gorm:"column:b2b_country_id;not null" json:"country_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Address) TableName() string {
|
func (Address) TableName() string {
|
||||||
return "b2b_addresses"
|
return "b2b_addresses"
|
||||||
}
|
}
|
||||||
|
|
||||||
type AddressUnparsed struct {
|
type AddressUnparsed interface{}
|
||||||
ID uint `gorm:"column:id;primaryKey;autoIncrement" json:"id"`
|
|
||||||
CustomerID uint `gorm:"column:b2b_customer_id;not null;index" json:"customer_id"`
|
|
||||||
AddressInfo AddressField `gorm:"column:address_info;not null" json:"address_info"`
|
|
||||||
CountryID uint `gorm:"column:b2b_country_id;not null" json:"country_id"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type AddressField interface {
|
|
||||||
}
|
|
||||||
|
|
||||||
// Address template in Poland
|
// Address template in Poland
|
||||||
type AddressPL struct {
|
type AddressPL struct {
|
||||||
|
|||||||
@@ -10,7 +10,8 @@ type ScannedCategory struct {
|
|||||||
LinkRewrite string `gorm:"column:link_rewrite"`
|
LinkRewrite string `gorm:"column:link_rewrite"`
|
||||||
IsoCode string `gorm:"column:iso_code"`
|
IsoCode string `gorm:"column:iso_code"`
|
||||||
|
|
||||||
Visited bool //this is for internal backend use only
|
Visited bool // this is for internal backend use only
|
||||||
|
Filter string // filter applicable to this category
|
||||||
}
|
}
|
||||||
|
|
||||||
type Category struct {
|
type Category struct {
|
||||||
@@ -25,6 +26,7 @@ type CategoryParams struct {
|
|||||||
CategoryID uint `json:"category_id" form:"category_id"`
|
CategoryID uint `json:"category_id" form:"category_id"`
|
||||||
LinkRewrite string `json:"link_rewrite" form:"link_rewrite"`
|
LinkRewrite string `json:"link_rewrite" form:"link_rewrite"`
|
||||||
Locale string `json:"locale" form:"locale"`
|
Locale string `json:"locale" form:"locale"`
|
||||||
|
Filter string `json:"filter" form:"filter"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CategoryInBreadcrumb struct {
|
type CategoryInBreadcrumb struct {
|
||||||
|
|||||||
@@ -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"
|
||||||
|
}
|
||||||
38
app/model/order.go
Normal file
38
app/model/order.go
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"git.ma-al.com/goc_daniel/b2b/app/model/enums"
|
||||||
|
)
|
||||||
|
|
||||||
|
type CustomerOrder struct {
|
||||||
|
OrderID uint `gorm:"column:order_id;primaryKey;autoIncrement" json:"order_id"`
|
||||||
|
UserID uint `gorm:"column:user_id;not null;index" json:"user_id"`
|
||||||
|
Name string `gorm:"column:name;not null" json:"name"`
|
||||||
|
CountryID uint `gorm:"column:country_id;not null" json:"country_id"`
|
||||||
|
AddressString string `gorm:"column:address_string;not null" json:"address_string"`
|
||||||
|
AddressUnparsed *AddressUnparsed `gorm:"-" json:"address_unparsed"`
|
||||||
|
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"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (CustomerOrder) TableName() string {
|
||||||
|
return "b2b_customer_orders"
|
||||||
|
}
|
||||||
|
|
||||||
|
type OrderProduct struct {
|
||||||
|
OrderID uint `gorm:"column:order_id;not null;index" json:"-"`
|
||||||
|
ProductID uint `gorm:"column:product_id;not null" json:"product_id"`
|
||||||
|
ProductAttributeID *uint `gorm:"column:product_attribute_id" json:"product_attribute_id,omitempty"`
|
||||||
|
Amount uint `gorm:"column:amount;not null" json:"amount"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (OrderProduct) TableName() string {
|
||||||
|
return "b2b_orders_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,6 +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 bool `gorm:"column:is_new" json:"is_new"`
|
||||||
|
IsOEM bool `gorm:"column:is_oem" json:"is_oem"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ProductFilters struct {
|
type ProductFilters struct {
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ type Route struct {
|
|||||||
Component string `gorm:"type:varchar(255);not null;comment:path to component file" json:"component"`
|
Component string `gorm:"type:varchar(255);not null;comment:path to component file" json:"component"`
|
||||||
Meta *string `gorm:"type:longtext;default:'{}'" json:"meta,omitempty"`
|
Meta *string `gorm:"type:longtext;default:'{}'" json:"meta,omitempty"`
|
||||||
Active *bool `gorm:"type:tinyint;default:1" json:"active,omitempty"`
|
Active *bool `gorm:"type:tinyint;default:1" json:"active,omitempty"`
|
||||||
SortOrder *int `gorm:"type:int;default:0" json:"sort_order,omitempty"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Route) TableName() string {
|
func (Route) TableName() string {
|
||||||
|
|||||||
@@ -48,9 +48,9 @@ func (repo *AddressesRepo) UserAddressesAmt(user_id uint) (uint, error) {
|
|||||||
|
|
||||||
func (repo *AddressesRepo) AddNewAddress(user_id uint, address_info string, country_id uint) error {
|
func (repo *AddressesRepo) AddNewAddress(user_id uint, address_info string, country_id uint) error {
|
||||||
address := model.Address{
|
address := model.Address{
|
||||||
CustomerID: user_id,
|
CustomerID: user_id,
|
||||||
AddressInfo: address_info,
|
AddressString: address_info,
|
||||||
CountryID: country_id,
|
CountryID: country_id,
|
||||||
}
|
}
|
||||||
|
|
||||||
return db.DB.
|
return db.DB.
|
||||||
@@ -60,10 +60,10 @@ func (repo *AddressesRepo) AddNewAddress(user_id uint, address_info string, coun
|
|||||||
|
|
||||||
func (repo *AddressesRepo) UpdateAddress(user_id uint, address_id uint, address_info string, country_id uint) error {
|
func (repo *AddressesRepo) UpdateAddress(user_id uint, address_id uint, address_info string, country_id uint) error {
|
||||||
address := model.Address{
|
address := model.Address{
|
||||||
ID: address_id,
|
ID: address_id,
|
||||||
CustomerID: user_id,
|
CustomerID: user_id,
|
||||||
AddressInfo: address_info,
|
AddressString: address_info,
|
||||||
CountryID: country_id,
|
CountryID: country_id,
|
||||||
}
|
}
|
||||||
|
|
||||||
return db.DB.
|
return db.DB.
|
||||||
|
|||||||
@@ -1,20 +1,26 @@
|
|||||||
package cartsRepo
|
package cartsRepo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
"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"
|
constdata "git.ma-al.com/goc_daniel/b2b/app/utils/const_data"
|
||||||
|
"git.ma-al.com/goc_daniel/b2b/app/utils/responseErrors"
|
||||||
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
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)
|
||||||
UserHasCart(user_id uint, cart_id uint) (uint, error)
|
RemoveCart(user_id uint, cart_id uint) 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
|
||||||
RetrieveCartsInfo(user_id uint) ([]model.CustomerCart, error)
|
RetrieveCartsInfo(user_id uint) ([]model.CustomerCart, error)
|
||||||
RetrieveCart(user_id uint, cart_id uint) (*model.CustomerCart, error)
|
RetrieveCart(user_id uint, cart_id uint) (*model.CustomerCart, error)
|
||||||
CheckProductExists(product_id uint, product_attribute_id *uint) (uint, error)
|
CheckProductExists(product_id uint, product_attribute_id *uint) (bool, error)
|
||||||
AddProduct(user_id uint, cart_id uint, product_id uint, product_attribute_id *uint, amount uint) error
|
AddProduct(cart_id uint, product_id uint, product_attribute_id *uint, amount uint, set_amount bool) error
|
||||||
|
RemoveProduct(cart_id uint, product_id uint, product_attribute_id *uint) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type CartsRepo struct{}
|
type CartsRepo struct{}
|
||||||
@@ -36,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,
|
||||||
@@ -49,7 +52,15 @@ func (repo *CartsRepo) CreateNewCart(user_id uint) (model.CustomerCart, error) {
|
|||||||
return cart, err
|
return cart, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repo *CartsRepo) UserHasCart(user_id uint, cart_id uint) (uint, error) {
|
func (repo *CartsRepo) RemoveCart(user_id uint, cart_id uint) error {
|
||||||
|
return db.DB.
|
||||||
|
Table("b2b_customer_carts").
|
||||||
|
Where("cart_id = ? AND user_id = ?", cart_id, user_id).
|
||||||
|
Delete(nil).
|
||||||
|
Error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (repo *CartsRepo) UserHasCart(user_id uint, cart_id uint) (bool, error) {
|
||||||
var amt uint
|
var amt uint
|
||||||
|
|
||||||
err := db.DB.
|
err := db.DB.
|
||||||
@@ -59,7 +70,7 @@ func (repo *CartsRepo) UserHasCart(user_id uint, cart_id uint) (uint, error) {
|
|||||||
Scan(&amt).
|
Scan(&amt).
|
||||||
Error
|
Error
|
||||||
|
|
||||||
return amt, err
|
return amt >= 1, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repo *CartsRepo) UpdateCartName(user_id uint, cart_id uint, new_name string) error {
|
func (repo *CartsRepo) UpdateCartName(user_id uint, cart_id uint, new_name string) error {
|
||||||
@@ -96,7 +107,7 @@ func (repo *CartsRepo) RetrieveCart(user_id uint, cart_id uint) (*model.Customer
|
|||||||
return &cart, err
|
return &cart, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repo *CartsRepo) CheckProductExists(product_id uint, product_attribute_id *uint) (uint, error) {
|
func (repo *CartsRepo) CheckProductExists(product_id uint, product_attribute_id *uint) (bool, error) {
|
||||||
var amt uint
|
var amt uint
|
||||||
|
|
||||||
if product_attribute_id == nil {
|
if product_attribute_id == nil {
|
||||||
@@ -106,7 +117,7 @@ func (repo *CartsRepo) CheckProductExists(product_id uint, product_attribute_id
|
|||||||
Where("id_product = ?", product_id).
|
Where("id_product = ?", product_id).
|
||||||
Scan(&amt).
|
Scan(&amt).
|
||||||
Error
|
Error
|
||||||
return amt, err
|
return amt >= 1, err
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
err := db.DB.
|
err := db.DB.
|
||||||
@@ -116,18 +127,65 @@ func (repo *CartsRepo) CheckProductExists(product_id uint, product_attribute_id
|
|||||||
Where("ps.id_product = ? AND pas.id_product_attribute = ?", product_id, *product_attribute_id).
|
Where("ps.id_product = ? AND pas.id_product_attribute = ?", product_id, *product_attribute_id).
|
||||||
Scan(&amt).
|
Scan(&amt).
|
||||||
Error
|
Error
|
||||||
return amt, err
|
return amt >= 1, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repo *CartsRepo) AddProduct(user_id uint, cart_id uint, product_id uint, product_attribute_id *uint, amount uint) error {
|
func (repo *CartsRepo) AddProduct(cart_id uint, product_id uint, product_attribute_id *uint, amount uint, set_amount bool) error {
|
||||||
product := model.CartProduct{
|
var product model.CartProduct
|
||||||
CartID: cart_id,
|
|
||||||
ProductID: product_id,
|
|
||||||
ProductAttributeID: product_attribute_id,
|
|
||||||
Amount: amount,
|
|
||||||
}
|
|
||||||
err := db.DB.Create(&product).Error
|
|
||||||
|
|
||||||
return err
|
err := db.DB.
|
||||||
|
Where(&model.CartProduct{
|
||||||
|
CartID: cart_id,
|
||||||
|
ProductID: product_id,
|
||||||
|
ProductAttributeID: product_attribute_id,
|
||||||
|
}).
|
||||||
|
First(&product).Error
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
|
if amount < 1 {
|
||||||
|
return responseErrors.ErrAmountMustBePositive
|
||||||
|
} else if amount > constdata.MAX_AMOUNT_OF_PRODUCT_IN_CART {
|
||||||
|
return responseErrors.ErrAmountMustBeReasonable
|
||||||
|
}
|
||||||
|
|
||||||
|
product = model.CartProduct{
|
||||||
|
CartID: cart_id,
|
||||||
|
ProductID: product_id,
|
||||||
|
ProductAttributeID: product_attribute_id,
|
||||||
|
Amount: amount,
|
||||||
|
}
|
||||||
|
|
||||||
|
return db.DB.Create(&product).Error
|
||||||
|
}
|
||||||
|
|
||||||
|
// Some other DB error
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Product already exists in cart
|
||||||
|
if set_amount {
|
||||||
|
product.Amount = amount
|
||||||
|
} else {
|
||||||
|
product.Amount = product.Amount + amount
|
||||||
|
}
|
||||||
|
|
||||||
|
if product.Amount < 1 {
|
||||||
|
return responseErrors.ErrAmountMustBePositive
|
||||||
|
} else if product.Amount > constdata.MAX_AMOUNT_OF_PRODUCT_IN_CART {
|
||||||
|
return responseErrors.ErrAmountMustBeReasonable
|
||||||
|
}
|
||||||
|
|
||||||
|
return db.DB.Save(&product).Error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (repo *CartsRepo) RemoveProduct(cart_id uint, product_id uint, product_attribute_id *uint) error {
|
||||||
|
return db.DB.
|
||||||
|
Where(&model.CartProduct{
|
||||||
|
CartID: cart_id,
|
||||||
|
ProductID: product_id,
|
||||||
|
ProductAttributeID: product_attribute_id,
|
||||||
|
}).
|
||||||
|
Delete(&model.CartProduct{}).Error
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,48 +0,0 @@
|
|||||||
package categoriesRepo
|
|
||||||
|
|
||||||
import (
|
|
||||||
"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/dbmodel"
|
|
||||||
constdata "git.ma-al.com/goc_daniel/b2b/app/utils/const_data"
|
|
||||||
)
|
|
||||||
|
|
||||||
type UICategoriesRepo interface {
|
|
||||||
GetAllCategories(idLang uint) ([]model.ScannedCategory, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
type CategoriesRepo struct{}
|
|
||||||
|
|
||||||
func New() UICategoriesRepo {
|
|
||||||
return &CategoriesRepo{}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *CategoriesRepo) GetAllCategories(idLang uint) ([]model.ScannedCategory, error) {
|
|
||||||
var allCategories []model.ScannedCategory
|
|
||||||
|
|
||||||
categoryTbl := (&dbmodel.PsCategory{}).TableName()
|
|
||||||
categoryLangTbl := (&dbmodel.PsCategoryLang{}).TableName()
|
|
||||||
categoryShopTbl := (&dbmodel.PsCategoryShop{}).TableName()
|
|
||||||
langTbl := (&dbmodel.PsLang{}).TableName()
|
|
||||||
|
|
||||||
err := db.Get().
|
|
||||||
Model(dbmodel.PsCategory{}).
|
|
||||||
Select(`
|
|
||||||
ps_category.id_category AS category_id,
|
|
||||||
ps_category_lang.name AS name,
|
|
||||||
ps_category.active AS active,
|
|
||||||
ps_category_shop.position AS position,
|
|
||||||
ps_category.id_parent AS id_parent,
|
|
||||||
ps_category.is_root_category AS is_root_category,
|
|
||||||
ps_category_lang.link_rewrite AS link_rewrite,
|
|
||||||
ps_lang.iso_code AS iso_code
|
|
||||||
`).
|
|
||||||
Joins(`LEFT JOIN `+categoryLangTbl+` ON `+categoryLangTbl+`.id_category = `+categoryTbl+`.id_category AND `+categoryLangTbl+`.id_shop = ? AND `+categoryLangTbl+`.id_lang = ?`,
|
|
||||||
constdata.SHOP_ID, idLang).
|
|
||||||
Joins(`LEFT JOIN `+categoryShopTbl+` ON `+categoryShopTbl+`.id_category = `+categoryTbl+`.id_category AND `+categoryShopTbl+`.id_shop = ?`,
|
|
||||||
constdata.SHOP_ID).
|
|
||||||
Joins(`JOIN ` + langTbl + ` ON ` + langTbl + `.id_lang = ` + categoryLangTbl + `.id_lang`).
|
|
||||||
Scan(&allCategories).Error
|
|
||||||
|
|
||||||
return allCategories, err
|
|
||||||
}
|
|
||||||
@@ -2,11 +2,14 @@ package categoryrepo
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"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/dbmodel"
|
"git.ma-al.com/goc_daniel/b2b/app/model/dbmodel"
|
||||||
|
constdata "git.ma-al.com/goc_daniel/b2b/app/utils/const_data"
|
||||||
)
|
)
|
||||||
|
|
||||||
type UICategoryRepo interface {
|
type UICategoryRepo interface {
|
||||||
GetCategoryTranslations(ids []uint, idLang uint) (map[uint]string, error)
|
GetCategoryTranslations(ids []uint, idLang uint) (map[uint]string, error)
|
||||||
|
RetrieveMenuCategories(idLang uint) ([]model.ScannedCategory, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type CategoryRepo struct{}
|
type CategoryRepo struct{}
|
||||||
@@ -42,3 +45,33 @@ func (r *CategoryRepo) GetCategoryTranslations(ids []uint, idLang uint) (map[uin
|
|||||||
|
|
||||||
return translations, nil
|
return translations, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *CategoryRepo) RetrieveMenuCategories(idLang uint) ([]model.ScannedCategory, error) {
|
||||||
|
var allCategories []model.ScannedCategory
|
||||||
|
|
||||||
|
categoryTbl := (&dbmodel.PsCategory{}).TableName()
|
||||||
|
categoryLangTbl := (&dbmodel.PsCategoryLang{}).TableName()
|
||||||
|
categoryShopTbl := (&dbmodel.PsCategoryShop{}).TableName()
|
||||||
|
langTbl := (&dbmodel.PsLang{}).TableName()
|
||||||
|
|
||||||
|
err := db.Get().
|
||||||
|
Model(dbmodel.PsCategory{}).
|
||||||
|
Select(`
|
||||||
|
ps_category.id_category AS category_id,
|
||||||
|
ps_category_lang.name AS name,
|
||||||
|
ps_category.active AS active,
|
||||||
|
ps_category_shop.position AS position,
|
||||||
|
ps_category.id_parent AS id_parent,
|
||||||
|
ps_category.is_root_category AS is_root_category,
|
||||||
|
ps_category_lang.link_rewrite AS link_rewrite,
|
||||||
|
ps_lang.iso_code AS iso_code
|
||||||
|
`).
|
||||||
|
Joins(`LEFT JOIN `+categoryLangTbl+` ON `+categoryLangTbl+`.id_category = `+categoryTbl+`.id_category AND `+categoryLangTbl+`.id_shop = ? AND `+categoryLangTbl+`.id_lang = ?`,
|
||||||
|
constdata.SHOP_ID, idLang).
|
||||||
|
Joins(`LEFT JOIN `+categoryShopTbl+` ON `+categoryShopTbl+`.id_category = `+categoryTbl+`.id_category AND `+categoryShopTbl+`.id_shop = ?`,
|
||||||
|
constdata.SHOP_ID).
|
||||||
|
Joins(`JOIN ` + langTbl + ` ON ` + langTbl + `.id_lang = ` + categoryLangTbl + `.id_lang`).
|
||||||
|
Scan(&allCategories).Error
|
||||||
|
|
||||||
|
return allCategories, err
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package customerRepo
|
package customerRepo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/db"
|
"git.ma-al.com/goc_daniel/b2b/app/db"
|
||||||
@@ -16,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{}
|
||||||
@@ -80,13 +82,16 @@ func (repo *CustomerRepo) Find(langId uint, p find.Paging, filt *filters.Filters
|
|||||||
for _, word := range words {
|
for _, word := range words {
|
||||||
|
|
||||||
conditions = append(conditions, `
|
conditions = append(conditions, `
|
||||||
(LOWER(first_name) LIKE ? OR
|
(
|
||||||
|
id = ? OR
|
||||||
|
LOWER(first_name) LIKE ? OR
|
||||||
LOWER(last_name) LIKE ? OR
|
LOWER(last_name) LIKE ? OR
|
||||||
LOWER(email) LIKE ?)
|
LOWER(email) LIKE ?)
|
||||||
`)
|
`)
|
||||||
|
|
||||||
|
args = append(args, strings.ToLower(word))
|
||||||
for range 3 {
|
for range 3 {
|
||||||
args = append(args, "%"+strings.ToLower(word)+"%")
|
args = append(args, fmt.Sprintf("%%%s%%", strings.ToLower(word)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,87 +116,6 @@ func (repo *CustomerRepo) Create(customer *model.Customer) error {
|
|||||||
return db.DB.Create(customer).Error
|
return db.DB.Create(customer).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
// func (repo *CustomerRepo) Search(
|
func (repo *CustomerRepo) SetCustomerNoVatStatus(customerID uint, isNoVat bool) error {
|
||||||
// customerId uint,
|
return db.DB.Model(&model.Customer{}).Where("id = ?", customerID).Update("is_no_vat", isNoVat).Error
|
||||||
// partnerCode string,
|
}
|
||||||
// p find.Paging,
|
|
||||||
// filt *filters.FiltersList,
|
|
||||||
// search string,
|
|
||||||
// ) (found find.Found[model.UserInList], err error) {
|
|
||||||
// words := strings.Fields(search)
|
|
||||||
// if len(words) > 5 {
|
|
||||||
// words = words[:5]
|
|
||||||
// }
|
|
||||||
|
|
||||||
// query := ctx.DB().
|
|
||||||
// Model(&model.Customer{}).
|
|
||||||
// Select("customer.id AS id, customer.first_name as first_name, customer.last_name as last_name, customer.phone_number AS phone_number, customer.email AS email, count(distinct investment_plan_contract.id) as iiplan_purchases, count(distinct `order`.id) as single_purchases, entity.name as entity_name").
|
|
||||||
// Where("customer.id <> ?", customerId).
|
|
||||||
// Where("(customer.id IN (SELECT id FROM customer WHERE partner_code IN (WITH RECURSIVE partners AS (SELECT code AS dst FROM partner WHERE code = ? UNION SELECT code FROM partner JOIN partners ON partners.dst = partner.superior_code) SELECT dst FROM partners)) OR customer.recommender_code = ?)", partnerCode, partnerCode).
|
|
||||||
// Scopes(view.CustomerListQuery())
|
|
||||||
|
|
||||||
// var conditions []string
|
|
||||||
// var args []interface{}
|
|
||||||
// for _, word := range words {
|
|
||||||
|
|
||||||
// conditions = append(conditions, `
|
|
||||||
// (LOWER(first_name) LIKE ? OR
|
|
||||||
// LOWER(last_name) LIKE ? OR
|
|
||||||
// phone_number LIKE ? OR
|
|
||||||
// LOWER(email) LIKE ?)
|
|
||||||
// `)
|
|
||||||
|
|
||||||
// for i := 0; i < 4; i++ {
|
|
||||||
// args = append(args, "%"+strings.ToLower(word)+"%")
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// finalQuery := strings.Join(conditions, " AND ")
|
|
||||||
|
|
||||||
// query = query.Where(finalQuery, args...).
|
|
||||||
// Scopes(filt.All()...)
|
|
||||||
|
|
||||||
// found, err = find.Paginate[V](ctx, p, query)
|
|
||||||
|
|
||||||
// return found, errs.Recorded(span, err)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// func (repo *ListRepo) ListUsers(id_lang uint, p find.Paging, filt *filters.FiltersList) (find.Found[model.UserInList], error) {
|
|
||||||
// var list []model.UserInList
|
|
||||||
// var total int64
|
|
||||||
|
|
||||||
// query := db.Get().
|
|
||||||
// Table("b2b_customers AS users").
|
|
||||||
// Select(`
|
|
||||||
// users.id AS id,
|
|
||||||
// users.email AS email,
|
|
||||||
// users.first_name AS first_name,
|
|
||||||
// users.last_name AS last_name,
|
|
||||||
// users.role AS role
|
|
||||||
// `)
|
|
||||||
|
|
||||||
// // Apply all filters
|
|
||||||
// if filt != nil {
|
|
||||||
// filt.ApplyAll(query)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // run counter first as query is without limit and offset
|
|
||||||
// err := query.Count(&total).Error
|
|
||||||
// if err != nil {
|
|
||||||
// return find.Found[model.UserInList]{}, err
|
|
||||||
// }
|
|
||||||
|
|
||||||
// err = query.
|
|
||||||
// Order("users.id DESC").
|
|
||||||
// Limit(p.Limit()).
|
|
||||||
// Offset(p.Offset()).
|
|
||||||
// Find(&list).Error
|
|
||||||
// if err != nil {
|
|
||||||
// return find.Found[model.UserInList]{}, err
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return find.Found[model.UserInList]{
|
|
||||||
// Items: list,
|
|
||||||
// Count: uint(total),
|
|
||||||
// }, nil
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package localeSelectorRepo
|
|||||||
import (
|
import (
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/db"
|
"git.ma-al.com/goc_daniel/b2b/app/db"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/model"
|
"git.ma-al.com/goc_daniel/b2b/app/model"
|
||||||
|
"git.ma-al.com/goc_daniel/b2b/app/model/dbmodel"
|
||||||
)
|
)
|
||||||
|
|
||||||
type UILocaleSelectorRepo interface {
|
type UILocaleSelectorRepo interface {
|
||||||
@@ -25,7 +26,9 @@ func (r *LocaleSelectorRepo) GetLanguages() ([]model.Language, error) {
|
|||||||
func (r *LocaleSelectorRepo) GetCountriesAndCurrencies() ([]model.Country, error) {
|
func (r *LocaleSelectorRepo) GetCountriesAndCurrencies() ([]model.Country, error) {
|
||||||
var countries []model.Country
|
var countries []model.Country
|
||||||
err := db.Get().
|
err := db.Get().
|
||||||
Preload("PSCurrency").
|
Select("*").
|
||||||
|
Preload("Currency").
|
||||||
|
Joins("LEFT JOIN " + dbmodel.TableNamePsCountryLang + " AS cl ON cl." + dbmodel.PsCountryLangCols.IDCountry.Col() + " = b2b_countries.ps_id_country AND cl." + dbmodel.PsCountryLangCols.IDLang.Col() + " = 2").
|
||||||
Find(&countries).Error
|
Find(&countries).Error
|
||||||
return countries, err
|
return countries, err
|
||||||
}
|
}
|
||||||
|
|||||||
192
app/repos/ordersRepo/ordersRepo.go
Normal file
192
app/repos/ordersRepo/ordersRepo.go
Normal file
@@ -0,0 +1,192 @@
|
|||||||
|
package ordersRepo
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"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/enums"
|
||||||
|
"git.ma-al.com/goc_daniel/b2b/app/utils/query/filters"
|
||||||
|
"git.ma-al.com/goc_daniel/b2b/app/utils/query/find"
|
||||||
|
)
|
||||||
|
|
||||||
|
type UIOrdersRepo interface {
|
||||||
|
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)
|
||||||
|
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
|
||||||
|
ChangeOrderStatus(orderId uint, newStatus enums.OrderStatus, userId uint) error
|
||||||
|
GetOrderStatus(orderID uint) (enums.OrderStatus, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type OrdersRepo struct{}
|
||||||
|
|
||||||
|
func New() UIOrdersRepo {
|
||||||
|
return &OrdersRepo{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (repo *OrdersRepo) UserHasOrder(user_id uint, order_id uint) (bool, error) {
|
||||||
|
var amt uint
|
||||||
|
|
||||||
|
err := db.DB.
|
||||||
|
Table("b2b_customer_orders").
|
||||||
|
Select("COUNT(*) AS amt").
|
||||||
|
Where("user_id = ? AND order_id = ?", user_id, order_id).
|
||||||
|
Scan(&amt).
|
||||||
|
Error
|
||||||
|
|
||||||
|
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) {
|
||||||
|
var list []model.CustomerOrder
|
||||||
|
var total int64
|
||||||
|
|
||||||
|
query := db.Get().
|
||||||
|
Model(&model.CustomerOrder{}).
|
||||||
|
Preload("Products").
|
||||||
|
Order("b2b_customer_orders.order_id DESC")
|
||||||
|
|
||||||
|
// Apply all filters
|
||||||
|
if filt != nil {
|
||||||
|
filt.ApplyAll(query)
|
||||||
|
}
|
||||||
|
|
||||||
|
// run counter first as query is without limit and offset
|
||||||
|
err := query.Count(&total).Error
|
||||||
|
if err != nil {
|
||||||
|
return &find.Found[model.CustomerOrder]{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = query.
|
||||||
|
Limit(p.Limit()).
|
||||||
|
Offset(p.Offset()).
|
||||||
|
Find(&list).Error
|
||||||
|
if err != nil {
|
||||||
|
return &find.Found[model.CustomerOrder]{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &find.Found[model.CustomerOrder]{
|
||||||
|
Items: list,
|
||||||
|
Count: uint(total),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (repo *OrdersRepo) PlaceNewOrder(cart *model.CustomerCart, name string, country_id uint, address_info string, originalUserId uint, base_price float64, tax_incl float64, tax_excl float64) (*model.CustomerOrder, error) {
|
||||||
|
order := model.CustomerOrder{
|
||||||
|
UserID: cart.UserID,
|
||||||
|
Name: name,
|
||||||
|
CountryID: country_id,
|
||||||
|
AddressString: address_info,
|
||||||
|
Status: enums.OrderStatusPending,
|
||||||
|
Products: make([]model.OrderProduct, 0, len(cart.Products)),
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, product := range cart.Products {
|
||||||
|
order.Products = append(order.Products, model.OrderProduct{
|
||||||
|
ProductID: product.ProductID,
|
||||||
|
ProductAttributeID: product.ProductAttributeID,
|
||||||
|
Amount: product.Amount,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
order.CreatedAt = time.Now()
|
||||||
|
order.UpdatedAt = time.Now()
|
||||||
|
order.BasePrice = base_price
|
||||||
|
order.TaxIncl = tax_incl
|
||||||
|
order.TaxExcl = tax_excl
|
||||||
|
tx := db.Get().Begin()
|
||||||
|
err := tx.Create(&order).Error
|
||||||
|
if err != nil {
|
||||||
|
tx.Rollback()
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
history := model.OrderStatusHistory{
|
||||||
|
OrderId: order.OrderID,
|
||||||
|
OldStatus: nil,
|
||||||
|
NewStatus: enums.OrderStatusPending,
|
||||||
|
UserId: originalUserId,
|
||||||
|
}
|
||||||
|
|
||||||
|
err = tx.Create(&history).Error
|
||||||
|
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 {
|
||||||
|
return db.DB.
|
||||||
|
Table("b2b_customer_orders").
|
||||||
|
Where("order_id = ?", order_id).
|
||||||
|
Updates(map[string]interface{}{
|
||||||
|
"country_id": country_id,
|
||||||
|
"address_string": address_info,
|
||||||
|
"updated_at": time.Now(),
|
||||||
|
}).
|
||||||
|
Error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (repo *OrdersRepo) ChangeOrderStatus(orderID uint, newStatus enums.OrderStatus, userId uint) error {
|
||||||
|
tx := db.Get().Begin()
|
||||||
|
|
||||||
|
var currentStatus enums.OrderStatus
|
||||||
|
err := tx.Table("b2b_customer_orders").
|
||||||
|
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
|
||||||
|
}
|
||||||
@@ -9,7 +9,6 @@ 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/model/dbmodel"
|
"git.ma-al.com/goc_daniel/b2b/app/model/dbmodel"
|
||||||
constdata "git.ma-al.com/goc_daniel/b2b/app/utils/const_data"
|
constdata "git.ma-al.com/goc_daniel/b2b/app/utils/const_data"
|
||||||
"github.com/WinterYukky/gorm-extra-clause-plugin/exclause"
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -17,7 +16,6 @@ type UIProductDescriptionRepo interface {
|
|||||||
GetProductDescription(productID uint, productid_lang uint) (*model.ProductDescription, error)
|
GetProductDescription(productID uint, productid_lang uint) (*model.ProductDescription, error)
|
||||||
CreateIfDoesNotExist(productID uint, productid_lang uint) error
|
CreateIfDoesNotExist(productID uint, productid_lang uint) error
|
||||||
UpdateFields(productID uint, productid_lang uint, updates map[string]string) error
|
UpdateFields(productID uint, productid_lang uint, updates map[string]string) error
|
||||||
GetMeiliProducts(id_lang uint, offset, limit int) ([]model.MeiliSearchProduct, error)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ProductDescriptionRepo struct{}
|
type ProductDescriptionRepo struct{}
|
||||||
@@ -118,108 +116,3 @@ func (r *ProductDescriptionRepo) UpdateFields(productID uint, productid_lang uin
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetMeiliProductsBatchedScanned returns a batch of products with LIMIT/OFFSET pagination
|
|
||||||
// The scanning is done inside the repo to keep the service layer cleaner
|
|
||||||
func (r *ProductDescriptionRepo) GetMeiliProducts(id_lang uint, offset, limit int) ([]model.MeiliSearchProduct, error) {
|
|
||||||
|
|
||||||
var products []model.MeiliSearchProduct
|
|
||||||
|
|
||||||
err := db.Get().
|
|
||||||
Table("ps_product_shop ps").
|
|
||||||
Select(`
|
|
||||||
ps.id_product AS id_product,
|
|
||||||
pl.name AS name,
|
|
||||||
TRIM(REGEXP_REPLACE(REGEXP_REPLACE(pl.description_short, '<[^>]*>', ' '), '[[:space:]]+', ' ')) AS description,
|
|
||||||
p.ean13,
|
|
||||||
p.reference,
|
|
||||||
ps.price,
|
|
||||||
ps.id_category_default AS id_category,
|
|
||||||
cl.name AS cat_name,
|
|
||||||
cl.link_rewrite AS l_rew,
|
|
||||||
COALESCE(vary.attributes, JSON_OBJECT()) AS attr,
|
|
||||||
COALESCE(feat.features, JSON_OBJECT()) AS feat,
|
|
||||||
img.id_image,
|
|
||||||
cat.category_ids,
|
|
||||||
(SELECT COUNT(*) FROM ps_product_attribute_shop pas2 WHERE pas2.id_product = ps.id_product AND pas2.id_shop = ?) AS variations
|
|
||||||
`, constdata.SHOP_ID).
|
|
||||||
Joins("JOIN ps_product p ON p.id_product = ps.id_product").
|
|
||||||
Joins("JOIN ps_product_lang pl ON pl.id_product = ps.id_product AND pl.id_shop = ? AND pl.id_lang = ?", constdata.SHOP_ID, id_lang).
|
|
||||||
Joins("JOIN ps_category_lang cl ON cl.id_category = ps.id_category_default AND cl.id_shop = ? AND cl.id_lang = ?", constdata.SHOP_ID, id_lang).
|
|
||||||
Joins("LEFT JOIN variations vary ON vary.id_product = ps.id_product").
|
|
||||||
Joins("LEFT JOIN features feat ON feat.id_product = ps.id_product").
|
|
||||||
Joins("LEFT JOIN images img ON img.id_product = ps.id_product").
|
|
||||||
Joins("LEFT JOIN categories cat ON cat.id_product = ps.id_product").
|
|
||||||
Joins("JOIN products_page pp ON pp.id_product = ps.id_product").
|
|
||||||
Where("ps.active = ?", 1).
|
|
||||||
Order("ps.id_product").
|
|
||||||
Clauses(exclause.With{CTEs: []exclause.CTE{
|
|
||||||
{
|
|
||||||
Name: "products_page",
|
|
||||||
Subquery: exclause.Subquery{
|
|
||||||
DB: db.Get().
|
|
||||||
Model(&dbmodel.PsProductShop{}).
|
|
||||||
Select("id_product, price").
|
|
||||||
Where("id_shop = ? AND active = 1", constdata.SHOP_ID).
|
|
||||||
Order("id_product").
|
|
||||||
Limit(limit).
|
|
||||||
Offset(offset),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "variation_attributes",
|
|
||||||
Subquery: exclause.Subquery{
|
|
||||||
DB: db.Get().
|
|
||||||
Table("ps_product_attribute_shop pas"). // <- explicit alias here
|
|
||||||
Select(`
|
|
||||||
pas.id_product,
|
|
||||||
pag.id_attribute_group AS attribute_name,
|
|
||||||
JSON_ARRAYAGG(DISTINCT pa.id_attribute) AS attribute_values
|
|
||||||
`).
|
|
||||||
Joins("JOIN ps_product_attribute_combination ppac ON ppac.id_product_attribute = pas.id_product_attribute").
|
|
||||||
Joins("JOIN ps_attribute pa ON pa.id_attribute = ppac.id_attribute").
|
|
||||||
Joins("JOIN ps_attribute_group pag ON pag.id_attribute_group = pa.id_attribute_group").
|
|
||||||
Where("pas.id_shop = ?", constdata.SHOP_ID).
|
|
||||||
Group("pas.id_product, pag.id_attribute_group"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "variations",
|
|
||||||
Subquery: exclause.Subquery{
|
|
||||||
DB: db.Get().
|
|
||||||
Table("variation_attributes").
|
|
||||||
Select("id_product, JSON_OBJECTAGG(attribute_name, attribute_values) AS attributes").
|
|
||||||
Group("id_product"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "features",
|
|
||||||
Subquery: exclause.Subquery{
|
|
||||||
DB: db.Get().
|
|
||||||
Table("ps_feature_product pfp"). // <- explicit alias
|
|
||||||
Select("pfp.id_product, JSON_OBJECTAGG(pfp.id_feature, pfp.id_feature_value) AS features").
|
|
||||||
Group("pfp.id_product"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "images",
|
|
||||||
Subquery: exclause.Subquery{
|
|
||||||
DB: db.Get().
|
|
||||||
Model(&dbmodel.PsImageShop{}).
|
|
||||||
Select("id_product, id_image").
|
|
||||||
Where("id_shop = ? AND cover = 1", constdata.SHOP_ID),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "categories",
|
|
||||||
Subquery: exclause.Subquery{
|
|
||||||
DB: db.Get().
|
|
||||||
Model(&dbmodel.PsCategoryProduct{}).
|
|
||||||
Select("id_product, JSON_ARRAYAGG(id_category) AS category_ids").
|
|
||||||
Group("id_product"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}}).Find(&products).Error
|
|
||||||
|
|
||||||
return products, err
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ type UIProductsRepo interface {
|
|||||||
// GetJSON(p_id_product, p_id_shop, p_id_lang, p_id_customer, b2b_id_country, p_quantity int) (*json.RawMessage, error)
|
// GetJSON(p_id_product, p_id_shop, p_id_lang, p_id_customer, b2b_id_country, p_quantity int) (*json.RawMessage, error)
|
||||||
Find(id_lang uint, userID uint, p find.Paging, filt *filters.FiltersList) (*find.Found[model.ProductInList], error)
|
Find(id_lang uint, userID uint, p find.Paging, filt *filters.FiltersList) (*find.Found[model.ProductInList], error)
|
||||||
GetProductVariants(langID uint, productID uint, shopID uint, customerID uint, countryID uint, quantity uint) ([]view.ProductAttribute, error)
|
GetProductVariants(langID uint, productID uint, shopID uint, customerID uint, countryID uint, quantity uint) ([]view.ProductAttribute, error)
|
||||||
GetBase(p_id_product, p_id_shop, p_id_lang uint) (view.Product, error)
|
GetBase(p_id_product, p_id_shop, p_id_lang, p_id_customer uint) (view.Product, error)
|
||||||
GetPrice(p_id_product uint, productAttributeID *uint, p_id_shop uint, p_id_customer uint, p_id_country uint, p_quantity uint) (view.Price, error)
|
GetPrice(p_id_product uint, productAttributeID *uint, p_id_shop uint, p_id_customer uint, p_id_country uint, p_quantity uint) (view.Price, error)
|
||||||
GetVariants(p_id_product, p_id_shop, p_id_lang, p_id_customer, p_id_country, p_quantity uint) ([]view.ProductAttribute, error)
|
GetVariants(p_id_product, p_id_shop, p_id_lang, p_id_customer, p_id_country, p_quantity uint) ([]view.ProductAttribute, error)
|
||||||
AddToFavorites(userID uint, productID uint) error
|
AddToFavorites(userID uint, productID uint) error
|
||||||
@@ -33,11 +33,11 @@ func New() UIProductsRepo {
|
|||||||
return &ProductsRepo{}
|
return &ProductsRepo{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repo *ProductsRepo) GetBase(p_id_product, p_id_shop, p_id_lang uint) (view.Product, error) {
|
func (repo *ProductsRepo) GetBase(p_id_product, p_id_shop, p_id_lang, p_id_customer uint) (view.Product, error) {
|
||||||
var result view.Product
|
var result view.Product
|
||||||
|
|
||||||
err := db.DB.Raw(`CALL get_product_base(?,?,?)`,
|
err := db.DB.Raw(`CALL get_product_base(?,?,?,?)`,
|
||||||
p_id_product, p_id_shop, p_id_lang).
|
p_id_product, p_id_shop, p_id_lang, p_id_customer).
|
||||||
Scan(&result).Error
|
Scan(&result).Error
|
||||||
|
|
||||||
return result, err
|
return result, err
|
||||||
@@ -105,57 +105,107 @@ func (repo *ProductsRepo) GetVariants(p_id_product, p_id_shop, p_id_lang, p_id_c
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (repo *ProductsRepo) Find(langID uint, userID uint, p find.Paging, filt *filters.FiltersList) (*find.Found[model.ProductInList], error) {
|
func (repo *ProductsRepo) Find(langID uint, userID uint, p find.Paging, filt *filters.FiltersList) (*find.Found[model.ProductInList], error) {
|
||||||
query := db.Get().
|
query := db.DB.
|
||||||
Table(gormcol.Field.Tab(dbmodel.PsProductShopCols.Active)+" AS ps").
|
Table("base_products AS bp").
|
||||||
Select(`
|
|
||||||
ps.id_product AS product_id,
|
|
||||||
pl.name AS name,
|
|
||||||
pl.link_rewrite AS link_rewrite,
|
|
||||||
CONCAT(?, '/', ims.id_image, '-small_default/', pl.link_rewrite, '.webp') AS image_link,
|
|
||||||
cl.name AS category_name,
|
|
||||||
p.reference AS reference,
|
|
||||||
COALESCE(v.variants_number, 0) AS variants_number,
|
|
||||||
sa.quantity AS quantity,
|
|
||||||
COALESCE(f.is_favorite, 0) AS is_favorite
|
|
||||||
`, config.Get().Image.ImagePrefix).
|
|
||||||
Joins("JOIN "+dbmodel.PsProductCols.IDProduct.Tab()+" p ON p.id_product = ps.id_product").
|
|
||||||
Joins("JOIN ps_product_lang pl ON pl.id_product = ps.id_product AND pl.id_lang = ?", langID).
|
|
||||||
Joins("JOIN ps_image_shop ims ON ims.id_product = ps.id_product AND ims.cover = 1").
|
|
||||||
Joins("JOIN ps_category_lang cl ON cl.id_category = ps.id_category_default AND cl.id_lang = ?", langID).
|
|
||||||
Joins("JOIN ps_category_product cp ON cp.id_product = ps.id_product").
|
|
||||||
Joins("LEFT JOIN variants v ON v.id_product = ps.id_product").
|
|
||||||
Joins("LEFT JOIN favorites f ON f.id_product = ps.id_product").
|
|
||||||
Joins("LEFT JOIN ps_stock_available sa ON sa.id_product = ps.id_product AND sa.id_product_attribute = 0").
|
|
||||||
Where("ps.active = ?", 1).
|
|
||||||
Group("ps.id_product").
|
|
||||||
Clauses(exclause.With{
|
Clauses(exclause.With{
|
||||||
CTEs: []exclause.CTE{
|
CTEs: []exclause.CTE{
|
||||||
{
|
|
||||||
Name: "variants",
|
|
||||||
Subquery: exclause.Subquery{
|
|
||||||
DB: db.Get().
|
|
||||||
Model(&dbmodel.PsProductAttributeShop{}).
|
|
||||||
Select("id_product", "COUNT(*) AS variants_number").
|
|
||||||
Group("id_product"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
{
|
||||||
Name: "favorites",
|
Name: "favorites",
|
||||||
Subquery: exclause.Subquery{
|
Subquery: exclause.Subquery{
|
||||||
DB: db.Get().
|
DB: db.DB.
|
||||||
Table("b2b_favorites").
|
Table("b2b_favorites").
|
||||||
Select(`
|
Select(`
|
||||||
product_id AS id_product,
|
product_id AS product_id,
|
||||||
COUNT(*) > 0 AS is_favorite
|
COUNT(*) > 0 AS is_favorite
|
||||||
`).
|
`).
|
||||||
Where("user_id = ?", userID).
|
Where("user_id = ?", userID).
|
||||||
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",
|
||||||
|
Subquery: exclause.Subquery{
|
||||||
|
DB: db.DB.
|
||||||
|
Table("ps_configuration").
|
||||||
|
Select("CAST(value AS SIGNED) AS days").
|
||||||
|
Where("name = ?", "PS_NB_DAYS_NEW_PRODUCT"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "variants",
|
||||||
|
Subquery: exclause.Subquery{
|
||||||
|
DB: db.DB.
|
||||||
|
Table("ps_product_attribute_shop").
|
||||||
|
Select("id_product, COUNT(*) AS variants_number").
|
||||||
|
Group("id_product"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "base_products",
|
||||||
|
Subquery: exclause.Subquery{
|
||||||
|
DB: db.DB.
|
||||||
|
Table(gormcol.Field.Tab(dbmodel.PsProductShopCols.Active)+" AS ps").
|
||||||
|
Select(`
|
||||||
|
ps.id_product AS product_id,
|
||||||
|
pl.name AS name,
|
||||||
|
ps.id_category_default AS category_id,
|
||||||
|
p.reference AS reference,
|
||||||
|
p.is_oem AS is_oem,
|
||||||
|
sa.quantity AS quantity,
|
||||||
|
COALESCE(f.is_favorite, 0) AS is_favorite,
|
||||||
|
CASE
|
||||||
|
WHEN ps.date_add >= DATE_SUB(
|
||||||
|
NOW(),
|
||||||
|
INTERVAL COALESCE(npd.days, 20) DAY
|
||||||
|
) AND ps.active = 1
|
||||||
|
THEN 1
|
||||||
|
ELSE 0
|
||||||
|
END AS is_new
|
||||||
|
`).
|
||||||
|
Joins("JOIN "+dbmodel.PsProductCols.IDProduct.Tab()+" p ON p.id_product = ps.id_product").
|
||||||
|
Joins("JOIN ps_product_lang pl ON pl.id_product = ps.id_product AND pl.id_lang = ?", langID).
|
||||||
|
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 new_product_days npd ON 1 = 1").
|
||||||
|
Joins("LEFT JOIN oems ON oems.product_id = ps.id_product").
|
||||||
|
Where("ps.active = ?", 1).
|
||||||
|
Where("(p.is_oem = 0 OR oems.is_customers_oem > 0)").
|
||||||
|
Group("ps.id_product"),
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}).
|
}).
|
||||||
Order("ps.id_product DESC")
|
Select(`
|
||||||
|
bp.product_id AS product_id,
|
||||||
|
bp.name AS name,
|
||||||
|
pl.link_rewrite AS link_rewrite,
|
||||||
|
CONCAT(?, '/', ims.id_image, '-small_default/', pl.link_rewrite, '.webp') AS image_link,
|
||||||
|
cl.name AS category_name,
|
||||||
|
bp.reference AS reference,
|
||||||
|
COALESCE(v.variants_number, 0) AS variants_number,
|
||||||
|
bp.quantity AS quantity,
|
||||||
|
bp.is_favorite AS is_favorite,
|
||||||
|
bp.is_new AS is_new,
|
||||||
|
bp.is_oem AS is_oem
|
||||||
|
`, 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_image_shop ims ON ims.id_product = bp.product_id AND ims.cover = 1").
|
||||||
|
Joins("JOIN ps_category_lang cl ON cl.id_category = bp.category_id AND cl.id_lang = ?", langID).
|
||||||
|
Joins("LEFT JOIN variants v ON v.id_product = bp.product_id").
|
||||||
|
Order("bp.product_id DESC")
|
||||||
|
|
||||||
query = query.Scopes(filt.All()...)
|
query = query.Scopes(filt.All()...)
|
||||||
|
|
||||||
|
|||||||
@@ -7,8 +7,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type UIRoutesRepo interface {
|
type UIRoutesRepo interface {
|
||||||
GetRoutes(langId 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{}
|
||||||
@@ -17,13 +18,18 @@ func New() UIRoutesRepo {
|
|||||||
return &RoutesRepo{}
|
return &RoutesRepo{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *RoutesRepo) GetRoutes(langId uint) ([]model.Route, error) {
|
func (p *RoutesRepo) GetRoutes(langId uint, roleId uint) ([]model.Route, error) {
|
||||||
routes := []model.Route{}
|
routes := []model.Route{}
|
||||||
err := db.DB.Find(&routes, model.Route{Active: nullable.GetNil(true)}).Error
|
|
||||||
if err != nil {
|
err := db.
|
||||||
return nil, err
|
Get().
|
||||||
}
|
Model(model.Route{}).
|
||||||
return routes, nil
|
Joins("JOIN b2b_route_roles rr ON rr.route_id = b2b_routes.id").
|
||||||
|
Where(model.Route{Active: nullable.GetNil(true)}).
|
||||||
|
Where("rr.role_id = ?", roleId).
|
||||||
|
Find(&routes).Error
|
||||||
|
|
||||||
|
return routes, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *RoutesRepo) GetTopMenu(langId uint, roleId uint) ([]model.B2BTopMenu, error) {
|
func (p *RoutesRepo) GetTopMenu(langId uint, roleId uint) ([]model.B2BTopMenu, error) {
|
||||||
@@ -33,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
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,7 +7,11 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"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/db"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/model"
|
"git.ma-al.com/goc_daniel/b2b/app/model"
|
||||||
|
"git.ma-al.com/goc_daniel/b2b/app/model/dbmodel"
|
||||||
|
constdata "git.ma-al.com/goc_daniel/b2b/app/utils/const_data"
|
||||||
|
"github.com/WinterYukky/gorm-extra-clause-plugin/exclause"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SearchProxyResponse struct {
|
type SearchProxyResponse struct {
|
||||||
@@ -17,6 +21,7 @@ type SearchProxyResponse struct {
|
|||||||
|
|
||||||
type UISearchRepo interface {
|
type UISearchRepo interface {
|
||||||
Search(index string, body []byte) (*SearchProxyResponse, error)
|
Search(index string, body []byte) (*SearchProxyResponse, error)
|
||||||
|
GetMeiliProducts(id_lang uint, offset, limit int) ([]model.MeiliSearchProduct, error)
|
||||||
GetIndexSettings(index string) (*SearchProxyResponse, error)
|
GetIndexSettings(index string) (*SearchProxyResponse, error)
|
||||||
GetRoutes(langId uint) ([]model.Route, error)
|
GetRoutes(langId uint) ([]model.Route, error)
|
||||||
}
|
}
|
||||||
@@ -80,3 +85,108 @@ func (r *SearchRepo) doRequest(method, url string, body []byte) (*SearchProxyRes
|
|||||||
func (r *SearchRepo) GetRoutes(langId uint) ([]model.Route, error) {
|
func (r *SearchRepo) GetRoutes(langId uint) ([]model.Route, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetMeiliProductsProducts returns a batch of products with LIMIT/OFFSET pagination
|
||||||
|
// The scanning is done inside the repo to keep the service layer cleaner
|
||||||
|
func (r *SearchRepo) GetMeiliProducts(id_lang uint, offset, limit int) ([]model.MeiliSearchProduct, error) {
|
||||||
|
|
||||||
|
var products []model.MeiliSearchProduct
|
||||||
|
|
||||||
|
err := db.Get().
|
||||||
|
Table("ps_product_shop ps").
|
||||||
|
Select(`
|
||||||
|
ps.id_product AS id_product,
|
||||||
|
pl.name AS name,
|
||||||
|
TRIM(REGEXP_REPLACE(REGEXP_REPLACE(pl.description_short, '<[^>]*>', ' '), '[[:space:]]+', ' ')) AS description,
|
||||||
|
p.ean13,
|
||||||
|
p.reference,
|
||||||
|
ps.price,
|
||||||
|
ps.id_category_default AS id_category,
|
||||||
|
cl.name AS cat_name,
|
||||||
|
cl.link_rewrite AS l_rew,
|
||||||
|
COALESCE(vary.attributes, JSON_OBJECT()) AS attr,
|
||||||
|
COALESCE(feat.features, JSON_OBJECT()) AS feat,
|
||||||
|
img.id_image,
|
||||||
|
cat.category_ids,
|
||||||
|
(SELECT COUNT(*) FROM ps_product_attribute_shop pas2 WHERE pas2.id_product = ps.id_product AND pas2.id_shop = ?) AS variations
|
||||||
|
`, constdata.SHOP_ID).
|
||||||
|
Joins("JOIN ps_product p ON p.id_product = ps.id_product").
|
||||||
|
Joins("JOIN ps_product_lang pl ON pl.id_product = ps.id_product AND pl.id_shop = ? AND pl.id_lang = ?", constdata.SHOP_ID, id_lang).
|
||||||
|
Joins("JOIN ps_category_lang cl ON cl.id_category = ps.id_category_default AND cl.id_shop = ? AND cl.id_lang = ?", constdata.SHOP_ID, id_lang).
|
||||||
|
Joins("LEFT JOIN variations vary ON vary.id_product = ps.id_product").
|
||||||
|
Joins("LEFT JOIN features feat ON feat.id_product = ps.id_product").
|
||||||
|
Joins("LEFT JOIN images img ON img.id_product = ps.id_product").
|
||||||
|
Joins("LEFT JOIN categories cat ON cat.id_product = ps.id_product").
|
||||||
|
Joins("JOIN products_page pp ON pp.id_product = ps.id_product").
|
||||||
|
Where("ps.active = ?", 1).
|
||||||
|
Order("ps.id_product").
|
||||||
|
Clauses(exclause.With{CTEs: []exclause.CTE{
|
||||||
|
{
|
||||||
|
Name: "products_page",
|
||||||
|
Subquery: exclause.Subquery{
|
||||||
|
DB: db.Get().
|
||||||
|
Model(&dbmodel.PsProductShop{}).
|
||||||
|
Select("id_product, price").
|
||||||
|
Where("id_shop = ? AND active = 1", constdata.SHOP_ID).
|
||||||
|
Order("id_product").
|
||||||
|
Limit(limit).
|
||||||
|
Offset(offset),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "variation_attributes",
|
||||||
|
Subquery: exclause.Subquery{
|
||||||
|
DB: db.Get().
|
||||||
|
Table("ps_product_attribute_shop pas"). // <- explicit alias here
|
||||||
|
Select(`
|
||||||
|
pas.id_product,
|
||||||
|
pag.id_attribute_group AS attribute_name,
|
||||||
|
JSON_ARRAYAGG(DISTINCT pa.id_attribute) AS attribute_values
|
||||||
|
`).
|
||||||
|
Joins("JOIN ps_product_attribute_combination ppac ON ppac.id_product_attribute = pas.id_product_attribute").
|
||||||
|
Joins("JOIN ps_attribute pa ON pa.id_attribute = ppac.id_attribute").
|
||||||
|
Joins("JOIN ps_attribute_group pag ON pag.id_attribute_group = pa.id_attribute_group").
|
||||||
|
Where("pas.id_shop = ?", constdata.SHOP_ID).
|
||||||
|
Group("pas.id_product, pag.id_attribute_group"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "variations",
|
||||||
|
Subquery: exclause.Subquery{
|
||||||
|
DB: db.Get().
|
||||||
|
Table("variation_attributes").
|
||||||
|
Select("id_product, JSON_OBJECTAGG(attribute_name, attribute_values) AS attributes").
|
||||||
|
Group("id_product"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "features",
|
||||||
|
Subquery: exclause.Subquery{
|
||||||
|
DB: db.Get().
|
||||||
|
Table("ps_feature_product pfp"). // <- explicit alias
|
||||||
|
Select("pfp.id_product, JSON_OBJECTAGG(pfp.id_feature, pfp.id_feature_value) AS features").
|
||||||
|
Group("pfp.id_product"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "images",
|
||||||
|
Subquery: exclause.Subquery{
|
||||||
|
DB: db.Get().
|
||||||
|
Model(&dbmodel.PsImageShop{}).
|
||||||
|
Select("id_product, id_image").
|
||||||
|
Where("id_shop = ? AND cover = 1", constdata.SHOP_ID),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "categories",
|
||||||
|
Subquery: exclause.Subquery{
|
||||||
|
DB: db.Get().
|
||||||
|
Model(&dbmodel.PsCategoryProduct{}).
|
||||||
|
Select("id_product, JSON_ARRAYAGG(id_category) AS category_ids").
|
||||||
|
Group("id_product"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}}).Find(&products).Error
|
||||||
|
|
||||||
|
return products, err
|
||||||
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ func New() *AddressesService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *AddressesService) GetTemplate(country_id uint) (model.AddressField, error) {
|
func (s *AddressesService) GetTemplate(country_id uint) (model.AddressUnparsed, error) {
|
||||||
switch country_id {
|
switch country_id {
|
||||||
|
|
||||||
case 1: // Poland
|
case 1: // Poland
|
||||||
@@ -49,7 +49,7 @@ func (s *AddressesService) AddNewAddress(user_id uint, address_info string, coun
|
|||||||
return responseErrors.ErrMaxAmtOfAddressesReached
|
return responseErrors.ErrMaxAmtOfAddressesReached
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = s.validateAddressJson(address_info, country_id)
|
_, err = s.ValidateAddressJson(address_info, country_id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -66,7 +66,7 @@ func (s *AddressesService) ModifyAddress(user_id uint, address_id uint, address_
|
|||||||
return responseErrors.ErrUserHasNoSuchAddress
|
return responseErrors.ErrUserHasNoSuchAddress
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = s.validateAddressJson(address_info, country_id)
|
_, err = s.ValidateAddressJson(address_info, country_id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -74,30 +74,23 @@ func (s *AddressesService) ModifyAddress(user_id uint, address_id uint, address_
|
|||||||
return s.repo.UpdateAddress(user_id, address_id, address_info, country_id)
|
return s.repo.UpdateAddress(user_id, address_id, address_info, country_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *AddressesService) RetrieveAddressesInfo(user_id uint) (*[]model.AddressUnparsed, error) {
|
func (s *AddressesService) RetrieveAddresses(user_id uint) (*[]model.Address, error) {
|
||||||
parsed_addresses, err := s.repo.RetrieveAddresses(user_id)
|
addresses, err := s.repo.RetrieveAddresses(user_id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var unparsed_addresses []model.AddressUnparsed
|
for i := 0; i < len(*addresses); i++ {
|
||||||
|
address_unparsed, err := s.ValidateAddressJson((*addresses)[i].AddressString, (*addresses)[i].CountryID)
|
||||||
for i := 0; i < len(*parsed_addresses); i++ {
|
|
||||||
var next_address model.AddressUnparsed
|
|
||||||
next_address.ID = (*parsed_addresses)[i].ID
|
|
||||||
next_address.CustomerID = (*parsed_addresses)[i].CustomerID
|
|
||||||
next_address.CountryID = (*parsed_addresses)[i].CountryID
|
|
||||||
|
|
||||||
next_address.AddressInfo, err = s.validateAddressJson((*parsed_addresses)[i].AddressInfo, next_address.CountryID)
|
|
||||||
// log such errors
|
// log such errors
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("err: %v\n", err)
|
fmt.Printf("err: %v\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
unparsed_addresses = append(unparsed_addresses, next_address)
|
(*addresses)[i].AddressUnparsed = &address_unparsed
|
||||||
}
|
}
|
||||||
|
|
||||||
return &unparsed_addresses, nil
|
return addresses, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *AddressesService) DeleteAddress(user_id uint, address_id uint) error {
|
func (s *AddressesService) DeleteAddress(user_id uint, address_id uint) error {
|
||||||
@@ -112,7 +105,7 @@ func (s *AddressesService) DeleteAddress(user_id uint, address_id uint) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// validateAddressJson makes sure that the info string represents a valid json of address in given country
|
// validateAddressJson makes sure that the info string represents a valid json of address in given country
|
||||||
func (s *AddressesService) validateAddressJson(info string, country_id uint) (model.AddressField, error) {
|
func (s *AddressesService) ValidateAddressJson(info string, country_id uint) (model.AddressUnparsed, error) {
|
||||||
dec := json.NewDecoder(strings.NewReader(info))
|
dec := json.NewDecoder(strings.NewReader(info))
|
||||||
dec.DisallowUnknownFields()
|
dec.DisallowUnknownFields()
|
||||||
|
|
||||||
|
|||||||
@@ -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,18 +29,43 @@ 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
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *CartsService) UpdateCartName(user_id uint, cart_id uint, new_name string) error {
|
func (s *CartsService) RemoveCart(user_id uint, cart_id uint) error {
|
||||||
amt, err := s.repo.UserHasCart(user_id, cart_id)
|
exists, err := s.repo.UserHasCart(user_id, cart_id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if amt != 1 {
|
if !exists {
|
||||||
|
return responseErrors.ErrUserHasNoSuchCart
|
||||||
|
}
|
||||||
|
|
||||||
|
return s.repo.RemoveCart(user_id, cart_id)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *CartsService) UpdateCartName(user_id uint, cart_id uint, new_name string) error {
|
||||||
|
exists, err := s.repo.UserHasCart(user_id, cart_id)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !exists {
|
||||||
return responseErrors.ErrUserHasNoSuchCart
|
return responseErrors.ErrUserHasNoSuchCart
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,33 +77,45 @@ func (s *CartsService) RetrieveCartsInfo(user_id uint) ([]model.CustomerCart, er
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *CartsService) RetrieveCart(user_id uint, cart_id uint) (*model.CustomerCart, error) {
|
func (s *CartsService) RetrieveCart(user_id uint, cart_id uint) (*model.CustomerCart, error) {
|
||||||
amt, err := s.repo.UserHasCart(user_id, cart_id)
|
exists, err := s.repo.UserHasCart(user_id, cart_id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if amt != 1 {
|
if !exists {
|
||||||
return nil, responseErrors.ErrUserHasNoSuchCart
|
return nil, responseErrors.ErrUserHasNoSuchCart
|
||||||
}
|
}
|
||||||
|
|
||||||
return s.repo.RetrieveCart(user_id, cart_id)
|
return s.repo.RetrieveCart(user_id, cart_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *CartsService) AddProduct(user_id uint, cart_id uint, product_id uint, product_attribute_id *uint, amount uint) error {
|
func (s *CartsService) AddProduct(user_id uint, cart_id uint, product_id uint, product_attribute_id *uint, amount int, set_amount bool) error {
|
||||||
amt, err := s.repo.UserHasCart(user_id, cart_id)
|
exists, err := s.repo.UserHasCart(user_id, cart_id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if amt != 1 {
|
if !exists {
|
||||||
return responseErrors.ErrUserHasNoSuchCart
|
return responseErrors.ErrUserHasNoSuchCart
|
||||||
}
|
}
|
||||||
|
|
||||||
amt, err = s.repo.CheckProductExists(product_id, product_attribute_id)
|
exists, err = s.repo.CheckProductExists(product_id, product_attribute_id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if amt != 1 {
|
if !exists {
|
||||||
return responseErrors.ErrProductOrItsVariationDoesNotExist
|
return responseErrors.ErrProductOrItsVariationDoesNotExist
|
||||||
}
|
}
|
||||||
|
|
||||||
return s.repo.AddProduct(user_id, cart_id, product_id, product_attribute_id, amount)
|
return s.repo.AddProduct(cart_id, product_id, product_attribute_id, uint(amount), set_amount)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *CartsService) RemoveProduct(user_id uint, cart_id uint, product_id uint, product_attribute_id *uint) error {
|
||||||
|
exists, err := s.repo.UserHasCart(user_id, cart_id)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !exists {
|
||||||
|
return responseErrors.ErrUserHasNoSuchCart
|
||||||
|
}
|
||||||
|
|
||||||
|
return s.repo.RemoveProduct(cart_id, product_id, product_attribute_id)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,6 +129,21 @@ func (s *EmailService) SendNewUserAdminNotification(userEmail, userName, baseURL
|
|||||||
return s.SendEmail(s.config.AdminEmail, subject, body)
|
return s.SendEmail(s.config.AdminEmail, subject, body)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SendNewOrderPlacedNotification sends an email to admin when new order is placed
|
||||||
|
func (s *EmailService) SendNewOrderPlacedNotification(userID uint) error {
|
||||||
|
if s.config.AdminEmail == "" {
|
||||||
|
logger.Warn("no admin email setup in the config",
|
||||||
|
"service", "EmailService.SendNewOrderPlacedNotification",
|
||||||
|
"user_id", userID,
|
||||||
|
)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
subject := "New Order Created"
|
||||||
|
body := s.newOrderPlacedTemplate(userID)
|
||||||
|
|
||||||
|
return s.SendEmail(s.config.AdminEmail, subject, body)
|
||||||
|
}
|
||||||
|
|
||||||
// verificationEmailTemplate returns the HTML template for email verification
|
// verificationEmailTemplate returns the HTML template for email verification
|
||||||
func (s *EmailService) verificationEmailTemplate(name, verificationURL string, langID uint) string {
|
func (s *EmailService) verificationEmailTemplate(name, verificationURL string, langID uint) string {
|
||||||
buf := bytes.Buffer{}
|
buf := bytes.Buffer{}
|
||||||
@@ -137,3 +164,10 @@ func (s *EmailService) newUserAdminNotificationTemplate(userEmail, userName, bas
|
|||||||
emails.EmailAdminNotificationWrapper(view.EmailLayout[view.EmailAdminNotificationData]{LangID: constdata.ADMIN_NOTIFICATION_LANGUAGE, Data: view.EmailAdminNotificationData{UserEmail: userEmail, UserName: userName, BaseURL: baseURL}}).Render(context.Background(), &buf)
|
emails.EmailAdminNotificationWrapper(view.EmailLayout[view.EmailAdminNotificationData]{LangID: constdata.ADMIN_NOTIFICATION_LANGUAGE, Data: view.EmailAdminNotificationData{UserEmail: userEmail, UserName: userName, BaseURL: baseURL}}).Render(context.Background(), &buf)
|
||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// newUserAdminNotificationTemplate returns the HTML template for admin notification
|
||||||
|
func (s *EmailService) newOrderPlacedTemplate(userID uint) string {
|
||||||
|
buf := bytes.Buffer{}
|
||||||
|
// emails.EmailNewOrderPlacedWrapper(view.EmailLayout[view.EmailNewOrderPlacedData]{LangID: constdata.ADMIN_NOTIFICATION_LANGUAGE, Data: view.EmailNewOrderPlacedData{UserID: userID}}).Render(context.Background(), &buf)
|
||||||
|
return buf.String()
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
|
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/config"
|
"git.ma-al.com/goc_daniel/b2b/app/config"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/model"
|
"git.ma-al.com/goc_daniel/b2b/app/model"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/repos/productDescriptionRepo"
|
searchrepo "git.ma-al.com/goc_daniel/b2b/app/repos/searchRepo"
|
||||||
constdata "git.ma-al.com/goc_daniel/b2b/app/utils/const_data"
|
constdata "git.ma-al.com/goc_daniel/b2b/app/utils/const_data"
|
||||||
"github.com/meilisearch/meilisearch-go"
|
"github.com/meilisearch/meilisearch-go"
|
||||||
)
|
)
|
||||||
@@ -20,8 +20,8 @@ type MeiliIndexSettings struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type MeiliService struct {
|
type MeiliService struct {
|
||||||
productDescriptionRepo productDescriptionRepo.UIProductDescriptionRepo
|
searchRepo searchrepo.UISearchRepo
|
||||||
meiliClient meilisearch.ServiceManager
|
meiliClient meilisearch.ServiceManager
|
||||||
}
|
}
|
||||||
|
|
||||||
func New() *MeiliService {
|
func New() *MeiliService {
|
||||||
@@ -32,8 +32,8 @@ func New() *MeiliService {
|
|||||||
)
|
)
|
||||||
|
|
||||||
return &MeiliService{
|
return &MeiliService{
|
||||||
meiliClient: client,
|
meiliClient: client,
|
||||||
productDescriptionRepo: productDescriptionRepo.New(),
|
searchRepo: searchrepo.New(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,7 +50,7 @@ func (s *MeiliService) CreateIndex(id_lang uint) error {
|
|||||||
|
|
||||||
for {
|
for {
|
||||||
// Get batch of products from repo (includes scanning)
|
// Get batch of products from repo (includes scanning)
|
||||||
products, err := s.productDescriptionRepo.GetMeiliProducts(id_lang, offset, batchSize)
|
products, err := s.searchRepo.GetMeiliProducts(id_lang, offset, batchSize)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to get products batch at offset %d: %w", offset, err)
|
return fmt.Errorf("failed to get products batch at offset %d: %w", offset, err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,31 +3,46 @@ package menuService
|
|||||||
import (
|
import (
|
||||||
"slices"
|
"slices"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"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/categoriesRepo"
|
categoryrepo "git.ma-al.com/goc_daniel/b2b/app/repos/categoryRepo"
|
||||||
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"
|
||||||
|
"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"
|
||||||
)
|
)
|
||||||
|
|
||||||
type MenuService struct {
|
type MenuService struct {
|
||||||
categoriesRepo categoriesRepo.UICategoriesRepo
|
categoryRepo categoryrepo.UICategoryRepo
|
||||||
routesRepo routesRepo.UIRoutesRepo
|
routesRepo routesRepo.UIRoutesRepo
|
||||||
}
|
}
|
||||||
|
|
||||||
func New() *MenuService {
|
func New() *MenuService {
|
||||||
return &MenuService{
|
return &MenuService{
|
||||||
categoriesRepo: categoriesRepo.New(),
|
categoryRepo: categoryrepo.New(),
|
||||||
routesRepo: routesRepo.New(),
|
routesRepo: routesRepo.New(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MenuService) GetCategoryTree(root_category_id uint, id_lang uint) (*model.Category, error) {
|
func (s *MenuService) GetCategoryTree(root_category_id uint, id_lang uint) (*model.Category, error) {
|
||||||
all_categories, err := s.categoriesRepo.GetAllCategories(id_lang)
|
all_categories, err := s.categoryRepo.RetrieveMenuCategories(id_lang)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &model.Category{}, err
|
return &model.Category{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// remove blacklisted categories
|
||||||
|
// to do so, we detach them from the main tree
|
||||||
|
for i := 0; i < len(all_categories); i++ {
|
||||||
|
if slices.Contains(constdata.CATEGORY_BLACKLIST, all_categories[i].CategoryID) {
|
||||||
|
all_categories[i].ParentID = all_categories[i].CategoryID
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
iso_code := all_categories[0].IsoCode
|
||||||
|
s.appendAdditional(&all_categories, id_lang, iso_code)
|
||||||
|
|
||||||
// find the root
|
// find the root
|
||||||
root_index := 0
|
root_index := 0
|
||||||
root_found := false
|
root_found := false
|
||||||
@@ -88,8 +103,8 @@ func (s *MenuService) createTree(index int, all_categories *([]model.ScannedCate
|
|||||||
return node, true
|
return node, true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MenuService) GetRoutes(id_lang uint) ([]model.Route, error) {
|
func (s *MenuService) GetRoutes(id_lang, roleId uint) ([]model.Route, error) {
|
||||||
return s.routesRepo.GetRoutes(id_lang)
|
return s.routesRepo.GetRoutes(id_lang, roleId)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MenuService) scannedToNormalCategory(scanned model.ScannedCategory) model.Category {
|
func (s *MenuService) scannedToNormalCategory(scanned model.ScannedCategory) model.Category {
|
||||||
@@ -98,7 +113,7 @@ func (s *MenuService) scannedToNormalCategory(scanned model.ScannedCategory) mod
|
|||||||
normal.CategoryID = scanned.CategoryID
|
normal.CategoryID = scanned.CategoryID
|
||||||
normal.Label = scanned.Name
|
normal.Label = scanned.Name
|
||||||
// normal.Active = scanned.Active == 1
|
// normal.Active = scanned.Active == 1
|
||||||
normal.Params = model.CategoryParams{CategoryID: normal.CategoryID, LinkRewrite: scanned.LinkRewrite, Locale: scanned.IsoCode}
|
normal.Params = model.CategoryParams{CategoryID: normal.CategoryID, LinkRewrite: scanned.LinkRewrite, Locale: scanned.IsoCode, Filter: scanned.Filter}
|
||||||
normal.Children = []model.Category{}
|
normal.Children = []model.Category{}
|
||||||
return normal
|
return normal
|
||||||
}
|
}
|
||||||
@@ -114,11 +129,14 @@ func (a ByPosition) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
|||||||
func (a ByPosition) Less(i, j int) bool { return a[i].Position < a[j].Position }
|
func (a ByPosition) Less(i, j int) bool { return a[i].Position < a[j].Position }
|
||||||
|
|
||||||
func (s *MenuService) GetBreadcrumb(root_category_id uint, start_category_id uint, id_lang uint) ([]model.CategoryInBreadcrumb, error) {
|
func (s *MenuService) GetBreadcrumb(root_category_id uint, start_category_id uint, id_lang uint) ([]model.CategoryInBreadcrumb, error) {
|
||||||
all_categories, err := s.categoriesRepo.GetAllCategories(id_lang)
|
all_categories, err := s.categoryRepo.RetrieveMenuCategories(id_lang)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return []model.CategoryInBreadcrumb{}, err
|
return []model.CategoryInBreadcrumb{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
iso_code := all_categories[0].IsoCode
|
||||||
|
s.appendAdditional(&all_categories, id_lang, iso_code)
|
||||||
|
|
||||||
breadcrumb := []model.CategoryInBreadcrumb{}
|
breadcrumb := []model.CategoryInBreadcrumb{}
|
||||||
|
|
||||||
start_index := 0
|
start_index := 0
|
||||||
@@ -176,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
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,5 +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) {
|
||||||
|
for i := 0; i < len(*all_categories); i++ {
|
||||||
|
(*all_categories)[i].Filter = "category_id_eq=" + strconv.Itoa(int((*all_categories)[i].CategoryID))
|
||||||
|
}
|
||||||
|
|
||||||
|
// the new products category
|
||||||
|
var new_products_category model.ScannedCategory
|
||||||
|
new_products_category.CategoryID = constdata.ADDITIONAL_CATEGORIES_INDEX + 1
|
||||||
|
new_products_category.Name = "New Products"
|
||||||
|
new_products_category.Active = 1
|
||||||
|
new_products_category.Position = 10
|
||||||
|
new_products_category.ParentID = 2
|
||||||
|
new_products_category.IsRoot = 0
|
||||||
|
new_products_category.LinkRewrite = i18n.T___(id_lang, "category.new_products")
|
||||||
|
new_products_category.IsoCode = iso_code
|
||||||
|
|
||||||
|
new_products_category.Visited = false
|
||||||
|
new_products_category.Filter = "is_new_eq=true"
|
||||||
|
|
||||||
|
*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)
|
||||||
}
|
}
|
||||||
|
|||||||
206
app/service/orderService/orderService.go
Normal file
206
app/service/orderService/orderService.go
Normal file
@@ -0,0 +1,206 @@
|
|||||||
|
package orderService
|
||||||
|
|
||||||
|
import (
|
||||||
|
"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/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/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/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/find"
|
||||||
|
"git.ma-al.com/goc_daniel/b2b/app/utils/responseErrors"
|
||||||
|
)
|
||||||
|
|
||||||
|
type OrderService struct {
|
||||||
|
ordersRepo ordersRepo.UIOrdersRepo
|
||||||
|
cartsRepo cartsRepo.UICartsRepo
|
||||||
|
productsRepo productsRepo.UIProductsRepo
|
||||||
|
addressesService *addressesService.AddressesService
|
||||||
|
emailService *emailService.EmailService
|
||||||
|
actionRegistry *orderStatusActions.ActionRegistry
|
||||||
|
}
|
||||||
|
|
||||||
|
func New() *OrderService {
|
||||||
|
return &OrderService{
|
||||||
|
ordersRepo: ordersRepo.New(),
|
||||||
|
cartsRepo: cartsRepo.New(),
|
||||||
|
productsRepo: productsRepo.New(),
|
||||||
|
addressesService: addressesService.New(),
|
||||||
|
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) {
|
||||||
|
if !user.HasPermission(perms.OrdersViewAll) {
|
||||||
|
// append filter to view only this user's orders
|
||||||
|
idStr := strconv.FormatUint(uint64(user.ID), 10)
|
||||||
|
filt.Append(filters.Where("b2b_customer_orders.user_id = " + idStr))
|
||||||
|
}
|
||||||
|
|
||||||
|
list, err := s.ordersRepo.Find(user.ID, p, filt)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < len(list.Items); i++ {
|
||||||
|
address_unparsed, err := s.addressesService.ValidateAddressJson(list.Items[i].AddressString, list.Items[i].CountryID)
|
||||||
|
if err != nil {
|
||||||
|
logger.Warn("failed to validate address",
|
||||||
|
"service", "orderService",
|
||||||
|
"order_id", list.Items[i].OrderID,
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
list.Items[i].AddressUnparsed = &address_unparsed
|
||||||
|
}
|
||||||
|
|
||||||
|
return list, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
exists, err := s.cartsRepo.UserHasCart(user_id, cart_id)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !exists {
|
||||||
|
return responseErrors.ErrUserHasNoSuchCart
|
||||||
|
}
|
||||||
|
|
||||||
|
cart, err := s.cartsRepo.RetrieveCart(user_id, cart_id)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if len(cart.Products) == 0 {
|
||||||
|
return responseErrors.ErrEmptyCart
|
||||||
|
}
|
||||||
|
|
||||||
|
if name == "" && cart.Name != nil {
|
||||||
|
name = *cart.Name
|
||||||
|
}
|
||||||
|
|
||||||
|
base_price, tax_incl, tax_excl, err := s.getOrderTotalPrice(user_id, cart_id, country_id)
|
||||||
|
|
||||||
|
// all checks passed
|
||||||
|
order, err := s.ordersRepo.PlaceNewOrder(cart, name, country_id, address_info, originalUserId, base_price, tax_incl, tax_excl)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
// from this point onward we do not cancel this order.
|
||||||
|
|
||||||
|
// if no error is returned, remove the cart. This should be smooth
|
||||||
|
err = s.cartsRepo.RemoveCart(user_id, cart_id)
|
||||||
|
if err != nil {
|
||||||
|
logger.Warn("failed to remove cart after order placement",
|
||||||
|
"service", "orderService",
|
||||||
|
"user_id", user_id,
|
||||||
|
"cart_id", cart_id,
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return s.ChangeOrderStatus(user_id, order.OrderID, enums.OrderStatusPending)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *OrderService) ChangeOrderAddress(user *model.Customer, order_id uint, country_id uint, address_info string) error {
|
||||||
|
_, err := s.addressesService.ValidateAddressJson(address_info, country_id)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !user.HasPermission(perms.OrdersModifyAll) {
|
||||||
|
exists, err := s.ordersRepo.UserHasOrder(user.ID, order_id)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !exists {
|
||||||
|
return responseErrors.ErrUserHasNoSuchOrder
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return s.ordersRepo.ChangeOrderAddress(order_id, country_id, address_info)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *OrderService) ChangeOrderStatus(userId, orderId uint, newStatus enums.OrderStatus) error {
|
||||||
|
order, err := s.ordersRepo.Get(orderId)
|
||||||
|
if err != nil {
|
||||||
|
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 {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
actionCtx := orderStatusActions.ActionContext{
|
||||||
|
Order: order,
|
||||||
|
UserId: &userId,
|
||||||
|
EmailService: s.emailService,
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
@@ -27,7 +27,7 @@ func (s *ProductService) Get(
|
|||||||
p_id_product, p_id_lang, p_id_customer, b2b_id_country, p_quantity uint,
|
p_id_product, p_id_lang, p_id_customer, b2b_id_country, p_quantity uint,
|
||||||
) (*json.RawMessage, error) {
|
) (*json.RawMessage, error) {
|
||||||
|
|
||||||
product, err := s.productsRepo.GetBase(p_id_product, constdata.SHOP_ID, p_id_lang)
|
product, err := s.productsRepo.GetBase(p_id_product, constdata.SHOP_ID, p_id_lang, p_id_customer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"unicode"
|
"unicode"
|
||||||
|
|
||||||
|
"git.ma-al.com/goc_daniel/b2b/app/db"
|
||||||
constdata "git.ma-al.com/goc_daniel/b2b/app/utils/const_data"
|
constdata "git.ma-al.com/goc_daniel/b2b/app/utils/const_data"
|
||||||
"github.com/dlclark/regexp2"
|
"github.com/dlclark/regexp2"
|
||||||
"golang.org/x/text/runes"
|
"golang.org/x/text/runes"
|
||||||
@@ -22,7 +23,7 @@ func SanitizeSlug(s string) string {
|
|||||||
s = strings.TrimSpace(strings.ToLower(s))
|
s = strings.TrimSpace(strings.ToLower(s))
|
||||||
|
|
||||||
// First apply explicit transliteration for language-specific letters.
|
// First apply explicit transliteration for language-specific letters.
|
||||||
s = transliterateWithTable(s)
|
s = transliterateSlug(s)
|
||||||
|
|
||||||
// Then normalize and strip any remaining combining marks.
|
// Then normalize and strip any remaining combining marks.
|
||||||
s = removeDiacritics(s)
|
s = removeDiacritics(s)
|
||||||
@@ -40,19 +41,17 @@ func SanitizeSlug(s string) string {
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func transliterateWithTable(s string) string {
|
func transliterateSlug(s string) string {
|
||||||
var b strings.Builder
|
var cleared string
|
||||||
b.Grow(len(s))
|
|
||||||
|
|
||||||
for _, r := range s {
|
err := db.DB.Raw("SELECT slugify_eu(?)", s).Scan(&cleared).Error
|
||||||
if repl, ok := constdata.TRANSLITERATION_TABLE[r]; ok {
|
if err != nil {
|
||||||
b.WriteString(repl)
|
// log error
|
||||||
} else {
|
_ = err
|
||||||
b.WriteRune(r)
|
return s
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return b.String()
|
return cleared
|
||||||
}
|
}
|
||||||
|
|
||||||
func removeDiacritics(s string) string {
|
func removeDiacritics(s string) string {
|
||||||
|
|||||||
26
app/templ/emails/emailNewOrderPlacedNotification.templ
Normal file
26
app/templ/emails/emailNewOrderPlacedNotification.templ
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
package emails
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.ma-al.com/goc_daniel/b2b/app/templ/layout"
|
||||||
|
"git.ma-al.com/goc_daniel/b2b/app/view"
|
||||||
|
"git.ma-al.com/goc_daniel/b2b/app/utils/i18n"
|
||||||
|
)
|
||||||
|
|
||||||
|
templ EmailNewOrderPlacedWrapper(data view.EmailLayout[view.EmailNewOrderPlacedData]) {
|
||||||
|
@layout.Base( i18n.T___(data.LangID, "email.email_new_order_placed_notification_title")) {
|
||||||
|
<div class="container">
|
||||||
|
<div class="email-wrapper">
|
||||||
|
<div class="email-header">
|
||||||
|
<h1>New Order Placed</h1>
|
||||||
|
</div>
|
||||||
|
<div class="email-body">
|
||||||
|
<p>Hello Administrator,</p>
|
||||||
|
<p>User with id { data.Data.UserID } has placed a new order. </p>
|
||||||
|
</div>
|
||||||
|
<div class="email-footer">
|
||||||
|
<p>© 2024 Gitea Manager. All rights reserved.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,14 +9,22 @@ 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
|
||||||
|
var CATEGORY_BLACKLIST = []uint{250}
|
||||||
|
|
||||||
const MAX_AMOUNT_OF_CARTS_PER_USER = 10
|
const MAX_AMOUNT_OF_CARTS_PER_USER = 10
|
||||||
const DEFAULT_NEW_CART_NAME = "new cart"
|
const DEFAULT_NEW_CART_NAME = "new cart"
|
||||||
|
const MAX_AMOUNT_OF_PRODUCT_IN_CART = 1024
|
||||||
|
|
||||||
const MAX_AMOUNT_OF_ADDRESSES_PER_USER = 10
|
const MAX_AMOUNT_OF_ADDRESSES_PER_USER = 10
|
||||||
|
|
||||||
const USER_LOCALE = "user"
|
const USER_LOCALE = "user"
|
||||||
|
|
||||||
|
// ORDERS
|
||||||
|
const NEW_ORDER_STATUS = "PENDING"
|
||||||
|
|
||||||
// WEBDAV
|
// WEBDAV
|
||||||
const NBYTES_IN_WEBDAV_TOKEN = 32
|
const NBYTES_IN_WEBDAV_TOKEN = 32
|
||||||
const WEBDAV_HREF_ROOT = "http://localhost:3000/api/v1/webdav/storage"
|
const WEBDAV_HREF_ROOT = "http://localhost:3000/api/v1/webdav/storage"
|
||||||
@@ -27,22 +35,4 @@ const NON_ALNUM_REGEX = `[^a-z0-9]+`
|
|||||||
const MULTI_DASH_REGEX = `-+`
|
const MULTI_DASH_REGEX = `-+`
|
||||||
const SLUG_REGEX = `^[a-z0-9]+(?:-[a-z0-9]+)*$`
|
const SLUG_REGEX = `^[a-z0-9]+(?:-[a-z0-9]+)*$`
|
||||||
|
|
||||||
// Currently supports only German+Polish specific cases
|
const UNLOGGED_USER_ROLE_ID = 4
|
||||||
var TRANSLITERATION_TABLE = map[rune]string{
|
|
||||||
// German
|
|
||||||
'ä': "ae",
|
|
||||||
'ö': "oe",
|
|
||||||
'ü': "ue",
|
|
||||||
'ß': "ss",
|
|
||||||
|
|
||||||
// Polish
|
|
||||||
'ą': "a",
|
|
||||||
'ć': "c",
|
|
||||||
'ę': "e",
|
|
||||||
'ł': "l",
|
|
||||||
'ń': "n",
|
|
||||||
'ó': "o",
|
|
||||||
'ś': "s",
|
|
||||||
'ż': "z",
|
|
||||||
'ź': "z",
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -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 {
|
||||||
@@ -22,14 +30,6 @@ func GetUserID(c fiber.Ctx) (uint, bool) {
|
|||||||
return user_locale.User.ID, true
|
return user_locale.User.ID, true
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetOriginalUserRole(c fiber.Ctx) (model.Role, bool) {
|
|
||||||
user_locale, ok := c.Locals(constdata.USER_LOCALE).(*model.UserLocale)
|
|
||||||
if !ok || user_locale.OriginalUser == nil || user_locale.OriginalUser.Role == nil {
|
|
||||||
return model.Role{}, false
|
|
||||||
}
|
|
||||||
return *user_locale.OriginalUser.Role, true
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetCustomer(c fiber.Ctx) (*model.Customer, bool) {
|
func GetCustomer(c fiber.Ctx) (*model.Customer, 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...)
|
||||||
|
}
|
||||||
@@ -65,12 +65,21 @@ var (
|
|||||||
ErrMaxAmtOfCartsReached = errors.New("maximal amount of carts reached")
|
ErrMaxAmtOfCartsReached = errors.New("maximal amount of carts reached")
|
||||||
ErrUserHasNoSuchCart = errors.New("user does not have cart with given id")
|
ErrUserHasNoSuchCart = errors.New("user does not have cart with given id")
|
||||||
ErrProductOrItsVariationDoesNotExist = errors.New("product or its variation with given ids does not exist")
|
ErrProductOrItsVariationDoesNotExist = errors.New("product or its variation with given ids does not exist")
|
||||||
|
ErrAmountMustBePositive = errors.New("amount must be positive")
|
||||||
|
ErrAmountMustBeReasonable = errors.New("amount must be reasonable")
|
||||||
|
|
||||||
|
// Typed errors for orders handler
|
||||||
|
ErrEmptyCart = errors.New("the cart is empty")
|
||||||
|
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'")
|
||||||
ErrPercentageRequired = errors.New("percentage_reduction required when reduction_type is percentage")
|
ErrPercentageRequired = errors.New("percentage_reduction required when reduction_type is percentage")
|
||||||
ErrPriceRequired = errors.New("price required when reduction_type is amount")
|
ErrPriceRequired = errors.New("price required when reduction_type is amount")
|
||||||
ErrSpecificPriceNotFound = errors.New("price reduction not found")
|
ErrSpecificPriceNotFound = errors.New("price reduction not found")
|
||||||
|
|
||||||
// Typed errors for storage
|
// Typed errors for storage
|
||||||
ErrAccessDenied = errors.New("access denied!")
|
ErrAccessDenied = errors.New("access denied!")
|
||||||
ErrFolderDoesNotExist = errors.New("folder does not exist")
|
ErrFolderDoesNotExist = errors.New("folder does not exist")
|
||||||
@@ -200,6 +209,15 @@ func GetErrorCode(c fiber.Ctx, err error) string {
|
|||||||
return i18n.T_(c, "error.err_user_has_no_such_cart")
|
return i18n.T_(c, "error.err_user_has_no_such_cart")
|
||||||
case errors.Is(err, ErrProductOrItsVariationDoesNotExist):
|
case errors.Is(err, ErrProductOrItsVariationDoesNotExist):
|
||||||
return i18n.T_(c, "error.err_product_or_its_variation_does_not_exist")
|
return i18n.T_(c, "error.err_product_or_its_variation_does_not_exist")
|
||||||
|
case errors.Is(err, ErrAmountMustBePositive):
|
||||||
|
return i18n.T_(c, "error.err_amount_must_be_positive")
|
||||||
|
case errors.Is(err, ErrAmountMustBeReasonable):
|
||||||
|
return i18n.T_(c, "error.err_amount_must_be_reasonable")
|
||||||
|
|
||||||
|
case errors.Is(err, ErrEmptyCart):
|
||||||
|
return i18n.T_(c, "error.err_cart_is_empty")
|
||||||
|
case errors.Is(err, ErrUserHasNoSuchOrder):
|
||||||
|
return i18n.T_(c, "error.err_user_has_no_such_order")
|
||||||
|
|
||||||
case errors.Is(err, ErrAccessDenied):
|
case errors.Is(err, ErrAccessDenied):
|
||||||
return i18n.T_(c, "error.err_access_denied")
|
return i18n.T_(c, "error.err_access_denied")
|
||||||
@@ -282,6 +300,10 @@ func GetErrorStatus(err error) int {
|
|||||||
errors.Is(err, ErrMaxAmtOfCartsReached),
|
errors.Is(err, ErrMaxAmtOfCartsReached),
|
||||||
errors.Is(err, ErrUserHasNoSuchCart),
|
errors.Is(err, ErrUserHasNoSuchCart),
|
||||||
errors.Is(err, ErrProductOrItsVariationDoesNotExist),
|
errors.Is(err, ErrProductOrItsVariationDoesNotExist),
|
||||||
|
errors.Is(err, ErrAmountMustBePositive),
|
||||||
|
errors.Is(err, ErrAmountMustBeReasonable),
|
||||||
|
errors.Is(err, ErrEmptyCart),
|
||||||
|
errors.Is(err, ErrUserHasNoSuchOrder),
|
||||||
errors.Is(err, ErrInvalidReductionType),
|
errors.Is(err, ErrInvalidReductionType),
|
||||||
errors.Is(err, ErrPercentageRequired),
|
errors.Is(err, ErrPercentageRequired),
|
||||||
errors.Is(err, ErrPriceRequired),
|
errors.Is(err, ErrPriceRequired),
|
||||||
@@ -294,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
|
||||||
|
|||||||
@@ -18,3 +18,7 @@ type EmailAdminNotificationData struct {
|
|||||||
type EmailPasswordResetData struct {
|
type EmailPasswordResetData struct {
|
||||||
ResetURL string
|
ResetURL string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type EmailNewOrderPlacedData struct {
|
||||||
|
UserID uint
|
||||||
|
}
|
||||||
|
|||||||
@@ -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"`
|
||||||
}
|
}
|
||||||
|
|||||||
17
bo/components.d.ts
vendored
17
bo/components.d.ts
vendored
@@ -11,7 +11,7 @@ export {}
|
|||||||
/* prettier-ignore */
|
/* prettier-ignore */
|
||||||
declare module 'vue' {
|
declare module 'vue' {
|
||||||
export interface GlobalComponents {
|
export interface GlobalComponents {
|
||||||
ButtonGoToProfile: typeof import('./src/components/customer-management/ButtonGoToProfile.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']
|
||||||
@@ -23,12 +23,16 @@ declare module 'vue' {
|
|||||||
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']
|
||||||
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']
|
||||||
PageCarts: typeof import('./src/components/customer/PageCarts.vue')['default']
|
PageCarts: typeof import('./src/components/customer/PageCarts.vue')['default']
|
||||||
|
PageCArts: typeof import('./src/components/customer/PageCArts.vue')['default']
|
||||||
|
PageCreateCart: typeof import('./src/components/customer/PageCreateCart.vue')['default']
|
||||||
PageOrders: typeof import('./src/components/customer/PageOrders.vue')['default']
|
PageOrders: typeof import('./src/components/customer/PageOrders.vue')['default']
|
||||||
PageProduct: typeof import('./src/components/customer/PageProduct.vue')['default']
|
PageProduct: typeof import('./src/components/customer/PageProduct.vue')['default']
|
||||||
PageProducts: typeof import('./src/components/admin/PageProducts.vue')['default']
|
PageProducts: typeof import('./src/components/admin/PageProducts.vue')['default']
|
||||||
PageProfileDetails: typeof import('./src/components/customer/PageProfileDetails.vue')['default']
|
PageProfileDetails: typeof import('./src/components/customer/PageProfileDetails.vue')['default']
|
||||||
PageProfileDetailsAddInfo: typeof import('./src/components/customer/PageProfileDetailsAddInfo.vue')['default']
|
PageProfileDetailsAddInfo: typeof import('./src/components/customer/PageProfileDetailsAddInfo.vue')['default']
|
||||||
|
PageSearchProducts: typeof import('./src/components/customer/PageSearchProducts.vue')['default']
|
||||||
PageStatistic: typeof import('./src/components/customer/PageStatistic.vue')['default']
|
PageStatistic: typeof import('./src/components/customer/PageStatistic.vue')['default']
|
||||||
Pl_PrivacyPolicyView: typeof import('./src/components/terms/pl_PrivacyPolicyView.vue')['default']
|
Pl_PrivacyPolicyView: typeof import('./src/components/terms/pl_PrivacyPolicyView.vue')['default']
|
||||||
Pl_TermsAndConditionsView: typeof import('./src/components/terms/pl_TermsAndConditionsView.vue')['default']
|
Pl_TermsAndConditionsView: typeof import('./src/components/terms/pl_TermsAndConditionsView.vue')['default']
|
||||||
@@ -38,14 +42,24 @@ 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']
|
||||||
|
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']
|
||||||
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']
|
||||||
@@ -66,6 +80,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",
|
||||||
|
|||||||
@@ -1,17 +1,25 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import { computed } from 'vue'
|
||||||
import { TooltipProvider } from 'reka-ui'
|
import { TooltipProvider } from 'reka-ui'
|
||||||
import { RouterView } from 'vue-router'
|
import { RouterView, useRoute } from 'vue-router'
|
||||||
|
import DefaultLayout from '@/layouts/default.vue'
|
||||||
|
import EmptyLayout from '@/layouts/empty.vue'
|
||||||
|
import ManagementLayout from '@/layouts/management.vue'
|
||||||
import { useAuthStore } from './stores/customer/auth'
|
import { useAuthStore } from './stores/customer/auth'
|
||||||
|
|
||||||
const authStore = useAuthStore()
|
const authStore = useAuthStore()
|
||||||
|
const route = useRoute()
|
||||||
|
const layout = computed(() => (route.meta.layout as string) || 'default')
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<Suspense>
|
<Suspense>
|
||||||
<TooltipProvider>
|
<TooltipProvider>
|
||||||
<RouterView />
|
<component :is="layout === 'empty' ? EmptyLayout : layout === 'management' ? ManagementLayout : DefaultLayout">
|
||||||
|
<RouterView v-slot="{ Component }">
|
||||||
|
<component :is="Component" />
|
||||||
|
</RouterView>
|
||||||
|
</component>
|
||||||
</TooltipProvider>
|
</TooltipProvider>
|
||||||
</Suspense>
|
</Suspense>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
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>
|
||||||
@@ -1,12 +1,9 @@
|
|||||||
<template>
|
<template>
|
||||||
<component :is="Default || 'div'">
|
<div>
|
||||||
<div>
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</component>
|
</template>
|
||||||
</template>
|
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import Default from '@/layouts/default.vue';
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<component :is="Default || 'div'">
|
<div class="flex flex-col md:flex-row gap-10">
|
||||||
<div class="flex flex-col md:flex-row gap-10">
|
|
||||||
<CategoryMenu />
|
<CategoryMenu />
|
||||||
<div class="w-full flex flex-col items-center gap-4">
|
<div class="w-full flex flex-col items-center gap-4">
|
||||||
<UTable :data="productsList" :columns="columns" class="flex-1 w-full" :ui="{
|
<UTable :data="productsList" :columns="columns" class="flex-1 w-full" :ui="{
|
||||||
@@ -9,13 +8,11 @@
|
|||||||
<UPagination v-model:page="page" :total="total" :items-per-page="perPage" />
|
<UPagination v-model:page="page" :total="total" :items-per-page="perPage" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</component>
|
</template>
|
||||||
</template>
|
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, watch, h, resolveComponent, computed } from 'vue'
|
import { ref, watch, h, resolveComponent, computed } from 'vue'
|
||||||
import { useFetchJson } from '@/composable/useFetchJson'
|
import { useFetchJson } from '@/composable/useFetchJson'
|
||||||
import Default from '@/layouts/default.vue'
|
|
||||||
import { useRoute, useRouter } from 'vue-router'
|
import { useRoute, useRouter } from 'vue-router'
|
||||||
import type { TableColumn } from '@nuxt/ui'
|
import type { TableColumn } from '@nuxt/ui'
|
||||||
import CategoryMenu from '../inner/CategoryMenu.vue'
|
import CategoryMenu from '../inner/CategoryMenu.vue'
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<component :is="Default || 'div'">
|
<div class="flex items-center gap-2 mb-4">
|
||||||
<div class="flex items-center gap-2 mb-4">
|
|
||||||
<UIcon name="line-md:arrow-left" class="text-(--text-sky-light) dark:text-(--text-sky-dark)" />
|
<UIcon name="line-md:arrow-left" class="text-(--text-sky-light) dark:text-(--text-sky-dark)" />
|
||||||
<p class="cursor-pointer text-(--text-sky-light) dark:text-(--text-sky-dark)" @click="backFromProduct()">
|
<p class="cursor-pointer text-(--text-sky-light) dark:text-(--text-sky-dark)" @click="backFromProduct()">
|
||||||
Back to products</p>
|
Back to products</p>
|
||||||
@@ -190,12 +189,10 @@
|
|||||||
</UTabs>
|
</UTabs>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</component>
|
</template>
|
||||||
</template>
|
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { useEditable } from '@/composable/useConteditable';
|
import { useEditable } from '@/composable/useConteditable';
|
||||||
import Default from '@/layouts/default.vue';
|
|
||||||
import { langs } from '@/router/langs';
|
import { langs } from '@/router/langs';
|
||||||
import { useProductStore } from '@/stores/product';
|
import { useProductStore } from '@/stores/product';
|
||||||
import { useSettingsStore } from '@/stores/admin/settings';
|
import { useSettingsStore } from '@/stores/admin/settings';
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<component :is="Default || 'div'">
|
<div class="flex items-center gap-2 mb-4">
|
||||||
<div class="flex items-center gap-2 mb-4">
|
|
||||||
<UIcon name="line-md:arrow-left" class="text-(--text-sky-light) dark:text-(--text-sky-dark)" />
|
<UIcon name="line-md:arrow-left" class="text-(--text-sky-light) dark:text-(--text-sky-dark)" />
|
||||||
<p class="cursor-pointer text-(--text-sky-light) dark:text-(--text-sky-dark)" @click="backFromProduct()">
|
<p class="cursor-pointer text-(--text-sky-light) dark:text-(--text-sky-dark)" @click="backFromProduct()">
|
||||||
Back to products</p>
|
Back to products</p>
|
||||||
@@ -154,11 +153,9 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class=""></div>
|
<div class=""></div>
|
||||||
</div>
|
</div>
|
||||||
</component>
|
</template>
|
||||||
</template>
|
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import Default from '@/layouts/default.vue';
|
|
||||||
import { langs } from '@/router/langs';
|
import { langs } from '@/router/langs';
|
||||||
import { useProductStore } from '@/stores/admin/product';
|
import { useProductStore } from '@/stores/admin/product';
|
||||||
import { useSettingsStore } from '@/stores/admin/settings';
|
import { useSettingsStore } from '@/stores/admin/settings';
|
||||||
|
|||||||
@@ -1,17 +1,14 @@
|
|||||||
<template>
|
<template>
|
||||||
<component :is="Default || 'div'">
|
<div class="flex flex-col md:flex-row gap-10">
|
||||||
<div class="flex flex-col md:flex-row gap-10">
|
|
||||||
<div class="w-full flex flex-col items-center gap-4">
|
<div class="w-full flex flex-col items-center gap-4">
|
||||||
<UTable :data="usersList" :columns="columns" class="flex-1 w-full"
|
<UTable :data="usersList" :columns="columns" class="flex-1 w-full"
|
||||||
:ui="{ root: 'max-w-100wv overflow-auto!' }" />
|
:ui="{ root: 'max-w-100wv overflow-auto!' }" />
|
||||||
<UPagination v-model:page="page" :total="total" :items-per-page="perPage" />
|
<UPagination v-model:page="page" :total="total" :items-per-page="perPage" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</component>
|
</template>
|
||||||
</template>
|
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import Default from '@/layouts/default.vue'
|
|
||||||
import { ref, computed, watch, resolveComponent, h } from 'vue'
|
import { ref, computed, watch, resolveComponent, h } from 'vue'
|
||||||
import { useFetchJson } from '@/composable/useFetchJson'
|
import { useFetchJson } from '@/composable/useFetchJson'
|
||||||
import { useRoute, useRouter } from 'vue-router'
|
import { useRoute, useRouter } from 'vue-router'
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
<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 Users</h1>
|
<h1 class="text-6xl font-bold text-black dark:text-white mb-14">Search Users</h1>
|
||||||
|
|
||||||
<div class="w-full max-w-4xl">
|
<div class="w-full max-w-4xl">
|
||||||
@@ -18,12 +17,10 @@
|
|||||||
No users found with that name or ID
|
No users found with that name or ID
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</component>
|
</template>
|
||||||
</template>
|
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, computed, watch, resolveComponent, h } from 'vue'
|
import { ref, computed, watch, resolveComponent, h } from 'vue'
|
||||||
import Default from '@/layouts/default.vue';
|
|
||||||
import type { TableColumn } from '@nuxt/ui';
|
import type { TableColumn } from '@nuxt/ui';
|
||||||
import { useRoute, useRouter } from 'vue-router';
|
import { useRoute, useRouter } from 'vue-router';
|
||||||
import { useFetchJson } from '@/composable/useFetchJson';
|
import { useFetchJson } from '@/composable/useFetchJson';
|
||||||
|
|||||||
278
bo/src/components/admin/product/TabGeneral.vue
Normal file
278
bo/src/components/admin/product/TabGeneral.vue
Normal file
@@ -0,0 +1,278 @@
|
|||||||
|
<template>
|
||||||
|
<div 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>
|
||||||
|
{{ addProductStore.images }}
|
||||||
|
|
||||||
|
<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">
|
||||||
|
<p class="text-sm font-medium text-black dark:text-white">Powiązany produkt</p>
|
||||||
|
|
||||||
|
<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.id_product"
|
||||||
|
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">
|
||||||
|
<span>{{ p.name }}</span>
|
||||||
|
<button type="button" @click="removeRelated(p.id_product)"
|
||||||
|
class="text-gray-400 hover:text-red-500 transition-colors ml-2">
|
||||||
|
<UIcon name="i-lucide-x" class="text-base" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<USelect :items="relatedResults" value-key="product_id" />
|
||||||
|
<div v-if="relatedResults.length > 0"
|
||||||
|
class="rounded-lg border border-(--border-light) dark:border-(--border-dark) overflow-hidden bg-white dark:bg-neutral-900">
|
||||||
|
<button v-for="p in relatedResults" :key="p.id_product" 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'
|
||||||
|
}">
|
||||||
|
<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'
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
item.children.unshift({
|
||||||
|
label: item.label,
|
||||||
|
icon: 'i-lucide-book-open',
|
||||||
|
params: item.params,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
item.icon = 'i-lucide-file-text'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return menu;
|
||||||
|
}
|
||||||
|
|
||||||
|
//there have to be request on filter category (but have to 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) {
|
||||||
|
console.log(cat);
|
||||||
|
|
||||||
|
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.id_product === product.id_product)) {
|
||||||
|
addProductStore.relatedProducts.push(product)
|
||||||
|
}
|
||||||
|
relatedSearch.value = ''
|
||||||
|
relatedResults.value = []
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeRelated(id: number) {
|
||||||
|
const idx = addProductStore.relatedProducts.findIndex(p => p.id_product === 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await addProductStore.loadCategories()
|
||||||
|
</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,11 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<component :is="Management || 'div'">
|
<div>customer-management</div>
|
||||||
<div>customer-management</div>
|
|
||||||
</component>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import Management from '@/layouts/management.vue';
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<component :is="Default || 'div'">
|
<div class="">
|
||||||
<div class="">
|
|
||||||
<h2
|
<h2
|
||||||
class="font-semibold text-black dark:text-white pb-6 text-2xl">
|
class="font-semibold text-black dark:text-white pb-6 text-2xl">
|
||||||
{{ t('Cart Items') }}
|
{{ t('Cart Items') }}
|
||||||
@@ -48,15 +47,13 @@
|
|||||||
</UButton>
|
</UButton>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</component>
|
</template>
|
||||||
</template>
|
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { useCartStore } from '@/stores/customer/cart'
|
import { useCartStore } from '@/stores/customer/cart'
|
||||||
import { ref } from 'vue'
|
import { ref } from 'vue'
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
import Default from '@/layouts/default.vue'
|
|
||||||
const cartStore = useCartStore()
|
const cartStore = useCartStore()
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|||||||
@@ -1,182 +1,239 @@
|
|||||||
<template>
|
<template>
|
||||||
<component :is="Default || 'div'">
|
<div class="flex flex-col gap-5">
|
||||||
<div class="">
|
<div class="flex justify-between items-center">
|
||||||
<div class="flex flex-col gap-5 mb-6">
|
|
||||||
<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">
|
<UIcon name="mdi:add-bold" />
|
||||||
<UInput v-model="searchQuery" type="text" :placeholder="t('Search address')"
|
{{ t('Add Address') }}
|
||||||
class="bg-white dark:bg-gray-800 text-black dark:text-white absolute" />
|
</UButton>
|
||||||
<UIcon name="ic:baseline-search"
|
|
||||||
class="text-[20px] text-(--text-sky-light) dark:text-(--text-sky-dark) relative left-40" />
|
|
||||||
</div>
|
|
||||||
<UButton color="primary" @click="openCreateModal"
|
|
||||||
class="bg-(--accent-blue-light) dark:bg-(--accent-blue-dark) text-white hover:bg-(--accent-blue-dark) dark:hover:bg-(--accent-blue-light)">
|
|
||||||
<UIcon name="mdi:add-bold" />
|
|
||||||
{{ t('Add Address') }}
|
|
||||||
</UButton>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div v-if="paginatedAddresses.length" class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-6">
|
|
||||||
<div v-for="address in paginatedAddresses" :key="address.id"
|
<div v-if="store.loading" class="text-center py-8 text-gray-500 dark:text-gray-400">
|
||||||
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">
|
{{ t('Loading...') }}
|
||||||
<div class="flex flex-col gap-2 items-strat justify-end">
|
</div>
|
||||||
<p class="text-black dark:text-white">{{ address.street }}</p>
|
<div v-else-if="store.error" class="text-center py-8 text-red-500">
|
||||||
<p class="text-black dark:text-white">{{ address.zipCode }}, {{ address.city }}</p>
|
{{ store.error }}
|
||||||
<p class="text-black dark:text-white">{{ address.country }}</p>
|
</div>
|
||||||
|
<div v-else-if="store.addresses.length" class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-6">
|
||||||
|
<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 class="flex flex-col items-end justify-between gap-2">
|
<div class="flex flex-col items-end justify-between">
|
||||||
<button @click="confirmDelete(address.id)"
|
<UButton size="xs" color="error" variant="ghost" :title="t('Delete')"
|
||||||
class="p-2 text-red-500 bg-red-100 dark:bg-(--main-dark) rounded transition-colors"
|
@click="confirmDelete(addr.id)">
|
||||||
:title="t('Remove')">
|
<UIcon name="material-symbols:delete" class="text-[18px]" />
|
||||||
<UIcon name="material-symbols:delete" class="text-[18px]" />
|
</UButton>
|
||||||
</button>
|
<UButton size="sm" color="neutral" variant="outline" @click="openModal(addr)">
|
||||||
<UButton size="sm" color="neutral" variant="outline" @click="openEditModal(address)"
|
{{ t('edit') }}
|
||||||
class="text-(--text-sky-light) dark:text-(--text-sky-dark) text-[13px]">
|
<UIcon name="ic:sharp-edit" class="text-[14px]" />
|
||||||
{{ t('edit') }}
|
</UButton>
|
||||||
<UIcon name="ic:sharp-edit" class="text-[15px]" />
|
|
||||||
</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.prevent="saveAddress" class="space-y-4" :validate="validate">
|
{{ editingId ? t('Edit Address') : t('Add Address') }}
|
||||||
<div>
|
</h3>
|
||||||
<label class="block text-sm font-medium text-black dark:text-white mb-1">Street *</label>
|
</template>
|
||||||
<UInput v-model="formData.street" placeholder="Enter street" name="street" class="w-full" />
|
<template #body>
|
||||||
</div>
|
<div class="flex flex-col gap-5">
|
||||||
<div>
|
<USelectMenu v-model="selectedCountry" :items="countries" class="w-full"
|
||||||
<label class="block text-sm font-medium text-black dark:text-white mb-1">Zip Code *</label>
|
@update:model-value="onCountryChange" :searchInput="false">
|
||||||
<UInput v-model="formData.zipCode" placeholder="Enter zip code" name="zipCode"
|
<template #default>
|
||||||
class="w-full" />
|
<div class="flex flex-col items-start leading-tight">
|
||||||
</div>
|
<span class="text-xs text-gray-400">{{ t('Country') }}</span>
|
||||||
<div>
|
<span v-if="selectedCountry" class="font-medium text-black dark:text-white">
|
||||||
<label class="block text-sm font-medium text-black dark:text-white mb-1">City *</label>
|
{{ selectedCountry.name }}
|
||||||
<UInput v-model="formData.city" placeholder="Enter city" name="city" class="w-full" />
|
</span>
|
||||||
</div>
|
<span v-else class="text-gray-400">{{ t('Select country') }}</span>
|
||||||
<div>
|
</div>
|
||||||
<label class="block text-sm font-medium text-black dark:text-white mb-1">Country *</label>
|
</template>
|
||||||
<UInput v-model="formData.country" placeholder="Enter country" name="country"
|
<template #item-leading="{ item }">
|
||||||
class="w-full" />
|
<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" />
|
||||||
|
</UFormField>
|
||||||
|
|
||||||
|
<div class="flex justify-end gap-2 pt-2">
|
||||||
|
<UButton variant="outline" color="neutral" @click="showModal = false">
|
||||||
|
{{ t('Cancel') }}
|
||||||
|
</UButton>
|
||||||
|
<UButton type="submit" color="info">
|
||||||
|
{{ t('Save') }}
|
||||||
|
</UButton>
|
||||||
</div>
|
</div>
|
||||||
</UForm>
|
</UForm>
|
||||||
<div class="flex justify-end gap-2">
|
|
||||||
<UButton variant="outline" color="neutral" @click="closeModal"
|
|
||||||
class="text-black dark:text-white">{{ t('Cancel') }}</UButton>
|
|
||||||
<UButton variant="outline" color="neutral" @click="saveAddress"
|
|
||||||
class="text-white bg-(--accent-blue-light) dark:bg-(--accent-blue-dark) hover:bg-(--accent-blue-dark) dark:hover:bg-(--accent-blue-light)">
|
|
||||||
{{ t('Save') }}</UButton>
|
|
||||||
</div>
|
|
||||||
</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">
|
||||||
</p>
|
{{ t('Are you sure you want to delete this address?') }}
|
||||||
<p class="text-gray-700 dark:text-gray-300">
|
</p>
|
||||||
{{ t('Are you sure you want to delete this address?') }}</p>
|
</div>
|
||||||
</div>
|
</template>
|
||||||
<div class="flex justify-center gap-5">
|
<template #footer>
|
||||||
<UButton variant="outline" color="neutral" @click="showDeleteConfirm = false"
|
<div class="flex justify-center gap-4">
|
||||||
class="dark:text-white text-black">{{ t('Cancel') }}
|
<UButton variant="outline" color="neutral" @click="showDeleteConfirm = false">
|
||||||
</UButton>
|
{{ t('Cancel') }}
|
||||||
<UButton variant="outline" color="neutral" @click="deleteAddress" class="text-red-700">
|
</UButton>
|
||||||
{{ t('Delete') }}</UButton>
|
<UButton variant="outline" color="error" @click="deleteAddress">
|
||||||
</div>
|
{{ t('Delete') }}
|
||||||
|
</UButton>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</UModal>
|
</UModal>
|
||||||
</div>
|
</div>
|
||||||
</component>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, computed, watch } from 'vue'
|
import { ref, reactive, computed } from 'vue'
|
||||||
import { useAddressStore } from '@/stores/customer/address'
|
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
import Default from '@/layouts/default.vue'
|
import { countries } from '@/router/langs'
|
||||||
const addressStore = useAddressStore()
|
import { useAddressStore } from '@/stores/customer/address'
|
||||||
|
import type { Country } from '@/types'
|
||||||
|
import type { Address } from '@/stores/customer/address'
|
||||||
|
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
const searchQuery = ref('')
|
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 formData = ref({ street: '', zipCode: '', city: '', country: '' })
|
const templateLoading = ref(false)
|
||||||
|
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 = ref(addressStore.currentPage)
|
const fieldLabels: Record<string, string> = {
|
||||||
const paginatedAddresses = computed(() => addressStore.paginatedAddresses)
|
recipient: 'Recipient',
|
||||||
const totalItems = computed(() => addressStore.totalItems)
|
street: 'Street',
|
||||||
const pageSize = addressStore.pageSize
|
thoroughfare: 'Street',
|
||||||
|
building_no: 'Building No',
|
||||||
|
building_name: 'Building Name',
|
||||||
|
house_number: 'House Number',
|
||||||
|
orientation_number: 'Orientation Number',
|
||||||
|
apartment_no: 'Apartment No',
|
||||||
|
sub_building: 'Sub Building',
|
||||||
|
postal_code: 'Zip Code',
|
||||||
|
post_town: 'City',
|
||||||
|
city: 'City',
|
||||||
|
county: 'County',
|
||||||
|
region: 'Region',
|
||||||
|
voivodeship: 'Region / Voivodeship',
|
||||||
|
address_line2: 'Address Line 2'
|
||||||
|
}
|
||||||
|
|
||||||
watch(page, (newPage) => addressStore.setPage(newPage))
|
function fieldLabel(key: string) {
|
||||||
watch(searchQuery, (val) => {
|
return t(fieldLabels[key] ?? key.replace(/_/g, ' ').replace(/\b\w/g, (c) => c.toUpperCase()))
|
||||||
addressStore.setSearchQuery(val)
|
|
||||||
})
|
|
||||||
function openCreateModal() {
|
|
||||||
resetForm()
|
|
||||||
isEditing.value = false
|
|
||||||
showModal.value = true
|
|
||||||
}
|
|
||||||
function openEditModal(address: any) {
|
|
||||||
formData.value = {
|
|
||||||
street: address.street,
|
|
||||||
zipCode: address.zipCode,
|
|
||||||
city: address.city,
|
|
||||||
country: address.country
|
|
||||||
}
|
|
||||||
isEditing.value = true
|
|
||||||
editingAddressId.value = address.id
|
|
||||||
showModal.value = true
|
|
||||||
}
|
|
||||||
function resetForm() {
|
|
||||||
formData.value = { street: '', zipCode: '', city: '', country: '' }
|
|
||||||
editingAddressId.value = null
|
|
||||||
}
|
|
||||||
function closeModal() {
|
|
||||||
showModal.value = false
|
|
||||||
resetForm()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function validate() {
|
function validate() {
|
||||||
const errors = []
|
return templateKeys.value
|
||||||
if (!formData.value.street) errors.push({ name: 'street', message: 'Street required' })
|
.filter((key) => !optionalFields.has(key) && !formData[key]?.trim())
|
||||||
if (!formData.value.zipCode) errors.push({ name: 'zipCode', message: 'Zip Code required' })
|
.map((key) => ({ name: key, message: t(`${fieldLabel(key)} is required`) }))
|
||||||
if (!formData.value.city) errors.push({ name: 'city', message: 'City required' })
|
|
||||||
if (!formData.value.country) errors.push({ name: 'country', message: 'Country required' })
|
|
||||||
return errors.length ? errors : null
|
|
||||||
}
|
}
|
||||||
function saveAddress() {
|
|
||||||
if (validate()) return
|
function applyTemplate(tpl: Record<string, string>, existing?: Record<string, string>) {
|
||||||
if (isEditing.value && editingAddressId.value) {
|
Object.keys(formData).forEach((k) => delete formData[k])
|
||||||
addressStore.updateAddress(editingAddressId.value, formData.value)
|
Object.keys(tpl).forEach((k) => {
|
||||||
|
formData[k] = existing?.[k] ?? ''
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function openModal(addr?: Address) {
|
||||||
|
template.value = {}
|
||||||
|
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 {
|
||||||
addressStore.addAddress(formData.value)
|
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
|
||||||
}
|
}
|
||||||
function deleteAddress() {
|
|
||||||
if (addressToDelete.value) {
|
async function deleteAddress() {
|
||||||
addressStore.deleteAddress(addressToDelete.value)
|
if (deleteId.value) await store.deleteAddress(deleteId.value)
|
||||||
}
|
|
||||||
showDeleteConfirm.value = false
|
showDeleteConfirm.value = false
|
||||||
addressToDelete.value = null
|
deleteId.value = null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
store.fetchAddresses()
|
||||||
</script>
|
</script>
|
||||||
14
bo/src/components/customer/PageCart.vue
Normal file
14
bo/src/components/customer/PageCart.vue
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<template>
|
||||||
|
<div class="flex flex-col gap-5 md:gap-10">
|
||||||
|
<h1 class="text-2xl font-bold text-black dark:text-white">
|
||||||
|
Shopping Cart
|
||||||
|
</h1>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { useCartStore } from '@/stores/customer/cart';
|
||||||
|
|
||||||
|
const cartStore =useCartStore()
|
||||||
|
|
||||||
|
</script>
|
||||||
@@ -1,204 +1,105 @@
|
|||||||
<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">{{ 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>
|
||||||
<div v-if="cartStore.items.length > 0">
|
</div>
|
||||||
<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>
|
|
||||||
<p class="text-black dark:text-white text-sm font-medium">{{ item.name }}</p>
|
|
||||||
<p class="text-black dark:text-white">${{ item.price.toFixed(2) }}</p>
|
|
||||||
<p class="text-black dark:text-white font-medium">${{ (item.price * item.quantity).toFixed(2)
|
|
||||||
}}</p>
|
|
||||||
|
|
||||||
<div class="flex items-center justify-end gap-10">
|
<div class="w-full">
|
||||||
<UInputNumber v-model="item.quantity" :min="1"
|
<div
|
||||||
@update:model-value="(val: number) => cartStore.updateQuantity(item.id, val)" />
|
class="bg-(--second-light) dark:bg-(--main-dark) rounded-lg border border-(--border-light) dark:border-(--border-dark) overflow-hidden">
|
||||||
<div class="flex justify-center">
|
<h2
|
||||||
<button @click="removeItem(item.id)"
|
class="text-lg font-semibold text-black dark:text-white p-4 border-b border-(--border-light) dark:border-(--border-dark)">
|
||||||
class="p-2 text-red-500 bg-red-100 dark:bg-(--main-dark) rounded transition-colors"
|
{{ t('Your Carts') }}
|
||||||
:title="t('Remove')">
|
</h2>
|
||||||
<UIcon name="material-symbols:delete" class="text-[20px]" />
|
<div v-if="cartStore.carts?.length > 0"
|
||||||
</button>
|
class="divide-y divide-(--border-light) dark:divide-(--border-dark)">
|
||||||
</div>
|
<div v-for="cart in cartStore.carts" :key="cart.cart_id"
|
||||||
|
@click="cartStore.setActiveCart(cart.cart_id)"
|
||||||
|
class="p-4 cursor-pointer flex gap-2 items-center justify-between" :class="cartStore.activeCartId === cart.cart_id
|
||||||
|
? 'bg-blue-50 dark:bg-blue-900/20'
|
||||||
|
: 'hover:bg-gray-50 dark:hover:bg-gray-800 border-l-4 border-transparent'">
|
||||||
|
<div class="flex-1 min-w-0">
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<p class="text-black dark:text-white font-medium truncate cursor-pointer"
|
||||||
|
@click="openCart(cart)">{{ cart.name }}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<input type="checkbox" :checked="cartStore.activeCartId === cart.cart_id"
|
||||||
|
@change="toggleCart(cart.cart_id)" />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<div v-else class="p-8 text-center flex items-center justify-center">
|
||||||
</div>
|
<UIcon name="mdi:cart-outline" class="text-4xl text-gray-300 dark:text-gray-600 mb-2" />
|
||||||
<div v-else class="p-8 text-center">
|
<p class="text-gray-500 dark:text-gray-400">{{ t('No carts yet') }}</p>
|
||||||
<UIcon name="mdi:cart-outline" class="text-6xl text-gray-300 dark:text-gray-600 mb-4" />
|
|
||||||
<p class="text-gray-500 dark:text-gray-400">{{ t('Your cart is empty') }}</p>
|
|
||||||
<RouterLink :to="{
|
|
||||||
name: 'customer-product', params: {
|
|
||||||
product_id: '51'
|
|
||||||
}
|
|
||||||
}" class="inline-block mt-4 text-(--text-sky-light) dark:text-(--text-sky-dark) hover:underline">
|
|
||||||
{{ t('Continue Shopping') }}
|
|
||||||
</RouterLink>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="lg:w-80">
|
|
||||||
<div
|
|
||||||
class="bg-(--second-light) dark:bg-(--main-dark) rounded-lg border border-(--border-light) dark:border-(--border-dark) p-6 sticky top-24">
|
|
||||||
<h2 class="text-lg font-semibold text-black dark:text-white mb-4">{{ t('Order Summary') }}</h2>
|
|
||||||
<div class="space-y-3 border-b border-(--border-light) dark:border-(--border-dark) pb-4 mb-4">
|
|
||||||
<div class="flex justify-between">
|
|
||||||
<span class="text-gray-600 dark:text-gray-400">{{ t('Products total') }}</span>
|
|
||||||
<span class="text-black dark:text-white">${{ cartStore.productsTotal.toFixed(2) }}</span>
|
|
||||||
</div>
|
|
||||||
<div class="flex justify-between">
|
|
||||||
<span class="text-gray-600 dark:text-gray-400">{{ t('Shipping') }}</span>
|
|
||||||
<span class="text-black dark:text-white">
|
|
||||||
{{ cartStore.shippingCost > 0 ? `$${cartStore.shippingCost.toFixed(2)}` : t('Free') }}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div class="flex justify-between">
|
|
||||||
<span class="text-gray-600 dark:text-gray-400">{{ t('VAT') }} ({{ (cartStore.vatRate * 100).toFixed(0)
|
|
||||||
}}%)</span>
|
|
||||||
<span class="text-black dark:text-white">${{ cartStore.vatAmount.toFixed(2) }}</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="flex justify-between mb-6">
|
|
||||||
<span class="text-black dark:text-white font-semibold text-lg">{{ t('Total') }}</span>
|
|
||||||
<span class="text-(--text-sky-light) dark:text-(--text-sky-dark) font-bold text-lg">${{
|
|
||||||
cartStore.orderTotal.toFixed(2) }}</span>
|
|
||||||
</div>
|
|
||||||
<div class="flex flex-col gap-3">
|
|
||||||
<UButton block color="primary" @click="placeOrder" :disabled="!canPlaceOrder"
|
|
||||||
class="bg-(--accent-blue-light) dark:bg-(--accent-blue-dark) text-white hover:bg-(--accent-blue-dark) dark:hover:bg-(--accent-blue-light) disabled:opacity-50 disabled:cursor-not-allowed">
|
|
||||||
{{ t('Place Order') }}
|
|
||||||
</UButton>
|
|
||||||
<UButton block variant="outline" color="neutral" @click="cancelOrder"
|
|
||||||
class="text-black dark:text-white border-(--border-light) dark:border-(--border-dark) hover:bg-gray-100 dark:hover:bg-gray-700">
|
|
||||||
{{ t('Cancel') }}
|
|
||||||
</UButton>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-5 md:gap-10">
|
|
||||||
<div class="flex-1">
|
|
||||||
<div
|
|
||||||
class="bg-(--second-light) dark:bg-(--main-dark) rounded-lg border border-(--border-light) dark:border-(--border-dark) p-6">
|
|
||||||
<h2 class="text-lg font-semibold text-black dark:text-white mb-4">{{ t('Select Delivery Address') }}</h2>
|
|
||||||
<div class="mb-4">
|
|
||||||
<UInput v-model="addressSearchQuery" type="text" :placeholder="t('Search address')"
|
|
||||||
class="w-full bg-white dark:bg-gray-800 text-black dark:text-white" />
|
|
||||||
</div>
|
|
||||||
<div v-if="addressStore.filteredAddresses.length > 0" class="space-y-3">
|
|
||||||
<label v-for="address in addressStore.filteredAddresses" :key="address.id"
|
|
||||||
class="flex items-start gap-3 p-4 border rounded-lg cursor-pointer transition-colors" :class="cartStore.selectedAddressId === address.id
|
|
||||||
? 'border-(--accent-blue-light) dark:border-(--accent-blue-dark) bg-blue-50 dark:bg-blue-900/20'
|
|
||||||
: 'border-(--border-light) dark:border-(--border-dark) hover:border-gray-400'">
|
|
||||||
<input type="radio" :value="address.id" v-model="selectedAddress"
|
|
||||||
class="mt-1 w-4 h-4 text-(--text-sky-light) dark:text-(--text-sky-dark)" />
|
|
||||||
<div class="flex-1">
|
|
||||||
<p class="text-black dark:text-white font-medium">{{ address.street }}</p>
|
|
||||||
<p class="text-gray-600 dark:text-gray-400 text-sm">{{ address.zipCode }}, {{ address.city }}</p>
|
|
||||||
<p class="text-gray-600 dark:text-gray-400 text-sm">{{ address.country }}</p>
|
|
||||||
</div>
|
</div>
|
||||||
</label>
|
|
||||||
</div>
|
</div>
|
||||||
<div v-else class="text-center py-6">
|
|
||||||
<UIcon name="mdi:map-marker-outline" class="text-4xl text-gray-400 mb-2" />
|
|
||||||
<p class="text-gray-500 dark:text-gray-400">{{ t('No addresses found') }}</p>
|
|
||||||
<RouterLink :to="{ name: 'addresses' }"
|
|
||||||
class="inline-block mt-2 text-(--text-sky-light) dark:text-(--text-sky-dark) hover:underline">
|
|
||||||
{{ t('Add Address') }}
|
|
||||||
</RouterLink>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="flex-1">
|
|
||||||
<div
|
|
||||||
class="bg-(--second-light) dark:bg-(--main-dark) rounded-lg border border-(--border-light) dark:border-(--border-dark) p-6">
|
|
||||||
<h2 class="text-lg font-semibold text-black dark:text-white mb-4">{{ t('Delivery Method') }}</h2>
|
|
||||||
<div class="space-y-3">
|
|
||||||
<label v-for="method in cartStore.deliveryMethods" :key="method.id"
|
|
||||||
class="flex items-center gap-3 p-4 border rounded-lg cursor-pointer transition-colors" :class="cartStore.selectedDeliveryMethodId === method.id
|
|
||||||
? 'border-(--accent-blue-light) dark:border-(--accent-blue-dark) bg-blue-50 dark:bg-blue-900/20'
|
|
||||||
: 'border-(--border-light) dark:border-(--border-dark) hover:border-gray-400'">
|
|
||||||
<input type="radio" :value="method.id" v-model="selectedDeliveryMethod"
|
|
||||||
class="w-4 h-4 text-(--text-sky-light) dark:text-(--text-sky-dark)" />
|
|
||||||
<div class="flex-1">
|
|
||||||
<div class="flex justify-between items-center">
|
|
||||||
<span class="text-black dark:text-white font-medium">{{ method.name }}</span>
|
|
||||||
<span class="text-(--text-sky-light) dark:text-(--text-sky-dark) font-medium">
|
|
||||||
{{ method.price > 0 ? `$${method.price.toFixed(2)}` : t('Free') }}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<p class="text-gray-500 dark:text-gray-400 text-sm">{{ method.description }}</p>
|
|
||||||
</div>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</component>
|
|
||||||
|
<UModal v-model:open="showCreateModal">
|
||||||
|
<template #header>
|
||||||
|
<h3 class="text-lg font-semibold text-black dark:text-white">{{ t('Create New Cart') }}</h3>
|
||||||
|
</template>
|
||||||
|
<template #body>
|
||||||
|
<div class="flex flex-col gap-4">
|
||||||
|
<UInput v-model="newCartName" :placeholder="t('Cart name')"
|
||||||
|
class="w-full bg-white dark:bg-gray-800 text-black dark:text-white" />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<template #footer>
|
||||||
|
<div class="flex justify-end gap-2">
|
||||||
|
<UButton variant="outline" color="neutral" @click="showCreateModal = false">
|
||||||
|
{{ t('Cancel') }}
|
||||||
|
</UButton>
|
||||||
|
<UButton color="primary" @click="createCart" :disabled="!newCartName.trim()"
|
||||||
|
class="bg-(--accent-blue-light) dark:bg-(--accent-blue-dark) text-white">
|
||||||
|
{{ t('Create') }}
|
||||||
|
</UButton>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</UModal>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, computed, watch } from 'vue'
|
import { ref, onMounted } from 'vue'
|
||||||
import { useCartStore } from '@/stores/customer/cart'
|
import { useCartStore } from '@/stores/customer/cart'
|
||||||
import { useAddressStore } from '@/stores/customer/address'
|
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
import Default from '@/layouts/default.vue'
|
|
||||||
const cartStore = useCartStore()
|
|
||||||
const addressStore = useAddressStore()
|
|
||||||
const { t } = useI18n()
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
const selectedAddress = ref<number | null>(cartStore.selectedAddressId)
|
const cartStore = useCartStore()
|
||||||
const selectedDeliveryMethod = ref<number | null>(cartStore.selectedDeliveryMethodId)
|
const { t } = useI18n()
|
||||||
const addressSearchQuery = ref('')
|
|
||||||
|
|
||||||
watch(addressSearchQuery, (val) => {
|
const showCreateModal = ref(false)
|
||||||
addressStore.setSearchQuery(val)
|
const newCartName = ref('')
|
||||||
})
|
|
||||||
|
|
||||||
watch(selectedAddress, (newValue) => {
|
async function createCart() {
|
||||||
cartStore.setSelectedAddress(newValue)
|
await cartStore.addNewCart(newCartName.value)
|
||||||
})
|
newCartName.value = ''
|
||||||
|
showCreateModal.value = false
|
||||||
watch(selectedDeliveryMethod, (newValue) => {
|
|
||||||
if (newValue) {
|
|
||||||
cartStore.setDeliveryMethod(newValue)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
const canPlaceOrder = computed(() => {
|
|
||||||
return cartStore.items.length > 0 &&
|
|
||||||
cartStore.selectedAddressId !== null &&
|
|
||||||
cartStore.selectedDeliveryMethodId !== null
|
|
||||||
})
|
|
||||||
function removeItem(itemId: number) {
|
|
||||||
cartStore.removeItem(itemId)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function placeOrder() {
|
onMounted(() => {
|
||||||
if (canPlaceOrder.value) {
|
cartStore.fetchCarts()
|
||||||
console.log('Placing order...')
|
})
|
||||||
alert(t('Order placed successfully!'))
|
|
||||||
cartStore.clearCart()
|
function openCart(cart) {
|
||||||
router.push({ name: 'home' })
|
router.push({ name: 'customer-cart', params: { id: cart.cart_id } });
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function cancelOrder() {
|
function toggleCart(cartId: number) {
|
||||||
router.back()
|
if (cartStore.activeCartId === cartId) {
|
||||||
|
cartStore.setActiveCart(null)
|
||||||
|
} else {
|
||||||
|
cartStore.setActiveCart(cartId)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
@@ -1,9 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<component :is="Default || 'div'">
|
Orders page
|
||||||
Orders page
|
</template>
|
||||||
</component>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import Default from '@/layouts/default.vue'
|
|
||||||
</script>
|
</script>
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<component :is="Default || 'div'">
|
<div class="">
|
||||||
<div class="">
|
|
||||||
<div class="flex md:flex-row flex-col justify-between gap-8 my-6">
|
<div class="flex md:flex-row flex-col justify-between gap-8 my-6">
|
||||||
<div class="flex-1">
|
<div class="flex-1">
|
||||||
<div
|
<div
|
||||||
@@ -79,14 +78,12 @@
|
|||||||
<hr class="border-t border-(--border-light) dark:border-(--border-dark) mb-8" />
|
<hr class="border-t border-(--border-light) dark:border-(--border-dark) mb-8" />
|
||||||
<ProductVariants />
|
<ProductVariants />
|
||||||
</div>
|
</div>
|
||||||
</component>
|
</template>
|
||||||
</template>
|
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, computed } from 'vue'
|
import { ref, computed } from 'vue'
|
||||||
import ProductCustomization from './components/ProductCustomization.vue'
|
import ProductCustomization from './components/ProductCustomization.vue'
|
||||||
import ProductVariants from './components/ProductVariants.vue'
|
import ProductVariants from './components/ProductVariants.vue'
|
||||||
import Default from '@/layouts/default.vue'
|
|
||||||
import { useFetchJson } from '@/composable/useFetchJson'
|
import { useFetchJson } from '@/composable/useFetchJson'
|
||||||
import { useRoute } from 'vue-router'
|
import { useRoute } from 'vue-router'
|
||||||
interface Color {
|
interface Color {
|
||||||
@@ -172,21 +169,21 @@ if (productData.colors.length > 0) {
|
|||||||
|
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
|
|
||||||
async function toggleFavorite() {
|
// async function toggleFavorite() {
|
||||||
const url = `/api/v1/restricted/product/favorite/${route.params.product_id}`
|
// const url = `/api/v1/restricted/product/favorite/${route.params.product_id}`
|
||||||
|
|
||||||
try {
|
// try {
|
||||||
if (!productData.is_favorite) {
|
// if (!productData.is_favorite) {
|
||||||
await useFetchJson(url, { method: 'POST' })
|
// await useFetchJson(url, { method: 'POST' })
|
||||||
} else {
|
// } else {
|
||||||
await useFetchJson(url, { method: 'DELETE' })
|
// await useFetchJson(url, { method: 'DELETE' })
|
||||||
}
|
// }
|
||||||
|
|
||||||
productData.is_favorite = !productData.is_favorite
|
// productData.is_favorite = !productData.is_favorite
|
||||||
} catch (e: unknown) {
|
// } catch (e: unknown) {
|
||||||
console.error(e)
|
// console.error(e)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<suspense>
|
<suspense>
|
||||||
<component :is="Default || 'div'">
|
<div class="">
|
||||||
<div class="">
|
|
||||||
<!-- <UNavigationMenu orientation="vertical" :items="listing" class="data-[orientation=vertical]:w-48">
|
<!-- <UNavigationMenu orientation="vertical" :items="listing" class="data-[orientation=vertical]:w-48">
|
||||||
<template #item="{ item, active }">
|
<template #item="{ item, active }">
|
||||||
<div class="flex items-center gap-2 px-3 py-2">
|
<div class="flex items-center gap-2 px-3 py-2">
|
||||||
@@ -39,18 +38,18 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</component>
|
</suspense>
|
||||||
</suspense>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, watch, h, resolveComponent, computed } from 'vue'
|
import { ref, watch, h, resolveComponent, computed } from 'vue'
|
||||||
import Default from '@/layouts/default.vue'
|
|
||||||
import { useRoute, useRouter } from 'vue-router'
|
import { useRoute, useRouter } from 'vue-router'
|
||||||
import type { TableColumn } from '@nuxt/ui'
|
import type { TableColumn } from '@nuxt/ui'
|
||||||
import CategoryMenu from '../inner/CategoryMenu.vue'
|
import CategoryMenu from '../inner/CategoryMenu.vue'
|
||||||
import { useCustomerProductStore } from '@/stores/customer/customer-product'
|
import { useCustomerProductStore } from '@/stores/customer/customer-product'
|
||||||
import type { Product } from '@/stores/customer/customer-product'
|
import type { Product } from '@/stores/customer/customer-product'
|
||||||
|
import { useCartStore } from '@/stores/customer/cart'
|
||||||
|
import { useToast } from '@nuxt/ui/runtime/composables/useToast.js'
|
||||||
|
|
||||||
|
|
||||||
const customerProductStore = useCustomerProductStore()
|
const customerProductStore = useCustomerProductStore()
|
||||||
@@ -310,10 +309,9 @@ const columns: TableColumn<Product>[] = [
|
|||||||
cell: ({ row }) => {
|
cell: ({ row }) => {
|
||||||
return h(UButton, {
|
return h(UButton, {
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
console.log('Clicked', row.original)
|
addToCart(row.original.product_id)
|
||||||
},
|
},
|
||||||
color: selectedCount.value.product_id !== row.original.product_id ? 'info' : 'primary',
|
color: selectedCount.value.product_id !== row.original.product_id ? 'info' : 'primary',
|
||||||
disabled: selectedCount.value.product_id !== row.original.product_id,
|
|
||||||
variant: 'solid'
|
variant: 'solid'
|
||||||
}, 'Add to cart')
|
}, 'Add to cart')
|
||||||
},
|
},
|
||||||
@@ -349,7 +347,7 @@ const columns: TableColumn<Product>[] = [
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
const columnsChild: TableColumn<Payment>[] = [
|
const columnsChild: TableColumn<Product>[] = [
|
||||||
{
|
{
|
||||||
accessorKey: 'product_id',
|
accessorKey: 'product_id',
|
||||||
header: '',
|
header: '',
|
||||||
@@ -405,7 +403,7 @@ const columnsChild: TableColumn<Payment>[] = [
|
|||||||
cell: ({ row }) => {
|
cell: ({ row }) => {
|
||||||
return h(UButton, {
|
return h(UButton, {
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
console.log('Clicked', row.original)
|
addToCart(row.original.product_id)
|
||||||
},
|
},
|
||||||
color: selectedCount.value.product_id !== row.original.product_id ? 'info' : 'primary',
|
color: selectedCount.value.product_id !== row.original.product_id ? 'info' : 'primary',
|
||||||
disabled: selectedCount.value.product_id !== row.original.product_id,
|
disabled: selectedCount.value.product_id !== row.original.product_id,
|
||||||
@@ -426,9 +424,47 @@ const columnsChild: TableColumn<Payment>[] = [
|
|||||||
variant: 'soft'
|
variant: 'soft'
|
||||||
}, () => 'Show product')
|
}, () => 'Show product')
|
||||||
},
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: 'counta',
|
||||||
|
header: '',
|
||||||
|
cell: ({ row }) => {
|
||||||
|
return h(UIcon, {
|
||||||
|
onClick: () => customerProductStore.toggleFavorite(row.original),
|
||||||
|
class: [
|
||||||
|
'cursor-pointer text-[20px] transition-transform duration-200 hover:scale-125',
|
||||||
|
row.original.is_favorite ? 'text-red-500' : 'text-blue-500'
|
||||||
|
],
|
||||||
|
name: 'material-symbols:favorite',
|
||||||
|
variant: 'soft',
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
const cartStore = useCartStore()
|
||||||
|
const toast = useToast()
|
||||||
|
async function addToCart(product_id: number) {
|
||||||
|
if (!cartStore.activeCartId) {
|
||||||
|
toast.add({
|
||||||
|
title: "No cart selected",
|
||||||
|
description: "Please select a cart before adding products",
|
||||||
|
icon: "i-heroicons-exclamation-triangle",
|
||||||
|
duration: 5000
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const count = selectedCount.value.count || 1
|
||||||
|
await cartStore.addProduct(product_id, count)
|
||||||
|
|
||||||
|
toast.add({
|
||||||
|
title: "Product added to cart",
|
||||||
|
description: `Quantity: ${count}`,
|
||||||
|
icon: "i-heroicons-check-circle",
|
||||||
|
duration: 5000
|
||||||
|
})
|
||||||
|
}
|
||||||
watch(
|
watch(
|
||||||
() => route.query,
|
() => route.query,
|
||||||
() => {
|
() => {
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<component :is="Default || 'div'">
|
<div class="">
|
||||||
<div class="">
|
|
||||||
<div class="flex flex-col gap-5 mb-6">
|
<div class="flex flex-col gap-5 mb-6">
|
||||||
<h1 class="text-2xl font-bold text-black dark:text-white">{{ t('Customer Data') }}</h1>
|
<h1 class="text-2xl font-bold text-black dark:text-white">{{ t('Customer Data') }}</h1>
|
||||||
|
|
||||||
@@ -97,8 +96,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</component>
|
</template>
|
||||||
</template>
|
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed } from 'vue'
|
import { computed } from 'vue'
|
||||||
@@ -106,7 +104,6 @@ import { useRouter } from 'vue-router'
|
|||||||
import { useCustomerStore } from '@/stores/customer'
|
import { useCustomerStore } from '@/stores/customer'
|
||||||
import { useAddressStore } from '@/stores/customer/address'
|
import { useAddressStore } from '@/stores/customer/address'
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
import Default from '@/layouts/default.vue'
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const customerStore = useCustomerStore()
|
const customerStore = useCustomerStore()
|
||||||
const addressStore = useAddressStore()
|
const addressStore = useAddressStore()
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<component :is="Default || 'div'">
|
<div class="">
|
||||||
<div class="">
|
|
||||||
<div class="max-w-2xl mx-auto">
|
<div class="max-w-2xl mx-auto">
|
||||||
<div class="flex flex-col gap-5 mb-6">
|
<div class="flex flex-col gap-5 mb-6">
|
||||||
<h1 class="text-2xl font-bold text-black dark:text-white">{{ t('Create Account') }}</h1>
|
<h1 class="text-2xl font-bold text-black dark:text-white">{{ t('Create Account') }}</h1>
|
||||||
@@ -109,8 +108,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</component>
|
</template>
|
||||||
</template>
|
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, watch } from 'vue'
|
import { ref, watch } from 'vue'
|
||||||
@@ -119,7 +117,6 @@ import { useCustomerStore } from '@/stores/customer'
|
|||||||
import { useAddressStore } from '@/stores/customer/address'
|
import { useAddressStore } from '@/stores/customer/address'
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
import { useCartStore } from '@/stores/customer/cart'
|
import { useCartStore } from '@/stores/customer/cart'
|
||||||
import Default from '@/layouts/default.vue'
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const customerStore = useCustomerStore()
|
const customerStore = useCustomerStore()
|
||||||
const addressStore = useAddressStore()
|
const addressStore = useAddressStore()
|
||||||
|
|||||||
158
bo/src/components/customer/PageSearchProducts.vue
Normal file
158
bo/src/components/customer/PageSearchProducts.vue
Normal file
@@ -0,0 +1,158 @@
|
|||||||
|
<template>
|
||||||
|
<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>
|
||||||
|
|
||||||
|
<div class="w-full max-w-4xl">
|
||||||
|
<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!' }" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="loading" class="mt-6">
|
||||||
|
Loading...
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<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
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { useFetchJson } from '@/composable/useFetchJson'
|
||||||
|
import { ref, watch, computed, resolveComponent } from 'vue'
|
||||||
|
import { useRoute, useRouter } from 'vue-router'
|
||||||
|
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 products = ref<Product[]>([])
|
||||||
|
const loading = ref(false)
|
||||||
|
const error = ref<string | null>(null)
|
||||||
|
|
||||||
|
|
||||||
|
async function fetchProducts() {
|
||||||
|
if (!searchQuery.value.trim()) {
|
||||||
|
products.value = []
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
loading.value = true
|
||||||
|
error.value = null
|
||||||
|
|
||||||
|
try {
|
||||||
|
const query = `name=~${searchQuery.value.trim()}`
|
||||||
|
|
||||||
|
const result = await useFetchJson(
|
||||||
|
`/api/v1/restricted/product/list?${query}`
|
||||||
|
)
|
||||||
|
|
||||||
|
products.value = result.items || result
|
||||||
|
} catch (e) {
|
||||||
|
error.value = 'Failed to load products'
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const debouncedFetch = debounce(fetchProducts, 400)
|
||||||
|
|
||||||
|
watch(searchQuery, () => {
|
||||||
|
debouncedFetch()
|
||||||
|
})
|
||||||
|
|
||||||
|
const route = useRoute()
|
||||||
|
const router = useRouter()
|
||||||
|
|
||||||
|
const sortField = computed({
|
||||||
|
get: () => [
|
||||||
|
route.query.sort as string | undefined,
|
||||||
|
route.query.direction as 'asc' | 'desc' | undefined
|
||||||
|
],
|
||||||
|
set: ([sort]: [string, 'asc' | 'desc']) => {
|
||||||
|
const query = { ...route.query, sort, direction: 'asc' }
|
||||||
|
router.push({ query })
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
function getIcon(name: string) {
|
||||||
|
if (sortField.value[0] === name) {
|
||||||
|
return sortField.value[1] === 'asc'
|
||||||
|
? 'i-lucide-arrow-up-narrow-wide'
|
||||||
|
: 'i-lucide-arrow-down-wide-narrow'
|
||||||
|
}
|
||||||
|
return 'i-lucide-arrow-up-down'
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const UInput = resolveComponent('UInput')
|
||||||
|
const UButton = resolveComponent('UButton')
|
||||||
|
const UIcon = resolveComponent('UIcon')
|
||||||
|
|
||||||
|
const columns: TableColumn<Product>[] = [
|
||||||
|
{
|
||||||
|
accessorKey: 'product_id',
|
||||||
|
header: 'ID',
|
||||||
|
cell: ({ row }) => `#${row.getValue('product_id')}`
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: 'image_link',
|
||||||
|
header: 'Image',
|
||||||
|
cell: ({ row }) =>
|
||||||
|
h('img', {
|
||||||
|
src: row.getValue('image_link'),
|
||||||
|
style: 'width:40px;height:40px;object-fit:cover;',
|
||||||
|
onError: (e: Event) => {
|
||||||
|
(e.target as HTMLImageElement).src = errorImg
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: 'name',
|
||||||
|
header: 'Name',
|
||||||
|
cell: ({ row }) => row.getValue('name')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: 'quantity',
|
||||||
|
header: 'In stock',
|
||||||
|
cell: ({ row }) => row.getValue('quantity')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: 'action',
|
||||||
|
header: '',
|
||||||
|
cell: ({ row }) =>
|
||||||
|
h(
|
||||||
|
UButton,
|
||||||
|
{
|
||||||
|
onClick: () =>
|
||||||
|
router.push({
|
||||||
|
name: 'admin-product-details',
|
||||||
|
params: {
|
||||||
|
product_id: row.original.product_id,
|
||||||
|
link_rewrite: row.original.link_rewrite
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
color: 'info',
|
||||||
|
variant: 'soft'
|
||||||
|
},
|
||||||
|
() => 'Show product'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
]
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
input::placeholder {
|
||||||
|
color: #9ca3af;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -1,9 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<component :is="Default || 'div'">
|
Statistic page
|
||||||
Statistic page
|
</template>
|
||||||
</component>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import Default from '@/layouts/default.vue'
|
|
||||||
</script>
|
</script>
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<component :is="Default || 'div'">
|
<div class="p-4">
|
||||||
<div class="p-4">
|
|
||||||
<div v-if="loading" class="flex justify-center py-8">
|
<div v-if="loading" class="flex justify-center py-8">
|
||||||
<ULoader />
|
<ULoader />
|
||||||
</div>
|
</div>
|
||||||
@@ -25,13 +24,11 @@
|
|||||||
</template>
|
</template>
|
||||||
</UTree>
|
</UTree>
|
||||||
</div>
|
</div>
|
||||||
</component>
|
</template>
|
||||||
</template>
|
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, computed } from 'vue'
|
import { ref, computed } from 'vue'
|
||||||
import { useFetchJson } from '@/composable/useFetchJson'
|
import { useFetchJson } from '@/composable/useFetchJson'
|
||||||
import Default from '@/layouts/default.vue'
|
|
||||||
|
|
||||||
interface FileItemRaw {
|
interface FileItemRaw {
|
||||||
Name: string
|
Name: string
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<UNavigationMenu orientation="vertical" type="single" :items="items" class="data-[orientation=vertical]:w-72" :ui="{
|
<UNavigationMenu orientation="vertical" type="single" :items="items" class="data-[orientation=vertical]:w-72" :ui="{
|
||||||
root:''
|
root: ''
|
||||||
}"/>
|
}" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
@@ -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) {
|
||||||
|
|||||||
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>
|
||||||
@@ -34,10 +34,33 @@
|
|||||||
|
|
||||||
<div class="flex-1 flex flex-col">
|
<div class="flex-1 flex flex-col">
|
||||||
<div class="flex h-(--ui-header-height) shrink-0 items-center justify-between px-4 border-b border-default">
|
<div class="flex h-(--ui-header-height) shrink-0 items-center justify-between px-4 border-b border-default">
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-5">
|
||||||
<UButton icon="i-lucide-panel-left" color="neutral" variant="ghost" aria-label="Toggle sidebar"
|
<div class="flex items-center gap-2">
|
||||||
@click="open = !open" />
|
<UButton icon="i-lucide-panel-left" color="neutral" variant="ghost" aria-label="Toggle sidebar"
|
||||||
<span class="text-[20px] font-medium">{{ pageTitle }}</span>
|
@click="open = !open" />
|
||||||
|
<span class="text-[20px] font-medium">{{ pageTitle }}</span>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<div v-if="cartStore.activeCart"
|
||||||
|
class="flex items-center gap-2 p-1 rounded-md bg-gray-100 dark:bg-gray-800">
|
||||||
|
<UIcon name="i-lucide-shopping-cart" />
|
||||||
|
|
||||||
|
<div class="flex gap-2">
|
||||||
|
<p class="text-sm font-medium">
|
||||||
|
{{ cartStore.activeCart.name }}-
|
||||||
|
<span class="text-xs text-gray-400">
|
||||||
|
ID: {{ cartStore.activeCart.cart_id }}
|
||||||
|
</span>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<span v-else class="text-sm text-red-400 flex gap-1 items-center">
|
||||||
|
<UIcon name="i-lucide-shopping-cart" />
|
||||||
|
No cart selected
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="hidden md:flex items-center gap-12">
|
<div class="hidden md:flex items-center gap-12">
|
||||||
@@ -50,7 +73,7 @@
|
|||||||
<button v-if="authStore.isAuthenticated" @click="authStore.logout()"
|
<button v-if="authStore.isAuthenticated" @click="authStore.logout()"
|
||||||
class="flex gap-2 items-center px-3 py-1.5 text-sm font-medium text-black dark:text-white hover:text-black dark:hover:text-white hover:bg-gray-100 dark:hover:bg-gray-600 rounded-lg transition-colors border border-(--border-light) dark:border-(--border-dark) whitespace-nowrap">
|
class="flex gap-2 items-center px-3 py-1.5 text-sm font-medium text-black dark:text-white hover:text-black dark:hover:text-white hover:bg-gray-100 dark:hover:bg-gray-600 rounded-lg transition-colors border border-(--border-light) dark:border-(--border-dark) whitespace-nowrap">
|
||||||
{{ $t('general.logout') }}
|
{{ $t('general.logout') }}
|
||||||
<UIcon name="ic:baseline-logout" class="text-red-700 dark:text-red-500"/>
|
<UIcon name="ic:baseline-logout" class="text-red-700 dark:text-red-500" />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -172,6 +195,7 @@ import LangSwitch from '@/components/inner/LangSwitch.vue'
|
|||||||
import ThemeSwitch from '@/components/inner/ThemeSwitch.vue'
|
import ThemeSwitch from '@/components/inner/ThemeSwitch.vue'
|
||||||
import type { LabelTrans, TopMenuItem } from '@/types'
|
import type { LabelTrans, TopMenuItem } from '@/types'
|
||||||
import { useUserStore } from '@/stores/user'
|
import { useUserStore } from '@/stores/user'
|
||||||
|
import { useCartStore } from '@/stores/customer/cart'
|
||||||
|
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
@@ -181,8 +205,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)
|
||||||
}
|
}
|
||||||
@@ -297,5 +320,11 @@ const userItems = computed<DropdownMenuItem[][]>(() => [
|
|||||||
]
|
]
|
||||||
])
|
])
|
||||||
|
|
||||||
|
const cartStore = useCartStore()
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
cartStore.initCart()
|
||||||
|
})
|
||||||
|
|
||||||
defineShortcuts(extractShortcuts(teamsItems.value))
|
defineShortcuts(extractShortcuts(teamsItems.value))
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -39,7 +39,7 @@
|
|||||||
<UButton icon="i-lucide-panel-left" color="neutral" variant="ghost" aria-label="Toggle sidebar"
|
<UButton icon="i-lucide-panel-left" color="neutral" variant="ghost" aria-label="Toggle sidebar"
|
||||||
@click="open = !open" />
|
@click="open = !open" />
|
||||||
<p class="font-bold text-xl">Customer-Management: <span class="text-[20px] font-medium">{{ pageTitle
|
<p class="font-bold text-xl">Customer-Management: <span class="text-[20px] font-medium">{{ pageTitle
|
||||||
}}</span></p>
|
}}</span></p>
|
||||||
</div>
|
</div>
|
||||||
<div class="hidden md:flex items-center gap-12">
|
<div class="hidden md:flex items-center gap-12">
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
@@ -179,8 +179,7 @@ const router = useRouter()
|
|||||||
|
|
||||||
const menu = ref<TopMenuItem[] | null>(null)
|
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-top-menu?target_user_id=${Id}`)
|
||||||
@@ -191,7 +190,6 @@ async function cmGetTopMenu() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(route)
|
|
||||||
watch(
|
watch(
|
||||||
() => route.params.user_id,
|
() => route.params.user_id,
|
||||||
() => {
|
() => {
|
||||||
|
|||||||
@@ -13,13 +13,30 @@ await getSettings()
|
|||||||
|
|
||||||
const routes = await getRoutes()
|
const routes = await getRoutes()
|
||||||
let newRoutes = []
|
let newRoutes = []
|
||||||
|
|
||||||
|
function getLayoutFromComponent(path: string) {
|
||||||
|
const emptyLayouts = [
|
||||||
|
'LoginView.vue',
|
||||||
|
'RegisterView.vue',
|
||||||
|
'PasswordRecoveryView.vue',
|
||||||
|
'VerifyEmailView.vue',
|
||||||
|
'ResetPasswordForm.vue'
|
||||||
|
]
|
||||||
|
return emptyLayouts.some((name) => path.includes(name)) ? 'empty' : 'default'
|
||||||
|
}
|
||||||
|
|
||||||
for (let r of routes) {
|
for (let r of routes) {
|
||||||
const component = () => import(/* @vite-ignore */ `..${r.component}`)
|
const component = () => import(/* @vite-ignore */ `..${r.component}`)
|
||||||
|
const parsedMeta = r.meta ? JSON.parse(r.meta) : {}
|
||||||
|
const layout = parsedMeta.layout ?? getLayoutFromComponent(r.component)
|
||||||
newRoutes.push({
|
newRoutes.push({
|
||||||
path: r.path,
|
path: r.path,
|
||||||
component,
|
component,
|
||||||
name: r.name,
|
name: r.name,
|
||||||
meta: r.meta ? JSON.parse(r.meta) : {},
|
meta: {
|
||||||
|
...parsedMeta,
|
||||||
|
layout,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,15 +90,19 @@ async function setRoutes() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const importedComponent = (await importer()).default
|
const importedComponent = (await importer()).default
|
||||||
|
const parsedMeta = item.meta ? JSON.parse(item.meta) : {}
|
||||||
|
const layout = parsedMeta.layout ?? getLayoutFromComponent(item.component)
|
||||||
|
|
||||||
router.addRoute('locale', {
|
router.addRoute('locale', {
|
||||||
path: item.path,
|
path: item.path,
|
||||||
component: importedComponent,
|
component: importedComponent,
|
||||||
name: item.name,
|
name: item.name,
|
||||||
meta: item.meta ? JSON.parse(item.meta) : {}
|
meta: {
|
||||||
|
...parsedMeta,
|
||||||
|
layout,
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { settings } from "./settings";
|
|||||||
|
|
||||||
const categoryId = ref()
|
const categoryId = ref()
|
||||||
export const getMenu = async () => {
|
export const getMenu = async () => {
|
||||||
if(!categoryId.value){
|
if (!categoryId.value) {
|
||||||
categoryId.value = settings['app'].category_tree_root_id
|
categoryId.value = settings['app'].category_tree_root_id
|
||||||
}
|
}
|
||||||
const resp = await useFetchJson<MenuItem>(`/api/v1/restricted/menu/get-category-tree?root_category_id=${categoryId.value}`);
|
const resp = await useFetchJson<MenuItem>(`/api/v1/restricted/menu/get-category-tree?root_category_id=${categoryId.value}`);
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user