Пример #1
0
func handleMedicUpdate(w http.ResponseWriter, r *http.Request) errors.Http {
	m := models.Medic{}

	if err := BuildStructFromReqBody(&m, r.Body); err != nil {
		return errors.BadRequest(err.Error())
	}

	if err := FillMedicIdWIthUrlValue(&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
}
Пример #2
0
func FillMedicIdWIthUrlValue(m *models.Medic, params url.Values) error {
	id, err := strconv.Atoi(params.Get("id"))
	if err != nil {
		return err
	}
	m.ID = id

	return nil
}
Пример #3
0
func handleMedicRetrieve(w http.ResponseWriter, r *http.Request) errors.Http {
	m := models.Medic{}
	if err := BuildStructFromQueryString(&m, r.URL.Query()); err != nil {
		return errors.BadRequest(err.Error())
	}

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

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

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

	return nil
}
Пример #4
0
/*
*	Handlers
 */
func handleUserCreated(msg []byte) {
	var usr authModels.User
	err := json.Unmarshal(msg, &usr)

	if err != nil {
		fmt.Println("[ERROR] ", err.Error())
	}

	switch usr.Scope {
	case "patient":
		p := models.Patient{}
		p.ID = usr.ID
		p.Name = usr.FirstName + " " + usr.LastName
		p.Email = usr.Email

		err = p.Save(db)

		createFeedEvent(p)
		return

	case "medic":
		m := models.Medic{}
		m.ID = usr.ID
		m.Name = usr.FirstName + " " + usr.LastName
		m.Email = usr.Email

		err = m.Create(db)

		return

	case "pharmacist":
		p := models.Pharmacist{}
		p.ID = usr.ID
		p.Name = usr.FirstName + " " + usr.LastName
		p.Email = usr.Email

		err = p.Save(db)
		return
	}
	if err != nil {
		fmt.Println("[ERROR] ", err.Error())
	}

}