mirror of
https://github.com/FJurmanovic/wallet-go-api.git
synced 2026-11-11 07:41:10 +00:00
add DI
This commit is contained in:
@@ -3,30 +3,33 @@ package controllers
|
||||
import (
|
||||
"wallet-api/pkg/middleware"
|
||||
"wallet-api/pkg/services"
|
||||
"wallet-api/pkg/utl/common"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type ApiController struct {
|
||||
ApiService *services.ApiService
|
||||
service *services.ApiService
|
||||
}
|
||||
|
||||
/*
|
||||
NewApiController
|
||||
|
||||
Initializes ApiController.
|
||||
|
||||
Args:
|
||||
*services.ApiService: API service
|
||||
*gin.RouterGroup: Gin Router Group
|
||||
Returns:
|
||||
*ApiController: Controller for "api" interactions
|
||||
*/
|
||||
func NewApiController(as *services.ApiService, s *gin.RouterGroup) *ApiController {
|
||||
ac := new(ApiController)
|
||||
ac.ApiService = as
|
||||
func NewApiController(as *services.ApiService, routeGroups *common.RouteGroups) *ApiController {
|
||||
ac := &ApiController{
|
||||
service: as,
|
||||
}
|
||||
|
||||
s.GET("", ac.getFirst)
|
||||
s.POST("migrate", middleware.SecretCode, ac.postMigrate)
|
||||
routeGroups.Api.GET("", ac.getFirst)
|
||||
routeGroups.Api.POST("migrate", middleware.SecretCode, ac.postMigrate)
|
||||
|
||||
return ac
|
||||
}
|
||||
@@ -38,7 +41,7 @@ getFirst
|
||||
*/
|
||||
// ROUTE (GET /api).
|
||||
func (ac *ApiController) getFirst(c *gin.Context) {
|
||||
apiModel := ac.ApiService.GetFirst(c)
|
||||
apiModel := ac.service.GetFirst(c)
|
||||
c.JSON(200, apiModel)
|
||||
}
|
||||
|
||||
@@ -53,7 +56,7 @@ Requires "SECRET_CODE", "VERSION" (optional) from body.
|
||||
func (ac *ApiController) postMigrate(c *gin.Context) {
|
||||
migrateModel := c.MustGet("migrate")
|
||||
version := migrateModel.(middleware.SecretCodeModel).Version
|
||||
mr, er := ac.ApiService.PostMigrate(c, version)
|
||||
mr, er := ac.service.PostMigrate(c, version)
|
||||
|
||||
if er.Message != "" {
|
||||
c.JSON(er.StatusCode, er)
|
||||
|
||||
@@ -5,32 +5,35 @@ import (
|
||||
"wallet-api/pkg/middleware"
|
||||
"wallet-api/pkg/models"
|
||||
"wallet-api/pkg/services"
|
||||
"wallet-api/pkg/utl/common"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type AuthController struct {
|
||||
UsersService *services.UsersService
|
||||
service *services.UsersService
|
||||
}
|
||||
|
||||
/*
|
||||
NewAuthController
|
||||
|
||||
Initializes AuthController.
|
||||
|
||||
Args:
|
||||
*services.UsersService: Users service
|
||||
*gin.RouterGroup: Gin Router Group
|
||||
Returns:
|
||||
*AuthController: Controller for "auth" interactions
|
||||
*/
|
||||
func NewAuthController(rs *services.UsersService, s *gin.RouterGroup) *AuthController {
|
||||
rc := new(AuthController)
|
||||
rc.UsersService = rs
|
||||
func NewAuthController(rs *services.UsersService, routeGroups *common.RouteGroups) *AuthController {
|
||||
rc := &AuthController{
|
||||
service: rs,
|
||||
}
|
||||
|
||||
s.POST("login", rc.PostLogin)
|
||||
s.POST("register", rc.PostRegister)
|
||||
s.DELETE("deactivate", middleware.Auth, rc.Delete)
|
||||
s.GET("check-token", rc.CheckToken)
|
||||
routeGroups.Auth.POST("login", rc.PostLogin)
|
||||
routeGroups.Auth.POST("register", rc.PostRegister)
|
||||
routeGroups.Auth.DELETE("deactivate", middleware.Auth, rc.Delete)
|
||||
routeGroups.Auth.GET("check-token", rc.CheckToken)
|
||||
|
||||
return rc
|
||||
}
|
||||
@@ -47,7 +50,7 @@ func (rc *AuthController) PostLogin(c *gin.Context) {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
returnedUser, exceptionReturn := rc.UsersService.Login(c, body)
|
||||
returnedUser, exceptionReturn := rc.service.Login(c, body)
|
||||
|
||||
if exceptionReturn.Message != "" {
|
||||
c.JSON(exceptionReturn.StatusCode, exceptionReturn)
|
||||
@@ -71,7 +74,7 @@ func (rc *AuthController) PostRegister(c *gin.Context) {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
returnedUser, exceptionReturn := rc.UsersService.Create(c, body)
|
||||
returnedUser, exceptionReturn := rc.service.Create(c, body)
|
||||
|
||||
if exceptionReturn.Message != "" {
|
||||
c.JSON(exceptionReturn.StatusCode, exceptionReturn)
|
||||
@@ -92,7 +95,7 @@ func (rc *AuthController) Delete(c *gin.Context) {
|
||||
authGet := c.MustGet("auth")
|
||||
auth.Id = authGet.(*models.Auth).Id
|
||||
|
||||
mr, er := rc.UsersService.Deactivate(c, auth)
|
||||
mr, er := rc.service.Deactivate(c, auth)
|
||||
|
||||
if er.Message != "" {
|
||||
c.JSON(er.StatusCode, er)
|
||||
|
||||
@@ -4,30 +4,33 @@ import (
|
||||
"net/http"
|
||||
"wallet-api/pkg/models"
|
||||
"wallet-api/pkg/services"
|
||||
"wallet-api/pkg/utl/common"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type SubscriptionTypeController struct {
|
||||
SubscriptionTypeService *services.SubscriptionTypeService
|
||||
service *services.SubscriptionTypeService
|
||||
}
|
||||
|
||||
/*
|
||||
NewSubscriptionTypeController
|
||||
|
||||
Initializes SubscriptionTypeController.
|
||||
|
||||
Args:
|
||||
*services.SubscriptionTypeService: Subscription type service
|
||||
*gin.RouterGroup: Gin Router Group
|
||||
Returns:
|
||||
*SubscriptionTypeController: Controller for "subscription-types" route interactions
|
||||
*/
|
||||
func NewSubscriptionTypeController(as *services.SubscriptionTypeService, s *gin.RouterGroup) *SubscriptionTypeController {
|
||||
wc := new(SubscriptionTypeController)
|
||||
wc.SubscriptionTypeService = as
|
||||
func NewSubscriptionTypeController(as *services.SubscriptionTypeService, routeGroups *common.RouteGroups) *SubscriptionTypeController {
|
||||
wc := &SubscriptionTypeController{
|
||||
service: as,
|
||||
}
|
||||
|
||||
s.POST("", wc.New)
|
||||
s.GET("", wc.GetAll)
|
||||
routeGroups.SubscriptionType.POST("", wc.New)
|
||||
routeGroups.SubscriptionType.GET("", wc.GetAll)
|
||||
|
||||
return wc
|
||||
}
|
||||
@@ -45,7 +48,7 @@ func (wc *SubscriptionTypeController) New(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
wm, exception := wc.SubscriptionTypeService.New(c, body)
|
||||
wm, exception := wc.service.New(c, body)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
@@ -62,7 +65,7 @@ GetAll
|
||||
func (wc *SubscriptionTypeController) GetAll(c *gin.Context) {
|
||||
embed, _ := c.GetQuery("embed")
|
||||
|
||||
wm, exception := wc.SubscriptionTypeService.GetAll(c, embed)
|
||||
wm, exception := wc.service.GetAll(c, embed)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
|
||||
@@ -4,34 +4,37 @@ import (
|
||||
"net/http"
|
||||
"wallet-api/pkg/models"
|
||||
"wallet-api/pkg/services"
|
||||
"wallet-api/pkg/utl/common"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type SubscriptionController struct {
|
||||
SubscriptionService *services.SubscriptionService
|
||||
service *services.SubscriptionService
|
||||
}
|
||||
|
||||
/*
|
||||
NewSubscriptionController
|
||||
|
||||
Initializes SubscriptionController.
|
||||
|
||||
Args:
|
||||
*services.SubscriptionService: Subscription service
|
||||
*gin.RouterGroup: Gin Router Group
|
||||
Returns:
|
||||
*SubscriptionController: Controller for "subscription" route interactions
|
||||
*/
|
||||
func NewSubscriptionController(as *services.SubscriptionService, s *gin.RouterGroup) *SubscriptionController {
|
||||
wc := new(SubscriptionController)
|
||||
wc.SubscriptionService = as
|
||||
func NewSubscriptionController(as *services.SubscriptionService, routeGroups *common.RouteGroups) *SubscriptionController {
|
||||
wc := &SubscriptionController{
|
||||
service: as,
|
||||
}
|
||||
|
||||
s.POST("", wc.New)
|
||||
s.PUT("/:id", wc.Edit)
|
||||
s.GET("/:id", wc.Get)
|
||||
s.GET("", wc.GetAll)
|
||||
routeGroups.Subscription.POST("", wc.New)
|
||||
routeGroups.Subscription.PUT("/:id", wc.Edit)
|
||||
routeGroups.Subscription.GET("/:id", wc.Get)
|
||||
routeGroups.Subscription.GET("", wc.GetAll)
|
||||
|
||||
se := s.Group("/end")
|
||||
se := routeGroups.Subscription.Group("/end")
|
||||
{
|
||||
se.PUT("/:id", wc.End)
|
||||
}
|
||||
@@ -52,7 +55,7 @@ func (wc *SubscriptionController) New(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
wm, exception := wc.SubscriptionService.New(c, body)
|
||||
wm, exception := wc.service.New(c, body)
|
||||
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
@@ -77,7 +80,7 @@ func (wc *SubscriptionController) Edit(c *gin.Context) {
|
||||
|
||||
id := c.Param("id")
|
||||
|
||||
wm, exception := wc.SubscriptionService.Edit(c, body, id)
|
||||
wm, exception := wc.service.Edit(c, body, id)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
@@ -103,7 +106,7 @@ func (wc *SubscriptionController) Get(c *gin.Context) {
|
||||
embed, _ := c.GetQuery("embed")
|
||||
params.Embed = embed
|
||||
|
||||
fr, exception := wc.SubscriptionService.Get(c, body, id, params)
|
||||
fr, exception := wc.service.Get(c, body, id, params)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
@@ -127,7 +130,7 @@ func (wc *SubscriptionController) End(c *gin.Context) {
|
||||
|
||||
id := c.Param("id")
|
||||
|
||||
fr, exception := wc.SubscriptionService.End(c, id)
|
||||
fr, exception := wc.service.End(c, id)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
@@ -150,7 +153,7 @@ func (wc *SubscriptionController) GetAll(c *gin.Context) {
|
||||
fr := FilteredResponse(c)
|
||||
wallet, _ := c.GetQuery("walletId")
|
||||
|
||||
exception := wc.SubscriptionService.GetAll(c, body, wallet, fr)
|
||||
exception := wc.service.GetAll(c, body, wallet, fr)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
|
||||
@@ -4,30 +4,33 @@ import (
|
||||
"net/http"
|
||||
"wallet-api/pkg/models"
|
||||
"wallet-api/pkg/services"
|
||||
"wallet-api/pkg/utl/common"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type TransactionStatusController struct {
|
||||
TransactionStatusService *services.TransactionStatusService
|
||||
service *services.TransactionStatusService
|
||||
}
|
||||
|
||||
/*
|
||||
NewTransactionStatusController
|
||||
|
||||
Initializes TransactionStatusController.
|
||||
|
||||
Args:
|
||||
*services.TransactionStatusService: Transaction Staus service
|
||||
*gin.RouterGroup: Gin Router Group
|
||||
Returns:
|
||||
*TransactionStatusController: Controller for "transaction-status" route interactions
|
||||
*/
|
||||
func NewTransactionStatusController(as *services.TransactionStatusService, s *gin.RouterGroup) *TransactionStatusController {
|
||||
wc := new(TransactionStatusController)
|
||||
wc.TransactionStatusService = as
|
||||
func NewTransactionStatusController(as *services.TransactionStatusService, routeGroups *common.RouteGroups) *TransactionStatusController {
|
||||
wc := &TransactionStatusController{
|
||||
service: as,
|
||||
}
|
||||
|
||||
s.POST("", wc.New)
|
||||
s.GET("", wc.GetAll)
|
||||
routeGroups.TransactionStatus.POST("", wc.New)
|
||||
routeGroups.TransactionStatus.GET("", wc.GetAll)
|
||||
|
||||
return wc
|
||||
}
|
||||
@@ -45,7 +48,7 @@ func (wc *TransactionStatusController) New(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
wm, exception := wc.TransactionStatusService.New(c, body)
|
||||
wm, exception := wc.service.New(c, body)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
@@ -62,7 +65,7 @@ GetAll
|
||||
func (wc *TransactionStatusController) GetAll(c *gin.Context) {
|
||||
embed, _ := c.GetQuery("embed")
|
||||
|
||||
wm, exception := wc.TransactionStatusService.GetAll(c, embed)
|
||||
wm, exception := wc.service.GetAll(c, embed)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
|
||||
@@ -4,30 +4,33 @@ import (
|
||||
"net/http"
|
||||
"wallet-api/pkg/models"
|
||||
"wallet-api/pkg/services"
|
||||
"wallet-api/pkg/utl/common"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type TransactionTypeController struct {
|
||||
TransactionTypeService *services.TransactionTypeService
|
||||
service *services.TransactionTypeService
|
||||
}
|
||||
|
||||
/*
|
||||
NewTransactionTypeController
|
||||
|
||||
Initializes TransactionTypeController.
|
||||
|
||||
Args:
|
||||
*services.TransactionTypeService: Transaction Type service
|
||||
*gin.RouterGroup: Gin Router Group
|
||||
Returns:
|
||||
*TransactionTypeController: Controller for "transaction-types" route interactions
|
||||
*/
|
||||
func NewTransactionTypeController(as *services.TransactionTypeService, s *gin.RouterGroup) *TransactionTypeController {
|
||||
wc := new(TransactionTypeController)
|
||||
wc.TransactionTypeService = as
|
||||
func NewTransactionTypeController(as *services.TransactionTypeService, routeGroups *common.RouteGroups) *TransactionTypeController {
|
||||
wc := &TransactionTypeController{
|
||||
service: as,
|
||||
}
|
||||
|
||||
s.POST("", wc.New)
|
||||
s.GET("", wc.GetAll)
|
||||
routeGroups.TransactionType.POST("", wc.New)
|
||||
routeGroups.TransactionType.GET("", wc.GetAll)
|
||||
|
||||
return wc
|
||||
}
|
||||
@@ -45,7 +48,7 @@ func (wc *TransactionTypeController) New(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
wm, exception := wc.TransactionTypeService.New(c, body)
|
||||
wm, exception := wc.service.New(c, body)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
@@ -62,7 +65,7 @@ GetAll
|
||||
func (wc *TransactionTypeController) GetAll(c *gin.Context) {
|
||||
embed, _ := c.GetQuery("embed")
|
||||
|
||||
wm, exception := wc.TransactionTypeService.GetAll(c, embed)
|
||||
wm, exception := wc.service.GetAll(c, embed)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
|
||||
@@ -4,39 +4,42 @@ import (
|
||||
"net/http"
|
||||
"wallet-api/pkg/models"
|
||||
"wallet-api/pkg/services"
|
||||
"wallet-api/pkg/utl/common"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type TransactionController struct {
|
||||
TransactionService *services.TransactionService
|
||||
service *services.TransactionService
|
||||
}
|
||||
|
||||
/*
|
||||
NewTransactionController
|
||||
|
||||
Initializes TransactionController.
|
||||
|
||||
Args:
|
||||
*services.TransactionService: Transaction service
|
||||
*gin.RouterGroup: Gin Router Group
|
||||
Returns:
|
||||
*TransactionController: Controller for "transaction" route interactions
|
||||
*/
|
||||
func NewTransactionController(as *services.TransactionService, s *gin.RouterGroup) *TransactionController {
|
||||
wc := new(TransactionController)
|
||||
wc.TransactionService = as
|
||||
func NewTransactionController(as *services.TransactionService, routeGroups *common.RouteGroups) *TransactionController {
|
||||
wc := &TransactionController{
|
||||
service: as,
|
||||
}
|
||||
|
||||
s.POST("", wc.New)
|
||||
s.GET("", wc.GetAll)
|
||||
s.PUT("/:id", wc.Edit)
|
||||
s.GET("/:id", wc.Get)
|
||||
routeGroups.Transaction.POST("", wc.New)
|
||||
routeGroups.Transaction.GET("", wc.GetAll)
|
||||
routeGroups.Transaction.PUT("/:id", wc.Edit)
|
||||
routeGroups.Transaction.GET("/:id", wc.Get)
|
||||
|
||||
bulkGroup := s.Group("bulk")
|
||||
bulkGroup := routeGroups.Transaction.Group("bulk")
|
||||
{
|
||||
bulkGroup.PUT("", wc.BulkEdit)
|
||||
}
|
||||
|
||||
checkGroup := s.Group("check")
|
||||
checkGroup := routeGroups.Transaction.Group("check")
|
||||
{
|
||||
checkGroup.GET("", wc.Check)
|
||||
}
|
||||
@@ -57,7 +60,7 @@ func (wc *TransactionController) New(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
wm, exception := wc.TransactionService.New(c, body)
|
||||
wm, exception := wc.service.New(c, body)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
@@ -82,7 +85,7 @@ func (wc *TransactionController) GetAll(c *gin.Context) {
|
||||
noPendingQry, _ := c.GetQuery("noPending")
|
||||
noPending := noPendingQry != ""
|
||||
|
||||
exception := wc.TransactionService.GetAll(c, body, wallet, fr, noPending)
|
||||
exception := wc.service.GetAll(c, body, wallet, fr, noPending)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
@@ -105,7 +108,7 @@ func (wc *TransactionController) Check(c *gin.Context) {
|
||||
fr := FilteredResponse(c)
|
||||
wallet, _ := c.GetQuery("walletId")
|
||||
|
||||
exception := wc.TransactionService.Check(c, body, wallet, fr)
|
||||
exception := wc.service.Check(c, body, wallet, fr)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
@@ -129,7 +132,7 @@ func (wc *TransactionController) Edit(c *gin.Context) {
|
||||
|
||||
id := c.Param("id")
|
||||
|
||||
wm, exception := wc.TransactionService.Edit(c, body, id)
|
||||
wm, exception := wc.service.Edit(c, body, id)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
@@ -150,7 +153,7 @@ func (wc *TransactionController) BulkEdit(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
wm, exception := wc.TransactionService.BulkEdit(c, body)
|
||||
wm, exception := wc.service.BulkEdit(c, body)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
@@ -176,7 +179,7 @@ func (wc *TransactionController) Get(c *gin.Context) {
|
||||
embed, _ := c.GetQuery("embed")
|
||||
params.Embed = embed
|
||||
|
||||
fr, exception := wc.TransactionService.Get(c, body, id, params)
|
||||
fr, exception := wc.service.Get(c, body, id, params)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
|
||||
@@ -3,29 +3,32 @@ package controllers
|
||||
import (
|
||||
"wallet-api/pkg/models"
|
||||
"wallet-api/pkg/services"
|
||||
"wallet-api/pkg/utl/common"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type WalletsHeaderController struct {
|
||||
WalletService *services.WalletService
|
||||
service *services.WalletService
|
||||
}
|
||||
|
||||
/*
|
||||
NewWalletsHeaderController
|
||||
|
||||
Initializes WalletsHeaderController.
|
||||
|
||||
Args:
|
||||
*services.WalletService: Wallet service
|
||||
*gin.RouterGroup: Gin Router Group
|
||||
Returns:
|
||||
*WalletsHeaderController: Controller for "wallet/wallet-header" route interactions
|
||||
*/
|
||||
func NewWalletsHeaderController(as *services.WalletService, s *gin.RouterGroup) *WalletsHeaderController {
|
||||
wc := new(WalletsHeaderController)
|
||||
wc.WalletService = as
|
||||
func NewWalletsHeaderController(as *services.WalletService, routeGroups *common.RouteGroups) *WalletsHeaderController {
|
||||
wc := &WalletsHeaderController{
|
||||
service: as,
|
||||
}
|
||||
|
||||
s.GET("", wc.Get)
|
||||
routeGroups.WalletHeader.GET("", wc.Get)
|
||||
|
||||
return wc
|
||||
}
|
||||
@@ -44,7 +47,7 @@ func (wc *WalletsHeaderController) Get(c *gin.Context) {
|
||||
auth := c.MustGet("auth")
|
||||
body.Id = auth.(*models.Auth).Id
|
||||
|
||||
wm, exception := wc.WalletService.GetHeader(c, body, walletId)
|
||||
wm, exception := wc.service.GetHeader(c, body, walletId)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
|
||||
@@ -4,32 +4,35 @@ import (
|
||||
"net/http"
|
||||
"wallet-api/pkg/models"
|
||||
"wallet-api/pkg/services"
|
||||
"wallet-api/pkg/utl/common"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type WalletsController struct {
|
||||
WalletService *services.WalletService
|
||||
service *services.WalletService
|
||||
}
|
||||
|
||||
/*
|
||||
NewWalletsController
|
||||
|
||||
Initializes WalletsController.
|
||||
|
||||
Args:
|
||||
*services.WalletService: Wallet service
|
||||
*gin.RouterGroup: Gin Router Group
|
||||
Returns:
|
||||
*WalletsController: Controller for "wallet" route interactions
|
||||
*/
|
||||
func NewWalletsController(as *services.WalletService, s *gin.RouterGroup) *WalletsController {
|
||||
wc := new(WalletsController)
|
||||
wc.WalletService = as
|
||||
func NewWalletsController(as *services.WalletService, routeGroups *common.RouteGroups) *WalletsController {
|
||||
wc := &WalletsController{
|
||||
service: as,
|
||||
}
|
||||
|
||||
s.POST("", wc.New)
|
||||
s.GET("", wc.GetAll)
|
||||
s.PUT("/:id", wc.Edit)
|
||||
s.GET("/:id", wc.Get)
|
||||
routeGroups.Wallet.POST("", wc.New)
|
||||
routeGroups.Wallet.GET("", wc.GetAll)
|
||||
routeGroups.Wallet.PUT("/:id", wc.Edit)
|
||||
routeGroups.Wallet.GET("/:id", wc.Get)
|
||||
|
||||
return wc
|
||||
}
|
||||
@@ -51,7 +54,7 @@ func (wc *WalletsController) New(c *gin.Context) {
|
||||
get := c.MustGet("auth")
|
||||
body.UserID = get.(*models.Auth).Id
|
||||
|
||||
wm, exception := wc.WalletService.New(c, body)
|
||||
wm, exception := wc.service.New(c, body)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
@@ -72,7 +75,7 @@ func (wc *WalletsController) GetAll(c *gin.Context) {
|
||||
|
||||
fr := FilteredResponse(c)
|
||||
|
||||
exception := wc.WalletService.GetAll(c, body, fr)
|
||||
exception := wc.service.GetAll(c, body, fr)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
@@ -96,7 +99,7 @@ func (wc *WalletsController) Edit(c *gin.Context) {
|
||||
|
||||
id := c.Param("id")
|
||||
|
||||
wm, exception := wc.WalletService.Edit(c, body, id)
|
||||
wm, exception := wc.service.Edit(c, body, id)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
@@ -118,7 +121,7 @@ func (wc *WalletsController) Get(c *gin.Context) {
|
||||
embed, _ := c.GetQuery("embed")
|
||||
params.Embed = embed
|
||||
|
||||
fr, exception := wc.WalletService.Get(c, id, params)
|
||||
fr, exception := wc.service.Get(c, id, params)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user