Example #1
0
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
}
Example #2
0
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
}