Skip to content

Commit

Permalink
feat : brands by manager_id added
Browse files Browse the repository at this point in the history
  • Loading branch information
surajhub255 committed Jun 30, 2024
1 parent 6a784a1 commit e320531
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
13 changes: 13 additions & 0 deletions controllers/brand_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 2 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit e320531

Please sign in to comment.