mirror of
https://github.com/FJurmanovic/wallet-go-api.git
synced 2026-02-06 06:08:16 +00:00
WA-10 - Implemented transactions
This commit is contained in:
42
pkg/controllers/transactionTypes.go
Normal file
42
pkg/controllers/transactionTypes.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"wallet-api/pkg/models"
|
||||
"wallet-api/pkg/services"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type TransactionTypeController struct {
|
||||
TransactionTypeService *services.TransactionTypeService
|
||||
}
|
||||
|
||||
func NewTransactionTypeController(as *services.TransactionTypeService, s *gin.RouterGroup) *TransactionTypeController {
|
||||
wc := new(TransactionTypeController)
|
||||
wc.TransactionTypeService = as
|
||||
|
||||
s.POST("", wc.New)
|
||||
s.GET("", wc.GetAll)
|
||||
|
||||
return wc
|
||||
}
|
||||
|
||||
func (wc *TransactionTypeController) New(c *gin.Context) {
|
||||
body := new(models.NewTransactionTypeBody)
|
||||
if err := c.ShouldBindJSON(body); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
wm := wc.TransactionTypeService.New(body)
|
||||
c.JSON(200, wm)
|
||||
}
|
||||
|
||||
func (wc *TransactionTypeController) GetAll(c *gin.Context) {
|
||||
embed, _ := c.GetQuery("embed")
|
||||
|
||||
wm := wc.TransactionTypeService.GetAll(embed)
|
||||
|
||||
c.JSON(200, wm)
|
||||
}
|
||||
43
pkg/controllers/transactions.go
Normal file
43
pkg/controllers/transactions.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"wallet-api/pkg/models"
|
||||
"wallet-api/pkg/services"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type TransactionController struct {
|
||||
TransactionService *services.TransactionService
|
||||
}
|
||||
|
||||
func NewTransactionController(as *services.TransactionService, s *gin.RouterGroup) *TransactionController {
|
||||
wc := new(TransactionController)
|
||||
wc.TransactionService = as
|
||||
|
||||
s.POST("", wc.New)
|
||||
s.GET("", wc.GetAll)
|
||||
|
||||
return wc
|
||||
}
|
||||
|
||||
func (wc *TransactionController) New(c *gin.Context) {
|
||||
body := new(models.NewTransactionBody)
|
||||
if err := c.ShouldBindJSON(body); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
wm := wc.TransactionService.New(body)
|
||||
c.JSON(200, wm)
|
||||
}
|
||||
|
||||
func (wc *TransactionController) GetAll(c *gin.Context) {
|
||||
embed, _ := c.GetQuery("embed")
|
||||
wallet, _ := c.GetQuery("walletId")
|
||||
|
||||
wm := wc.TransactionService.GetAll(wallet, embed)
|
||||
|
||||
c.JSON(200, wm)
|
||||
}
|
||||
Reference in New Issue
Block a user