added exception messages to controllers

This commit is contained in:
Fran Jurmanović
2022-02-20 10:38:08 +01:00
parent 1b418ec5a2
commit 341647ccd9
18 changed files with 516 additions and 182 deletions

View File

@@ -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

View File

@@ -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)
}

View File

@@ -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)
}

View File

@@ -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)
}

View File

@@ -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)
}

View File

@@ -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)
}

View File

@@ -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)
}

View File

@@ -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)
}