From d0c642faf552e7aba5448c60c7273ee127a2843a Mon Sep 17 00:00:00 2001 From: dylanhitt Date: Wed, 20 Nov 2024 13:38:12 -0500 Subject: [PATCH] refactor(full-app-gourmet): to use options rather than deprecated builder pattern --- examples/full-app-gourmet/controller/recipe.go | 18 ++++++++++-------- examples/full-app-gourmet/controller/routes.go | 15 ++++++++++----- examples/full-app-gourmet/views/views.go | 4 +++- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/examples/full-app-gourmet/controller/recipe.go b/examples/full-app-gourmet/controller/recipe.go index 5e965cbe..aef8abb1 100644 --- a/examples/full-app-gourmet/controller/recipe.go +++ b/examples/full-app-gourmet/controller/recipe.go @@ -6,6 +6,7 @@ import ( "github.com/go-fuego/fuego" "github.com/go-fuego/fuego/examples/full-app-gourmet/store" + "github.com/go-fuego/fuego/option" ) type recipeResource struct { @@ -14,16 +15,17 @@ type recipeResource struct { } func (rs recipeResource) MountRoutes(s *fuego.Server) { - fuego.GetStd(s, "/recipes-standard-with-helpers", rs.getAllRecipesStandardWithHelpers). - AddTags("Recipe") - + fuego.GetStd(s, "/recipes-standard-with-helpers", rs.getAllRecipesStandardWithHelpers, + option.Tags("Recipe"), + ) recipeGroup := fuego.Group(s, "/recipes") - fuego.Get(recipeGroup, "/", rs.getAllRecipes). - Summary("Get all recipes").Description("Get all recipes"). - QueryParam("limit", "number of recipes to return"). - AddTags("custom") - + fuego.Get(recipeGroup, "/", rs.getAllRecipes, + option.Summary("Get all recipes"), + option.Description("Get all recipes"), + option.Query("limit", "number of recipes to return"), + option.Tags("customer"), + ) fuego.Post(recipeGroup, "/new", rs.newRecipe) fuego.Get(recipeGroup, "/{id}", rs.getRecipeWithIngredients) } diff --git a/examples/full-app-gourmet/controller/routes.go b/examples/full-app-gourmet/controller/routes.go index a63b43ce..a32937dd 100644 --- a/examples/full-app-gourmet/controller/routes.go +++ b/examples/full-app-gourmet/controller/routes.go @@ -8,6 +8,7 @@ import ( "github.com/go-fuego/fuego" "github.com/go-fuego/fuego/middleware/basicauth" + "github.com/go-fuego/fuego/option" ) // Resource is the global struct that holds useful sources of information available for the controllers. @@ -58,13 +59,17 @@ func (rs Resource) MountRoutes(s *fuego.Server) { fuego.Use(adminRoutes, fuego.AuthWall("admin", "superadmin")) // Only admin and superadmin can access the routes in this group fuego.Use(adminRoutes, fuego.AuthWallRegex(`^(super)?admin$`)) // Same as above, but with a regex - fuego.Get(adminRoutes, "/users", placeholderController). - Description("Get all users"). - Summary("Get all users"). - Tags("Admin") + fuego.Get(adminRoutes, "/users", placeholderController, + option.Description("Get all users"), + option.Summary("Get all users"), + option.Tags("Admin"), + ) testRoutes := fuego.Group(s, "/tests") - fuego.Get(testRoutes, "/slow", slow).Description("This is a slow route").Summary("Slow route") + fuego.Get(testRoutes, "/slow", slow, + option.Description("This is a slow route"), + option.Summary("Slow route"), + ) fuego.Get(testRoutes, "/mounted-route", placeholderController) fuego.Post(testRoutes, "/mounted-route-post", placeholderController) diff --git a/examples/full-app-gourmet/views/views.go b/examples/full-app-gourmet/views/views.go index b190df3e..90b6e1c4 100644 --- a/examples/full-app-gourmet/views/views.go +++ b/examples/full-app-gourmet/views/views.go @@ -32,7 +32,9 @@ func (rs Resource) Routes(s *fuego.Server) { // Public Chunks fuego.Get(s, "/recipes-list", rs.showRecipesList) - fuego.Get(s, "/search", rs.searchRecipes).AddError(http.StatusUnauthorized, "Authorization Error").AddError(500, "My Server Error") + fuego.Get(s, "/search", rs.searchRecipes).AddError(http.StatusUnauthorized, "Authorization Error", + option.AddError(500, "My Server Error"), + ) fuego.Get(s, "/ingredients/preselect-unit", rs.unitPreselected, option.Query("id", "ID", param.Required(), param.Default("1"), param.Example("example", "abcde1245")), )