mirror of
https://github.com/FJurmanovic/wallet-go-api.git
synced 2026-02-06 14:18:12 +00:00
subscription controller, service and model
This commit is contained in:
42
pkg/controllers/subscriptionTypes.go
Normal file
42
pkg/controllers/subscriptionTypes.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 SubscriptionTypeController struct {
|
||||
SubscriptionTypeService *services.SubscriptionTypeService
|
||||
}
|
||||
|
||||
func NewSubscriptionTypeController(as *services.SubscriptionTypeService, s *gin.RouterGroup) *SubscriptionTypeController {
|
||||
wc := new(SubscriptionTypeController)
|
||||
wc.SubscriptionTypeService = as
|
||||
|
||||
s.POST("", wc.New)
|
||||
s.GET("", wc.GetAll)
|
||||
|
||||
return wc
|
||||
}
|
||||
|
||||
func (wc *SubscriptionTypeController) New(c *gin.Context) {
|
||||
body := new(models.NewSubscriptionTypeBody)
|
||||
if err := c.ShouldBind(body); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
wm := wc.SubscriptionTypeService.New(body)
|
||||
c.JSON(200, wm)
|
||||
}
|
||||
|
||||
func (wc *SubscriptionTypeController) GetAll(c *gin.Context) {
|
||||
embed, _ := c.GetQuery("embed")
|
||||
|
||||
wm := wc.SubscriptionTypeService.GetAll(embed)
|
||||
|
||||
c.JSON(200, wm)
|
||||
}
|
||||
47
pkg/controllers/subscriptions.go
Normal file
47
pkg/controllers/subscriptions.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"wallet-api/pkg/models"
|
||||
"wallet-api/pkg/services"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type SubscriptionController struct {
|
||||
SubscriptionService *services.SubscriptionService
|
||||
}
|
||||
|
||||
func NewSubscriptionController(as *services.SubscriptionService, s *gin.RouterGroup) *SubscriptionController {
|
||||
wc := new(SubscriptionController)
|
||||
wc.SubscriptionService = as
|
||||
|
||||
s.POST("", wc.New)
|
||||
s.GET("", wc.GetAll)
|
||||
|
||||
return wc
|
||||
}
|
||||
|
||||
func (wc *SubscriptionController) New(c *gin.Context) {
|
||||
body := new(models.NewSubscriptionBody)
|
||||
if err := c.ShouldBind(body); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
wm := wc.SubscriptionService.New(body)
|
||||
c.JSON(200, wm)
|
||||
}
|
||||
|
||||
func (wc *SubscriptionController) GetAll(c *gin.Context) {
|
||||
body := new(models.Auth)
|
||||
auth := c.MustGet("auth")
|
||||
body.Id = auth.(*models.Auth).Id
|
||||
|
||||
fr := FilteredResponse(c)
|
||||
wallet, _ := c.GetQuery("walletId")
|
||||
|
||||
wc.SubscriptionService.GetAll(body, wallet, fr)
|
||||
|
||||
c.JSON(200, fr)
|
||||
}
|
||||
Reference in New Issue
Block a user