-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from voltgizerz/develop
Add user routes and refactor
- Loading branch information
Showing
12 changed files
with
183 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package handler | ||
|
||
import ( | ||
"github.com/gofiber/fiber/v3" | ||
"github.com/voltgizerz/POS-restaurant/internal/app/ports" | ||
) | ||
|
||
type UserHandler struct { | ||
userService ports.IUserService | ||
} | ||
|
||
func NewUserHandler(userService ports.IUserService) *UserHandler { | ||
return &UserHandler{ | ||
userService: userService, | ||
} | ||
} | ||
|
||
func (h *UserHandler) Login(c fiber.Ctx) error { | ||
// TODO | ||
return nil | ||
} | ||
|
||
func (h *UserHandler) Register(c fiber.Ctx) error { | ||
// TODO | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package api | ||
|
||
import ( | ||
"github.com/gofiber/fiber/v3" | ||
"github.com/voltgizerz/POS-restaurant/pkg/logger" | ||
) | ||
|
||
// InitRouter initializes routes for the API server. | ||
func (s *Server) InitRouter() *fiber.App { | ||
app := fiber.New() | ||
|
||
v1 := app.Group("api/v1") | ||
s.initUserRoutes(v1) | ||
s.initPingRoute(v1) | ||
|
||
// Print all routes when server starts | ||
printRoutes(app) | ||
|
||
return app | ||
} | ||
|
||
// initUserRoutes initializes user-related routes. | ||
func (s *Server) initUserRoutes(group fiber.Router) { | ||
userRoutes := group.Group("/user") | ||
userRoutes.Post("/login", s.userHandler.Login) | ||
userRoutes.Post("/register", s.userHandler.Register) | ||
} | ||
|
||
// initPingRoute initializes the ping route. | ||
func (s *Server) initPingRoute(group fiber.Router) { | ||
group.Get("/ping", func(c fiber.Ctx) error { | ||
return c.SendString("Pong") | ||
}) | ||
} | ||
|
||
// printRoutes prints all registered routes. | ||
func printRoutes(app *fiber.App) { | ||
for _, route := range app.GetRoutes() { | ||
logger.Log.Infof("[%s] %s", route.Method, route.Path) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,29 @@ | ||
package api | ||
|
||
import ( | ||
"github.com/gofiber/fiber/v3" | ||
"github.com/voltgizerz/POS-restaurant/config" | ||
"github.com/voltgizerz/POS-restaurant/internal/app/interactor" | ||
"github.com/voltgizerz/POS-restaurant/internal/app/ports" | ||
"github.com/voltgizerz/POS-restaurant/pkg/logger" | ||
) | ||
|
||
func NewServer(cfg config.API) { | ||
app := fiber.New() | ||
type Server struct { | ||
cfg config.API | ||
userHandler ports.IUserHandler | ||
} | ||
|
||
func NewServer(interactor interactor.APInteractor) *Server { | ||
return &Server{ | ||
cfg: interactor.Cfg, | ||
userHandler: interactor.UserHandler, | ||
} | ||
} | ||
|
||
app.Get("/ping", func(c fiber.Ctx) error { | ||
return c.SendString("pong") | ||
}) | ||
func (s *Server) Initialize() { | ||
app := s.InitRouter() | ||
|
||
logger.LogStdErr.Fatal(app.Listen(":" + cfg.PORT)) | ||
err := app.Listen(":" + s.cfg.PORT) | ||
if err != nil { | ||
logger.LogStdErr.Fatalf("[Initialize] error on: %s", err.Error()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,11 @@ | ||
package interactor | ||
|
||
import ( | ||
"github.com/voltgizerz/POS-restaurant/config" | ||
"github.com/voltgizerz/POS-restaurant/internal/app/ports" | ||
) | ||
|
||
type APInteractor struct { | ||
Cfg config.API | ||
UserHandler ports.IUserHandler | ||
} |
2 changes: 1 addition & 1 deletion
2
internal/app/interfaces/auth.interface.go → internal/app/ports/auth_ports.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package interfaces | ||
package ports | ||
|
||
type IAuth interface { | ||
} |
11 changes: 10 additions & 1 deletion
11
internal/app/interfaces/user.interface.go → internal/app/ports/user_ports.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,20 @@ | ||
package interfaces | ||
package ports | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/gofiber/fiber/v3" | ||
"github.com/voltgizerz/POS-restaurant/internal/app/entity" | ||
) | ||
|
||
type IUserRepository interface { | ||
GetUser(ctx context.Context, int64 int64) (*entity.User, error) | ||
} | ||
|
||
type IUserService interface { | ||
} | ||
|
||
type IUserHandler interface { | ||
Login(c fiber.Ctx) error | ||
Register(c fiber.Ctx) error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package service | ||
|
||
import ( | ||
"github.com/voltgizerz/POS-restaurant/internal/app/ports" | ||
) | ||
|
||
type UserService struct { | ||
userRepository ports.IUserRepository | ||
} | ||
|
||
func NewUserService(repository ports.IUserRepository) *UserService { | ||
return &UserService{ | ||
userRepository: repository, | ||
} | ||
} | ||
|
||
func (s *UserService) Login(email string, password string) error { | ||
// TODO | ||
return nil | ||
} | ||
|
||
func (s *UserService) Register(email string, password string, confirmPass string) error { | ||
// TODO | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package service |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters