mirror of
https://github.com/FJurmanovic/wallet-go-api.git
synced 2026-02-06 06:08:16 +00:00
restructured controllers
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -9,6 +9,8 @@ _obj
|
|||||||
_test
|
_test
|
||||||
vendor
|
vendor
|
||||||
bin
|
bin
|
||||||
|
.vscode
|
||||||
|
.idea
|
||||||
|
|
||||||
.env
|
.env
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package main
|
|||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"wallet-api/pkg/api"
|
"wallet-api/pkg/api"
|
||||||
"wallet-api/pkg/utl/common"
|
|
||||||
"wallet-api/pkg/utl/db"
|
"wallet-api/pkg/utl/db"
|
||||||
"wallet-api/pkg/utl/server"
|
"wallet-api/pkg/utl/server"
|
||||||
|
|
||||||
@@ -12,8 +11,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
err := godotenv.Load()
|
godotenv.Load()
|
||||||
common.CheckError(err)
|
|
||||||
|
|
||||||
dbUrl := os.Getenv("DATABASE_URL")
|
dbUrl := os.Getenv("DATABASE_URL")
|
||||||
r := gin.Default()
|
r := gin.Default()
|
||||||
|
|||||||
@@ -3,18 +3,21 @@ package api
|
|||||||
import (
|
import (
|
||||||
"wallet-api/pkg/controllers"
|
"wallet-api/pkg/controllers"
|
||||||
"wallet-api/pkg/services"
|
"wallet-api/pkg/services"
|
||||||
|
"wallet-api/pkg/utl/configs"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/go-pg/pg/v10"
|
"github.com/go-pg/pg/v10"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Routes(s *gin.Engine, db *pg.DB) {
|
func Routes(s *gin.Engine, db *pg.DB) {
|
||||||
|
ver := s.Group(configs.Prefix)
|
||||||
|
|
||||||
|
api := ver.Group("api")
|
||||||
|
register := ver.Group("register")
|
||||||
|
|
||||||
apiService := services.ApiService{Db: db}
|
apiService := services.ApiService{Db: db}
|
||||||
registerService := services.RegisterService{Db: db}
|
registerService := services.RegisterService{Db: db}
|
||||||
|
|
||||||
apiController := controllers.ApiController{ApiService: &apiService}
|
controllers.NewApiController(&apiService, api)
|
||||||
registerController := controllers.RegisterController{RegisterService: ®isterService}
|
controllers.NewRegisterController(®isterService, register)
|
||||||
|
|
||||||
apiController.Init(s)
|
|
||||||
registerController.Init(s)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,9 +10,13 @@ type ApiController struct {
|
|||||||
ApiService *services.ApiService
|
ApiService *services.ApiService
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ac *ApiController) Init(s *gin.Engine) {
|
func NewApiController(as *services.ApiService, s *gin.RouterGroup) *ApiController {
|
||||||
apiGroup := s.Group("/api")
|
ac := new(ApiController)
|
||||||
apiGroup.GET("", ac.getFirst)
|
ac.ApiService = as
|
||||||
|
|
||||||
|
s.GET("", ac.getFirst)
|
||||||
|
|
||||||
|
return ac
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ac *ApiController) getFirst(c *gin.Context) {
|
func (ac *ApiController) getFirst(c *gin.Context) {
|
||||||
|
|||||||
@@ -13,9 +13,13 @@ type RegisterController struct {
|
|||||||
RegisterService *services.RegisterService
|
RegisterService *services.RegisterService
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rc *RegisterController) Init(s *gin.Engine) {
|
func NewRegisterController(rs *services.RegisterService, s *gin.RouterGroup) *RegisterController {
|
||||||
apiGroup := s.Group("/register")
|
rc := new(RegisterController)
|
||||||
apiGroup.POST("", rc.Post)
|
rc.RegisterService = rs
|
||||||
|
|
||||||
|
s.POST("", rc.Post)
|
||||||
|
|
||||||
|
return rc
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rc *RegisterController) Post(c *gin.Context) {
|
func (rc *RegisterController) Post(c *gin.Context) {
|
||||||
|
|||||||
@@ -1 +1,6 @@
|
|||||||
package configs
|
package configs
|
||||||
|
|
||||||
|
const (
|
||||||
|
Version = "0.0.1"
|
||||||
|
Prefix = "v1"
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user