Example #1
0
func deleteMedication(w http.ResponseWriter, r *http.Request) errors.Http {
	m := models.Medication{}
	if err := FillMedicationIdWIthUrlValue(&m, r.URL.Query()); err != nil {
		return errors.BadRequest(err.Error())
	}

	if err := m.Delete(db); err != nil {
		return errors.InternalServerError(err.Error())
	}

	rend.JSON(w, http.StatusOK, m.ID)
	return nil
}
Example #2
0
func FillMedicationIdWIthUrlValue(m *models.Medication, params url.Values) error {
	id, err := strconv.Atoi(params.Get("id"))
	if err != nil {
		return err
	}
	m.ID = id

	return nil
}
Example #3
0
func retreiveMedication(w http.ResponseWriter, r *http.Request) errors.Http {
	m := models.Medication{}
	if err := BuildStructFromQueryString(&m, r.URL.Query()); err != nil {
		return errors.BadRequest(err.Error())
	}

	m.Base.Query = r.URL.Query()

	medications, err := m.Retrieve(db)
	if err != nil {
		return errors.BadRequest(err.Error())
	}

	if len(medications) == 0 {
		return errors.NotFound("record not found")
	}
	rend.JSON(w, http.StatusOK, medications)

	return nil
}