From 950064de6cb1224c6e73bdb590f32cd0e1c9efa5 Mon Sep 17 00:00:00 2001 From: abhishek Date: Wed, 15 Jul 2026 15:25:50 +0530 Subject: [PATCH] productRepository created --- controllers/productController.go | 38 +++++++++++++++++++++++++++++++ repositories/productRepository.go | 10 +++++++- routes/productroutes.go | 1 + scratch/check_db_schema.go | 2 ++ scratch/query_stores.go | 2 ++ scratch/seed_users.go | 2 ++ scratch/test_delete.go | 2 ++ services/productService.go | 6 +++++ 8 files changed, 62 insertions(+), 1 deletion(-) diff --git a/controllers/productController.go b/controllers/productController.go index 32f9ba3..7f026fb 100644 --- a/controllers/productController.go +++ b/controllers/productController.go @@ -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, + }) +} diff --git a/repositories/productRepository.go b/repositories/productRepository.go index 3318b56..e04aaf4 100644 --- a/repositories/productRepository.go +++ b/repositories/productRepository.go @@ -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 +} diff --git a/routes/productroutes.go b/routes/productroutes.go index 524c135..d132359 100644 --- a/routes/productroutes.go +++ b/routes/productroutes.go @@ -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) diff --git a/scratch/check_db_schema.go b/scratch/check_db_schema.go index 6802f56..57f6e8d 100644 --- a/scratch/check_db_schema.go +++ b/scratch/check_db_schema.go @@ -1,3 +1,5 @@ +//go:build ignore + package main import ( diff --git a/scratch/query_stores.go b/scratch/query_stores.go index d1b063b..0adafaa 100644 --- a/scratch/query_stores.go +++ b/scratch/query_stores.go @@ -1,3 +1,5 @@ +//go:build ignore + package main import ( diff --git a/scratch/seed_users.go b/scratch/seed_users.go index 8f183c4..e76e0b0 100644 --- a/scratch/seed_users.go +++ b/scratch/seed_users.go @@ -1,3 +1,5 @@ +//go:build ignore + package main import ( diff --git a/scratch/test_delete.go b/scratch/test_delete.go index 6d05e4d..556ff02 100644 --- a/scratch/test_delete.go +++ b/scratch/test_delete.go @@ -1,3 +1,5 @@ +//go:build ignore + package main import ( diff --git a/services/productService.go b/services/productService.go index 18c8750..7ff3457 100644 --- a/services/productService.go +++ b/services/productService.go @@ -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) +} +