chore: add bruno endpoints
This commit is contained in:
@@ -32,7 +32,6 @@ func CurrencyHandlerRoutes(r fiber.Router) fiber.Router {
|
||||
|
||||
r.Post("/currency-rate", handler.PostCurrencyRate)
|
||||
r.Get("/currency-rate/:id", handler.GetCurrencyRate)
|
||||
// r.Get("/currencies", handler.GetCurrencyRates)
|
||||
return r
|
||||
}
|
||||
|
||||
@@ -65,33 +64,5 @@ func (h *CurrencyHandler) GetCurrencyRate(c fiber.Ctx) error {
|
||||
return c.Status(responseErrors.GetErrorStatus(err)).JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||
}
|
||||
|
||||
// err = h.CurrencyService.GetCurrencyRate(userID, uint(productID), uint(productShopID), uint(productLangID), updates)
|
||||
// if err != nil {
|
||||
// return c.Status(responseErrors.GetErrorStatus(err)).
|
||||
// JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||
// }
|
||||
|
||||
return c.JSON(response.Make(currency, 0, i18n.T_(c, response.Message_OK)))
|
||||
}
|
||||
|
||||
func (h *CurrencyHandler) GetCurrencyRates(c fiber.Ctx) error {
|
||||
idStr := c.Params("id")
|
||||
id, err := strconv.Atoi(idStr)
|
||||
if err != nil {
|
||||
return c.Status(responseErrors.GetErrorStatus(err)).JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||
|
||||
}
|
||||
|
||||
currency, err := h.CurrencyService.GetCurrency(uint(id))
|
||||
if err != nil {
|
||||
return c.Status(responseErrors.GetErrorStatus(err)).JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||
}
|
||||
|
||||
// err = h.CurrencyService.GetCurrencyRate(userID, uint(productID), uint(productShopID), uint(productLangID), updates)
|
||||
// if err != nil {
|
||||
// return c.Status(responseErrors.GetErrorStatus(err)).
|
||||
// JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||
// }
|
||||
|
||||
return c.JSON(response.Make(currency, 0, i18n.T_(c, response.Message_OK)))
|
||||
}
|
||||
|
||||
@@ -31,7 +31,6 @@ func NewProductsHandler() *ProductsHandler {
|
||||
func ProductsHandlerRoutes(r fiber.Router) fiber.Router {
|
||||
handler := NewProductsHandler()
|
||||
|
||||
//TODO: WIP doesn't work yet
|
||||
r.Get("/:id/:country_id/:quantity", handler.GetProductJson)
|
||||
|
||||
return r
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
package productsRepo
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"git.ma-al.com/goc_daniel/b2b/app/db"
|
||||
)
|
||||
|
||||
type UIProductsRepo interface {
|
||||
GetJSON(p_id_product, p_id_shop, p_id_lang, p_id_customer, b2b_id_country, p_quantity int) (*string, error)
|
||||
GetJSON(p_id_product, p_id_shop, p_id_lang, p_id_customer, b2b_id_country, p_quantity int) (*json.RawMessage, error)
|
||||
}
|
||||
|
||||
type ProductsRepo struct{}
|
||||
@@ -14,12 +17,23 @@ func New() UIProductsRepo {
|
||||
return &ProductsRepo{}
|
||||
}
|
||||
|
||||
func (repo *ProductsRepo) GetJSON(p_id_product, p_id_shop, p_id_lang, p_id_customer, b2b_id_country, p_quantity int) (*string, error) {
|
||||
var product string
|
||||
func (repo *ProductsRepo) GetJSON(p_id_product, p_id_shop, p_id_lang, p_id_customer, b2b_id_country, p_quantity int) (*json.RawMessage, error) {
|
||||
var productStr string // ← Scan as string first
|
||||
|
||||
err := db.DB.Raw(`CALL get_full_product(?,?,?,?,?,?)`, p_id_product, p_id_shop, p_id_lang, p_id_customer, b2b_id_country, p_quantity).
|
||||
Scan(&product).
|
||||
err := db.DB.Raw(`CALL get_full_product(?,?,?,?,?,?)`,
|
||||
p_id_product, p_id_shop, p_id_lang, p_id_customer, b2b_id_country, p_quantity).
|
||||
Scan(&productStr).
|
||||
Error
|
||||
|
||||
return &product, err
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Optional: validate it's valid JSON
|
||||
if !json.Valid([]byte(productStr)) {
|
||||
return nil, fmt.Errorf("invalid json returned from stored procedure")
|
||||
}
|
||||
|
||||
raw := json.RawMessage(productStr)
|
||||
return &raw, nil
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package productService
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"git.ma-al.com/goc_daniel/b2b/app/repos/productsRepo"
|
||||
constdata "git.ma-al.com/goc_daniel/b2b/app/utils/const_data"
|
||||
)
|
||||
@@ -15,7 +17,7 @@ func New() *ProductService {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *ProductService) GetJSON(p_id_product, p_id_lang, p_id_customer, b2b_id_country, p_quantity int) (*string, error) {
|
||||
func (s *ProductService) GetJSON(p_id_product, p_id_lang, p_id_customer, b2b_id_country, p_quantity int) (*json.RawMessage, error) {
|
||||
products, err := s.productsRepo.GetJSON(p_id_product, constdata.SHOP_ID, p_id_lang, p_id_customer, b2b_id_country, p_quantity)
|
||||
if err != nil {
|
||||
return products, err
|
||||
|
||||
Reference in New Issue
Block a user