Skip to content

Commit

Permalink
feat: added GetRouter to Controller interface and implementation
Browse files Browse the repository at this point in the history
* Added GetRouter to Controller interface and implementation
* Renamed Create as CreateRouter on Controller interface
  • Loading branch information
ralvarezdev committed Jan 25, 2025
1 parent 6166b0d commit 696c28e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 26 deletions.
48 changes: 28 additions & 20 deletions http/factory/controller.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package factory

import (
"github.com/goccy/go-json"
gonethttproute "github.com/ralvarezdev/go-net/http/route"
)

type (
// ControllerWrapper is the interface for the route controller
ControllerWrapper interface {
Create(baseRouter gonethttproute.RouterWrapper, path string) error
CreateRouter(baseRouter gonethttproute.RouterWrapper, path string) error
GetRouter() gonethttproute.RouterWrapper
RegisterRoutes()
RegisterGroups()
gonethttproute.RouterWrapper
Expand All @@ -18,26 +18,34 @@ type (
Controller struct {
gonethttproute.RouterWrapper
}
)

// Create creates the controller
func (c *Controller) Create(baseRouter gonethttproute.RouterWrapper, path string) error {
// Check if the base route is nil
if baseRouter == nil {
return gonethttproute.ErrNilRouter
}
// CreateRouter creates the controller
func (c *Controller) CreateRouter(
baseRouter gonethttproute.RouterWrapper,
path string,
) error {
// Check if the base route is nil
if baseRouter == nil {
return gonethttproute.ErrNilRouter
}

// Set the base route
c.RouterWrapper = baseRouter.NewGroup(path)
// Set the base route
c.RouterWrapper = baseRouter.NewGroup(path)

// Register the controller routes and groups
c.RegisterRoutes()
c.RegisterGroups()
return nil
}
// Register the controller routes and groups
c.RegisterRoutes()
c.RegisterGroups()
return nil
}

// RegisterRoutes registers the routes
func (c *Controller) RegisterRoutes() {}
// GetRouter returns the router
func (c *Controller) GetRouter() gonethttproute.RouterWrapper {
return c.RouterWrapper
}

// RegisterGroups registers the groups
func (c *Controller) RegisterGroups() {}
)
// RegisterRoutes registers the routes
func (c *Controller) RegisterRoutes() {}

// RegisterGroups registers the groups
func (c *Controller) RegisterGroups() {}
7 changes: 1 addition & 6 deletions http/factory/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ type (
// ModuleWrapper is the interface for the route module
ModuleWrapper interface {
Create(baseRouter gonethttproute.RouterWrapper, path string) error
CreateSubmodule(submodule ModuleWrapper, path string) error
}

// Module is the struct for the route module
Expand Down Expand Up @@ -37,10 +36,6 @@ func (m *Module) Create(
baseRouter gonethttproute.RouterWrapper,
path string,
) error {
return m.Controller.Create(baseRouter, path)
}
return m.Controller.CreateRouter(baseRouter, path)

// CreateSubmodule is a function that creates a new submodule of the Module struct
func (m *Module) CreateSubmodule(submodule ModuleWrapper, path string) error {
return submodule.Create(m.Controller, path)
}

0 comments on commit 696c28e

Please sign in to comment.