Skip to content

Commit

Permalink
Add a button to refresh all your workouts
Browse files Browse the repository at this point in the history
Useful for debugging purposes now...

Signed-off-by: Jo Vandeginste <[email protected]>
  • Loading branch information
jovandeginste committed Feb 21, 2024
1 parent 51fac0c commit b32b2c6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/app/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ func (a *App) secureRoutes(e *echo.Group) *echo.Group {
secureGroup.GET("/", a.dashboardHandler).Name = "dashboard"
secureGroup.GET("/statistics", a.statisticsHandler).Name = "statistics"
secureGroup.GET("/user/profile", a.userProfileHandler).Name = "user-profile"
secureGroup.POST("/user/refresh", a.userRefreshHandler).Name = "user-refresh"

usersGroup := secureGroup.Group("/users")
usersGroup.GET("/:id", a.userShowHandler).Name = "user-show"
Expand Down
21 changes: 21 additions & 0 deletions pkg/app/users_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,27 @@ func (a *App) userProfileHandler(c echo.Context) error {
return c.Render(http.StatusOK, "user_profile.html", data)
}

func (a *App) userRefreshHandler(c echo.Context) error {
u := a.getCurrentUser(c)

workouts, err := u.GetWorkouts(a.db)
if err != nil {
return a.redirectWithError(c, a.echo.Reverse("user-signout"), err)
}

for _, w := range workouts {
a.logger.Debug("Refreshing workout: " + w.Name)

if err := w.UpdateData(a.db); err != nil {
return a.redirectWithError(c, a.echo.Reverse("user-signout"), err)
}
}

a.setNotice(c, "All workouts have been refreshed.")

return c.Redirect(http.StatusFound, a.echo.Reverse("user-profile"))
}

func (a *App) userShowHandler(c echo.Context) error {
data := a.defaultData(c)

Expand Down
8 changes: 8 additions & 0 deletions views/user/user_profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
{{ template "header" . }}
<div class="content">
<h2 class="{{ IconFor `user-profile` }}">Your profile</h2>
<div class="inner-form">
<form method="post" action="{{ RouteFor `user-refresh` }}">
<label for="refresh">Refresh all your workouts</label>
<button type="submit">
<a class="{{ IconFor `refresh` }}"></a>
</button>
</form>
</div>
</div>

{{ template "footer" . }}
Expand Down

0 comments on commit b32b2c6

Please sign in to comment.