mirror of
https://github.com/FJurmanovic/wallet-go-api.git
synced 2026-02-06 06:08:16 +00:00
added exception messages to controllers
This commit is contained in:
@@ -51,6 +51,7 @@ func (rc *AuthController) PostLogin(c *gin.Context) {
|
||||
|
||||
if exceptionReturn.Message != "" {
|
||||
c.JSON(exceptionReturn.StatusCode, exceptionReturn)
|
||||
return
|
||||
} else {
|
||||
c.JSON(200, returnedUser)
|
||||
}
|
||||
@@ -74,6 +75,7 @@ func (rc *AuthController) PostRegister(c *gin.Context) {
|
||||
|
||||
if exceptionReturn.Message != "" {
|
||||
c.JSON(exceptionReturn.StatusCode, exceptionReturn)
|
||||
return
|
||||
} else {
|
||||
c.JSON(200, returnedUser.Payload())
|
||||
}
|
||||
@@ -94,6 +96,7 @@ func (rc *AuthController) Delete(c *gin.Context) {
|
||||
|
||||
if er.Message != "" {
|
||||
c.JSON(er.StatusCode, er)
|
||||
return
|
||||
} else {
|
||||
c.JSON(200, mr)
|
||||
}
|
||||
@@ -114,6 +117,7 @@ func (rc *AuthController) CheckToken(c *gin.Context) {
|
||||
if err != nil {
|
||||
re.Valid = false
|
||||
c.AbortWithStatusJSON(400, re)
|
||||
return
|
||||
}
|
||||
|
||||
re.Valid = true
|
||||
|
||||
@@ -45,7 +45,11 @@ func (wc *SubscriptionTypeController) New(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
wm := wc.SubscriptionTypeService.New(c, body)
|
||||
wm, exception := wc.SubscriptionTypeService.New(c, body)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
}
|
||||
c.JSON(200, wm)
|
||||
}
|
||||
|
||||
@@ -58,7 +62,10 @@ GetAll
|
||||
func (wc *SubscriptionTypeController) GetAll(c *gin.Context) {
|
||||
embed, _ := c.GetQuery("embed")
|
||||
|
||||
wm := wc.SubscriptionTypeService.GetAll(c, embed)
|
||||
|
||||
wm, exception := wc.SubscriptionTypeService.GetAll(c, embed)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
}
|
||||
c.JSON(200, wm)
|
||||
}
|
||||
|
||||
@@ -52,7 +52,13 @@ func (wc *SubscriptionController) New(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
wm := wc.SubscriptionService.New(c, body)
|
||||
wm, exception := wc.SubscriptionService.New(c, body)
|
||||
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(200, wm)
|
||||
}
|
||||
|
||||
@@ -71,7 +77,11 @@ func (wc *SubscriptionController) Edit(c *gin.Context) {
|
||||
|
||||
id := c.Param("id")
|
||||
|
||||
wm := wc.SubscriptionService.Edit(c, body, id)
|
||||
wm, exception := wc.SubscriptionService.Edit(c, body, id)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
}
|
||||
c.JSON(200, wm)
|
||||
}
|
||||
|
||||
@@ -93,7 +103,11 @@ func (wc *SubscriptionController) Get(c *gin.Context) {
|
||||
embed, _ := c.GetQuery("embed")
|
||||
params.Embed = embed
|
||||
|
||||
fr := wc.SubscriptionService.Get(c, body, id, params)
|
||||
fr, exception := wc.SubscriptionService.Get(c, body, id, params)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(200, fr)
|
||||
}
|
||||
@@ -113,7 +127,11 @@ func (wc *SubscriptionController) End(c *gin.Context) {
|
||||
|
||||
id := c.Param("id")
|
||||
|
||||
fr := wc.SubscriptionService.End(c, id)
|
||||
fr, exception := wc.SubscriptionService.End(c, id)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(200, fr)
|
||||
}
|
||||
@@ -132,7 +150,11 @@ func (wc *SubscriptionController) GetAll(c *gin.Context) {
|
||||
fr := FilteredResponse(c)
|
||||
wallet, _ := c.GetQuery("walletId")
|
||||
|
||||
wc.SubscriptionService.GetAll(c, body, wallet, fr)
|
||||
exception := wc.SubscriptionService.GetAll(c, body, wallet, fr)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(200, fr)
|
||||
}
|
||||
|
||||
@@ -45,7 +45,11 @@ func (wc *TransactionStatusController) New(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
wm := wc.TransactionStatusService.New(c, body)
|
||||
wm, exception := wc.TransactionStatusService.New(c, body)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
}
|
||||
c.JSON(200, wm)
|
||||
}
|
||||
|
||||
@@ -58,7 +62,11 @@ GetAll
|
||||
func (wc *TransactionStatusController) GetAll(c *gin.Context) {
|
||||
embed, _ := c.GetQuery("embed")
|
||||
|
||||
wm := wc.TransactionStatusService.GetAll(c, embed)
|
||||
wm, exception := wc.TransactionStatusService.GetAll(c, embed)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(200, wm)
|
||||
}
|
||||
|
||||
@@ -45,7 +45,11 @@ func (wc *TransactionTypeController) New(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
wm := wc.TransactionTypeService.New(c, body)
|
||||
wm, exception := wc.TransactionTypeService.New(c, body)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
}
|
||||
c.JSON(200, wm)
|
||||
}
|
||||
|
||||
@@ -58,7 +62,11 @@ GetAll
|
||||
func (wc *TransactionTypeController) GetAll(c *gin.Context) {
|
||||
embed, _ := c.GetQuery("embed")
|
||||
|
||||
wm := wc.TransactionTypeService.GetAll(c, embed)
|
||||
wm, exception := wc.TransactionTypeService.GetAll(c, embed)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(200, wm)
|
||||
}
|
||||
|
||||
@@ -30,8 +30,16 @@ func NewTransactionController(as *services.TransactionService, s *gin.RouterGrou
|
||||
s.GET("", wc.GetAll)
|
||||
s.PUT("/:id", wc.Edit)
|
||||
s.GET("/:id", wc.Get)
|
||||
s.GET("check", wc.Check)
|
||||
s.PUT("/bulk", wc.BulkEdit)
|
||||
|
||||
bulkGroup := s.Group("bulk")
|
||||
{
|
||||
bulkGroup.PUT("", wc.BulkEdit)
|
||||
}
|
||||
|
||||
checkGroup := s.Group("check")
|
||||
{
|
||||
checkGroup.GET("check", wc.Check)
|
||||
}
|
||||
|
||||
return wc
|
||||
}
|
||||
@@ -49,7 +57,11 @@ func (wc *TransactionController) New(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
wm := wc.TransactionService.New(c, body)
|
||||
wm, exception := wc.TransactionService.New(c, body)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
}
|
||||
c.JSON(200, wm)
|
||||
}
|
||||
|
||||
@@ -70,7 +82,11 @@ func (wc *TransactionController) GetAll(c *gin.Context) {
|
||||
noPendingQry, _ := c.GetQuery("noPending")
|
||||
noPending := noPendingQry != ""
|
||||
|
||||
wc.TransactionService.GetAll(c, body, wallet, fr, noPending)
|
||||
exception := wc.TransactionService.GetAll(c, body, wallet, fr, noPending)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(200, fr)
|
||||
}
|
||||
@@ -89,7 +105,11 @@ func (wc *TransactionController) Check(c *gin.Context) {
|
||||
fr := FilteredResponse(c)
|
||||
wallet, _ := c.GetQuery("walletId")
|
||||
|
||||
wc.TransactionService.Check(c, body, wallet, fr)
|
||||
exception := wc.TransactionService.Check(c, body, wallet, fr)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(200, fr)
|
||||
}
|
||||
@@ -109,7 +129,11 @@ func (wc *TransactionController) Edit(c *gin.Context) {
|
||||
|
||||
id := c.Param("id")
|
||||
|
||||
wm := wc.TransactionService.Edit(c, body, id)
|
||||
wm, exception := wc.TransactionService.Edit(c, body, id)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
}
|
||||
c.JSON(200, wm)
|
||||
}
|
||||
|
||||
@@ -126,7 +150,11 @@ func (wc *TransactionController) BulkEdit(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
wm := wc.TransactionService.BulkEdit(c, body)
|
||||
wm, exception := wc.TransactionService.BulkEdit(c, body)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
}
|
||||
c.JSON(200, wm)
|
||||
}
|
||||
|
||||
@@ -148,7 +176,11 @@ func (wc *TransactionController) Get(c *gin.Context) {
|
||||
embed, _ := c.GetQuery("embed")
|
||||
params.Embed = embed
|
||||
|
||||
fr := wc.TransactionService.Get(c, body, id, params)
|
||||
fr, exception := wc.TransactionService.Get(c, body, id, params)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(200, fr)
|
||||
}
|
||||
|
||||
@@ -44,7 +44,11 @@ func (wc *WalletsHeaderController) Get(c *gin.Context) {
|
||||
auth := c.MustGet("auth")
|
||||
body.Id = auth.(*models.Auth).Id
|
||||
|
||||
wm := wc.WalletService.GetHeader(c, body, walletId)
|
||||
wm, exception := wc.WalletService.GetHeader(c, body, walletId)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(200, wm)
|
||||
}
|
||||
|
||||
@@ -51,7 +51,11 @@ func (wc *WalletsController) New(c *gin.Context) {
|
||||
get := c.MustGet("auth")
|
||||
body.UserID = get.(*models.Auth).Id
|
||||
|
||||
wm := wc.WalletService.New(c, body)
|
||||
wm, exception := wc.WalletService.New(c, body)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
}
|
||||
c.JSON(200, wm)
|
||||
}
|
||||
|
||||
@@ -68,7 +72,11 @@ func (wc *WalletsController) GetAll(c *gin.Context) {
|
||||
|
||||
fr := FilteredResponse(c)
|
||||
|
||||
wc.WalletService.GetAll(c, body, fr)
|
||||
exception := wc.WalletService.GetAll(c, body, fr)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(200, fr)
|
||||
}
|
||||
@@ -88,7 +96,11 @@ func (wc *WalletsController) Edit(c *gin.Context) {
|
||||
|
||||
id := c.Param("id")
|
||||
|
||||
wm := wc.WalletService.Edit(c, body, id)
|
||||
wm, exception := wc.WalletService.Edit(c, body, id)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
}
|
||||
c.JSON(200, wm)
|
||||
}
|
||||
|
||||
@@ -106,7 +118,11 @@ func (wc *WalletsController) Get(c *gin.Context) {
|
||||
embed, _ := c.GetQuery("embed")
|
||||
params.Embed = embed
|
||||
|
||||
fr := wc.WalletService.Get(c, id, params)
|
||||
fr, exception := wc.WalletService.Get(c, id, params)
|
||||
if exception != nil {
|
||||
c.JSON(exception.StatusCode, exception)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(200, fr)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user