func insertMedication(w http.ResponseWriter, r *http.Request) errors.Http { im := models.IntermediateMedication{} if err := BuildStructFromReqBody(&im, r.Body); err != nil { return errors.BadRequest(err.Error()) } m := im.Medication() if err := m.Save(db); err != nil { return errors.InternalServerError(err.Error()) } sendProductCreated(m) rend.JSON(w, http.StatusOK, m) return nil }
func updateMedication(w http.ResponseWriter, r *http.Request) errors.Http { im := models.IntermediateMedication{} if err := BuildStructFromReqBody(&im, r.Body); err != nil { return errors.BadRequest(err.Error()) } m := im.Medication() if err := FillMedicationIdWIthUrlValue(m, r.URL.Query()); err != nil { return errors.BadRequest(err.Error()) } if err := m.Update(db); err != nil { return errors.InternalServerError(err.Error()) } rend.JSON(w, http.StatusOK, m) return nil }