Ejemplo n.º 1
0
func FindTravel(request *restful.Request, response *restful.Response) {
	id := request.PathParameter("travel-id")
	session := utils.NewSession()
	rows, err := session.DB.Query("SELECT id, name, description, date_begin, date_end FROM travel WHERE id = " + id)
	if err != nil {
		panic(err.Error())
	}
	defer rows.Close()
	var travel TravelResource
	for rows.Next() {
		err := rows.Scan(&travel.ID, &travel.Name, &travel.Description, &travel.DateBegin, &travel.DateEnd)
		if err != nil {
			panic(err)
		}
	}
	session.Close()
	response.WriteAsJson(travel)
}
Ejemplo n.º 2
0
func GetTravels(request *restful.Request, response *restful.Response) {
	session := utils.NewSession()
	rows, err := session.DB.Query("SELECT id, name, description, date_begin, date_end FROM travel")
	if err != nil {
		panic(err.Error())
	}
	defer rows.Close()
	var results []TravelResource
	var travel TravelResource
	for rows.Next() {
		err := rows.Scan(&travel.ID, &travel.Name, &travel.Description, &travel.DateBegin, &travel.DateEnd)
		if err != nil {
			panic(err)
		}
		results = append(results, travel)
	}
	session.Close()
	response.WriteAsJson(results)
}