Compare commits
17 Commits
orders
...
countries_
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2fd9472db1 | ||
| 80a1314dc0 | |||
|
|
100a9f57d4 | ||
| 773e7d3c20 | |||
| 03a0e5ea64 | |||
| ce8c19f715 | |||
| 4edcb0a852 | |||
| a4120dafa2 | |||
| 5e1a8e898c | |||
| 8e3e41d6fe | |||
| b33da9d072 | |||
| ab783b599d | |||
| d173af29fe | |||
| f14d60d67b | |||
| 967b101f9b | |||
| 97ca510b99 | |||
| 83b7cd49dd |
@@ -7,17 +7,18 @@ 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"
|
||||||
|
"git.ma-al.com/goc_daniel/b2b/app/utils/localeExtractor"
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v3"
|
"github.com/gofiber/fiber/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 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")
|
||||||
@@ -25,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]
|
||||||
}
|
}
|
||||||
@@ -43,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
|
||||||
@@ -78,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)
|
||||||
@@ -114,6 +103,18 @@ func AuthMiddleware() fiber.Handler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Authorize() fiber.Handler {
|
||||||
|
return func(c fiber.Ctx) error {
|
||||||
|
_, ok := localeExtractor.GetUserID(c)
|
||||||
|
if !ok {
|
||||||
|
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
|
||||||
|
"error": "not authenticated",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return c.Next()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Webdav
|
// Webdav
|
||||||
func Webdav() fiber.Handler {
|
func Webdav() fiber.Handler {
|
||||||
authService := authService.NewAuthService()
|
authService := authService.NewAuthService()
|
||||||
|
|||||||
@@ -14,4 +14,5 @@ const (
|
|||||||
SearchCreateIndex Permission = "search.create_index"
|
SearchCreateIndex Permission = "search.create_index"
|
||||||
OrdersViewAll Permission = "orders.view_all"
|
OrdersViewAll Permission = "orders.view_all"
|
||||||
OrdersModifyAll Permission = "orders.modify_all"
|
OrdersModifyAll Permission = "orders.modify_all"
|
||||||
|
Teleport Permission = "teleport"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|
||||||
|
|||||||
@@ -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)))
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ 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"
|
||||||
@@ -30,7 +31,7 @@ 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)
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,10 +76,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,12 +84,6 @@ 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 {
|
||||||
|
|||||||
@@ -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())
|
||||||
|
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
@@ -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"
|
||||||
@@ -80,13 +81,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)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,88 +114,3 @@ func (repo *CustomerRepo) Save(customer *model.Customer) error {
|
|||||||
func (repo *CustomerRepo) Create(customer *model.Customer) error {
|
func (repo *CustomerRepo) Create(customer *model.Customer) error {
|
||||||
return db.DB.Create(customer).Error
|
return db.DB.Create(customer).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
// func (repo *CustomerRepo) Search(
|
|
||||||
// customerId uint,
|
|
||||||
// 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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -17,13 +17,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) {
|
||||||
|
|||||||
@@ -102,8 +102,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 {
|
||||||
|
|||||||
@@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,3 +32,5 @@ const WEBDAV_TRIMMED_ROOT = "localhost:3000/api/v1/webdav/storage"
|
|||||||
const NON_ALNUM_REGEX = `[^a-z0-9]+`
|
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]+)*$`
|
||||||
|
|
||||||
|
const UNLOGGED_USER_ROLE_ID = 4
|
||||||
|
|||||||
15
bruno/api_v1/routes/Routes.yml
Normal file
15
bruno/api_v1/routes/Routes.yml
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
info:
|
||||||
|
name: Routes
|
||||||
|
type: http
|
||||||
|
seq: 1
|
||||||
|
|
||||||
|
http:
|
||||||
|
method: GET
|
||||||
|
url: ""
|
||||||
|
auth: inherit
|
||||||
|
|
||||||
|
settings:
|
||||||
|
encodeUrl: true
|
||||||
|
timeout: 0
|
||||||
|
followRedirects: true
|
||||||
|
maxRedirects: 5
|
||||||
7
bruno/api_v1/routes/folder.yml
Normal file
7
bruno/api_v1/routes/folder.yml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
info:
|
||||||
|
name: routes
|
||||||
|
type: folder
|
||||||
|
seq: 10
|
||||||
|
|
||||||
|
request:
|
||||||
|
auth: inherit
|
||||||
@@ -43,7 +43,6 @@ INSERT IGNORE INTO `b2b_top_menu` (`menu_id`, `label`, `parent_id`, `params`, `a
|
|||||||
(9, JSON_COMPACT('{"name":"carts","trans":{"pl":{"label":"Koszyki"},"en":{"label":"Carts"},"de":{"label":"Warenkörbe"}}}'),3,JSON_COMPACT('{"route": {"name": "home", "params":{"locale": ""}}}'),1,1);
|
(9, JSON_COMPACT('{"name":"carts","trans":{"pl":{"label":"Koszyki"},"en":{"label":"Carts"},"de":{"label":"Warenkörbe"}}}'),3,JSON_COMPACT('{"route": {"name": "home", "params":{"locale": ""}}}'),1,1);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- +goose Down
|
-- +goose Down
|
||||||
|
|
||||||
DROP TABLE IF EXISTS b2b_routes;
|
DROP TABLE IF EXISTS b2b_routes;
|
||||||
|
|||||||
@@ -338,6 +338,24 @@ ON b2b_specific_price_customer (b2b_id_customer);
|
|||||||
CREATE INDEX idx_bsp_country_rel
|
CREATE INDEX idx_bsp_country_rel
|
||||||
ON b2b_specific_price_country (b2b_id_country);
|
ON b2b_specific_price_country (b2b_id_country);
|
||||||
|
|
||||||
|
CREATE TABLE b2b_route_roles (
|
||||||
|
route_id INT NOT NULL,
|
||||||
|
role_id BIGINT UNSIGNED NOT NULL,
|
||||||
|
PRIMARY KEY (route_id, role_id),
|
||||||
|
INDEX idx_role_id (role_id),
|
||||||
|
INDEX idx_route_id (route_id),
|
||||||
|
CONSTRAINT FK_b2b_route_roles_route_id
|
||||||
|
FOREIGN KEY (route_id)
|
||||||
|
REFERENCES b2b_routes (id)
|
||||||
|
ON DELETE CASCADE
|
||||||
|
ON UPDATE CASCADE,
|
||||||
|
CONSTRAINT FK_b2b_route_roles_role_id
|
||||||
|
FOREIGN KEY (role_id)
|
||||||
|
REFERENCES b2b_roles (id)
|
||||||
|
ON DELETE CASCADE
|
||||||
|
ON UPDATE CASCADE
|
||||||
|
) ENGINE=InnoDB;
|
||||||
|
|
||||||
DELIMITER //
|
DELIMITER //
|
||||||
|
|
||||||
CREATE FUNCTION IF NOT EXISTS slugify_eu(input TEXT)
|
CREATE FUNCTION IF NOT EXISTS slugify_eu(input TEXT)
|
||||||
@@ -438,6 +456,7 @@ DROP TABLE IF EXISTS b2b_customer_carts;
|
|||||||
DROP TABLE IF EXISTS b2b_specific_price_country;
|
DROP TABLE IF EXISTS b2b_specific_price_country;
|
||||||
DROP TABLE IF EXISTS b2b_specific_price_customer;
|
DROP TABLE IF EXISTS b2b_specific_price_customer;
|
||||||
DROP TABLE IF EXISTS b2b_specific_price_product_attribute;
|
DROP TABLE IF EXISTS b2b_specific_price_product_attribute;
|
||||||
|
DROP TABLE IF EXISTS b2b_route_roles;
|
||||||
DROP TABLE IF EXISTS b2b_specific_price_category;
|
DROP TABLE IF EXISTS b2b_specific_price_category;
|
||||||
DROP TABLE IF EXISTS b2b_specific_price_product;
|
DROP TABLE IF EXISTS b2b_specific_price_product;
|
||||||
DROP TABLE IF EXISTS b2b_specific_price;
|
DROP TABLE IF EXISTS b2b_specific_price;
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ VALUES
|
|||||||
INSERT INTO `b2b_roles` (`name`, `id`) VALUES ('user','1');
|
INSERT INTO `b2b_roles` (`name`, `id`) VALUES ('user','1');
|
||||||
INSERT INTO `b2b_roles` (`name`, `id`) VALUES ('admin','2');
|
INSERT INTO `b2b_roles` (`name`, `id`) VALUES ('admin','2');
|
||||||
INSERT INTO `b2b_roles` (`name`, `id`) VALUES ('super_admin','3');
|
INSERT INTO `b2b_roles` (`name`, `id`) VALUES ('super_admin','3');
|
||||||
|
INSERT INTO `b2b_roles` (`name`, `id`) VALUES ('unlogged','4');
|
||||||
|
|
||||||
|
|
||||||
-- insert sample admin user admin@ma-al.com/Maal12345678
|
-- insert sample admin user admin@ma-al.com/Maal12345678
|
||||||
@@ -39,6 +40,9 @@ INSERT INTO `b2b_permissions` (`id`, `name`) VALUES ('6', 'webdav.create_token')
|
|||||||
INSERT INTO `b2b_permissions` (`id`, `name`) VALUES ('7', 'product_translation.save');
|
INSERT INTO `b2b_permissions` (`id`, `name`) VALUES ('7', 'product_translation.save');
|
||||||
INSERT INTO `b2b_permissions` (`id`, `name`) VALUES ('8', 'product_translation.translate');
|
INSERT INTO `b2b_permissions` (`id`, `name`) VALUES ('8', 'product_translation.translate');
|
||||||
INSERT INTO `b2b_permissions` (`id`, `name`) VALUES ('9', 'search.create_index');
|
INSERT INTO `b2b_permissions` (`id`, `name`) VALUES ('9', 'search.create_index');
|
||||||
|
INSERT INTO `b2b_permissions` (`id`, `name`) VALUES ('10', 'orders.view_all');
|
||||||
|
INSERT INTO `b2b_permissions` (`id`, `name`) VALUES ('11', 'orders.modify_all');
|
||||||
|
INSERT INTO `b2b_permissions` (`id`, `name`) VALUES ('12', 'teleport');
|
||||||
|
|
||||||
INSERT INTO `b2b_role_permissions` (`role_id`, `permission_id`) VALUES ('2', '1');
|
INSERT INTO `b2b_role_permissions` (`role_id`, `permission_id`) VALUES ('2', '1');
|
||||||
INSERT INTO `b2b_role_permissions` (`role_id`, `permission_id`) VALUES ('2', '2');
|
INSERT INTO `b2b_role_permissions` (`role_id`, `permission_id`) VALUES ('2', '2');
|
||||||
@@ -49,6 +53,9 @@ INSERT INTO `b2b_role_permissions` (`role_id`, `permission_id`) VALUES ('2', '6'
|
|||||||
INSERT INTO `b2b_role_permissions` (`role_id`, `permission_id`) VALUES ('2', '7');
|
INSERT INTO `b2b_role_permissions` (`role_id`, `permission_id`) VALUES ('2', '7');
|
||||||
INSERT INTO `b2b_role_permissions` (`role_id`, `permission_id`) VALUES ('2', '8');
|
INSERT INTO `b2b_role_permissions` (`role_id`, `permission_id`) VALUES ('2', '8');
|
||||||
INSERT INTO `b2b_role_permissions` (`role_id`, `permission_id`) VALUES ('2', '9');
|
INSERT INTO `b2b_role_permissions` (`role_id`, `permission_id`) VALUES ('2', '9');
|
||||||
|
INSERT INTO `b2b_role_permissions` (`role_id`, `permission_id`) VALUES ('2', '10');
|
||||||
|
INSERT INTO `b2b_role_permissions` (`role_id`, `permission_id`) VALUES ('2', '11');
|
||||||
|
INSERT INTO `b2b_role_permissions` (`role_id`, `permission_id`) VALUES ('2', '12');
|
||||||
INSERT INTO `b2b_role_permissions` (`role_id`, `permission_id`) VALUES ('3', '1');
|
INSERT INTO `b2b_role_permissions` (`role_id`, `permission_id`) VALUES ('3', '1');
|
||||||
INSERT INTO `b2b_role_permissions` (`role_id`, `permission_id`) VALUES ('3', '2');
|
INSERT INTO `b2b_role_permissions` (`role_id`, `permission_id`) VALUES ('3', '2');
|
||||||
INSERT INTO `b2b_role_permissions` (`role_id`, `permission_id`) VALUES ('3', '3');
|
INSERT INTO `b2b_role_permissions` (`role_id`, `permission_id`) VALUES ('3', '3');
|
||||||
@@ -58,4 +65,35 @@ INSERT INTO `b2b_role_permissions` (`role_id`, `permission_id`) VALUES ('3', '6'
|
|||||||
INSERT INTO `b2b_role_permissions` (`role_id`, `permission_id`) VALUES ('3', '7');
|
INSERT INTO `b2b_role_permissions` (`role_id`, `permission_id`) VALUES ('3', '7');
|
||||||
INSERT INTO `b2b_role_permissions` (`role_id`, `permission_id`) VALUES ('3', '8');
|
INSERT INTO `b2b_role_permissions` (`role_id`, `permission_id`) VALUES ('3', '8');
|
||||||
INSERT INTO `b2b_role_permissions` (`role_id`, `permission_id`) VALUES ('3', '9');
|
INSERT INTO `b2b_role_permissions` (`role_id`, `permission_id`) VALUES ('3', '9');
|
||||||
|
INSERT INTO `b2b_role_permissions` (`role_id`, `permission_id`) VALUES ('3', '10');
|
||||||
|
INSERT INTO `b2b_role_permissions` (`role_id`, `permission_id`) VALUES ('3', '11');
|
||||||
|
INSERT INTO `b2b_role_permissions` (`role_id`, `permission_id`) VALUES ('3', '12');
|
||||||
|
|
||||||
|
INSERT INTO `b2b_route_roles` (`route_id`, `role_id`) VALUES
|
||||||
|
(1, '1'),
|
||||||
|
(1, '2'),
|
||||||
|
(1, '3'),
|
||||||
|
(2, '1'),
|
||||||
|
(2, '2'),
|
||||||
|
(2, '3'),
|
||||||
|
(3, '1'),
|
||||||
|
(3, '2'),
|
||||||
|
(3, '3'),
|
||||||
|
(3, '4'),
|
||||||
|
(4, '1'),
|
||||||
|
(4, '2'),
|
||||||
|
(4, '3'),
|
||||||
|
(4, '4'),
|
||||||
|
(5, '1'),
|
||||||
|
(5, '2'),
|
||||||
|
(5, '3'),
|
||||||
|
(5, '4'),
|
||||||
|
(6, '1'),
|
||||||
|
(6, '2'),
|
||||||
|
(6, '3'),
|
||||||
|
(6, '4'),
|
||||||
|
(7, '1'),
|
||||||
|
(7, '2'),
|
||||||
|
(7, '3'),
|
||||||
|
(7, '4');
|
||||||
-- +goose Down
|
-- +goose Down
|
||||||
@@ -319,7 +319,8 @@ DROP PROCEDURE IF EXISTS get_product_base //
|
|||||||
CREATE PROCEDURE get_product_base(
|
CREATE PROCEDURE get_product_base(
|
||||||
IN p_id_product INT,
|
IN p_id_product INT,
|
||||||
IN p_id_shop INT,
|
IN p_id_shop INT,
|
||||||
IN p_id_lang INT
|
IN p_id_lang INT,
|
||||||
|
IN p_id_customer INT
|
||||||
)
|
)
|
||||||
BEGIN
|
BEGIN
|
||||||
SELECT
|
SELECT
|
||||||
@@ -376,14 +377,12 @@ BEGIN
|
|||||||
|
|
||||||
-- Relations
|
-- Relations
|
||||||
m.name AS manufacturer,
|
m.name AS manufacturer,
|
||||||
cl.name AS category
|
cl.name AS category,
|
||||||
|
|
||||||
-- This doesn't fit to base product, I'll add proper is_favorite to product later
|
EXISTS(
|
||||||
|
SELECT 1 FROM b2b_favorites f
|
||||||
-- EXISTS(
|
WHERE f.user_id = p_id_customer AND f.product_id = p_id_product
|
||||||
-- SELECT 1 FROM b2b_favorites f
|
) AS is_favorite
|
||||||
-- WHERE f.user_id = p_id_customer AND f.product_id = p_id_product
|
|
||||||
-- ) AS is_favorite
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user