Reviewed-on: tim/me-fit#124
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"log"
|
||||
"me-fit/template"
|
||||
"me-fit/template/workout"
|
||||
|
||||
@@ -77,9 +78,8 @@ func HandleNewWorkout(db *sql.DB) http.HandlerFunc {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
wo := workout.Workout{
|
||||
Date: r.FormValue("date"),
|
||||
Date: renderDate(date),
|
||||
Type: r.FormValue("type"),
|
||||
Sets: r.FormValue("sets"),
|
||||
Reps: r.FormValue("reps"),
|
||||
@@ -115,6 +115,12 @@ func HandleGetWorkouts(db *sql.DB) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
workout.Date, err = renderDateStr(workout.Date)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
workouts = append(workouts, workout)
|
||||
}
|
||||
|
||||
@@ -152,3 +158,17 @@ func HandleDeleteWorkout(db *sql.DB) http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func renderDateStr(date string) (string, error) {
|
||||
log.Println(date)
|
||||
t, err := time.Parse("2006-01-02 15:04:05-07:00", date)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return renderDate(t), nil
|
||||
}
|
||||
|
||||
func renderDate(date time.Time) string {
|
||||
return date.Format("2006-01-02")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user