Add Balance Api
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
package balance
|
||||
|
||||
import (
|
||||
"context"
|
||||
"furtuna-be/internal/common/logger"
|
||||
"furtuna-be/internal/entity"
|
||||
"furtuna-be/internal/repository"
|
||||
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type BalanceService struct {
|
||||
repo repository.WalletRepository
|
||||
}
|
||||
|
||||
func NewBalanceService(repo repository.WalletRepository) *BalanceService {
|
||||
return &BalanceService{
|
||||
repo: repo,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *BalanceService) GetByID(ctx context.Context, id int64) (*entity.Balance, error) {
|
||||
balanceDB, err := s.repo.GetByPartnerID(ctx, nil, id)
|
||||
if err != nil {
|
||||
logger.ContextLogger(ctx).Error("error when get branch by id", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &entity.Balance{
|
||||
PartnerID: id,
|
||||
Balance: balanceDB.Balance,
|
||||
AuthBalance: balanceDB.AuthBalance,
|
||||
}, nil
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package services
|
||||
import (
|
||||
"context"
|
||||
"furtuna-be/internal/common/mycontext"
|
||||
"furtuna-be/internal/services/balance"
|
||||
"furtuna-be/internal/services/branch"
|
||||
service "furtuna-be/internal/services/license"
|
||||
"furtuna-be/internal/services/order"
|
||||
@@ -36,6 +37,7 @@ type ServiceManagerImpl struct {
|
||||
SiteSvc Site
|
||||
LicenseSvc License
|
||||
Transaction Transaction
|
||||
Balance Balance
|
||||
}
|
||||
|
||||
func NewServiceManagerImpl(cfg *config.Config, repo *repository.RepoManagerImpl) *ServiceManagerImpl {
|
||||
@@ -53,6 +55,7 @@ func NewServiceManagerImpl(cfg *config.Config, repo *repository.RepoManagerImpl)
|
||||
SiteSvc: site.NewSiteService(repo.Site),
|
||||
LicenseSvc: service.NewLicenseService(repo.License),
|
||||
Transaction: transaction.New(repo.Transaction),
|
||||
Balance: balance.NewBalanceService(repo.Wallet),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,3 +147,7 @@ type License interface {
|
||||
type Transaction interface {
|
||||
GetTransactionList(ctx mycontext.Context, req entity.TransactionSearch) ([]*entity.TransactionList, int, error)
|
||||
}
|
||||
|
||||
type Balance interface {
|
||||
GetByID(ctx context.Context, id int64) (*entity.Balance, error)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user