Add Balance Api
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
package balance
|
||||
|
||||
import (
|
||||
"furtuna-be/internal/common/errors"
|
||||
"furtuna-be/internal/entity"
|
||||
"furtuna-be/internal/handlers/request"
|
||||
"furtuna-be/internal/handlers/response"
|
||||
"furtuna-be/internal/services"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type Handler struct {
|
||||
service services.Balance
|
||||
}
|
||||
|
||||
func (h *Handler) Route(group *gin.RouterGroup, jwt gin.HandlerFunc) {
|
||||
route := group.Group("/balance")
|
||||
|
||||
route.GET("/partner", jwt, h.GetPartnerBalance)
|
||||
}
|
||||
|
||||
func NewHandler(service services.Balance) *Handler {
|
||||
return &Handler{
|
||||
service: service,
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Handler) GetPartnerBalance(c *gin.Context) {
|
||||
ctx := request.GetMyContext(c)
|
||||
|
||||
if !ctx.IsPartnerAdmin() {
|
||||
response.ErrorWrapper(c, errors.ErrorBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
updatedBranch, err := h.service.GetByID(ctx, *ctx.GetPartnerID())
|
||||
if err != nil {
|
||||
response.ErrorWrapper(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, response.BaseResponse{
|
||||
Success: true,
|
||||
Status: http.StatusOK,
|
||||
Data: h.toBalanceResponse(updatedBranch),
|
||||
})
|
||||
}
|
||||
|
||||
func (h *Handler) toBalanceResponse(resp *entity.Balance) response.Balance {
|
||||
return response.Balance{
|
||||
PartnerID: resp.PartnerID,
|
||||
Balance: resp.Balance,
|
||||
AuthBalance: resp.AuthBalance,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user