productRepository created
This commit is contained in:
@@ -514,3 +514,41 @@ func (ctl *ProductController) CreateProductVariant(c *fiber.Ctx) error {
|
|||||||
"status": true,
|
"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
|
UpdateProductLocation(input models.Productlocations) error
|
||||||
CreateProductLocation(input []models.Productlocations) error
|
CreateProductLocation(input []models.Productlocations) error
|
||||||
CreateProductVariant(input models.Productvariant) error
|
CreateProductVariant(input models.Productvariant) error
|
||||||
|
DeleteProductLocation(tenantid, locationid, productid int) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type productRepository struct {
|
type productRepository struct {
|
||||||
@@ -695,7 +696,7 @@ func (r *productRepository) CreateProductLocation(input []models.Productlocation
|
|||||||
// Insert or update product location
|
// Insert or update product location
|
||||||
if err := tx.Clauses(clause.OnConflict{
|
if err := tx.Clauses(clause.OnConflict{
|
||||||
Columns: []clause.Column{{Name: "tenantid"}, {Name: "locationid"}, {Name: "productid"}},
|
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 {
|
}).Create(&input).Error; err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return err
|
return err
|
||||||
@@ -745,3 +746,10 @@ func (r *productRepository) CreateProductVariant(input models.Productvariant) er
|
|||||||
|
|
||||||
return nil
|
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.Get("/getallproducts", f.ProductController.GetAllProducts)
|
||||||
products.Put("/updateproductlocation", f.ProductController.UpdateProductLocation)
|
products.Put("/updateproductlocation", f.ProductController.UpdateProductLocation)
|
||||||
products.Post("/createproductlocation", f.ProductController.CreateProductLocation)
|
products.Post("/createproductlocation", f.ProductController.CreateProductLocation)
|
||||||
|
products.Delete("/deleteproductlocation", f.ProductController.DeleteProductLocation)
|
||||||
products.Post("/createproductvariant", f.ProductController.CreateProductVariant)
|
products.Post("/createproductvariant", f.ProductController.CreateProductVariant)
|
||||||
|
|
||||||
products.Post("/createstockrequest", f.StockRequestController.CreateStockRequest)
|
products.Post("/createstockrequest", f.StockRequestController.CreateStockRequest)
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
//go:build ignore
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
//go:build ignore
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
//go:build ignore
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
//go:build ignore
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ type ProductService interface {
|
|||||||
UpdateProductLocation(input models.Productlocations) error
|
UpdateProductLocation(input models.Productlocations) error
|
||||||
CreateProductLocation(input []models.Productlocations) error
|
CreateProductLocation(input []models.Productlocations) error
|
||||||
CreateProductVariant(input models.Productvariant) error
|
CreateProductVariant(input models.Productvariant) error
|
||||||
|
DeleteProductLocation(tenantid, locationid, productid int) error
|
||||||
}
|
}
|
||||||
type productService struct {
|
type productService struct {
|
||||||
repo repositories.ProductRepository
|
repo repositories.ProductRepository
|
||||||
@@ -206,3 +207,8 @@ func (s *productService) CreateProductLocation(input []models.Productlocations)
|
|||||||
func (s *productService) CreateProductVariant(input models.Productvariant) error {
|
func (s *productService) CreateProductVariant(input models.Productvariant) error {
|
||||||
return s.repo.CreateProductVariant(input)
|
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