Skip to content

Commit

Permalink
refactor(full-app-gourmet): to use options rather than deprecated bui…
Browse files Browse the repository at this point in the history
…lder pattern
  • Loading branch information
dylanhitt authored and EwenQuim committed Nov 21, 2024
1 parent be0fe5d commit d0c642f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
18 changes: 10 additions & 8 deletions examples/full-app-gourmet/controller/recipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
Expand Down
15 changes: 10 additions & 5 deletions examples/full-app-gourmet/controller/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)

Expand Down
4 changes: 3 additions & 1 deletion examples/full-app-gourmet/views/views.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
)
Expand Down

0 comments on commit d0c642f

Please sign in to comment.