| 1234567891011121314151617181920212223242526272829 |
- package controller
- import (
- "kng_feed_api/model"
- "net/http"
- "github.com/gin-gonic/gin"
- )
- type Categories struct {
- Categories []model.Category `binding:"dive" json:"categories"`
- }
- func CreateUpdateCategories(context *gin.Context) {
- var categories Categories
- err := context.ShouldBindJSON(&categories)
- if err != nil {
- context.JSON(http.StatusBadRequest, gin.H{"error": err.Error})
- }
- for _, cat := range categories.Categories {
- _, err := cat.Save()
- if err != nil {
- context.JSON(http.StatusBadRequest, gin.H{"error": err.Error, "desc": "Error whyle saving data"})
- return
- }
- }
- context.JSON(http.StatusCreated, gin.H{"ok": "Сохранено"})
- }
|