Ejemplo n.º 1
0
func ServeWorkout(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	wIdStr := vars["workoutId"]
	wId, err := strconv.ParseInt(wIdStr, 10, 64)
	if err != nil {
		failParams := models.Response{Success: false, Debug: fmt.Sprintf("Invalid workout id, %s", wIdStr), Message: "Failed Retrieving the Workout"}
		api.JSONResponse(w, failParams, 400)
		return
	}
	pl := models.WorkoutResponse{Id: wId}
	err = pl.FindById()
	if err != nil {
		failParams := models.Response{Success: false, Debug: "Internal server error. If this issue persists, please submit a bug report to {{serviceName}}", Message: "Failed Retrieving the Workout"}
		api.JSONResponse(w, failParams, 500)
		return
	}
	w.Header().Set("Content-Type", "text/html; charset=utf-8")
	workoutTempl.Execute(w, pl)
}
Ejemplo n.º 2
0
func V0_API_Get_Workout(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	wIdStr := vars["workoutId"]
	wId, err := strconv.ParseInt(wIdStr, 10, 64)
	if err != nil {
		failParams := models.Response{Success: false, Debug: fmt.Sprintf("Invalid workout id, %s", wIdStr), Message: "Failed Retrieving the Workout"}
		JSONResponse(w, failParams, 400)
		return
	}
	pl := models.WorkoutResponse{Id: wId}
	err = pl.FindById()
	if err != nil {
		failParams := models.Response{Success: false, Debug: "Internal server error. If this issue persists, please submit a bug report to {{serviceName}}", Message: "Failed Retrieving the Workout"}
		JSONResponse(w, failParams, 500)
		return
	}
	successResp := models.Response{Success: true, Data: pl, Message: "Successfully Retrieved the Workout"}
	JSONResponse(w, successResp, 200)
}