category.go 516 B

123456789101112131415161718192021222324
  1. package controller
  2. import (
  3. "kng_feed_api/model"
  4. "net/http"
  5. "github.com/gin-gonic/gin"
  6. )
  7. func CreateUpdateCategories(context *gin.Context) {
  8. var categories model.Categories
  9. err := context.ShouldBindJSON(&categories)
  10. if err != nil {
  11. context.JSON(http.StatusBadRequest, gin.H{"error": err.Error})
  12. }
  13. for _, cat := range categories.Categories {
  14. _, err := cat.Save()
  15. if err != nil {
  16. context.JSON(http.StatusBadRequest, gin.H{"error": err.Error, "desc": "Error whyle saving data"})
  17. return
  18. }
  19. }
  20. }