Skip to content

Commit

Permalink
Merge pull request #283 from jovandeginste/split-routes
Browse files Browse the repository at this point in the history
chore: Move the route handlers to their own files
  • Loading branch information
jovandeginste authored Sep 2, 2024
2 parents ad6743e + e0e42c7 commit f19516c
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 56 deletions.
11 changes: 11 additions & 0 deletions pkg/app/equipment_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ import (
"github.com/labstack/echo/v4"
)

func (a *App) addRoutesEquipment(e *echo.Group) {
equipmentGroup := e.Group("/equipment")
equipmentGroup.GET("", a.equipmentHandler).Name = "equipment"
equipmentGroup.POST("", a.addEquipment).Name = "equipment-create"
equipmentGroup.GET("/:id", a.equipmentShowHandler).Name = "equipment-show"
equipmentGroup.POST("/:id", a.equipmentUpdateHandler).Name = "equipment-update"
equipmentGroup.GET("/:id/edit", a.equipmentEditHandler).Name = "equipment-edit"
equipmentGroup.POST("/:id/delete", a.equipmentDeleteHandler).Name = "equipment-delete"
equipmentGroup.GET("/add", a.equipmentAddHandler).Name = "equipment-add"
}

func (a *App) addEquipment(c echo.Context) error {
u := a.getCurrentUser(c)
p := database.Equipment{}
Expand Down
14 changes: 14 additions & 0 deletions pkg/app/route_segments_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@ import (
"github.com/labstack/echo/v4"
)

func (a *App) addRoutesSegments(e *echo.Group) {
routeSegmentsGroup := e.Group("/route_segments")
routeSegmentsGroup.GET("", a.routeSegmentsHandler).Name = "route-segments"
routeSegmentsGroup.POST("", a.addRouteSegment).Name = "route-segments-create"
routeSegmentsGroup.GET("/:id", a.routeSegmentsShowHandler).Name = "route-segment-show"
routeSegmentsGroup.POST("/:id", a.routeSegmentsUpdateHandler).Name = "route-segment-update"
routeSegmentsGroup.GET("/:id/download", a.routeSegmentsDownloadHandler).Name = "route-segment-download"
routeSegmentsGroup.GET("/:id/edit", a.routeSegmentsEditHandler).Name = "route-segment-edit"
routeSegmentsGroup.POST("/:id/delete", a.routeSegmentsDeleteHandler).Name = "route-segment-delete"
routeSegmentsGroup.POST("/:id/refresh", a.routeSegmentsRefreshHandler).Name = "route-segment-refresh"
routeSegmentsGroup.POST("/:id/matches", a.routeSegmentFindMatches).Name = "route-segment-matches"
routeSegmentsGroup.GET("/add", a.routeSegmentsAddHandler).Name = "route-segment-add"
}

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

Expand Down
56 changes: 0 additions & 56 deletions pkg/app/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,59 +127,3 @@ func (a *App) addRoutesSecure(e *echo.Group) *echo.Group {

return secureGroup
}

func (a *App) addRoutesUsers(e *echo.Group) {
usersGroup := e.Group("/users")
usersGroup.GET("/:id", a.userShowHandler).Name = "user-show"
}

func (a *App) addRoutesWorkouts(e *echo.Group) {
workoutsGroup := e.Group("/workouts")
workoutsGroup.GET("", a.workoutsHandler).Name = "workouts"
workoutsGroup.POST("", a.addWorkout).Name = "workouts-create"
workoutsGroup.GET("/:id", a.workoutsShowHandler).Name = "workout-show"
workoutsGroup.POST("/:id", a.workoutsUpdateHandler).Name = "workout-update"
workoutsGroup.GET("/:id/download", a.workoutsDownloadHandler).Name = "workout-download"
workoutsGroup.GET("/:id/edit", a.workoutsEditHandler).Name = "workout-edit"
workoutsGroup.POST("/:id/delete", a.workoutsDeleteHandler).Name = "workout-delete"
workoutsGroup.POST("/:id/refresh", a.workoutsRefreshHandler).Name = "workout-refresh"
workoutsGroup.GET("/:id/route-segment", a.workoutsCreateRouteSegmentHandler).Name = "workout-route-segment"
workoutsGroup.POST("/:id/route-segment", a.workoutsCreateRouteSegmentFromWorkoutHandler).Name = "workout-route-segment-create"
workoutsGroup.GET("/add", a.workoutsAddHandler).Name = "workout-add"
workoutsGroup.GET("/form", a.workoutsFormHandler).Name = "workout-form"
}

func (a *App) addRoutesEquipment(e *echo.Group) {
equipmentGroup := e.Group("/equipment")
equipmentGroup.GET("", a.equipmentHandler).Name = "equipment"
equipmentGroup.POST("", a.addEquipment).Name = "equipment-create"
equipmentGroup.GET("/:id", a.equipmentShowHandler).Name = "equipment-show"
equipmentGroup.POST("/:id", a.equipmentUpdateHandler).Name = "equipment-update"
equipmentGroup.GET("/:id/edit", a.equipmentEditHandler).Name = "equipment-edit"
equipmentGroup.POST("/:id/delete", a.equipmentDeleteHandler).Name = "equipment-delete"
equipmentGroup.GET("/add", a.equipmentAddHandler).Name = "equipment-add"
}

func (a *App) addRoutesSelf(e *echo.Group) {
selfGroup := e.Group("/user")
selfGroup.GET("/profile", a.userProfileHandler).Name = "user-profile"
selfGroup.POST("/profile", a.userProfileUpdateHandler).Name = "user-profile-update"
selfGroup.POST("/profile/preferred-units", a.userProfilePreferredUnitsUpdateHandler).Name = "user-profile-preferred-units-update"
selfGroup.POST("/refresh", a.userRefreshHandler).Name = "user-refresh"
selfGroup.POST("/reset-api-key", a.userProfileResetAPIKeyHandler).Name = "user-profile-reset-api-key"
selfGroup.POST("/update-version", a.userUpdateVersion).Name = "user-update-version"
}

func (a *App) addRoutesSegments(e *echo.Group) {
routeSegmentsGroup := e.Group("/route_segments")
routeSegmentsGroup.GET("", a.routeSegmentsHandler).Name = "route-segments"
routeSegmentsGroup.POST("", a.addRouteSegment).Name = "route-segments-create"
routeSegmentsGroup.GET("/:id", a.routeSegmentsShowHandler).Name = "route-segment-show"
routeSegmentsGroup.POST("/:id", a.routeSegmentsUpdateHandler).Name = "route-segment-update"
routeSegmentsGroup.GET("/:id/download", a.routeSegmentsDownloadHandler).Name = "route-segment-download"
routeSegmentsGroup.GET("/:id/edit", a.routeSegmentsEditHandler).Name = "route-segment-edit"
routeSegmentsGroup.POST("/:id/delete", a.routeSegmentsDeleteHandler).Name = "route-segment-delete"
routeSegmentsGroup.POST("/:id/refresh", a.routeSegmentsRefreshHandler).Name = "route-segment-refresh"
routeSegmentsGroup.POST("/:id/matches", a.routeSegmentFindMatches).Name = "route-segment-matches"
routeSegmentsGroup.GET("/add", a.routeSegmentsAddHandler).Name = "route-segment-add"
}
10 changes: 10 additions & 0 deletions pkg/app/self_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ import (
"github.com/labstack/echo/v4"
)

func (a *App) addRoutesSelf(e *echo.Group) {
selfGroup := e.Group("/user")
selfGroup.GET("/profile", a.userProfileHandler).Name = "user-profile"
selfGroup.POST("/profile", a.userProfileUpdateHandler).Name = "user-profile-update"
selfGroup.POST("/profile/preferred-units", a.userProfilePreferredUnitsUpdateHandler).Name = "user-profile-preferred-units-update"
selfGroup.POST("/refresh", a.userRefreshHandler).Name = "user-refresh"
selfGroup.POST("/reset-api-key", a.userProfileResetAPIKeyHandler).Name = "user-profile-reset-api-key"
selfGroup.POST("/update-version", a.userUpdateVersion).Name = "user-update-version"
}

func (a *App) userProfileHandler(c echo.Context) error {
data := a.defaultData(c)
return c.Render(http.StatusOK, "user_profile.html", data)
Expand Down
5 changes: 5 additions & 0 deletions pkg/app/users_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ import (

var ErrLoginFailed = errors.New("username or password incorrect")

func (a *App) addRoutesUsers(e *echo.Group) {
usersGroup := e.Group("/users")
usersGroup.GET("/:id", a.userShowHandler).Name = "user-show"
}

// userSigninHandler will be executed after SignInForm submission.
func (a *App) userSigninHandler(c echo.Context) error {
// Initiate a new User struct.
Expand Down
16 changes: 16 additions & 0 deletions pkg/app/workouts_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@ import (
"github.com/labstack/echo/v4"
)

func (a *App) addRoutesWorkouts(e *echo.Group) {
workoutsGroup := e.Group("/workouts")
workoutsGroup.GET("", a.workoutsHandler).Name = "workouts"
workoutsGroup.POST("", a.addWorkout).Name = "workouts-create"
workoutsGroup.GET("/:id", a.workoutsShowHandler).Name = "workout-show"
workoutsGroup.POST("/:id", a.workoutsUpdateHandler).Name = "workout-update"
workoutsGroup.GET("/:id/download", a.workoutsDownloadHandler).Name = "workout-download"
workoutsGroup.GET("/:id/edit", a.workoutsEditHandler).Name = "workout-edit"
workoutsGroup.POST("/:id/delete", a.workoutsDeleteHandler).Name = "workout-delete"
workoutsGroup.POST("/:id/refresh", a.workoutsRefreshHandler).Name = "workout-refresh"
workoutsGroup.GET("/:id/route-segment", a.workoutsCreateRouteSegmentHandler).Name = "workout-route-segment"
workoutsGroup.POST("/:id/route-segment", a.workoutsCreateRouteSegmentFromWorkoutHandler).Name = "workout-route-segment-create"
workoutsGroup.GET("/add", a.workoutsAddHandler).Name = "workout-add"
workoutsGroup.GET("/form", a.workoutsFormHandler).Name = "workout-form"
}

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

Expand Down

0 comments on commit f19516c

Please sign in to comment.