productRepository created
This commit is contained in:
@@ -514,3 +514,41 @@ func (ctl *ProductController) CreateProductVariant(c *fiber.Ctx) error {
|
||||
"status": true,
|
||||
})
|
||||
}
|
||||
|
||||
func (ctl *ProductController) DeleteProductLocation(c *fiber.Ctx) error {
|
||||
var input struct {
|
||||
Tenantid int `json:"tenantid"`
|
||||
Locationid int `json:"locationid"`
|
||||
Productid int `json:"productid"`
|
||||
}
|
||||
|
||||
if err := c.BodyParser(&input); err != nil {
|
||||
return c.Status(http.StatusBadRequest).JSON(fiber.Map{
|
||||
"code": http.StatusBadRequest,
|
||||
"message": "Invalid request body",
|
||||
"status": false,
|
||||
})
|
||||
}
|
||||
|
||||
if input.Tenantid == 0 || input.Locationid == 0 || input.Productid == 0 {
|
||||
return c.Status(http.StatusBadRequest).JSON(fiber.Map{
|
||||
"code": http.StatusBadRequest,
|
||||
"message": "tenantid, locationid, and productid are required",
|
||||
"status": false,
|
||||
})
|
||||
}
|
||||
|
||||
if err := ctl.productService.DeleteProductLocation(input.Tenantid, input.Locationid, input.Productid); err != nil {
|
||||
return c.Status(http.StatusConflict).JSON(fiber.Map{
|
||||
"code": http.StatusConflict,
|
||||
"message": err.Error(),
|
||||
"status": false,
|
||||
})
|
||||
}
|
||||
|
||||
return c.Status(http.StatusOK).JSON(fiber.Map{
|
||||
"code": http.StatusOK,
|
||||
"message": "Product location deleted successfully",
|
||||
"status": true,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ type ProductRepository interface {
|
||||
UpdateProductLocation(input models.Productlocations) error
|
||||
CreateProductLocation(input []models.Productlocations) error
|
||||
CreateProductVariant(input models.Productvariant) error
|
||||
DeleteProductLocation(tenantid, locationid, productid int) error
|
||||
}
|
||||
|
||||
type productRepository struct {
|
||||
@@ -695,7 +696,7 @@ func (r *productRepository) CreateProductLocation(input []models.Productlocation
|
||||
// Insert or update product location
|
||||
if err := tx.Clauses(clause.OnConflict{
|
||||
Columns: []clause.Column{{Name: "tenantid"}, {Name: "locationid"}, {Name: "productid"}},
|
||||
DoUpdates: clause.AssignmentColumns([]string{"price", "minquantity", "maxquantity"}),
|
||||
DoUpdates: clause.AssignmentColumns([]string{"price", "minquantity", "maxquantity", "status"}),
|
||||
}).Create(&input).Error; err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
@@ -745,3 +746,10 @@ func (r *productRepository) CreateProductVariant(input models.Productvariant) er
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *productRepository) DeleteProductLocation(tenantid, locationid, productid int) error {
|
||||
if err := r.db.Where("tenantid = ? AND locationid = ? AND productid = ?", tenantid, locationid, productid).Delete(&models.Productlocations{}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ func RegisterProductRoutes(api fiber.Router, f *facade.Facade) {
|
||||
products.Get("/getallproducts", f.ProductController.GetAllProducts)
|
||||
products.Put("/updateproductlocation", f.ProductController.UpdateProductLocation)
|
||||
products.Post("/createproductlocation", f.ProductController.CreateProductLocation)
|
||||
products.Delete("/deleteproductlocation", f.ProductController.DeleteProductLocation)
|
||||
products.Post("/createproductvariant", f.ProductController.CreateProductVariant)
|
||||
|
||||
products.Post("/createstockrequest", f.StockRequestController.CreateStockRequest)
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
//go:build ignore
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
//go:build ignore
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
//go:build ignore
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
//go:build ignore
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
|
||||
@@ -27,6 +27,7 @@ type ProductService interface {
|
||||
UpdateProductLocation(input models.Productlocations) error
|
||||
CreateProductLocation(input []models.Productlocations) error
|
||||
CreateProductVariant(input models.Productvariant) error
|
||||
DeleteProductLocation(tenantid, locationid, productid int) error
|
||||
}
|
||||
type productService struct {
|
||||
repo repositories.ProductRepository
|
||||
@@ -206,3 +207,8 @@ func (s *productService) CreateProductLocation(input []models.Productlocations)
|
||||
func (s *productService) CreateProductVariant(input models.Productvariant) error {
|
||||
return s.repo.CreateProductVariant(input)
|
||||
}
|
||||
|
||||
func (s *productService) DeleteProductLocation(tenantid, locationid, productid int) error {
|
||||
return s.repo.DeleteProductLocation(tenantid, locationid, productid)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user