mirror of
https://github.com/FJurmanovic/wallet-go-api.git
synced 2026-02-06 06:08:16 +00:00
added wallet controller
This commit is contained in:
44
pkg/controllers/wallets.go
Normal file
44
pkg/controllers/wallets.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"wallet-api/pkg/models"
|
||||
"wallet-api/pkg/services"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type WalletsController struct {
|
||||
WalletService *services.WalletService
|
||||
}
|
||||
|
||||
func NewWalletsController(as *services.WalletService, s *gin.RouterGroup) *WalletsController {
|
||||
wc := new(WalletsController)
|
||||
wc.WalletService = as
|
||||
|
||||
s.POST("", wc.New)
|
||||
s.GET("", wc.Get)
|
||||
|
||||
return wc
|
||||
}
|
||||
|
||||
func (wc *WalletsController) New(c *gin.Context) {
|
||||
body := new(models.AuthModel)
|
||||
|
||||
get := c.MustGet("auth")
|
||||
body.Id = get.(*models.AuthModel).Id
|
||||
|
||||
wm := wc.WalletService.New(body)
|
||||
c.JSON(200, wm)
|
||||
}
|
||||
|
||||
func (wc *WalletsController) Get(c *gin.Context) {
|
||||
body := new(models.AuthModel)
|
||||
|
||||
embed, _ := c.GetQuery("embed")
|
||||
auth := c.MustGet("auth")
|
||||
body.Id = auth.(*models.AuthModel).Id
|
||||
|
||||
wm := wc.WalletService.Get(body, embed)
|
||||
|
||||
c.JSON(200, wm)
|
||||
}
|
||||
Reference in New Issue
Block a user