mirror of
https://github.com/FJurmanovic/wallet-go-api.git
synced 2026-02-06 06:08:16 +00:00
add DI
This commit is contained in:
@@ -4,57 +4,65 @@ import (
|
|||||||
"wallet-api/pkg/controllers"
|
"wallet-api/pkg/controllers"
|
||||||
"wallet-api/pkg/middleware"
|
"wallet-api/pkg/middleware"
|
||||||
"wallet-api/pkg/services"
|
"wallet-api/pkg/services"
|
||||||
|
"wallet-api/pkg/utl/common"
|
||||||
"wallet-api/pkg/utl/configs"
|
"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"
|
||||||
|
"go.uber.org/dig"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Routes
|
Routes
|
||||||
|
|
||||||
Initializes web api controllers and its corresponding routes.
|
Initializes web api controllers and its corresponding routes.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
*gin.Engine: Gin Engine
|
*gin.Engine: Gin Engine
|
||||||
*pg.DB: Postgres database client
|
*pg.DB: Postgres database client
|
||||||
*/
|
*/
|
||||||
func Routes(s *gin.Engine, db *pg.DB) {
|
func Routes(s *gin.Engine, db *pg.DB) {
|
||||||
|
c := dig.New()
|
||||||
ver := s.Group(configs.Prefix)
|
ver := s.Group(configs.Prefix)
|
||||||
|
|
||||||
api := ver.Group("api")
|
routeGroups := &common.RouteGroups{
|
||||||
auth := ver.Group("auth")
|
Api: ver.Group("api"),
|
||||||
wallet := ver.Group("wallet", middleware.Auth)
|
Auth: ver.Group("auth"),
|
||||||
walletHeader := ver.Group("wallet/wallet-header", middleware.Auth)
|
Wallet: ver.Group("wallet", middleware.Auth),
|
||||||
transaction := ver.Group("transaction", middleware.Auth)
|
WalletHeader: ver.Group("wallet/wallet-header", middleware.Auth),
|
||||||
transactionType := ver.Group("transaction-type", middleware.Auth)
|
Transaction: ver.Group("transaction", middleware.Auth),
|
||||||
subscription := ver.Group("subscription", middleware.Auth)
|
TransactionType: ver.Group("transaction-type", middleware.Auth),
|
||||||
subscriptionType := ver.Group("subscription-type", middleware.Auth)
|
Subscription: ver.Group("subscription", middleware.Auth),
|
||||||
transactionStatus := ver.Group("transaction-status", middleware.Auth)
|
SubscriptionType: ver.Group("subscription-type", middleware.Auth),
|
||||||
|
TransactionStatus: ver.Group("transaction-status", middleware.Auth),
|
||||||
|
}
|
||||||
|
|
||||||
s.NoRoute(func(c *gin.Context) {
|
s.NoRoute(func(c *gin.Context) {
|
||||||
c.JSON(404, gin.H{"code": "PAGE_NOT_FOUND", "message": "Page not found"})
|
c.JSON(404, gin.H{"code": "PAGE_NOT_FOUND", "message": "Page not found"})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
c.Provide(func() *common.RouteGroups {
|
||||||
|
return routeGroups
|
||||||
|
})
|
||||||
|
c.Provide(func() *pg.DB {
|
||||||
|
return db
|
||||||
|
})
|
||||||
|
c.Provide(services.NewApiService)
|
||||||
|
c.Provide(services.NewSubscriptionService)
|
||||||
|
c.Provide(services.NewSubscriptionTypeService)
|
||||||
|
c.Provide(services.NewTransactionService)
|
||||||
|
c.Provide(services.NewTransactionStatusService)
|
||||||
|
c.Provide(services.NewTransactionTypeService)
|
||||||
|
c.Provide(services.NewUsersService)
|
||||||
|
c.Provide(services.NewWalletService)
|
||||||
|
|
||||||
apiService := services.ApiService{Db: db}
|
c.Invoke(controllers.NewApiController)
|
||||||
usersService := services.UsersService{Db: db}
|
c.Invoke(controllers.NewAuthController)
|
||||||
walletService := services.WalletService{Db: db}
|
c.Invoke(controllers.NewWalletsController)
|
||||||
transactionService := services.TransactionService{Db: db}
|
c.Invoke(controllers.NewWalletsHeaderController)
|
||||||
transactionTypeService := services.TransactionTypeService{Db: db}
|
c.Invoke(controllers.NewTransactionController)
|
||||||
subscriptionService := services.SubscriptionService{Db: db}
|
c.Invoke(controllers.NewTransactionStatusController)
|
||||||
subscriptionTypeService := services.SubscriptionTypeService{Db: db}
|
c.Invoke(controllers.NewTransactionTypeController)
|
||||||
transactionStatusService := services.TransactionStatusService{Db: db}
|
c.Invoke(controllers.NewSubscriptionController)
|
||||||
|
c.Invoke(controllers.NewSubscriptionTypeController)
|
||||||
walletService.Ss = &subscriptionService
|
|
||||||
transactionService.Ss = &subscriptionService
|
|
||||||
|
|
||||||
controllers.NewApiController(&apiService, api)
|
|
||||||
controllers.NewAuthController(&usersService, auth)
|
|
||||||
controllers.NewWalletsController(&walletService, wallet)
|
|
||||||
controllers.NewWalletsHeaderController(&walletService, walletHeader)
|
|
||||||
controllers.NewTransactionController(&transactionService, transaction)
|
|
||||||
controllers.NewTransactionTypeController(&transactionTypeService, transactionType)
|
|
||||||
controllers.NewSubscriptionController(&subscriptionService, subscription)
|
|
||||||
controllers.NewSubscriptionTypeController(&subscriptionTypeService, subscriptionType)
|
|
||||||
controllers.NewTransactionStatusController(&transactionStatusService, transactionStatus)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,30 +3,33 @@ package controllers
|
|||||||
import (
|
import (
|
||||||
"wallet-api/pkg/middleware"
|
"wallet-api/pkg/middleware"
|
||||||
"wallet-api/pkg/services"
|
"wallet-api/pkg/services"
|
||||||
|
"wallet-api/pkg/utl/common"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ApiController struct {
|
type ApiController struct {
|
||||||
ApiService *services.ApiService
|
service *services.ApiService
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
NewApiController
|
NewApiController
|
||||||
|
|
||||||
Initializes ApiController.
|
Initializes ApiController.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
*services.ApiService: API service
|
*services.ApiService: API service
|
||||||
*gin.RouterGroup: Gin Router Group
|
*gin.RouterGroup: Gin Router Group
|
||||||
Returns:
|
Returns:
|
||||||
*ApiController: Controller for "api" interactions
|
*ApiController: Controller for "api" interactions
|
||||||
*/
|
*/
|
||||||
func NewApiController(as *services.ApiService, s *gin.RouterGroup) *ApiController {
|
func NewApiController(as *services.ApiService, routeGroups *common.RouteGroups) *ApiController {
|
||||||
ac := new(ApiController)
|
ac := &ApiController{
|
||||||
ac.ApiService = as
|
service: as,
|
||||||
|
}
|
||||||
|
|
||||||
s.GET("", ac.getFirst)
|
routeGroups.Api.GET("", ac.getFirst)
|
||||||
s.POST("migrate", middleware.SecretCode, ac.postMigrate)
|
routeGroups.Api.POST("migrate", middleware.SecretCode, ac.postMigrate)
|
||||||
|
|
||||||
return ac
|
return ac
|
||||||
}
|
}
|
||||||
@@ -38,7 +41,7 @@ getFirst
|
|||||||
*/
|
*/
|
||||||
// ROUTE (GET /api).
|
// ROUTE (GET /api).
|
||||||
func (ac *ApiController) getFirst(c *gin.Context) {
|
func (ac *ApiController) getFirst(c *gin.Context) {
|
||||||
apiModel := ac.ApiService.GetFirst(c)
|
apiModel := ac.service.GetFirst(c)
|
||||||
c.JSON(200, apiModel)
|
c.JSON(200, apiModel)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,7 +56,7 @@ Requires "SECRET_CODE", "VERSION" (optional) from body.
|
|||||||
func (ac *ApiController) postMigrate(c *gin.Context) {
|
func (ac *ApiController) postMigrate(c *gin.Context) {
|
||||||
migrateModel := c.MustGet("migrate")
|
migrateModel := c.MustGet("migrate")
|
||||||
version := migrateModel.(middleware.SecretCodeModel).Version
|
version := migrateModel.(middleware.SecretCodeModel).Version
|
||||||
mr, er := ac.ApiService.PostMigrate(c, version)
|
mr, er := ac.service.PostMigrate(c, version)
|
||||||
|
|
||||||
if er.Message != "" {
|
if er.Message != "" {
|
||||||
c.JSON(er.StatusCode, er)
|
c.JSON(er.StatusCode, er)
|
||||||
|
|||||||
@@ -5,32 +5,35 @@ import (
|
|||||||
"wallet-api/pkg/middleware"
|
"wallet-api/pkg/middleware"
|
||||||
"wallet-api/pkg/models"
|
"wallet-api/pkg/models"
|
||||||
"wallet-api/pkg/services"
|
"wallet-api/pkg/services"
|
||||||
|
"wallet-api/pkg/utl/common"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
type AuthController struct {
|
type AuthController struct {
|
||||||
UsersService *services.UsersService
|
service *services.UsersService
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
NewAuthController
|
NewAuthController
|
||||||
|
|
||||||
Initializes AuthController.
|
Initializes AuthController.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
*services.UsersService: Users service
|
*services.UsersService: Users service
|
||||||
*gin.RouterGroup: Gin Router Group
|
*gin.RouterGroup: Gin Router Group
|
||||||
Returns:
|
Returns:
|
||||||
*AuthController: Controller for "auth" interactions
|
*AuthController: Controller for "auth" interactions
|
||||||
*/
|
*/
|
||||||
func NewAuthController(rs *services.UsersService, s *gin.RouterGroup) *AuthController {
|
func NewAuthController(rs *services.UsersService, routeGroups *common.RouteGroups) *AuthController {
|
||||||
rc := new(AuthController)
|
rc := &AuthController{
|
||||||
rc.UsersService = rs
|
service: rs,
|
||||||
|
}
|
||||||
|
|
||||||
s.POST("login", rc.PostLogin)
|
routeGroups.Auth.POST("login", rc.PostLogin)
|
||||||
s.POST("register", rc.PostRegister)
|
routeGroups.Auth.POST("register", rc.PostRegister)
|
||||||
s.DELETE("deactivate", middleware.Auth, rc.Delete)
|
routeGroups.Auth.DELETE("deactivate", middleware.Auth, rc.Delete)
|
||||||
s.GET("check-token", rc.CheckToken)
|
routeGroups.Auth.GET("check-token", rc.CheckToken)
|
||||||
|
|
||||||
return rc
|
return rc
|
||||||
}
|
}
|
||||||
@@ -47,7 +50,7 @@ func (rc *AuthController) PostLogin(c *gin.Context) {
|
|||||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
returnedUser, exceptionReturn := rc.UsersService.Login(c, body)
|
returnedUser, exceptionReturn := rc.service.Login(c, body)
|
||||||
|
|
||||||
if exceptionReturn.Message != "" {
|
if exceptionReturn.Message != "" {
|
||||||
c.JSON(exceptionReturn.StatusCode, exceptionReturn)
|
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()})
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
returnedUser, exceptionReturn := rc.UsersService.Create(c, body)
|
returnedUser, exceptionReturn := rc.service.Create(c, body)
|
||||||
|
|
||||||
if exceptionReturn.Message != "" {
|
if exceptionReturn.Message != "" {
|
||||||
c.JSON(exceptionReturn.StatusCode, exceptionReturn)
|
c.JSON(exceptionReturn.StatusCode, exceptionReturn)
|
||||||
@@ -92,7 +95,7 @@ func (rc *AuthController) Delete(c *gin.Context) {
|
|||||||
authGet := c.MustGet("auth")
|
authGet := c.MustGet("auth")
|
||||||
auth.Id = authGet.(*models.Auth).Id
|
auth.Id = authGet.(*models.Auth).Id
|
||||||
|
|
||||||
mr, er := rc.UsersService.Deactivate(c, auth)
|
mr, er := rc.service.Deactivate(c, auth)
|
||||||
|
|
||||||
if er.Message != "" {
|
if er.Message != "" {
|
||||||
c.JSON(er.StatusCode, er)
|
c.JSON(er.StatusCode, er)
|
||||||
|
|||||||
@@ -4,30 +4,33 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"wallet-api/pkg/models"
|
"wallet-api/pkg/models"
|
||||||
"wallet-api/pkg/services"
|
"wallet-api/pkg/services"
|
||||||
|
"wallet-api/pkg/utl/common"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SubscriptionTypeController struct {
|
type SubscriptionTypeController struct {
|
||||||
SubscriptionTypeService *services.SubscriptionTypeService
|
service *services.SubscriptionTypeService
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
NewSubscriptionTypeController
|
NewSubscriptionTypeController
|
||||||
|
|
||||||
Initializes SubscriptionTypeController.
|
Initializes SubscriptionTypeController.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
*services.SubscriptionTypeService: Subscription type service
|
*services.SubscriptionTypeService: Subscription type service
|
||||||
*gin.RouterGroup: Gin Router Group
|
*gin.RouterGroup: Gin Router Group
|
||||||
Returns:
|
Returns:
|
||||||
*SubscriptionTypeController: Controller for "subscription-types" route interactions
|
*SubscriptionTypeController: Controller for "subscription-types" route interactions
|
||||||
*/
|
*/
|
||||||
func NewSubscriptionTypeController(as *services.SubscriptionTypeService, s *gin.RouterGroup) *SubscriptionTypeController {
|
func NewSubscriptionTypeController(as *services.SubscriptionTypeService, routeGroups *common.RouteGroups) *SubscriptionTypeController {
|
||||||
wc := new(SubscriptionTypeController)
|
wc := &SubscriptionTypeController{
|
||||||
wc.SubscriptionTypeService = as
|
service: as,
|
||||||
|
}
|
||||||
|
|
||||||
s.POST("", wc.New)
|
routeGroups.SubscriptionType.POST("", wc.New)
|
||||||
s.GET("", wc.GetAll)
|
routeGroups.SubscriptionType.GET("", wc.GetAll)
|
||||||
|
|
||||||
return wc
|
return wc
|
||||||
}
|
}
|
||||||
@@ -45,7 +48,7 @@ func (wc *SubscriptionTypeController) New(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
wm, exception := wc.SubscriptionTypeService.New(c, body)
|
wm, exception := wc.service.New(c, body)
|
||||||
if exception != nil {
|
if exception != nil {
|
||||||
c.JSON(exception.StatusCode, exception)
|
c.JSON(exception.StatusCode, exception)
|
||||||
return
|
return
|
||||||
@@ -62,7 +65,7 @@ GetAll
|
|||||||
func (wc *SubscriptionTypeController) GetAll(c *gin.Context) {
|
func (wc *SubscriptionTypeController) GetAll(c *gin.Context) {
|
||||||
embed, _ := c.GetQuery("embed")
|
embed, _ := c.GetQuery("embed")
|
||||||
|
|
||||||
wm, exception := wc.SubscriptionTypeService.GetAll(c, embed)
|
wm, exception := wc.service.GetAll(c, embed)
|
||||||
if exception != nil {
|
if exception != nil {
|
||||||
c.JSON(exception.StatusCode, exception)
|
c.JSON(exception.StatusCode, exception)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -4,34 +4,37 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"wallet-api/pkg/models"
|
"wallet-api/pkg/models"
|
||||||
"wallet-api/pkg/services"
|
"wallet-api/pkg/services"
|
||||||
|
"wallet-api/pkg/utl/common"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SubscriptionController struct {
|
type SubscriptionController struct {
|
||||||
SubscriptionService *services.SubscriptionService
|
service *services.SubscriptionService
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
NewSubscriptionController
|
NewSubscriptionController
|
||||||
|
|
||||||
Initializes SubscriptionController.
|
Initializes SubscriptionController.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
*services.SubscriptionService: Subscription service
|
*services.SubscriptionService: Subscription service
|
||||||
*gin.RouterGroup: Gin Router Group
|
*gin.RouterGroup: Gin Router Group
|
||||||
Returns:
|
Returns:
|
||||||
*SubscriptionController: Controller for "subscription" route interactions
|
*SubscriptionController: Controller for "subscription" route interactions
|
||||||
*/
|
*/
|
||||||
func NewSubscriptionController(as *services.SubscriptionService, s *gin.RouterGroup) *SubscriptionController {
|
func NewSubscriptionController(as *services.SubscriptionService, routeGroups *common.RouteGroups) *SubscriptionController {
|
||||||
wc := new(SubscriptionController)
|
wc := &SubscriptionController{
|
||||||
wc.SubscriptionService = as
|
service: as,
|
||||||
|
}
|
||||||
|
|
||||||
s.POST("", wc.New)
|
routeGroups.Subscription.POST("", wc.New)
|
||||||
s.PUT("/:id", wc.Edit)
|
routeGroups.Subscription.PUT("/:id", wc.Edit)
|
||||||
s.GET("/:id", wc.Get)
|
routeGroups.Subscription.GET("/:id", wc.Get)
|
||||||
s.GET("", wc.GetAll)
|
routeGroups.Subscription.GET("", wc.GetAll)
|
||||||
|
|
||||||
se := s.Group("/end")
|
se := routeGroups.Subscription.Group("/end")
|
||||||
{
|
{
|
||||||
se.PUT("/:id", wc.End)
|
se.PUT("/:id", wc.End)
|
||||||
}
|
}
|
||||||
@@ -52,7 +55,7 @@ func (wc *SubscriptionController) New(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
wm, exception := wc.SubscriptionService.New(c, body)
|
wm, exception := wc.service.New(c, body)
|
||||||
|
|
||||||
if exception != nil {
|
if exception != nil {
|
||||||
c.JSON(exception.StatusCode, exception)
|
c.JSON(exception.StatusCode, exception)
|
||||||
@@ -77,7 +80,7 @@ func (wc *SubscriptionController) Edit(c *gin.Context) {
|
|||||||
|
|
||||||
id := c.Param("id")
|
id := c.Param("id")
|
||||||
|
|
||||||
wm, exception := wc.SubscriptionService.Edit(c, body, id)
|
wm, exception := wc.service.Edit(c, body, id)
|
||||||
if exception != nil {
|
if exception != nil {
|
||||||
c.JSON(exception.StatusCode, exception)
|
c.JSON(exception.StatusCode, exception)
|
||||||
return
|
return
|
||||||
@@ -103,7 +106,7 @@ func (wc *SubscriptionController) Get(c *gin.Context) {
|
|||||||
embed, _ := c.GetQuery("embed")
|
embed, _ := c.GetQuery("embed")
|
||||||
params.Embed = 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 {
|
if exception != nil {
|
||||||
c.JSON(exception.StatusCode, exception)
|
c.JSON(exception.StatusCode, exception)
|
||||||
return
|
return
|
||||||
@@ -127,7 +130,7 @@ func (wc *SubscriptionController) End(c *gin.Context) {
|
|||||||
|
|
||||||
id := c.Param("id")
|
id := c.Param("id")
|
||||||
|
|
||||||
fr, exception := wc.SubscriptionService.End(c, id)
|
fr, exception := wc.service.End(c, id)
|
||||||
if exception != nil {
|
if exception != nil {
|
||||||
c.JSON(exception.StatusCode, exception)
|
c.JSON(exception.StatusCode, exception)
|
||||||
return
|
return
|
||||||
@@ -150,7 +153,7 @@ func (wc *SubscriptionController) GetAll(c *gin.Context) {
|
|||||||
fr := FilteredResponse(c)
|
fr := FilteredResponse(c)
|
||||||
wallet, _ := c.GetQuery("walletId")
|
wallet, _ := c.GetQuery("walletId")
|
||||||
|
|
||||||
exception := wc.SubscriptionService.GetAll(c, body, wallet, fr)
|
exception := wc.service.GetAll(c, body, wallet, fr)
|
||||||
if exception != nil {
|
if exception != nil {
|
||||||
c.JSON(exception.StatusCode, exception)
|
c.JSON(exception.StatusCode, exception)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -4,30 +4,33 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"wallet-api/pkg/models"
|
"wallet-api/pkg/models"
|
||||||
"wallet-api/pkg/services"
|
"wallet-api/pkg/services"
|
||||||
|
"wallet-api/pkg/utl/common"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TransactionStatusController struct {
|
type TransactionStatusController struct {
|
||||||
TransactionStatusService *services.TransactionStatusService
|
service *services.TransactionStatusService
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
NewTransactionStatusController
|
NewTransactionStatusController
|
||||||
|
|
||||||
Initializes TransactionStatusController.
|
Initializes TransactionStatusController.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
*services.TransactionStatusService: Transaction Staus service
|
*services.TransactionStatusService: Transaction Staus service
|
||||||
*gin.RouterGroup: Gin Router Group
|
*gin.RouterGroup: Gin Router Group
|
||||||
Returns:
|
Returns:
|
||||||
*TransactionStatusController: Controller for "transaction-status" route interactions
|
*TransactionStatusController: Controller for "transaction-status" route interactions
|
||||||
*/
|
*/
|
||||||
func NewTransactionStatusController(as *services.TransactionStatusService, s *gin.RouterGroup) *TransactionStatusController {
|
func NewTransactionStatusController(as *services.TransactionStatusService, routeGroups *common.RouteGroups) *TransactionStatusController {
|
||||||
wc := new(TransactionStatusController)
|
wc := &TransactionStatusController{
|
||||||
wc.TransactionStatusService = as
|
service: as,
|
||||||
|
}
|
||||||
|
|
||||||
s.POST("", wc.New)
|
routeGroups.TransactionStatus.POST("", wc.New)
|
||||||
s.GET("", wc.GetAll)
|
routeGroups.TransactionStatus.GET("", wc.GetAll)
|
||||||
|
|
||||||
return wc
|
return wc
|
||||||
}
|
}
|
||||||
@@ -45,7 +48,7 @@ func (wc *TransactionStatusController) New(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
wm, exception := wc.TransactionStatusService.New(c, body)
|
wm, exception := wc.service.New(c, body)
|
||||||
if exception != nil {
|
if exception != nil {
|
||||||
c.JSON(exception.StatusCode, exception)
|
c.JSON(exception.StatusCode, exception)
|
||||||
return
|
return
|
||||||
@@ -62,7 +65,7 @@ GetAll
|
|||||||
func (wc *TransactionStatusController) GetAll(c *gin.Context) {
|
func (wc *TransactionStatusController) GetAll(c *gin.Context) {
|
||||||
embed, _ := c.GetQuery("embed")
|
embed, _ := c.GetQuery("embed")
|
||||||
|
|
||||||
wm, exception := wc.TransactionStatusService.GetAll(c, embed)
|
wm, exception := wc.service.GetAll(c, embed)
|
||||||
if exception != nil {
|
if exception != nil {
|
||||||
c.JSON(exception.StatusCode, exception)
|
c.JSON(exception.StatusCode, exception)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -4,30 +4,33 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"wallet-api/pkg/models"
|
"wallet-api/pkg/models"
|
||||||
"wallet-api/pkg/services"
|
"wallet-api/pkg/services"
|
||||||
|
"wallet-api/pkg/utl/common"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TransactionTypeController struct {
|
type TransactionTypeController struct {
|
||||||
TransactionTypeService *services.TransactionTypeService
|
service *services.TransactionTypeService
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
NewTransactionTypeController
|
NewTransactionTypeController
|
||||||
|
|
||||||
Initializes TransactionTypeController.
|
Initializes TransactionTypeController.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
*services.TransactionTypeService: Transaction Type service
|
*services.TransactionTypeService: Transaction Type service
|
||||||
*gin.RouterGroup: Gin Router Group
|
*gin.RouterGroup: Gin Router Group
|
||||||
Returns:
|
Returns:
|
||||||
*TransactionTypeController: Controller for "transaction-types" route interactions
|
*TransactionTypeController: Controller for "transaction-types" route interactions
|
||||||
*/
|
*/
|
||||||
func NewTransactionTypeController(as *services.TransactionTypeService, s *gin.RouterGroup) *TransactionTypeController {
|
func NewTransactionTypeController(as *services.TransactionTypeService, routeGroups *common.RouteGroups) *TransactionTypeController {
|
||||||
wc := new(TransactionTypeController)
|
wc := &TransactionTypeController{
|
||||||
wc.TransactionTypeService = as
|
service: as,
|
||||||
|
}
|
||||||
|
|
||||||
s.POST("", wc.New)
|
routeGroups.TransactionType.POST("", wc.New)
|
||||||
s.GET("", wc.GetAll)
|
routeGroups.TransactionType.GET("", wc.GetAll)
|
||||||
|
|
||||||
return wc
|
return wc
|
||||||
}
|
}
|
||||||
@@ -45,7 +48,7 @@ func (wc *TransactionTypeController) New(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
wm, exception := wc.TransactionTypeService.New(c, body)
|
wm, exception := wc.service.New(c, body)
|
||||||
if exception != nil {
|
if exception != nil {
|
||||||
c.JSON(exception.StatusCode, exception)
|
c.JSON(exception.StatusCode, exception)
|
||||||
return
|
return
|
||||||
@@ -62,7 +65,7 @@ GetAll
|
|||||||
func (wc *TransactionTypeController) GetAll(c *gin.Context) {
|
func (wc *TransactionTypeController) GetAll(c *gin.Context) {
|
||||||
embed, _ := c.GetQuery("embed")
|
embed, _ := c.GetQuery("embed")
|
||||||
|
|
||||||
wm, exception := wc.TransactionTypeService.GetAll(c, embed)
|
wm, exception := wc.service.GetAll(c, embed)
|
||||||
if exception != nil {
|
if exception != nil {
|
||||||
c.JSON(exception.StatusCode, exception)
|
c.JSON(exception.StatusCode, exception)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -4,39 +4,42 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"wallet-api/pkg/models"
|
"wallet-api/pkg/models"
|
||||||
"wallet-api/pkg/services"
|
"wallet-api/pkg/services"
|
||||||
|
"wallet-api/pkg/utl/common"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TransactionController struct {
|
type TransactionController struct {
|
||||||
TransactionService *services.TransactionService
|
service *services.TransactionService
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
NewTransactionController
|
NewTransactionController
|
||||||
|
|
||||||
Initializes TransactionController.
|
Initializes TransactionController.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
*services.TransactionService: Transaction service
|
*services.TransactionService: Transaction service
|
||||||
*gin.RouterGroup: Gin Router Group
|
*gin.RouterGroup: Gin Router Group
|
||||||
Returns:
|
Returns:
|
||||||
*TransactionController: Controller for "transaction" route interactions
|
*TransactionController: Controller for "transaction" route interactions
|
||||||
*/
|
*/
|
||||||
func NewTransactionController(as *services.TransactionService, s *gin.RouterGroup) *TransactionController {
|
func NewTransactionController(as *services.TransactionService, routeGroups *common.RouteGroups) *TransactionController {
|
||||||
wc := new(TransactionController)
|
wc := &TransactionController{
|
||||||
wc.TransactionService = as
|
service: as,
|
||||||
|
}
|
||||||
|
|
||||||
s.POST("", wc.New)
|
routeGroups.Transaction.POST("", wc.New)
|
||||||
s.GET("", wc.GetAll)
|
routeGroups.Transaction.GET("", wc.GetAll)
|
||||||
s.PUT("/:id", wc.Edit)
|
routeGroups.Transaction.PUT("/:id", wc.Edit)
|
||||||
s.GET("/:id", wc.Get)
|
routeGroups.Transaction.GET("/:id", wc.Get)
|
||||||
|
|
||||||
bulkGroup := s.Group("bulk")
|
bulkGroup := routeGroups.Transaction.Group("bulk")
|
||||||
{
|
{
|
||||||
bulkGroup.PUT("", wc.BulkEdit)
|
bulkGroup.PUT("", wc.BulkEdit)
|
||||||
}
|
}
|
||||||
|
|
||||||
checkGroup := s.Group("check")
|
checkGroup := routeGroups.Transaction.Group("check")
|
||||||
{
|
{
|
||||||
checkGroup.GET("", wc.Check)
|
checkGroup.GET("", wc.Check)
|
||||||
}
|
}
|
||||||
@@ -57,7 +60,7 @@ func (wc *TransactionController) New(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
wm, exception := wc.TransactionService.New(c, body)
|
wm, exception := wc.service.New(c, body)
|
||||||
if exception != nil {
|
if exception != nil {
|
||||||
c.JSON(exception.StatusCode, exception)
|
c.JSON(exception.StatusCode, exception)
|
||||||
return
|
return
|
||||||
@@ -82,7 +85,7 @@ func (wc *TransactionController) GetAll(c *gin.Context) {
|
|||||||
noPendingQry, _ := c.GetQuery("noPending")
|
noPendingQry, _ := c.GetQuery("noPending")
|
||||||
noPending := noPendingQry != ""
|
noPending := noPendingQry != ""
|
||||||
|
|
||||||
exception := wc.TransactionService.GetAll(c, body, wallet, fr, noPending)
|
exception := wc.service.GetAll(c, body, wallet, fr, noPending)
|
||||||
if exception != nil {
|
if exception != nil {
|
||||||
c.JSON(exception.StatusCode, exception)
|
c.JSON(exception.StatusCode, exception)
|
||||||
return
|
return
|
||||||
@@ -105,7 +108,7 @@ func (wc *TransactionController) Check(c *gin.Context) {
|
|||||||
fr := FilteredResponse(c)
|
fr := FilteredResponse(c)
|
||||||
wallet, _ := c.GetQuery("walletId")
|
wallet, _ := c.GetQuery("walletId")
|
||||||
|
|
||||||
exception := wc.TransactionService.Check(c, body, wallet, fr)
|
exception := wc.service.Check(c, body, wallet, fr)
|
||||||
if exception != nil {
|
if exception != nil {
|
||||||
c.JSON(exception.StatusCode, exception)
|
c.JSON(exception.StatusCode, exception)
|
||||||
return
|
return
|
||||||
@@ -129,7 +132,7 @@ func (wc *TransactionController) Edit(c *gin.Context) {
|
|||||||
|
|
||||||
id := c.Param("id")
|
id := c.Param("id")
|
||||||
|
|
||||||
wm, exception := wc.TransactionService.Edit(c, body, id)
|
wm, exception := wc.service.Edit(c, body, id)
|
||||||
if exception != nil {
|
if exception != nil {
|
||||||
c.JSON(exception.StatusCode, exception)
|
c.JSON(exception.StatusCode, exception)
|
||||||
return
|
return
|
||||||
@@ -150,7 +153,7 @@ func (wc *TransactionController) BulkEdit(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
wm, exception := wc.TransactionService.BulkEdit(c, body)
|
wm, exception := wc.service.BulkEdit(c, body)
|
||||||
if exception != nil {
|
if exception != nil {
|
||||||
c.JSON(exception.StatusCode, exception)
|
c.JSON(exception.StatusCode, exception)
|
||||||
return
|
return
|
||||||
@@ -176,7 +179,7 @@ func (wc *TransactionController) Get(c *gin.Context) {
|
|||||||
embed, _ := c.GetQuery("embed")
|
embed, _ := c.GetQuery("embed")
|
||||||
params.Embed = 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 {
|
if exception != nil {
|
||||||
c.JSON(exception.StatusCode, exception)
|
c.JSON(exception.StatusCode, exception)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -3,29 +3,32 @@ package controllers
|
|||||||
import (
|
import (
|
||||||
"wallet-api/pkg/models"
|
"wallet-api/pkg/models"
|
||||||
"wallet-api/pkg/services"
|
"wallet-api/pkg/services"
|
||||||
|
"wallet-api/pkg/utl/common"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
type WalletsHeaderController struct {
|
type WalletsHeaderController struct {
|
||||||
WalletService *services.WalletService
|
service *services.WalletService
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
NewWalletsHeaderController
|
NewWalletsHeaderController
|
||||||
|
|
||||||
Initializes WalletsHeaderController.
|
Initializes WalletsHeaderController.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
*services.WalletService: Wallet service
|
*services.WalletService: Wallet service
|
||||||
*gin.RouterGroup: Gin Router Group
|
*gin.RouterGroup: Gin Router Group
|
||||||
Returns:
|
Returns:
|
||||||
*WalletsHeaderController: Controller for "wallet/wallet-header" route interactions
|
*WalletsHeaderController: Controller for "wallet/wallet-header" route interactions
|
||||||
*/
|
*/
|
||||||
func NewWalletsHeaderController(as *services.WalletService, s *gin.RouterGroup) *WalletsHeaderController {
|
func NewWalletsHeaderController(as *services.WalletService, routeGroups *common.RouteGroups) *WalletsHeaderController {
|
||||||
wc := new(WalletsHeaderController)
|
wc := &WalletsHeaderController{
|
||||||
wc.WalletService = as
|
service: as,
|
||||||
|
}
|
||||||
|
|
||||||
s.GET("", wc.Get)
|
routeGroups.WalletHeader.GET("", wc.Get)
|
||||||
|
|
||||||
return wc
|
return wc
|
||||||
}
|
}
|
||||||
@@ -44,7 +47,7 @@ func (wc *WalletsHeaderController) Get(c *gin.Context) {
|
|||||||
auth := c.MustGet("auth")
|
auth := c.MustGet("auth")
|
||||||
body.Id = auth.(*models.Auth).Id
|
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 {
|
if exception != nil {
|
||||||
c.JSON(exception.StatusCode, exception)
|
c.JSON(exception.StatusCode, exception)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -4,32 +4,35 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"wallet-api/pkg/models"
|
"wallet-api/pkg/models"
|
||||||
"wallet-api/pkg/services"
|
"wallet-api/pkg/services"
|
||||||
|
"wallet-api/pkg/utl/common"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
type WalletsController struct {
|
type WalletsController struct {
|
||||||
WalletService *services.WalletService
|
service *services.WalletService
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
NewWalletsController
|
NewWalletsController
|
||||||
|
|
||||||
Initializes WalletsController.
|
Initializes WalletsController.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
*services.WalletService: Wallet service
|
*services.WalletService: Wallet service
|
||||||
*gin.RouterGroup: Gin Router Group
|
*gin.RouterGroup: Gin Router Group
|
||||||
Returns:
|
Returns:
|
||||||
*WalletsController: Controller for "wallet" route interactions
|
*WalletsController: Controller for "wallet" route interactions
|
||||||
*/
|
*/
|
||||||
func NewWalletsController(as *services.WalletService, s *gin.RouterGroup) *WalletsController {
|
func NewWalletsController(as *services.WalletService, routeGroups *common.RouteGroups) *WalletsController {
|
||||||
wc := new(WalletsController)
|
wc := &WalletsController{
|
||||||
wc.WalletService = as
|
service: as,
|
||||||
|
}
|
||||||
|
|
||||||
s.POST("", wc.New)
|
routeGroups.Wallet.POST("", wc.New)
|
||||||
s.GET("", wc.GetAll)
|
routeGroups.Wallet.GET("", wc.GetAll)
|
||||||
s.PUT("/:id", wc.Edit)
|
routeGroups.Wallet.PUT("/:id", wc.Edit)
|
||||||
s.GET("/:id", wc.Get)
|
routeGroups.Wallet.GET("/:id", wc.Get)
|
||||||
|
|
||||||
return wc
|
return wc
|
||||||
}
|
}
|
||||||
@@ -51,7 +54,7 @@ func (wc *WalletsController) New(c *gin.Context) {
|
|||||||
get := c.MustGet("auth")
|
get := c.MustGet("auth")
|
||||||
body.UserID = get.(*models.Auth).Id
|
body.UserID = get.(*models.Auth).Id
|
||||||
|
|
||||||
wm, exception := wc.WalletService.New(c, body)
|
wm, exception := wc.service.New(c, body)
|
||||||
if exception != nil {
|
if exception != nil {
|
||||||
c.JSON(exception.StatusCode, exception)
|
c.JSON(exception.StatusCode, exception)
|
||||||
return
|
return
|
||||||
@@ -72,7 +75,7 @@ func (wc *WalletsController) GetAll(c *gin.Context) {
|
|||||||
|
|
||||||
fr := FilteredResponse(c)
|
fr := FilteredResponse(c)
|
||||||
|
|
||||||
exception := wc.WalletService.GetAll(c, body, fr)
|
exception := wc.service.GetAll(c, body, fr)
|
||||||
if exception != nil {
|
if exception != nil {
|
||||||
c.JSON(exception.StatusCode, exception)
|
c.JSON(exception.StatusCode, exception)
|
||||||
return
|
return
|
||||||
@@ -96,7 +99,7 @@ func (wc *WalletsController) Edit(c *gin.Context) {
|
|||||||
|
|
||||||
id := c.Param("id")
|
id := c.Param("id")
|
||||||
|
|
||||||
wm, exception := wc.WalletService.Edit(c, body, id)
|
wm, exception := wc.service.Edit(c, body, id)
|
||||||
if exception != nil {
|
if exception != nil {
|
||||||
c.JSON(exception.StatusCode, exception)
|
c.JSON(exception.StatusCode, exception)
|
||||||
return
|
return
|
||||||
@@ -118,7 +121,7 @@ func (wc *WalletsController) Get(c *gin.Context) {
|
|||||||
embed, _ := c.GetQuery("embed")
|
embed, _ := c.GetQuery("embed")
|
||||||
params.Embed = embed
|
params.Embed = embed
|
||||||
|
|
||||||
fr, exception := wc.WalletService.Get(c, id, params)
|
fr, exception := wc.service.Get(c, id, params)
|
||||||
if exception != nil {
|
if exception != nil {
|
||||||
c.JSON(exception.StatusCode, exception)
|
c.JSON(exception.StatusCode, exception)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -9,21 +9,27 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type ApiService struct {
|
type ApiService struct {
|
||||||
Db *pg.DB
|
db *pg.DB
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewApiService(db *pg.DB) *ApiService {
|
||||||
|
return &ApiService{
|
||||||
|
db: db,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
GetFirst
|
GetFirst
|
||||||
|
|
||||||
Gets first row from API table.
|
Gets first row from API table.
|
||||||
Args:
|
|
||||||
context.Context: Application context
|
|
||||||
Returns:
|
|
||||||
models.ApiModel: Api object from database.
|
|
||||||
*/
|
|
||||||
func (as *ApiService) GetFirst(ctx context.Context) models.ApiModel {
|
|
||||||
db := as.Db.WithContext(ctx)
|
|
||||||
|
|
||||||
|
Args:
|
||||||
|
context.Context: Application context
|
||||||
|
Returns:
|
||||||
|
models.ApiModel: Api object from database.
|
||||||
|
*/
|
||||||
|
func (as ApiService) GetFirst(ctx context.Context) models.ApiModel {
|
||||||
|
db := as.db.WithContext(ctx)
|
||||||
apiModel := models.ApiModel{Api: "Works"}
|
apiModel := models.ApiModel{Api: "Works"}
|
||||||
db.Model(&apiModel).First()
|
db.Model(&apiModel).First()
|
||||||
return apiModel
|
return apiModel
|
||||||
@@ -33,15 +39,16 @@ func (as *ApiService) GetFirst(ctx context.Context) models.ApiModel {
|
|||||||
PostMigrate
|
PostMigrate
|
||||||
|
|
||||||
Starts database migration.
|
Starts database migration.
|
||||||
Args:
|
|
||||||
context.Context: Application context
|
Args:
|
||||||
string: Migration version
|
context.Context: Application context
|
||||||
Returns:
|
string: Migration version
|
||||||
*models.MessageResponse: Message response object.
|
Returns:
|
||||||
*models.Exception: Exception response object.
|
*models.MessageResponse: Message response object.
|
||||||
|
*models.Exception: Exception response object.
|
||||||
*/
|
*/
|
||||||
func (as *ApiService) PostMigrate(ctx context.Context, version string) (*models.MessageResponse, *models.Exception) {
|
func (as ApiService) PostMigrate(ctx context.Context, version string) (*models.MessageResponse, *models.Exception) {
|
||||||
db := as.Db.WithContext(ctx)
|
db := as.db.WithContext(ctx)
|
||||||
|
|
||||||
mr := new(models.MessageResponse)
|
mr := new(models.MessageResponse)
|
||||||
er := new(models.Exception)
|
er := new(models.Exception)
|
||||||
|
|||||||
@@ -10,22 +10,29 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type SubscriptionTypeService struct {
|
type SubscriptionTypeService struct {
|
||||||
Db *pg.DB
|
db *pg.DB
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewSubscriptionTypeService(db *pg.DB) *SubscriptionTypeService {
|
||||||
|
return &SubscriptionTypeService{
|
||||||
|
db: db,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
New
|
New
|
||||||
|
|
||||||
Inserts new row to subscription type table.
|
Inserts new row to subscription type table.
|
||||||
Args:
|
|
||||||
context.Context: Application context
|
Args:
|
||||||
*models.NewSubscriptionTypeBody: Values to create new row
|
context.Context: Application context
|
||||||
Returns:
|
*models.NewSubscriptionTypeBody: Values to create new row
|
||||||
*models.SubscriptionType: Created row from database.
|
Returns:
|
||||||
*models.Exception: Exception payload.
|
*models.SubscriptionType: Created row from database.
|
||||||
|
*models.Exception: Exception payload.
|
||||||
*/
|
*/
|
||||||
func (as *SubscriptionTypeService) New(ctx context.Context, body *models.NewSubscriptionTypeBody) (*models.SubscriptionType, *models.Exception) {
|
func (as *SubscriptionTypeService) New(ctx context.Context, body *models.NewSubscriptionTypeBody) (*models.SubscriptionType, *models.Exception) {
|
||||||
db := as.Db.WithContext(ctx)
|
db := as.db.WithContext(ctx)
|
||||||
|
|
||||||
tm := new(models.SubscriptionType)
|
tm := new(models.SubscriptionType)
|
||||||
exceptionReturn := new(models.Exception)
|
exceptionReturn := new(models.Exception)
|
||||||
@@ -49,15 +56,16 @@ func (as *SubscriptionTypeService) New(ctx context.Context, body *models.NewSubs
|
|||||||
GetAll
|
GetAll
|
||||||
|
|
||||||
Gets all rows from subscription type table.
|
Gets all rows from subscription type table.
|
||||||
Args:
|
|
||||||
context.Context: Application context
|
Args:
|
||||||
string: Relations to embed
|
context.Context: Application context
|
||||||
Returns:
|
string: Relations to embed
|
||||||
*[]models.SubscriptionType: List of subscription type objects.
|
Returns:
|
||||||
*models.Exception: Exception payload.
|
*[]models.SubscriptionType: List of subscription type objects.
|
||||||
|
*models.Exception: Exception payload.
|
||||||
*/
|
*/
|
||||||
func (as *SubscriptionTypeService) GetAll(ctx context.Context, embed string) (*[]models.SubscriptionType, *models.Exception) {
|
func (as *SubscriptionTypeService) GetAll(ctx context.Context, embed string) (*[]models.SubscriptionType, *models.Exception) {
|
||||||
db := as.Db.WithContext(ctx)
|
db := as.db.WithContext(ctx)
|
||||||
|
|
||||||
wm := new([]models.SubscriptionType)
|
wm := new([]models.SubscriptionType)
|
||||||
exceptionReturn := new(models.Exception)
|
exceptionReturn := new(models.Exception)
|
||||||
|
|||||||
@@ -12,22 +12,29 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type SubscriptionService struct {
|
type SubscriptionService struct {
|
||||||
Db *pg.DB
|
db *pg.DB
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewSubscriptionService(db *pg.DB) *SubscriptionService {
|
||||||
|
return &SubscriptionService{
|
||||||
|
db: db,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
New
|
New
|
||||||
|
|
||||||
Inserts new row to subscription table.
|
Inserts new row to subscription table.
|
||||||
Args:
|
|
||||||
context.Context: Application context
|
Args:
|
||||||
*models.NewSubscriptionBody: Request body
|
context.Context: Application context
|
||||||
Returns:
|
*models.NewSubscriptionBody: Request body
|
||||||
*models.Subscription: Created Subscription row object from database.
|
Returns:
|
||||||
*models.Exception: Exception payload.
|
*models.Subscription: Created Subscription row object from database.
|
||||||
|
*models.Exception: Exception payload.
|
||||||
*/
|
*/
|
||||||
func (as *SubscriptionService) New(ctx context.Context, body *models.NewSubscriptionBody) (*models.Subscription, *models.Exception) {
|
func (as *SubscriptionService) New(ctx context.Context, body *models.NewSubscriptionBody) (*models.Subscription, *models.Exception) {
|
||||||
db := as.Db.WithContext(ctx)
|
db := as.db.WithContext(ctx)
|
||||||
|
|
||||||
tm := new(models.Subscription)
|
tm := new(models.Subscription)
|
||||||
exceptionReturn := new(models.Exception)
|
exceptionReturn := new(models.Exception)
|
||||||
@@ -69,17 +76,18 @@ func (as *SubscriptionService) New(ctx context.Context, body *models.NewSubscrip
|
|||||||
Get
|
Get
|
||||||
|
|
||||||
Gets row from subscription table by id.
|
Gets row from subscription table by id.
|
||||||
Args:
|
|
||||||
context.Context: Application context
|
Args:
|
||||||
*models.Auth: Authentication model
|
context.Context: Application context
|
||||||
string: subscription id to search
|
*models.Auth: Authentication model
|
||||||
params: *models.Params
|
string: subscription id to search
|
||||||
Returns:
|
params: *models.Params
|
||||||
*models.Subscription: Subscription row object from database.
|
Returns:
|
||||||
*models.Exception: Exception payload.
|
*models.Subscription: Subscription row object from database.
|
||||||
|
*models.Exception: Exception payload.
|
||||||
*/
|
*/
|
||||||
func (as *SubscriptionService) Get(ctx context.Context, am *models.Auth, id string, params *models.Params) (*models.Subscription, *models.Exception) {
|
func (as *SubscriptionService) Get(ctx context.Context, am *models.Auth, id string, params *models.Params) (*models.Subscription, *models.Exception) {
|
||||||
db := as.Db.WithContext(ctx)
|
db := as.db.WithContext(ctx)
|
||||||
|
|
||||||
exceptionReturn := new(models.Exception)
|
exceptionReturn := new(models.Exception)
|
||||||
wm := new(models.Subscription)
|
wm := new(models.Subscription)
|
||||||
@@ -106,16 +114,17 @@ func (as *SubscriptionService) Get(ctx context.Context, am *models.Auth, id stri
|
|||||||
GetAll
|
GetAll
|
||||||
|
|
||||||
Gets filtered rows from subscription table.
|
Gets filtered rows from subscription table.
|
||||||
Args:
|
|
||||||
context.Context: Application context
|
Args:
|
||||||
*models.Auth: Authentication object
|
context.Context: Application context
|
||||||
string: Wallet id to search
|
*models.Auth: Authentication object
|
||||||
*models.FilteredResponse: filter options
|
string: Wallet id to search
|
||||||
Returns:
|
*models.FilteredResponse: filter options
|
||||||
*models.Exception: Exception payload.
|
Returns:
|
||||||
|
*models.Exception: Exception payload.
|
||||||
*/
|
*/
|
||||||
func (as *SubscriptionService) GetAll(ctx context.Context, am *models.Auth, walletId string, filtered *models.FilteredResponse) *models.Exception {
|
func (as *SubscriptionService) GetAll(ctx context.Context, am *models.Auth, walletId string, filtered *models.FilteredResponse) *models.Exception {
|
||||||
db := as.Db.WithContext(ctx)
|
db := as.db.WithContext(ctx)
|
||||||
|
|
||||||
wm := new([]models.Subscription)
|
wm := new([]models.Subscription)
|
||||||
exceptionReturn := new(models.Exception)
|
exceptionReturn := new(models.Exception)
|
||||||
@@ -144,16 +153,17 @@ func (as *SubscriptionService) GetAll(ctx context.Context, am *models.Auth, wall
|
|||||||
Edit
|
Edit
|
||||||
|
|
||||||
Updates row from subscription table by id.
|
Updates row from subscription table by id.
|
||||||
Args:
|
|
||||||
context.Context: Application context
|
Args:
|
||||||
*models.SubscriptionEdit: Values to edit
|
context.Context: Application context
|
||||||
string: id to search
|
*models.SubscriptionEdit: Values to edit
|
||||||
Returns:
|
string: id to search
|
||||||
*models.Subscription: Edited Subscription row object from database.
|
Returns:
|
||||||
*models.Exception: Exception payload.
|
*models.Subscription: Edited Subscription row object from database.
|
||||||
|
*models.Exception: Exception payload.
|
||||||
*/
|
*/
|
||||||
func (as *SubscriptionService) Edit(ctx context.Context, body *models.SubscriptionEdit, id string) (*models.Subscription, *models.Exception) {
|
func (as *SubscriptionService) Edit(ctx context.Context, body *models.SubscriptionEdit, id string) (*models.Subscription, *models.Exception) {
|
||||||
db := as.Db.WithContext(ctx)
|
db := as.db.WithContext(ctx)
|
||||||
|
|
||||||
amount, _ := body.Amount.Float64()
|
amount, _ := body.Amount.Float64()
|
||||||
exceptionReturn := new(models.Exception)
|
exceptionReturn := new(models.Exception)
|
||||||
@@ -188,15 +198,16 @@ End
|
|||||||
Updates row in subscription table by id.
|
Updates row in subscription table by id.
|
||||||
|
|
||||||
Ends subscription with current date.
|
Ends subscription with current date.
|
||||||
Args:
|
|
||||||
context.Context: Application context
|
Args:
|
||||||
string: id to search
|
context.Context: Application context
|
||||||
Returns:
|
string: id to search
|
||||||
*models.Subscription: Created Subscription row object from database.
|
Returns:
|
||||||
*models.Exception: Exception payload.
|
*models.Subscription: Created Subscription row object from database.
|
||||||
|
*models.Exception: Exception payload.
|
||||||
*/
|
*/
|
||||||
func (as *SubscriptionService) End(ctx context.Context, id string) (*models.Subscription, *models.Exception) {
|
func (as *SubscriptionService) End(ctx context.Context, id string) (*models.Subscription, *models.Exception) {
|
||||||
db := as.Db.WithContext(ctx)
|
db := as.db.WithContext(ctx)
|
||||||
exceptionReturn := new(models.Exception)
|
exceptionReturn := new(models.Exception)
|
||||||
|
|
||||||
tm := new(models.Subscription)
|
tm := new(models.Subscription)
|
||||||
@@ -224,11 +235,12 @@ func (as *SubscriptionService) End(ctx context.Context, id string) (*models.Subs
|
|||||||
SubToTrans
|
SubToTrans
|
||||||
|
|
||||||
Generates and Inserts new Transaction rows from the subscription model.
|
Generates and Inserts new Transaction rows from the subscription model.
|
||||||
Args:
|
|
||||||
*models.Subscription: Subscription model to generate new transactions from
|
Args:
|
||||||
*pg.Tx: Postgres query context
|
*models.Subscription: Subscription model to generate new transactions from
|
||||||
Returns:
|
*pg.Tx: Postgres query context
|
||||||
*models.Exception: Exception payload.
|
Returns:
|
||||||
|
*models.Exception: Exception payload.
|
||||||
*/
|
*/
|
||||||
func (as *SubscriptionService) SubToTrans(subModel *models.Subscription, tx *pg.Tx) *models.Exception {
|
func (as *SubscriptionService) SubToTrans(subModel *models.Subscription, tx *pg.Tx) *models.Exception {
|
||||||
exceptionReturn := new(models.Exception)
|
exceptionReturn := new(models.Exception)
|
||||||
|
|||||||
@@ -10,22 +10,29 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type TransactionStatusService struct {
|
type TransactionStatusService struct {
|
||||||
Db *pg.DB
|
db *pg.DB
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewTransactionStatusService(db *pg.DB) *TransactionStatusService {
|
||||||
|
return &TransactionStatusService{
|
||||||
|
db: db,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
New
|
New
|
||||||
|
|
||||||
Inserts new row to transaction status table.
|
Inserts new row to transaction status table.
|
||||||
Args:
|
|
||||||
context.Context: Application context
|
Args:
|
||||||
*models.NewTransactionStatusBody: object to create
|
context.Context: Application context
|
||||||
Returns:
|
*models.NewTransactionStatusBody: object to create
|
||||||
*models.TransactionType: Transaction Type object from database.
|
Returns:
|
||||||
*models.Exception: Exception payload.
|
*models.TransactionType: Transaction Type object from database.
|
||||||
|
*models.Exception: Exception payload.
|
||||||
*/
|
*/
|
||||||
func (as *TransactionStatusService) New(ctx context.Context, body *models.NewTransactionStatusBody) (*models.TransactionStatus, *models.Exception) {
|
func (as *TransactionStatusService) New(ctx context.Context, body *models.NewTransactionStatusBody) (*models.TransactionStatus, *models.Exception) {
|
||||||
db := as.Db.WithContext(ctx)
|
db := as.db.WithContext(ctx)
|
||||||
|
|
||||||
tm := new(models.TransactionStatus)
|
tm := new(models.TransactionStatus)
|
||||||
exceptionReturn := new(models.Exception)
|
exceptionReturn := new(models.Exception)
|
||||||
@@ -49,15 +56,16 @@ func (as *TransactionStatusService) New(ctx context.Context, body *models.NewTra
|
|||||||
GetAll
|
GetAll
|
||||||
|
|
||||||
Gets all rows from transaction status table.
|
Gets all rows from transaction status table.
|
||||||
Args:
|
|
||||||
context.Context: Application context
|
Args:
|
||||||
string: Relations to embed
|
context.Context: Application context
|
||||||
Returns:
|
string: Relations to embed
|
||||||
*[]models.TransactionStatus: List of Transaction status objects from database.
|
Returns:
|
||||||
*models.Exception: Exception payload.
|
*[]models.TransactionStatus: List of Transaction status objects from database.
|
||||||
|
*models.Exception: Exception payload.
|
||||||
*/
|
*/
|
||||||
func (as *TransactionStatusService) GetAll(ctx context.Context, embed string) (*[]models.TransactionStatus, *models.Exception) {
|
func (as *TransactionStatusService) GetAll(ctx context.Context, embed string) (*[]models.TransactionStatus, *models.Exception) {
|
||||||
db := as.Db.WithContext(ctx)
|
db := as.db.WithContext(ctx)
|
||||||
|
|
||||||
wm := new([]models.TransactionStatus)
|
wm := new([]models.TransactionStatus)
|
||||||
exceptionReturn := new(models.Exception)
|
exceptionReturn := new(models.Exception)
|
||||||
|
|||||||
@@ -10,22 +10,29 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type TransactionTypeService struct {
|
type TransactionTypeService struct {
|
||||||
Db *pg.DB
|
db *pg.DB
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewTransactionTypeService(db *pg.DB) *TransactionTypeService {
|
||||||
|
return &TransactionTypeService{
|
||||||
|
db: db,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
New
|
New
|
||||||
|
|
||||||
Inserts new row to transaction type table.
|
Inserts new row to transaction type table.
|
||||||
Args:
|
|
||||||
context.Context: Application context
|
Args:
|
||||||
*models.NewTransactionTypeBody: object to create
|
context.Context: Application context
|
||||||
Returns:
|
*models.NewTransactionTypeBody: object to create
|
||||||
*models.TransactionType: Transaction Type object from database.
|
Returns:
|
||||||
*models.Exception: Exception payload.
|
*models.TransactionType: Transaction Type object from database.
|
||||||
|
*models.Exception: Exception payload.
|
||||||
*/
|
*/
|
||||||
func (as *TransactionTypeService) New(ctx context.Context, body *models.NewTransactionTypeBody) (*models.TransactionType, *models.Exception) {
|
func (as *TransactionTypeService) New(ctx context.Context, body *models.NewTransactionTypeBody) (*models.TransactionType, *models.Exception) {
|
||||||
db := as.Db.WithContext(ctx)
|
db := as.db.WithContext(ctx)
|
||||||
|
|
||||||
tm := new(models.TransactionType)
|
tm := new(models.TransactionType)
|
||||||
exceptionReturn := new(models.Exception)
|
exceptionReturn := new(models.Exception)
|
||||||
@@ -49,15 +56,16 @@ func (as *TransactionTypeService) New(ctx context.Context, body *models.NewTrans
|
|||||||
GetAll
|
GetAll
|
||||||
|
|
||||||
Gets all rows from transaction type table.
|
Gets all rows from transaction type table.
|
||||||
Args:
|
|
||||||
context.Context: Application context
|
Args:
|
||||||
string: Relations to embed
|
context.Context: Application context
|
||||||
Returns:
|
string: Relations to embed
|
||||||
*[]models.TransactionType: List of Transaction type objects from database.
|
Returns:
|
||||||
*models.Exception: Exception payload.
|
*[]models.TransactionType: List of Transaction type objects from database.
|
||||||
|
*models.Exception: Exception payload.
|
||||||
*/
|
*/
|
||||||
func (as *TransactionTypeService) GetAll(ctx context.Context, embed string) (*[]models.TransactionType, *models.Exception) {
|
func (as *TransactionTypeService) GetAll(ctx context.Context, embed string) (*[]models.TransactionType, *models.Exception) {
|
||||||
db := as.Db.WithContext(ctx)
|
db := as.db.WithContext(ctx)
|
||||||
|
|
||||||
wm := new([]models.TransactionType)
|
wm := new([]models.TransactionType)
|
||||||
exceptionReturn := new(models.Exception)
|
exceptionReturn := new(models.Exception)
|
||||||
|
|||||||
@@ -12,23 +12,31 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type TransactionService struct {
|
type TransactionService struct {
|
||||||
Db *pg.DB
|
db *pg.DB
|
||||||
Ss *SubscriptionService
|
subscriptionService *SubscriptionService
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewTransactionService(db *pg.DB, ss *SubscriptionService) *TransactionService {
|
||||||
|
return &TransactionService{
|
||||||
|
db: db,
|
||||||
|
subscriptionService: ss,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
New new row into transaction table
|
New row into transaction table
|
||||||
|
|
||||||
Inserts
|
Inserts
|
||||||
Args:
|
|
||||||
context.Context: Application context
|
Args:
|
||||||
*models.NewTransactionBody: Transaction body object
|
context.Context: Application context
|
||||||
Returns:
|
*models.NewTransactionBody: Transaction body object
|
||||||
*models.Transaction: Transaction object
|
Returns:
|
||||||
*models.Exception: Exception payload.
|
*models.Transaction: Transaction object
|
||||||
|
*models.Exception: Exception payload.
|
||||||
*/
|
*/
|
||||||
func (as *TransactionService) New(ctx context.Context, body *models.NewTransactionBody) (*models.Transaction, *models.Exception) {
|
func (as *TransactionService) New(ctx context.Context, body *models.NewTransactionBody) (*models.Transaction, *models.Exception) {
|
||||||
db := as.Db.WithContext(ctx)
|
db := as.db.WithContext(ctx)
|
||||||
exceptionReturn := new(models.Exception)
|
exceptionReturn := new(models.Exception)
|
||||||
|
|
||||||
tm := new(models.Transaction)
|
tm := new(models.Transaction)
|
||||||
@@ -83,7 +91,7 @@ Gets all rows from subscription type table.
|
|||||||
*/
|
*/
|
||||||
// Gets filtered rows from transaction table.
|
// Gets filtered rows from transaction table.
|
||||||
func (as *TransactionService) GetAll(ctx context.Context, am *models.Auth, walletId string, filtered *models.FilteredResponse, noPending bool) *models.Exception {
|
func (as *TransactionService) GetAll(ctx context.Context, am *models.Auth, walletId string, filtered *models.FilteredResponse, noPending bool) *models.Exception {
|
||||||
db := as.Db.WithContext(ctx)
|
db := as.db.WithContext(ctx)
|
||||||
|
|
||||||
exceptionReturn := new(models.Exception)
|
exceptionReturn := new(models.Exception)
|
||||||
wm := new([]models.Transaction)
|
wm := new([]models.Transaction)
|
||||||
@@ -132,7 +140,7 @@ Checks subscriptions and create transacitons.
|
|||||||
*/
|
*/
|
||||||
// Gets filtered rows from transaction table.
|
// Gets filtered rows from transaction table.
|
||||||
func (as *TransactionService) Check(ctx context.Context, am *models.Auth, walletId string, filtered *models.FilteredResponse) *models.Exception {
|
func (as *TransactionService) Check(ctx context.Context, am *models.Auth, walletId string, filtered *models.FilteredResponse) *models.Exception {
|
||||||
db := as.Db.WithContext(ctx)
|
db := as.db.WithContext(ctx)
|
||||||
|
|
||||||
wm := new([]models.Transaction)
|
wm := new([]models.Transaction)
|
||||||
sm := new([]models.Subscription)
|
sm := new([]models.Subscription)
|
||||||
@@ -157,7 +165,7 @@ func (as *TransactionService) Check(ctx context.Context, am *models.Auth, wallet
|
|||||||
|
|
||||||
for _, sub := range *sm {
|
for _, sub := range *sm {
|
||||||
if sub.HasNew() {
|
if sub.HasNew() {
|
||||||
as.Ss.SubToTrans(&sub, tx)
|
as.subscriptionService.SubToTrans(&sub, tx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,16 +191,17 @@ func (as *TransactionService) Check(ctx context.Context, am *models.Auth, wallet
|
|||||||
Edit
|
Edit
|
||||||
|
|
||||||
Updates row in transaction table by id.
|
Updates row in transaction table by id.
|
||||||
Args:
|
|
||||||
context.Context: Application context
|
Args:
|
||||||
*models.TransactionEdit: Object to edit
|
context.Context: Application context
|
||||||
string: id to search
|
*models.TransactionEdit: Object to edit
|
||||||
Returns:
|
string: id to search
|
||||||
*models.Transaction: Transaction object from database.
|
Returns:
|
||||||
*models.Exception: Exception payload.
|
*models.Transaction: Transaction object from database.
|
||||||
|
*models.Exception: Exception payload.
|
||||||
*/
|
*/
|
||||||
func (as *TransactionService) Edit(ctx context.Context, body *models.TransactionEdit, id string) (*models.Transaction, *models.Exception) {
|
func (as *TransactionService) Edit(ctx context.Context, body *models.TransactionEdit, id string) (*models.Transaction, *models.Exception) {
|
||||||
db := as.Db.WithContext(ctx)
|
db := as.db.WithContext(ctx)
|
||||||
|
|
||||||
amount, _ := body.Amount.Float64()
|
amount, _ := body.Amount.Float64()
|
||||||
|
|
||||||
@@ -236,16 +245,17 @@ func (as *TransactionService) Edit(ctx context.Context, body *models.Transaction
|
|||||||
Bulk Edit
|
Bulk Edit
|
||||||
|
|
||||||
Updates row in transaction table by id.
|
Updates row in transaction table by id.
|
||||||
Args:
|
|
||||||
context.Context: Application context
|
Args:
|
||||||
?[]models.Transaction Bulk Edit: Object to edit
|
context.Context: Application context
|
||||||
string: id to search
|
?[]models.Transaction Bulk Edit: Object to edit
|
||||||
Returns:
|
string: id to search
|
||||||
*models.Transaction: Transaction object from database.
|
Returns:
|
||||||
*models.Exception: Exception payload.
|
*models.Transaction: Transaction object from database.
|
||||||
|
*models.Exception: Exception payload.
|
||||||
*/
|
*/
|
||||||
func (as *TransactionService) BulkEdit(ctx context.Context, body *[]models.TransactionEdit) (*[]models.Transaction, *models.Exception) {
|
func (as *TransactionService) BulkEdit(ctx context.Context, body *[]models.TransactionEdit) (*[]models.Transaction, *models.Exception) {
|
||||||
db := as.Db.WithContext(ctx)
|
db := as.db.WithContext(ctx)
|
||||||
tx, _ := db.Begin()
|
tx, _ := db.Begin()
|
||||||
defer tx.Rollback()
|
defer tx.Rollback()
|
||||||
|
|
||||||
@@ -284,17 +294,18 @@ func (as *TransactionService) BulkEdit(ctx context.Context, body *[]models.Trans
|
|||||||
Get
|
Get
|
||||||
|
|
||||||
Gets row from transaction table by id.
|
Gets row from transaction table by id.
|
||||||
Args:
|
|
||||||
context.Context: Application context
|
Args:
|
||||||
*models.Auth: Authentication object
|
context.Context: Application context
|
||||||
string: id to search
|
*models.Auth: Authentication object
|
||||||
*model.Params: url query parameters
|
string: id to search
|
||||||
Returns:
|
*model.Params: url query parameters
|
||||||
*models.Transaction: Transaction object from database.
|
Returns:
|
||||||
*models.Exception: Exception payload.
|
*models.Transaction: Transaction object from database.
|
||||||
|
*models.Exception: Exception payload.
|
||||||
*/
|
*/
|
||||||
func (as *TransactionService) Get(ctx context.Context, am *models.Auth, id string, params *models.Params) (*models.Transaction, *models.Exception) {
|
func (as *TransactionService) Get(ctx context.Context, am *models.Auth, id string, params *models.Params) (*models.Transaction, *models.Exception) {
|
||||||
db := as.Db.WithContext(ctx)
|
db := as.db.WithContext(ctx)
|
||||||
|
|
||||||
exceptionReturn := new(models.Exception)
|
exceptionReturn := new(models.Exception)
|
||||||
wm := new(models.Transaction)
|
wm := new(models.Transaction)
|
||||||
|
|||||||
@@ -15,22 +15,29 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type UsersService struct {
|
type UsersService struct {
|
||||||
Db *pg.DB
|
db *pg.DB
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewUsersService(db *pg.DB) *UsersService {
|
||||||
|
return &UsersService{
|
||||||
|
db: db,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Create
|
Create
|
||||||
|
|
||||||
Inserts new row to users table.
|
Inserts new row to users table.
|
||||||
Args:
|
|
||||||
context.Context: Application context
|
Args:
|
||||||
*models.User: User object to create
|
context.Context: Application context
|
||||||
Returns:
|
*models.User: User object to create
|
||||||
*models.User: User object from database
|
Returns:
|
||||||
*models.Exception
|
*models.User: User object from database
|
||||||
|
*models.Exception
|
||||||
*/
|
*/
|
||||||
func (us *UsersService) Create(ctx context.Context, registerBody *models.User) (*models.User, *models.Exception) {
|
func (us *UsersService) Create(ctx context.Context, registerBody *models.User) (*models.User, *models.Exception) {
|
||||||
db := us.Db.WithContext(ctx)
|
db := us.db.WithContext(ctx)
|
||||||
|
|
||||||
check := new(models.User)
|
check := new(models.User)
|
||||||
exceptionReturn := new(models.Exception)
|
exceptionReturn := new(models.Exception)
|
||||||
@@ -67,15 +74,16 @@ func (us *UsersService) Create(ctx context.Context, registerBody *models.User) (
|
|||||||
Login
|
Login
|
||||||
|
|
||||||
Gets row from users table by email and valid password.
|
Gets row from users table by email and valid password.
|
||||||
Args:
|
|
||||||
context.Context: Application context
|
Args:
|
||||||
*models.Login: object to search
|
context.Context: Application context
|
||||||
Returns:
|
*models.Login: object to search
|
||||||
*models.Token: new session token
|
Returns:
|
||||||
*models.Exception
|
*models.Token: new session token
|
||||||
|
*models.Exception
|
||||||
*/
|
*/
|
||||||
func (us *UsersService) Login(ctx context.Context, loginBody *models.Login) (*models.Token, *models.Exception) {
|
func (us *UsersService) Login(ctx context.Context, loginBody *models.Login) (*models.Token, *models.Exception) {
|
||||||
db := us.Db.WithContext(ctx)
|
db := us.db.WithContext(ctx)
|
||||||
|
|
||||||
check := new(models.User)
|
check := new(models.User)
|
||||||
exceptionReturn := new(models.Exception)
|
exceptionReturn := new(models.Exception)
|
||||||
@@ -123,15 +131,16 @@ Deactivate
|
|||||||
Updates row in users table.
|
Updates row in users table.
|
||||||
|
|
||||||
IsActive column is set to false
|
IsActive column is set to false
|
||||||
Args:
|
|
||||||
context.Context: Application context
|
Args:
|
||||||
*models.Auth: Authentication object
|
context.Context: Application context
|
||||||
Returns:
|
*models.Auth: Authentication object
|
||||||
*models.MessageResponse
|
Returns:
|
||||||
*models.Exception
|
*models.MessageResponse
|
||||||
|
*models.Exception
|
||||||
*/
|
*/
|
||||||
func (us *UsersService) Deactivate(ctx context.Context, auth *models.Auth) (*models.MessageResponse, *models.Exception) {
|
func (us *UsersService) Deactivate(ctx context.Context, auth *models.Auth) (*models.MessageResponse, *models.Exception) {
|
||||||
db := us.Db.WithContext(ctx)
|
db := us.db.WithContext(ctx)
|
||||||
|
|
||||||
mm := new(models.MessageResponse)
|
mm := new(models.MessageResponse)
|
||||||
me := new(models.Exception)
|
me := new(models.Exception)
|
||||||
@@ -171,12 +180,13 @@ CreateToken
|
|||||||
Generates new jwt token.
|
Generates new jwt token.
|
||||||
|
|
||||||
It encodes the user id. Based on rememberMe it is valid through 48hours or 2hours.
|
It encodes the user id. Based on rememberMe it is valid through 48hours or 2hours.
|
||||||
Args:
|
|
||||||
*models.User: User object to encode
|
Args:
|
||||||
bool: Should function generate longer lasting token (48hrs)
|
*models.User: User object to encode
|
||||||
Returns:
|
bool: Should function generate longer lasting token (48hrs)
|
||||||
string: Generated token
|
Returns:
|
||||||
error: Error that occured in the process
|
string: Generated token
|
||||||
|
error: Error that occured in the process
|
||||||
*/
|
*/
|
||||||
func CreateToken(user *models.User, rememberMe bool) (string, error) {
|
func CreateToken(user *models.User, rememberMe bool) (string, error) {
|
||||||
atClaims := jwt.MapClaims{}
|
atClaims := jwt.MapClaims{}
|
||||||
|
|||||||
@@ -11,23 +11,31 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type WalletService struct {
|
type WalletService struct {
|
||||||
Db *pg.DB
|
db *pg.DB
|
||||||
Ss *SubscriptionService
|
subscriptionService *SubscriptionService
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewWalletService(db *pg.DB, ss *SubscriptionService) *WalletService {
|
||||||
|
return &WalletService{
|
||||||
|
db: db,
|
||||||
|
subscriptionService: ss,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
New
|
New
|
||||||
|
|
||||||
Inserts row to wallets table.
|
Inserts row to wallets table.
|
||||||
Args:
|
|
||||||
context.Context: Application context
|
Args:
|
||||||
*models.NewWalletBody: Object to be inserted
|
context.Context: Application context
|
||||||
Returns:
|
*models.NewWalletBody: Object to be inserted
|
||||||
*models.Wallet: Wallet object from database.
|
Returns:
|
||||||
*models.Exception: Exception payload.
|
*models.Wallet: Wallet object from database.
|
||||||
|
*models.Exception: Exception payload.
|
||||||
*/
|
*/
|
||||||
func (as *WalletService) New(ctx context.Context, am *models.NewWalletBody) (*models.Wallet, *models.Exception) {
|
func (as *WalletService) New(ctx context.Context, am *models.NewWalletBody) (*models.Wallet, *models.Exception) {
|
||||||
db := as.Db.WithContext(ctx)
|
db := as.db.WithContext(ctx)
|
||||||
|
|
||||||
exceptionReturn := new(models.Exception)
|
exceptionReturn := new(models.Exception)
|
||||||
walletModel := new(models.Wallet)
|
walletModel := new(models.Wallet)
|
||||||
@@ -48,16 +56,17 @@ func (as *WalletService) New(ctx context.Context, am *models.NewWalletBody) (*mo
|
|||||||
Edit
|
Edit
|
||||||
|
|
||||||
Updates row in wallets table by id.
|
Updates row in wallets table by id.
|
||||||
Args:
|
|
||||||
context.Context: Application context
|
Args:
|
||||||
*models.WalletEdit: Object to be edited
|
context.Context: Application context
|
||||||
string: id to search
|
*models.WalletEdit: Object to be edited
|
||||||
Returns:
|
string: id to search
|
||||||
*models.Wallet: Wallet object from database.
|
Returns:
|
||||||
*models.Exception: Exception payload.
|
*models.Wallet: Wallet object from database.
|
||||||
|
*models.Exception: Exception payload.
|
||||||
*/
|
*/
|
||||||
func (as *WalletService) Edit(ctx context.Context, body *models.WalletEdit, id string) (*models.Wallet, *models.Exception) {
|
func (as *WalletService) Edit(ctx context.Context, body *models.WalletEdit, id string) (*models.Wallet, *models.Exception) {
|
||||||
db := as.Db.WithContext(ctx)
|
db := as.db.WithContext(ctx)
|
||||||
|
|
||||||
exceptionReturn := new(models.Exception)
|
exceptionReturn := new(models.Exception)
|
||||||
tm := new(models.Wallet)
|
tm := new(models.Wallet)
|
||||||
@@ -84,16 +93,17 @@ func (as *WalletService) Edit(ctx context.Context, body *models.WalletEdit, id s
|
|||||||
Get
|
Get
|
||||||
|
|
||||||
Gets row in wallets table by id.
|
Gets row in wallets table by id.
|
||||||
Args:
|
|
||||||
context.Context: Application context
|
Args:
|
||||||
string: id to search
|
context.Context: Application context
|
||||||
*models.Params: url query parameters
|
string: id to search
|
||||||
Returns:
|
*models.Params: url query parameters
|
||||||
*models.Wallet: Wallet object from database
|
Returns:
|
||||||
*models.Exception: Exception payload.
|
*models.Wallet: Wallet object from database
|
||||||
|
*models.Exception: Exception payload.
|
||||||
*/
|
*/
|
||||||
func (as *WalletService) Get(ctx context.Context, id string, params *models.Params) (*models.Wallet, *models.Exception) {
|
func (as *WalletService) Get(ctx context.Context, id string, params *models.Params) (*models.Wallet, *models.Exception) {
|
||||||
db := as.Db.WithContext(ctx)
|
db := as.db.WithContext(ctx)
|
||||||
exceptionReturn := new(models.Exception)
|
exceptionReturn := new(models.Exception)
|
||||||
|
|
||||||
wm := new(models.Wallet)
|
wm := new(models.Wallet)
|
||||||
@@ -120,16 +130,17 @@ func (as *WalletService) Get(ctx context.Context, id string, params *models.Para
|
|||||||
GetAll
|
GetAll
|
||||||
|
|
||||||
Gets filtered rows from wallets table.
|
Gets filtered rows from wallets table.
|
||||||
Args:
|
|
||||||
context.Context: Application context
|
Args:
|
||||||
*models.Auth: Authentication object
|
context.Context: Application context
|
||||||
*models.FilteredResponse: filter options
|
*models.Auth: Authentication object
|
||||||
Returns:
|
*models.FilteredResponse: filter options
|
||||||
*models.Exception: Exception payload.
|
Returns:
|
||||||
|
*models.Exception: Exception payload.
|
||||||
*/
|
*/
|
||||||
func (as *WalletService) GetAll(ctx context.Context, am *models.Auth, filtered *models.FilteredResponse) *models.Exception {
|
func (as *WalletService) GetAll(ctx context.Context, am *models.Auth, filtered *models.FilteredResponse) *models.Exception {
|
||||||
exceptionReturn := new(models.Exception)
|
exceptionReturn := new(models.Exception)
|
||||||
db := as.Db.WithContext(ctx)
|
db := as.db.WithContext(ctx)
|
||||||
wm := new([]models.Wallet)
|
wm := new([]models.Wallet)
|
||||||
|
|
||||||
query := db.Model(wm).Where("? = ?", pg.Ident("user_id"), am.Id)
|
query := db.Model(wm).Where("? = ?", pg.Ident("user_id"), am.Id)
|
||||||
@@ -149,16 +160,17 @@ GetHeader
|
|||||||
Gets row from wallets table.
|
Gets row from wallets table.
|
||||||
|
|
||||||
Calculates previous month, current and next month totals.
|
Calculates previous month, current and next month totals.
|
||||||
Args:
|
|
||||||
context.Context: Application context
|
Args:
|
||||||
*models.Auth: Authentication object
|
context.Context: Application context
|
||||||
string: wallet id to search
|
*models.Auth: Authentication object
|
||||||
Returns:
|
string: wallet id to search
|
||||||
*models.WalletHeader: generated wallet header object
|
Returns:
|
||||||
*models.Exception: Exception payload.
|
*models.WalletHeader: generated wallet header object
|
||||||
|
*models.Exception: Exception payload.
|
||||||
*/
|
*/
|
||||||
func (as *WalletService) GetHeader(ctx context.Context, am *models.Auth, walletId string) (*models.WalletHeader, *models.Exception) {
|
func (as *WalletService) GetHeader(ctx context.Context, am *models.Auth, walletId string) (*models.WalletHeader, *models.Exception) {
|
||||||
db := as.Db.WithContext(ctx)
|
db := as.db.WithContext(ctx)
|
||||||
|
|
||||||
wm := new(models.WalletHeader)
|
wm := new(models.WalletHeader)
|
||||||
wallets := new([]models.WalletTransactions)
|
wallets := new([]models.WalletTransactions)
|
||||||
@@ -286,12 +298,13 @@ addWhere
|
|||||||
Appends Transaction to the belonging walletId.
|
Appends Transaction to the belonging walletId.
|
||||||
|
|
||||||
If missing, it creates the item list.
|
If missing, it creates the item list.
|
||||||
Args:
|
|
||||||
*[]models.WalletTransactions: list to append to
|
Args:
|
||||||
string: wallet id to check
|
*[]models.WalletTransactions: list to append to
|
||||||
models.Transaction: Transaction to append
|
string: wallet id to check
|
||||||
Returns:
|
models.Transaction: Transaction to append
|
||||||
*models.Exception: Exception payload.
|
Returns:
|
||||||
|
*models.Exception: Exception payload.
|
||||||
*/
|
*/
|
||||||
func addWhere(s *[]models.WalletTransactions, walletId string, e models.Transaction) {
|
func addWhere(s *[]models.WalletTransactions, walletId string, e models.Transaction) {
|
||||||
var exists bool
|
var exists bool
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package common
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
@@ -8,6 +9,18 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type RouteGroups struct {
|
||||||
|
Api *gin.RouterGroup
|
||||||
|
Auth *gin.RouterGroup
|
||||||
|
Wallet *gin.RouterGroup
|
||||||
|
WalletHeader *gin.RouterGroup
|
||||||
|
Transaction *gin.RouterGroup
|
||||||
|
TransactionType *gin.RouterGroup
|
||||||
|
Subscription *gin.RouterGroup
|
||||||
|
SubscriptionType *gin.RouterGroup
|
||||||
|
TransactionStatus *gin.RouterGroup
|
||||||
|
}
|
||||||
|
|
||||||
func CheckError(err error) {
|
func CheckError(err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error occured. %v", err)
|
log.Printf("Error occured. %v", err)
|
||||||
|
|||||||
Reference in New Issue
Block a user