Skip to content

Commit

Permalink
Merge pull request #29 from the-go-dragons/develop
Browse files Browse the repository at this point in the history
Added wallet balance endpoint
  • Loading branch information
fazelsamar authored Jul 14, 2023
2 parents 9d64b4a + 66f8a40 commit 063dafe
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func routing(e *echo.Echo) {

e.POST("/wallets/charge-request", walletHandler.CharageRequest, customeMiddleware.RequireAuth)
e.POST("/wallets/finalize-charge", walletHandler.FinalizeCharge, customeMiddleware.RequireAuth)
e.GET("/wallet/balance", walletHandler.GetUserBalance, customeMiddleware.RequireAuth)

e.GET("/numbers", numberHandler.GetAvailables)
e.GET("/numbers/user", numberHandler.GetUserNumbers, customeMiddleware.RequireAuth)
Expand Down
12 changes: 12 additions & 0 deletions internal/interfaces/http/wallet_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package http

import (
"net/http"
"strconv"

"github.com/labstack/echo/v4"
"github.com/labstack/gommon/log"
Expand Down Expand Up @@ -86,3 +87,14 @@ func (wh WalletHandler) FinalizeCharge(c echo.Context) error {
return c.JSON(http.StatusOK, WalletFinalizeCharageResponse{walletId})

}

func (wh WalletHandler) GetUserBalance(c echo.Context) error {
user := c.Get("user").(domain.User)

wallet, err := wh.walletService.GetByUserId(user.ID)
if err != nil || wallet.ID == 0 {
return c.JSON(http.StatusBadRequest, Response{Message: "Can't get the wallet"})
}

return c.JSON(http.StatusOK, Response{Message: strconv.Itoa(int(wallet.Balance))})
}

0 comments on commit 063dafe

Please sign in to comment.