package controllers import ( "encoding/json" "ExpiryDatesManager/server/model" "ExpiryDatesManager/server/utils" "net/http" ) var GetPositions = func(w http.ResponseWriter, r *http.Request) { data := model.GetPositions() resp := utils.Message(true, "success") resp["data"] = data utils.Respond(w, resp) } var CreateOrUpdatePosition = func(w http.ResponseWriter, r *http.Request) { position := &model.ProductExpiryPosition{} err := json.NewDecoder(r.Body).Decode(position) if err != nil { utils.Respond(w, utils.Message(false, "Error while decoding request body")) return } data := position.CreateOrUpdate() if data.ID == 0 { utils.Respond(w, utils.Message(false, "Database error")) return } resp := utils.Message(true, "success") resp["data"] = data utils.Respond(w, resp) }