mirror of
https://github.com/FJurmanovic/wallet-go-api.git
synced 2026-02-06 06:08:16 +00:00
add repositories and fixed services
This commit is contained in:
@@ -56,11 +56,11 @@ 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.service.PostMigrate(c, version)
|
||||
er := ac.service.PostMigrate(c, version)
|
||||
|
||||
if er.Message != "" {
|
||||
c.JSON(er.StatusCode, er)
|
||||
if len(er) > 0 {
|
||||
c.JSON(500, er)
|
||||
} else {
|
||||
c.JSON(200, mr)
|
||||
c.JSON(200, nil)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +56,9 @@ func (wc *SubscriptionController) New(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
wm, exception := wc.service.New(c, body)
|
||||
mdl := body.ToSubscription()
|
||||
|
||||
wm, exception := wc.service.New(c, mdl)
|
||||
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
@@ -81,7 +83,10 @@ func (wc *SubscriptionController) Edit(c *gin.Context) {
|
||||
|
||||
id := c.Param("id")
|
||||
|
||||
wm, exception := wc.service.Edit(c, body, id)
|
||||
mdl := body.ToSubscription()
|
||||
mdl.Id = id
|
||||
|
||||
wm, exception := wc.service.Edit(c, mdl)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
@@ -96,11 +101,10 @@ Get
|
||||
*/
|
||||
// ROUTE (GET /subscription/:id)
|
||||
func (wc *SubscriptionController) Get(c *gin.Context) {
|
||||
body := new(model.Auth)
|
||||
params := new(model.Params)
|
||||
|
||||
auth := c.MustGet("auth")
|
||||
body.Id = auth.(*model.Auth).Id
|
||||
userId := auth.(*model.Auth).Id
|
||||
|
||||
id := c.Param("id")
|
||||
|
||||
@@ -109,8 +113,9 @@ func (wc *SubscriptionController) Get(c *gin.Context) {
|
||||
|
||||
flt := filter.NewSubscriptionFilter(*params)
|
||||
flt.Id = id
|
||||
flt.UserId = userId
|
||||
|
||||
fr, exception := wc.service.Get(c, body, *flt)
|
||||
fr, exception := wc.service.Get(c, *flt)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
@@ -121,17 +126,6 @@ func (wc *SubscriptionController) Get(c *gin.Context) {
|
||||
|
||||
// ROUTE (PUT /subscription/end/:id)
|
||||
func (wc *SubscriptionController) End(c *gin.Context) {
|
||||
body := new(model.Auth)
|
||||
|
||||
auth := c.MustGet("auth")
|
||||
body.Id = auth.(*model.Auth).Id
|
||||
|
||||
end := new(model.SubscriptionEnd)
|
||||
if err := c.ShouldBind(end); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
id := c.Param("id")
|
||||
|
||||
fr, exception := wc.service.End(c, id)
|
||||
@@ -152,14 +146,14 @@ GetAll
|
||||
func (wc *SubscriptionController) GetAll(c *gin.Context) {
|
||||
auth := c.MustGet("auth")
|
||||
|
||||
fr := FilteredResponse(c)
|
||||
wallet, _ := c.GetQuery("walletId")
|
||||
embed, _ := c.GetQuery("embed")
|
||||
|
||||
flt := filter.NewSubscriptionFilter(model.Params{})
|
||||
flt := filter.NewSubscriptionFilter(model.Params{Embed: embed})
|
||||
flt.WalletId = wallet
|
||||
flt.Id = auth.(*model.Auth).Id
|
||||
flt.UserId = auth.(*model.Auth).Id
|
||||
|
||||
exception := wc.service.GetAll(c, flt, fr)
|
||||
fr, exception := wc.service.GetAll(c, flt)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
|
||||
@@ -2,6 +2,7 @@ package controller
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"wallet-api/pkg/filter"
|
||||
"wallet-api/pkg/model"
|
||||
"wallet-api/pkg/service"
|
||||
"wallet-api/pkg/utl/common"
|
||||
@@ -48,7 +49,9 @@ func (wc *SubscriptionTypeController) New(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
wm, exception := wc.service.New(c, body)
|
||||
mdl := body.ToSubscriptionType()
|
||||
|
||||
wm, exception := wc.service.New(c, mdl)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
@@ -65,7 +68,9 @@ GetAll
|
||||
func (wc *SubscriptionTypeController) GetAll(c *gin.Context) {
|
||||
embed, _ := c.GetQuery("embed")
|
||||
|
||||
wm, exception := wc.service.GetAll(c, embed)
|
||||
flt := filter.NewSubscriptionTypeFilter(model.Params{Embed: embed})
|
||||
|
||||
wm, exception := wc.service.GetAll(c, flt)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
|
||||
@@ -2,6 +2,7 @@ package controller
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"wallet-api/pkg/filter"
|
||||
"wallet-api/pkg/model"
|
||||
"wallet-api/pkg/service"
|
||||
"wallet-api/pkg/utl/common"
|
||||
@@ -60,7 +61,9 @@ func (wc *TransactionController) New(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
wm, exception := wc.service.New(c, body)
|
||||
mdl := body.ToTransaction()
|
||||
|
||||
wm, exception := wc.service.New(c, mdl)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
@@ -75,17 +78,22 @@ GetAll
|
||||
*/
|
||||
// ROUTE (GET /transactions)
|
||||
func (wc *TransactionController) GetAll(c *gin.Context) {
|
||||
body := new(model.Auth)
|
||||
auth := c.MustGet("auth")
|
||||
body.Id = auth.(*model.Auth).Id
|
||||
userId := auth.(*model.Auth).Id
|
||||
|
||||
fr := FilteredResponse(c)
|
||||
wallet, _ := c.GetQuery("walletId")
|
||||
embed, _ := c.GetQuery("embed")
|
||||
|
||||
noPendingQry, _ := c.GetQuery("noPending")
|
||||
noPending := noPendingQry != ""
|
||||
|
||||
exception := wc.service.GetAll(c, body, wallet, fr, noPending)
|
||||
flt := filter.NewTransactionFilter(model.Params{Embed: embed})
|
||||
flt.WalletId = wallet
|
||||
flt.NoPending = noPending
|
||||
flt.UserId = userId
|
||||
|
||||
fr, exception := wc.service.GetAll(c, flt)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
@@ -101,14 +109,17 @@ Check
|
||||
*/
|
||||
// ROUTE (GET /transactions)
|
||||
func (wc *TransactionController) Check(c *gin.Context) {
|
||||
body := new(model.Auth)
|
||||
auth := c.MustGet("auth")
|
||||
body.Id = auth.(*model.Auth).Id
|
||||
userId := auth.(*model.Auth).Id
|
||||
|
||||
fr := FilteredResponse(c)
|
||||
wallet, _ := c.GetQuery("walletId")
|
||||
|
||||
exception := wc.service.Check(c, body, wallet, fr)
|
||||
flt := filter.NewTransactionFilter(model.Params{})
|
||||
flt.WalletId = wallet
|
||||
flt.UserId = userId
|
||||
|
||||
fr, exception := wc.service.Check(c, flt)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
@@ -131,8 +142,10 @@ func (wc *TransactionController) Edit(c *gin.Context) {
|
||||
}
|
||||
|
||||
id := c.Param("id")
|
||||
mdl := body.ToTransaction()
|
||||
mdl.Id = id
|
||||
|
||||
wm, exception := wc.service.Edit(c, body, id)
|
||||
wm, exception := wc.service.Edit(c, mdl)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
@@ -153,7 +166,13 @@ func (wc *TransactionController) BulkEdit(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
wm, exception := wc.service.BulkEdit(c, body)
|
||||
mdl := new([]model.Transaction)
|
||||
for _, transaction := range *body {
|
||||
tm := transaction.ToTransaction()
|
||||
*mdl = append(*mdl, *tm)
|
||||
}
|
||||
|
||||
wm, exception := wc.service.BulkEdit(c, mdl)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
@@ -168,18 +187,21 @@ Get
|
||||
*/
|
||||
// ROUTE (GET /transactions/:id)
|
||||
func (wc *TransactionController) Get(c *gin.Context) {
|
||||
body := new(model.Auth)
|
||||
params := new(model.Params)
|
||||
|
||||
auth := c.MustGet("auth")
|
||||
body.Id = auth.(*model.Auth).Id
|
||||
userId := auth.(*model.Auth).Id
|
||||
|
||||
id := c.Param("id")
|
||||
|
||||
embed, _ := c.GetQuery("embed")
|
||||
params.Embed = embed
|
||||
|
||||
fr, exception := wc.service.Get(c, body, id, params)
|
||||
flt := filter.NewTransactionFilter(*params)
|
||||
flt.Id = id
|
||||
flt.UserId = userId
|
||||
|
||||
fr, exception := wc.service.Get(c, flt)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
|
||||
@@ -2,6 +2,7 @@ package controller
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"wallet-api/pkg/filter"
|
||||
"wallet-api/pkg/model"
|
||||
"wallet-api/pkg/service"
|
||||
"wallet-api/pkg/utl/common"
|
||||
@@ -48,7 +49,9 @@ func (wc *TransactionStatusController) New(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
wm, exception := wc.service.New(c, body)
|
||||
mdl := body.ToTransactionStatus()
|
||||
|
||||
wm, exception := wc.service.New(c, mdl)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
@@ -64,8 +67,9 @@ GetAll
|
||||
// ROUTE (GET /transaction-status)
|
||||
func (wc *TransactionStatusController) GetAll(c *gin.Context) {
|
||||
embed, _ := c.GetQuery("embed")
|
||||
flt := filter.NewTransactionStatusFilter(model.Params{Embed: embed})
|
||||
|
||||
wm, exception := wc.service.GetAll(c, embed)
|
||||
wm, exception := wc.service.GetAll(c, flt)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
|
||||
@@ -2,6 +2,7 @@ package controller
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"wallet-api/pkg/filter"
|
||||
"wallet-api/pkg/model"
|
||||
"wallet-api/pkg/service"
|
||||
"wallet-api/pkg/utl/common"
|
||||
@@ -47,8 +48,9 @@ func (wc *TransactionTypeController) New(c *gin.Context) {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
mdl := body.ToTransactionType()
|
||||
|
||||
wm, exception := wc.service.New(c, body)
|
||||
wm, exception := wc.service.New(c, mdl)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
@@ -65,7 +67,9 @@ GetAll
|
||||
func (wc *TransactionTypeController) GetAll(c *gin.Context) {
|
||||
embed, _ := c.GetQuery("embed")
|
||||
|
||||
wm, exception := wc.service.GetAll(c, embed)
|
||||
flt := filter.NewTransactionTypeFilter(model.Params{Embed: embed})
|
||||
|
||||
wm, exception := wc.service.GetAll(c, flt)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
|
||||
@@ -2,6 +2,7 @@ package controller
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"wallet-api/pkg/filter"
|
||||
"wallet-api/pkg/middleware"
|
||||
"wallet-api/pkg/model"
|
||||
"wallet-api/pkg/service"
|
||||
@@ -91,11 +92,13 @@ Delete
|
||||
*/
|
||||
// ROUTE (DELETE /auth/deactivate).
|
||||
func (rc *UserController) Delete(c *gin.Context) {
|
||||
auth := new(model.Auth)
|
||||
authGet := c.MustGet("auth")
|
||||
auth.Id = authGet.(*model.Auth).Id
|
||||
userId := authGet.(*model.Auth).Id
|
||||
|
||||
mr, er := rc.service.Deactivate(c, auth)
|
||||
flt := filter.NewUserFilter(model.Params{})
|
||||
flt.UserId = userId
|
||||
|
||||
mr, er := rc.service.Deactivate(c, flt)
|
||||
|
||||
if er.Message != "" {
|
||||
c.JSON(er.StatusCode, er)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"wallet-api/pkg/filter"
|
||||
"wallet-api/pkg/model"
|
||||
"wallet-api/pkg/service"
|
||||
"wallet-api/pkg/utl/common"
|
||||
@@ -40,14 +41,17 @@ Get
|
||||
*/
|
||||
// ROUTE (GET /wallet/wallet-header)
|
||||
func (wc *WalletHeaderController) Get(c *gin.Context) {
|
||||
body := new(model.Auth)
|
||||
|
||||
walletId, _ := c.GetQuery("walletId")
|
||||
|
||||
auth := c.MustGet("auth")
|
||||
body.Id = auth.(*model.Auth).Id
|
||||
userId := auth.(*model.Auth).Id
|
||||
embed, _ := c.GetQuery("embed")
|
||||
|
||||
wm, exception := wc.service.GetHeader(c, body, walletId)
|
||||
flt := filter.NewWalletHeaderFilter(model.Params{Embed: embed})
|
||||
flt.UserId = userId
|
||||
flt.WalletId = walletId
|
||||
|
||||
wm, exception := wc.service.GetHeader(c, flt)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
|
||||
@@ -2,6 +2,7 @@ package controller
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"wallet-api/pkg/filter"
|
||||
"wallet-api/pkg/model"
|
||||
"wallet-api/pkg/service"
|
||||
"wallet-api/pkg/utl/common"
|
||||
@@ -69,13 +70,14 @@ GetAll
|
||||
*/
|
||||
// ROUTE (GET /wallet)
|
||||
func (wc *WalletController) GetAll(c *gin.Context) {
|
||||
body := new(model.Auth)
|
||||
auth := c.MustGet("auth")
|
||||
body.Id = auth.(*model.Auth).Id
|
||||
userId := auth.(*model.Auth).Id
|
||||
|
||||
fr := FilteredResponse(c)
|
||||
embed, _ := c.GetQuery("embed")
|
||||
flt := filter.NewWalletFilter(model.Params{Embed: embed})
|
||||
flt.UserId = userId
|
||||
|
||||
exception := wc.service.GetAll(c, body, fr)
|
||||
fr, exception := wc.service.GetAll(c, flt)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
@@ -99,7 +101,10 @@ func (wc *WalletController) Edit(c *gin.Context) {
|
||||
|
||||
id := c.Param("id")
|
||||
|
||||
wm, exception := wc.service.Edit(c, body, id)
|
||||
mdl := body.ToWallet()
|
||||
mdl.Id = id
|
||||
|
||||
wm, exception := wc.service.Edit(c, mdl)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
@@ -121,7 +126,10 @@ func (wc *WalletController) Get(c *gin.Context) {
|
||||
embed, _ := c.GetQuery("embed")
|
||||
params.Embed = embed
|
||||
|
||||
fr, exception := wc.service.Get(c, id, params)
|
||||
flt := filter.NewWalletFilter(*params)
|
||||
flt.Id = id
|
||||
|
||||
fr, exception := wc.service.Get(c, flt)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user