Erweiterung der Produktpflege
This commit is contained in:
@@ -27,22 +27,23 @@ func (bc *BOMController) CreateBillOfMaterial(c *gin.Context) {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
err = bc.bomService.CreateBillOfMaterial(&bom)
|
||||
createdBOM, err := bc.bomService.CreateBillOfMaterial(&bom)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.Status(http.StatusCreated)
|
||||
c.JSON(http.StatusCreated, createdBOM)
|
||||
// Removed redundant error check and status setting
|
||||
}
|
||||
|
||||
func (bc *BOMController) GetBOMProductsByBOMId(c *gin.Context) {
|
||||
bomIdStr := c.Query("bomId")
|
||||
bomId, err := strconv.ParseInt(bomIdStr, 10, 64)
|
||||
func (bc *BOMController) GetBOMByProductID(c *gin.Context) {
|
||||
productIdStr := c.Param("productId")
|
||||
productId, err := strconv.Atoi(productIdStr)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
contents, err := bc.bomService.GetBOMProductsByBOMId(bomId)
|
||||
contents, err := bc.bomService.GetBOMByProductID(productId)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
@@ -51,8 +52,8 @@ func (bc *BOMController) GetBOMProductsByBOMId(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (bc *BOMController) GetBOMVariantNodesByBOMId(c *gin.Context) {
|
||||
bomIdStr := c.Query("bomId")
|
||||
bomId, err := strconv.ParseInt(bomIdStr, 10, 64)
|
||||
bomIdStr := c.Param("bomId")
|
||||
bomId, err := strconv.Atoi(bomIdStr)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
@@ -87,17 +88,17 @@ func (bc *BOMController) UpdateVariantNode(c *gin.Context) {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
err = bc.bomService.UpdateVariantNode(&variantNode)
|
||||
updatedVariantNode, err := bc.bomService.UpdateVariantNode(&variantNode)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.Status(http.StatusOK)
|
||||
c.JSON(http.StatusOK, updatedVariantNode)
|
||||
}
|
||||
|
||||
func (bc *BOMController) DeleteVariantNode(c *gin.Context) {
|
||||
variantNodeIdStr := c.Query("variantNodeId")
|
||||
variantNodeId, err := strconv.ParseInt(variantNodeIdStr, 10, 64)
|
||||
variantNodeId, err := strconv.Atoi(variantNodeIdStr)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
@@ -112,7 +113,7 @@ func (bc *BOMController) DeleteVariantNode(c *gin.Context) {
|
||||
|
||||
func (bc *BOMController) GetVariantNode(c *gin.Context) {
|
||||
variantNodeIdStr := c.Query("variantNodeId")
|
||||
variantNodeId, err := strconv.ParseInt(variantNodeIdStr, 10, 64)
|
||||
variantNodeId, err := strconv.Atoi(variantNodeIdStr)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
@@ -127,7 +128,7 @@ func (bc *BOMController) GetVariantNode(c *gin.Context) {
|
||||
|
||||
func (bc *BOMController) GetVariantNodeProductsByVariantNodeId(c *gin.Context) {
|
||||
variantNodeIdStr := c.Query("variantNodeId")
|
||||
variantNodeId, err := strconv.ParseInt(variantNodeIdStr, 10, 64)
|
||||
variantNodeId, err := strconv.Atoi(variantNodeIdStr)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
@@ -147,17 +148,17 @@ func (bc *BOMController) UpdateBillOfMaterial(c *gin.Context) {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
err = bc.bomService.UpdateBillOfMaterial(&bom)
|
||||
updatedBOM, err := bc.bomService.UpdateBillOfMaterial(&bom)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.Status(http.StatusOK)
|
||||
c.JSON(http.StatusOK, updatedBOM)
|
||||
}
|
||||
|
||||
func (bc *BOMController) DeleteBillOfMaterial(c *gin.Context) {
|
||||
bomIdStr := c.Query("id")
|
||||
bomId, err := strconv.ParseInt(bomIdStr, 10, 64)
|
||||
bomId, err := strconv.Atoi(bomIdStr)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
@@ -172,7 +173,7 @@ func (bc *BOMController) DeleteBillOfMaterial(c *gin.Context) {
|
||||
|
||||
func (bc *BOMController) GetBillOfMaterial(c *gin.Context) {
|
||||
bomIdStr := c.Query("id")
|
||||
bomId, err := strconv.ParseInt(bomIdStr, 10, 64)
|
||||
bomId, err := strconv.Atoi(bomIdStr)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
@@ -184,3 +185,18 @@ func (bc *BOMController) GetBillOfMaterial(c *gin.Context) {
|
||||
}
|
||||
c.JSON(http.StatusOK, bom)
|
||||
}
|
||||
|
||||
func (bc *BOMController) GetBOMContentByBOMId(c *gin.Context) {
|
||||
bomIdStr := c.Param("bomId")
|
||||
bomId, err := strconv.Atoi(bomIdStr)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
contents, err := bc.bomService.GetBOMContentByBOMId(bomId)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, contents)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"simplycpq/models"
|
||||
"simplycpq/services"
|
||||
@@ -264,6 +265,40 @@ func (vc *ValueController) DeleteValueFromPropertyId(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{"message": "Value deleted from Property", "valueId": valueIdInt, "propertyId": propertyIdInt})
|
||||
}
|
||||
|
||||
func (vc *ValueController) UpdateValue(c *gin.Context) {
|
||||
var value models.Value
|
||||
if err := c.ShouldBindJSON(&value); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
if err := vc.valueService.UpdateValue(&value); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"message": "Value updated", "data": value})
|
||||
}
|
||||
|
||||
func (vc *ValueController) CreateValueForPropertyId(c *gin.Context) {
|
||||
propertyId, err := strconv.Atoi(c.Param("propertyId"))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid property id"})
|
||||
return
|
||||
}
|
||||
var value models.Value
|
||||
log.Println("Received request to create value for property ID:", propertyId) // Debugging line
|
||||
log.Println("Request body:", c.Request.Body) // Debugging line
|
||||
if err := c.ShouldBindJSON(&value); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
createdValue, err := vc.valueService.CreateValueForPropertyId(propertyId, &value)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"message": "Value created for Property", "propertyId": propertyId, "data": createdValue})
|
||||
}
|
||||
|
||||
func (vc *ValueController) GetValue(c *gin.Context) {
|
||||
id := c.Param("id")
|
||||
idInt, err := strconv.Atoi(id)
|
||||
|
||||
@@ -0,0 +1,184 @@
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"simplycpq/models"
|
||||
)
|
||||
|
||||
type BomRepository struct {
|
||||
db *sql.DB
|
||||
productRepository *ProductRepository
|
||||
}
|
||||
|
||||
func NewBomRepository(db *sql.DB, pr *ProductRepository) *BomRepository {
|
||||
return &BomRepository{db: db, productRepository: pr}
|
||||
}
|
||||
|
||||
func (r *BomRepository) GetBOMByProductID(productID int) (models.BillOfMaterial, error) {
|
||||
var bom models.BillOfMaterial
|
||||
query := "SELECT id, label, description, parentBOMId FROM boms WHERE productId = $1"
|
||||
err := r.db.QueryRow(query, productID).Scan(&bom.ID, &bom.Label, &bom.Description, &bom.ParentBOMID)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return bom, fmt.Errorf("bom with product id %d not found", productID)
|
||||
}
|
||||
return bom, err
|
||||
}
|
||||
return bom, nil
|
||||
}
|
||||
|
||||
func (r *BomRepository) GetBOMContentByBOMId(bomID int) ([]models.BOMContent, error) {
|
||||
var contents []models.BOMContent
|
||||
query := "SELECT id, productId, min, max FROM bom_contents WHERE bomId = $1"
|
||||
rows, err := r.db.Query(query, bomID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
var content models.BOMContent
|
||||
err := rows.Scan(&content.ID, &content.ProductID, &content.Min, &content.Max)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
contents = append(contents, content)
|
||||
}
|
||||
if err = rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return contents, nil
|
||||
}
|
||||
|
||||
func (r *BomRepository) GetBOMVariantNodesByBOMId(bomID int) ([]models.VariantNode, error) {
|
||||
var variantNodes []models.VariantNode
|
||||
query := "SELECT id, label, description FROM variant_nodes WHERE bomId = $1"
|
||||
rows, err := r.db.Query(query, bomID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
var variantNode models.VariantNode
|
||||
err := rows.Scan(&variantNode.ID, &variantNode.Label, &variantNode.Description)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
variantNodes = append(variantNodes, variantNode)
|
||||
}
|
||||
if err = rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return variantNodes, nil
|
||||
}
|
||||
|
||||
func (r *BomRepository) CreateBillOfMaterial(bom *models.BillOfMaterial) (models.BillOfMaterial, error) {
|
||||
query := "INSERT INTO boms (productId, label, description, parentBOMId) VALUES ($1, $2, $3, $4) RETURNING id"
|
||||
err := r.db.QueryRow(query, bom.ProductID, bom.Label, bom.Description, bom.ParentBOMID).Scan(&bom.ID)
|
||||
if err != nil {
|
||||
return models.BillOfMaterial{}, err
|
||||
}
|
||||
return *bom, nil
|
||||
}
|
||||
|
||||
func (r *BomRepository) CreateVariantNode(node *models.VariantNode) (models.VariantNode, error) {
|
||||
query := "INSERT INTO variantNode (label, description, bomId) VALUES ($1, $2, $3) RETURNING id"
|
||||
err := r.db.QueryRow(query, node.Label, node.Description, node.BOMID).Scan(&node.ID)
|
||||
if err != nil {
|
||||
return models.VariantNode{}, err
|
||||
}
|
||||
return *node, nil
|
||||
}
|
||||
|
||||
func (r *BomRepository) GetVariantNodeByID(id int) (models.VariantNode, error) {
|
||||
var node models.VariantNode
|
||||
query := "SELECT id, label, description, bomId FROM variantNodes WHERE id = $1"
|
||||
err := r.db.QueryRow(query, id).Scan(&node.ID, &node.Label, &node.Description, &node.BOMID)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return models.VariantNode{}, fmt.Errorf("variant node with id %d not found", id)
|
||||
}
|
||||
return models.VariantNode{}, err
|
||||
}
|
||||
return node, nil
|
||||
}
|
||||
|
||||
func (r *BomRepository) UpdateVariantNode(node *models.VariantNode) (models.VariantNode, error) {
|
||||
query := "UPDATE variantNode SET label = $1, description = $2 WHERE id = $3"
|
||||
_, err := r.db.Exec(query, node.Label, node.Description, node.ID)
|
||||
if err != nil {
|
||||
return models.VariantNode{}, err
|
||||
}
|
||||
return *node, nil
|
||||
}
|
||||
|
||||
func (r *BomRepository) DeleteVariantNode(id int) error {
|
||||
query := "DELETE FROM variantNode WHERE id = $1"
|
||||
_, err := r.db.Exec(query, id)
|
||||
return err
|
||||
}
|
||||
|
||||
func (r *BomRepository) GetVariantNode(id int) (models.VariantNode, error) {
|
||||
return r.GetVariantNodeByID(id)
|
||||
}
|
||||
|
||||
func (r *BomRepository) GetVariantNodeProductsByVariantNodeId(variantNodeID int) ([]models.Product, error) {
|
||||
var products []models.Product
|
||||
query := "SELECT productId from variantNodeContent WHERE variantNodeId = $1"
|
||||
rows, err := r.db.Query(query, variantNodeID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
var productID int
|
||||
if err := rows.Scan(&productID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
product, err := r.productRepository.GetProductById(productID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if product == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
products = append(products, *product)
|
||||
}
|
||||
if err = rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return products, nil
|
||||
}
|
||||
|
||||
func (r *BomRepository) UpdateBillOfMaterial(bom *models.BillOfMaterial) (models.BillOfMaterial, error) {
|
||||
query := "UPDATE billOfMaterial SET productId = $1, label = $2, description = $3, parentBOMId = $4 WHERE id = $5"
|
||||
_, err := r.db.Exec(query, bom.ProductID, bom.Label, bom.Description, bom.ParentBOMID, bom.ID)
|
||||
if err != nil {
|
||||
return models.BillOfMaterial{}, err
|
||||
}
|
||||
return *bom, nil
|
||||
}
|
||||
|
||||
func (r *BomRepository) DeleteBillOfMaterial(id int) error {
|
||||
query := "DELETE FROM billOfMaterial WHERE id = $1"
|
||||
_, err := r.db.Exec(query, id)
|
||||
return err
|
||||
}
|
||||
|
||||
func (r *BomRepository) GetBillOfMaterial(id int) (models.BillOfMaterial, error) {
|
||||
var bom models.BillOfMaterial
|
||||
query := "SELECT id, productId, label, description, parentBOMId FROM billOfMaterial WHERE id = $1"
|
||||
err := r.db.QueryRow(query, id).Scan(&bom.ID, &bom.ProductID, &bom.Label, &bom.Description, &bom.ParentBOMID)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return models.BillOfMaterial{}, fmt.Errorf("bill of material with id %d not found", id)
|
||||
}
|
||||
return models.BillOfMaterial{}, err
|
||||
}
|
||||
return bom, nil
|
||||
}
|
||||
@@ -2,8 +2,8 @@ package repositories
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"simplycpq/models"
|
||||
"log"
|
||||
"simplycpq/models"
|
||||
)
|
||||
|
||||
type ProductRepository struct {
|
||||
@@ -84,7 +84,7 @@ func (pr *ProductRepository) GetProductsByGroupId(groupId int) ([]*models.Produc
|
||||
for rows.Next() {
|
||||
product := &models.Product{}
|
||||
log.Println("Scanning row into product struct") // Debugging line
|
||||
log.Println("Row data:", rows) // Debugging line
|
||||
log.Println("Row data:", rows) // Debugging line
|
||||
err := rows.Scan(&product.ID, &product.Label, &product.ExternalID, &product.Description, &product.ProductGroupID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -103,9 +103,11 @@ func (pr *ProductRepository) AddPropertyToProduct(productId int, propertyId int)
|
||||
}
|
||||
|
||||
func (pr *ProductRepository) DeletePropertyFromProduct(productId int, propertyId int) error {
|
||||
// Implement the logic to delete a property from a product in the database
|
||||
query := "DELETE FROM product_properties WHERE productId = $1 AND propertyId = $2"
|
||||
_, err := pr.dbHandler.Exec(query, productId, propertyId)
|
||||
// remove the property owned by this product, including its values
|
||||
if _, err := pr.dbHandler.Exec("DELETE FROM values WHERE propertyId = $1", propertyId); err != nil {
|
||||
return err
|
||||
}
|
||||
_, err := pr.dbHandler.Exec("DELETE FROM properties WHERE productId = $1 AND id = $2", productId, propertyId)
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -291,6 +291,13 @@ func (vr *ValueRepository) DeleteValueFromPropertyId(valueId int, propertyId int
|
||||
return nil
|
||||
}
|
||||
|
||||
func (vr *ValueRepository) UpdateValue(value *models.Value) error {
|
||||
// Implement the logic to update the label/description of an existing value
|
||||
query := `UPDATE values SET label=$1, description=$2 WHERE id=$3 AND propertyid=$4`
|
||||
_, err := vr.db.Exec(query, value.Label, value.Description, value.ID, value.PropertyID)
|
||||
return err
|
||||
}
|
||||
|
||||
func (vr *ValueRepository) GetValue(id int) (*models.Value, error) {
|
||||
// Implement the logic to retrieve the value from the database for the given id
|
||||
query := `SELECT id, label, description FROM values WHERE id=$1`
|
||||
|
||||
@@ -31,14 +31,14 @@ func InitHttpServer(config *viper.Viper, dbHandler *sql.DB) HttpServer {
|
||||
productGroupRepository := repositories.NewProductGroupRepository(dbHandler, valueRepository)
|
||||
productRepository := repositories.NewProductRepository(dbHandler, productGroupRepository, valueRepository)
|
||||
importRepository := repositories.NewImportRepository(dbHandler, productGroupRepository, productRepository, valueRepository)
|
||||
bomRepository := repositories.NewBOMRepository(dbHandler, productRepository)
|
||||
bomRepository := repositories.NewBomRepository(dbHandler, productRepository)
|
||||
|
||||
// service initialisation:
|
||||
valueService := services.NewValueService(valueRepository)
|
||||
productGroupService := services.NewProductGroupService(productGroupRepository)
|
||||
productService := services.NewProductService(productRepository)
|
||||
importService := services.NewImportService(importRepository)
|
||||
bomService := services.NewBOMService(bomRepository)
|
||||
bomService := services.NewBomService(bomRepository)
|
||||
|
||||
// controller initialisation:
|
||||
valueController := controller.NewValueController(valueService)
|
||||
@@ -69,6 +69,8 @@ func InitHttpServer(config *viper.Viper, dbHandler *sql.DB) HttpServer {
|
||||
router.GET("/getValuesFromPropertyTypeId/:propertyTypeId", valueController.GetValuesFromPropertyTypeId) // get all Values from PropertyType by ID
|
||||
router.GET("/getValuesFromPropertyId/:propertyId", valueController.GetValuesFromPropertyId) // get all Values from Property by ID
|
||||
router.DELETE("/deleteValueFromPropertyId/:valueId/:propertyId", valueController.DeleteValueFromPropertyId) // delete Value from Property by ID
|
||||
router.POST("/createValueForPropertyId/:propertyId", valueController.CreateValueForPropertyId) // create Value for Property by ID
|
||||
router.PUT("/updateValue", valueController.UpdateValue) // update Value
|
||||
router.GET("/getValue/:id", valueController.GetValue)
|
||||
router.POST("/SetTerminalValueForProperty/:propertyId/:value", valueController.SetTerminalValueForProperty) // set Terminal Value for Property
|
||||
|
||||
@@ -101,8 +103,9 @@ func InitHttpServer(config *viper.Viper, dbHandler *sql.DB) HttpServer {
|
||||
router.PUT("/updateBillOfMaterial", bomController.UpdateBillOfMaterial)
|
||||
router.DELETE("/deleteBillOfMaterial/:id", bomController.DeleteBillOfMaterial)
|
||||
router.GET("/getBillOfMaterial/:id", bomController.GetBillOfMaterial)
|
||||
router.GET("/getBOMProductsByBOMId/:bomId", bomController.GetBOMProductsByBOMId) // get all BOMContents by BOM ID
|
||||
router.GET("/getBOMContentByProductId/:productId", bomController.GetBOMByProductID) // get all BOMContents by Product ID
|
||||
router.GET("/getBOMVariantNodesByBOMId/:bomId", bomController.GetBOMVariantNodesByBOMId) // get all VariantNodes by BOM ID
|
||||
router.GET("/getBOMContentByBOMId/:bomId", bomController.GetBOMContentByBOMId) // get all BOMContents by BOM ID
|
||||
router.POST("/createVariantNode/:bomId", bomController.CreateVariantNode)
|
||||
router.PUT("/updateVariantNode", bomController.UpdateVariantNode)
|
||||
router.DELETE("/deleteVariantNode/:id", bomController.DeleteVariantNode)
|
||||
|
||||
@@ -16,37 +16,37 @@ func NewBomService(bomRepo *repositories.BomRepository) *BomService {
|
||||
}
|
||||
}
|
||||
|
||||
func (bs *BomService) GetBOMByProductID(productID int) ([]models.BillOfMaterial, error) {
|
||||
func (bs *BomService) GetBOMByProductID(productID int) (*models.BillOfMaterial, error) {
|
||||
bomData, err := bs.bomRepository.GetBOMByProductID(productID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to retrieve BOM data: %w", err)
|
||||
}
|
||||
return bomData, nil
|
||||
return &bomData, nil
|
||||
}
|
||||
|
||||
func (bs *BomService) CreateBillOfMaterial(bom *models.BillOfMaterial) error {
|
||||
func (bs *BomService) CreateBillOfMaterial(bom *models.BillOfMaterial) (*models.BillOfMaterial, error) {
|
||||
// Validate the BOM data
|
||||
if bom.ProductID <= 0 {
|
||||
return fmt.Errorf("invalid product ID")
|
||||
return nil, fmt.Errorf("invalid product ID")
|
||||
}
|
||||
|
||||
// Create the BOM in the repository
|
||||
err := bs.bomRepository.CreateBillOfMaterial(bom)
|
||||
createdBOM, err := bs.bomRepository.CreateBillOfMaterial(bom)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create BOM: %w", err)
|
||||
return nil, fmt.Errorf("failed to create BOM: %w", err)
|
||||
}
|
||||
return nil
|
||||
return &createdBOM, nil
|
||||
}
|
||||
|
||||
func (bs *BomService) GetBOMProductsByBOMId(bomId int64) ([]models.Product, error) {
|
||||
products, err := bs.bomRepository.GetBOMProductsByBOMId(bomId)
|
||||
func (bs *BomService) GetBOMContentByBOMId(bomId int) ([]models.BOMContent, error) {
|
||||
contents, err := bs.bomRepository.GetBOMContentByBOMId(bomId)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to retrieve BOM products: %w", err)
|
||||
return nil, fmt.Errorf("failed to retrieve BOM contents: %w", err)
|
||||
}
|
||||
return products, nil
|
||||
return contents, nil
|
||||
}
|
||||
|
||||
func (bs *BomService) GetBOMVariantNodesByBOMId(bomId int64) ([]models.VariantNode, error) {
|
||||
func (bs *BomService) GetBOMVariantNodesByBOMId(bomId int) ([]models.VariantNode, error) {
|
||||
variantNodes, err := bs.bomRepository.GetBOMVariantNodesByBOMId(bomId)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to retrieve BOM variant nodes: %w", err)
|
||||
@@ -57,31 +57,31 @@ func (bs *BomService) GetBOMVariantNodesByBOMId(bomId int64) ([]models.VariantNo
|
||||
func (bs *BomService) CreateVariantNode(variantNode *models.VariantNode) (*models.VariantNode, error) {
|
||||
|
||||
// Create the VariantNode in the repository
|
||||
variantNode, err := bs.bomRepository.CreateVariantNode(variantNode)
|
||||
variantNode2, err := bs.bomRepository.CreateVariantNode(variantNode)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create VariantNode: %w", err)
|
||||
}
|
||||
return variantNode, nil
|
||||
return &variantNode2, nil
|
||||
}
|
||||
|
||||
func (bs *BomService) GetVariantNodeByID(id int64) (*models.VariantNode, error) {
|
||||
func (bs *BomService) GetVariantNodeByID(id int) (*models.VariantNode, error) {
|
||||
variantNode, err := bs.bomRepository.GetVariantNodeByID(id)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to retrieve VariantNode: %w", err)
|
||||
}
|
||||
return variantNode, nil
|
||||
return &variantNode, nil
|
||||
}
|
||||
|
||||
func (bs *BomService) UpdateVariantNode(variantNode *models.VariantNode) error {
|
||||
func (bs *BomService) UpdateVariantNode(variantNode *models.VariantNode) (*models.VariantNode, error) {
|
||||
// Update the VariantNode in the repository
|
||||
err := bs.bomRepository.UpdateVariantNode(variantNode)
|
||||
variantNode2, err := bs.bomRepository.UpdateVariantNode(variantNode)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to update VariantNode: %w", err)
|
||||
return nil, fmt.Errorf("failed to update VariantNode: %w", err)
|
||||
}
|
||||
return nil
|
||||
return &variantNode2, nil
|
||||
}
|
||||
|
||||
func (bs *BomService) DeleteVariantNode(id int64) error {
|
||||
func (bs *BomService) DeleteVariantNode(id int) error {
|
||||
// Delete the VariantNode in the repository
|
||||
err := bs.bomRepository.DeleteVariantNode(id)
|
||||
if err != nil {
|
||||
@@ -90,32 +90,32 @@ func (bs *BomService) DeleteVariantNode(id int64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (bs *BomService) GetVariantNode(parentID int64) ([]models.VariantNode, error) {
|
||||
variantNodes, err := bs.bomRepository.GetVariantNode(parentID)
|
||||
func (bs *BomService) GetVariantNode(id int) (*models.VariantNode, error) {
|
||||
variantNode, err := bs.bomRepository.GetVariantNode(id)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to retrieve VariantNodes: %w", err)
|
||||
return nil, fmt.Errorf("failed to retrieve VariantNode: %w", err)
|
||||
}
|
||||
return variantNodes, nil
|
||||
return &variantNode, nil
|
||||
}
|
||||
|
||||
func (bs *BomService) GetVariantNodeProductsByVariantNodeId(parentID int64) ([]models.Product, error) {
|
||||
products, err := bs.bomRepository.GetVariantNodeProductsByVariantNodeId(parentID)
|
||||
func (bs *BomService) GetVariantNodeProductsByVariantNodeId(id int) ([]models.Product, error) {
|
||||
products, err := bs.bomRepository.GetVariantNodeProductsByVariantNodeId(id)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to retrieve VariantNode products: %w", err)
|
||||
}
|
||||
return products, nil
|
||||
}
|
||||
|
||||
func (bs *BomService) UpdateBillOfMaterial(bom *models.BillOfMaterial) error {
|
||||
func (bs *BomService) UpdateBillOfMaterial(bom *models.BillOfMaterial) (*models.BillOfMaterial, error) {
|
||||
// Update the BOM in the repository
|
||||
err := bs.bomRepository.UpdateBillOfMaterial(bom)
|
||||
bom2, err := bs.bomRepository.UpdateBillOfMaterial(bom)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to update BOM: %w", err)
|
||||
return nil, fmt.Errorf("failed to update BOM: %w", err)
|
||||
}
|
||||
return nil
|
||||
return &bom2, nil
|
||||
}
|
||||
|
||||
func (bs *BomService) DeleteBillOfMaterial(id int64) error {
|
||||
func (bs *BomService) DeleteBillOfMaterial(id int) error {
|
||||
// Delete the BOM in the repository
|
||||
err := bs.bomRepository.DeleteBillOfMaterial(id)
|
||||
if err != nil {
|
||||
@@ -124,10 +124,10 @@ func (bs *BomService) DeleteBillOfMaterial(id int64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (bs *BomService) GetBillOfMaterial(id int64) (*models.BillOfMaterial, error) {
|
||||
func (bs *BomService) GetBillOfMaterial(id int) (*models.BillOfMaterial, error) {
|
||||
bom, err := bs.bomRepository.GetBillOfMaterial(id)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to retrieve BOM: %w", err)
|
||||
}
|
||||
return bom, nil
|
||||
return &bom, nil
|
||||
}
|
||||
|
||||
@@ -87,6 +87,10 @@ func (vs *ValueService) CreateValueForPropertyId(propertyId int, value *models.V
|
||||
return vs.valueRepository.CreateValueForPropertyId(propertyId, value)
|
||||
}
|
||||
|
||||
func (vs *ValueService) UpdateValue(value *models.Value) error {
|
||||
return vs.valueRepository.UpdateValue(value)
|
||||
}
|
||||
|
||||
func (vs *ValueService) GetValue(id int) (*models.Value, error) {
|
||||
return vs.valueRepository.GetValue(id)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user