debug runtim
This commit is contained in:
@@ -3,6 +3,7 @@ package repositories
|
|||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"simplycpq/models"
|
"simplycpq/models"
|
||||||
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ProductRepository struct {
|
type ProductRepository struct {
|
||||||
@@ -72,6 +73,7 @@ func (pr *ProductRepository) DeleteProduct(id int) error {
|
|||||||
func (pr *ProductRepository) GetProductsByGroupId(groupId int) ([]*models.Product, error) {
|
func (pr *ProductRepository) GetProductsByGroupId(groupId int) ([]*models.Product, error) {
|
||||||
// Implement the logic to retrieve all products by their group ID from the database
|
// Implement the logic to retrieve all products by their group ID from the database
|
||||||
query := "SELECT id, label, externalId, description, productGroupId FROM products WHERE productGroupId = $1"
|
query := "SELECT id, label, externalId, description, productGroupId FROM products WHERE productGroupId = $1"
|
||||||
|
log.Println("Executing query:", query, "with groupId:", groupId) // Debugging line
|
||||||
rows, err := pr.dbHandler.Query(query, groupId)
|
rows, err := pr.dbHandler.Query(query, groupId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -81,10 +83,13 @@ func (pr *ProductRepository) GetProductsByGroupId(groupId int) ([]*models.Produc
|
|||||||
products := []*models.Product{}
|
products := []*models.Product{}
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
product := &models.Product{}
|
product := &models.Product{}
|
||||||
|
log.Println("Scanning row into product struct") // Debugging line
|
||||||
|
log.Println("Row data:", rows) // Debugging line
|
||||||
err := rows.Scan(&product.ID, &product.Label, &product.ExternalID, &product.Description, &product.ProductGroupID)
|
err := rows.Scan(&product.ID, &product.Label, &product.ExternalID, &product.Description, &product.ProductGroupID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
log.Println("Retrieved product:", product) // Debugging line
|
||||||
products = append(products, product)
|
products = append(products, product)
|
||||||
}
|
}
|
||||||
return products, nil
|
return products, nil
|
||||||
|
|||||||
Reference in New Issue
Block a user