package task import ( "net/http" "git.tek.govt.hu/dowerx/szoe-pontok/database/task" "git.tek.govt.hu/dowerx/szoe-pontok/model" "github.com/gin-gonic/gin" "github.com/gin-gonic/gin/binding" "github.com/go-playground/validator/v10" ) func Add(c *gin.Context) { var tsk model.Task if c.MustBindWith(&tsk, binding.Form) != nil { return } issuer, ok := c.Get("neptun") if !ok { c.JSON(http.StatusBadRequest, gin.H{ "status": http.StatusBadRequest, "error": "not logged in", }) return } tsk.Issuer = issuer.(string) val := validator.New(validator.WithRequiredStructEnabled()) if err := val.Struct(tsk); err != nil { c.JSON(http.StatusBadRequest, gin.H{ "status": http.StatusBadRequest, "error": err.Error(), }) return } if err := task.Add(tsk); err != nil { c.JSON(http.StatusBadRequest, gin.H{ "status": http.StatusBadRequest, "error": err.Error(), }) return } else { c.JSON(http.StatusOK, gin.H{ "status": http.StatusOK, "message": "added", }) } }