Esempio n. 1
0
// FetchPersonIDs ... Fetch all the regions/state of a country
func (c PersonController) FetchPersonIDs(res http.ResponseWriter, req *http.Request, next http.HandlerFunc) {
	r := render.New(render.Options{})
	vars := mux.Vars(req)
	personID := vars["person_id"]

	// find in the database
	ids := models.PersonIDType{}
	idTypes := models.IDType{}
	//query := c.Db.Where("person_id = ?", personID).Find(&ids)
	//c.Db.Model(&ids).Related(&idTypes, "IDType")
	qryparam := map[string]interface{}{"person_id": personID}
	err := c.DataStore.FetchRelatedObject(qryparam, &ids, &idTypes, "IDType")
	ids.IDTypes = idTypes

	if err != nil && err.ErrNo == 1001 {
		r.JSON(res, 404, err.Error())
	} else if err == nil {
		//User exist in database, confirm his password
		r.JSON(res, 200, ids)
	} else {
		panic(err)
	}
}