mirror of
https://github.com/getAlby/lndhub.go.git
synced 2025-12-21 14:44:45 +01:00
46 lines
1.0 KiB
Go
46 lines
1.0 KiB
Go
package controllers
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/getAlby/lndhub.go/lib/responses"
|
|
"github.com/getAlby/lndhub.go/lib/service"
|
|
"github.com/labstack/echo/v4"
|
|
"github.com/labstack/gommon/log"
|
|
)
|
|
|
|
// BalanceController : BalanceController struct
|
|
type BalanceController struct {
|
|
svc *service.LndhubService
|
|
}
|
|
|
|
func NewBalanceController(svc *service.LndhubService) *BalanceController {
|
|
return &BalanceController{svc: svc}
|
|
}
|
|
|
|
type BalanceResponse struct {
|
|
BTC struct {
|
|
AvailableBalance int64
|
|
}
|
|
}
|
|
|
|
func (controller *BalanceController) Balance(c echo.Context) error {
|
|
userId := c.Get("UserID").(int64)
|
|
balance, err := controller.svc.CurrentUserBalance(c.Request().Context(), userId)
|
|
if err != nil {
|
|
c.Logger().Errorj(
|
|
log.JSON{
|
|
"message": "failed to retrieve user balance",
|
|
"lndhub_user_id": userId,
|
|
"error": err,
|
|
},
|
|
)
|
|
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
|
|
}
|
|
return c.JSON(http.StatusOK, &BalanceResponse{
|
|
BTC: struct{ AvailableBalance int64 }{
|
|
AvailableBalance: balance,
|
|
},
|
|
})
|
|
}
|