Example #1
0
func ShowComponents(ren render.Render, db *sql.DB, t *template.TemplateData) {
	var err error

	t.Data, err = repository.GetComponents(db)

	if err != nil {
		t.SessionMessage.AddDanger("Failed to load components.")

		ren.Redirect("/")

		return
	}

	ren.HTML(200, "blah/component/list", t)
}
Example #2
0
func GetAllInJson(r render.Render, db *sql.DB) {
	var err error

	json := entity.AllInJson{}

	json.LatestNewsCollection, err = repository.GetLatestNewsCollection(db, true)
	if err != nil {
		log.Fatalln(err)
		r.JSON(500, "Loading data failed")
		return
	}

	json.Corals, err = repository.GetCorals(db)
	if err != nil {
		log.Fatalln(err)
		r.JSON(500, "Loading data failed")
		return
	}

	json.Components, err = repository.GetComponents(db)
	if err != nil {
		log.Fatalln(err)
		r.JSON(500, "Loading data failed")
		return
	}

	json.Inhabitants, err = repository.GetInhabitants(db)
	if err != nil {
		log.Fatalln(err)
		r.JSON(500, "Loading data failed")
		return
	}

	json.Invertebrates, err = repository.GetInvertebrates(db)
	if err != nil {
		log.Fatalln(err)
		r.JSON(500, "Loading data failed")
		return
	}

	json.Plants, err = repository.GetPlants(db)
	if err != nil {
		log.Fatalln(err)
		r.JSON(500, "Loading data failed")
		return
	}

	media, err := repository.GetAllMedia(db)
	if err != nil {
		log.Fatalln(err)
		r.JSON(500, "Loading data failed")
		return
	}

	json.AssignMediaToEntities(&media)

	popular_names, err := repository.GetAllPopularNames(db)
	if err != nil {
		log.Fatalln(err)
		r.JSON(500, "Loading data failed")
		return
	}

	json.AssignPopularNamesToEntities(popular_names)

	r.JSON(200, json)
}