diff --git a/controllers/brand_controller.go b/controllers/brand_controller.go index 4238d61..4022892 100644 --- a/controllers/brand_controller.go +++ b/controllers/brand_controller.go @@ -43,6 +43,19 @@ func GetAllBrands(c *gin.Context) { } c.JSON(http.StatusOK, brands) } +func GetBrandsByManager(c *gin.Context) { + managerID := c.Param("manager_id") + var brands []models.Brand + if err := db.DB.Where("manager_id = ?", managerID).Find(&brands).Error; err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) + return + } + if len(brands) == 0 { + c.JSON(http.StatusNotFound, gin.H{"error": "No brands found for the specified manager_id"}) + return + } + c.JSON(http.StatusOK, brands) +} func UpdateBrand(c *gin.Context) { id := c.Param("id") diff --git a/server/server.go b/server/server.go index 75574e5..3fca1c8 100644 --- a/server/server.go +++ b/server/server.go @@ -43,6 +43,8 @@ func Routes(r *gin.Engine) { r.GET("/brands/all", controllers.GetAllBrands) r.PUT("/brands/:id", controllers.UpdateBrand) r.DELETE("/brands/:id", controllers.DeleteBrand) + r.GET("/brands/manager/:manager_id", controllers.GetBrandsByManager) + // Collection routes r.POST("/collections", controllers.CreateCollection)