Files
lndhub.go/controllers/balance.ctrl.go
2022-01-19 21:16:20 +01:00

34 lines
705 B
Go

package controllers
import (
"context"
"net/http"
"github.com/getAlby/lndhub.go/lib/service"
"github.com/labstack/echo/v4"
)
// BalanceController : BalanceController struct
type BalanceController struct {
svc *service.LndhubService
}
func NewBalanceController(svc *service.LndhubService) *BalanceController {
return &BalanceController{svc: svc}
}
// Balance : Balance Controller
func (controller *BalanceController) Balance(c echo.Context) error {
userId := c.Get("UserID").(int64)
balance, err := controller.svc.CurrentUserBalance(context.TODO(), userId)
if err != nil {
return err
}
return c.JSON(http.StatusOK, echo.Map{
"BTC": echo.Map{
"AvailableBalance": balance,
},
})
}