add service
All checks were successful
Deploy Smart Search Backend Test / deploy (push) Successful in 2m25s
All checks were successful
Deploy Smart Search Backend Test / deploy (push) Successful in 2m25s
This commit is contained in:
@@ -20,6 +20,7 @@ type UserService interface {
|
||||
GetInfo(ctx context.Context, userID int) (*UserInfo, error)
|
||||
GetBalance(ctx context.Context, userID int) (float64, error)
|
||||
GetStatistics(ctx context.Context, userID int) (*Statistics, error)
|
||||
GetBalanceStatistics(ctx context.Context, userID int) (*BalanceStatistics, error)
|
||||
}
|
||||
|
||||
type InviteService interface {
|
||||
|
||||
@@ -3,14 +3,16 @@ package service
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.techease.ru/Smart-search/smart-search-back/internal/model"
|
||||
"git.techease.ru/Smart-search/smart-search-back/internal/repository"
|
||||
"git.techease.ru/Smart-search/smart-search-back/pkg/crypto"
|
||||
)
|
||||
|
||||
type userService struct {
|
||||
userRepo repository.UserRepository
|
||||
requestRepo repository.RequestRepository
|
||||
cryptoHelper *crypto.Crypto
|
||||
userRepo repository.UserRepository
|
||||
requestRepo repository.RequestRepository
|
||||
tokenUsageRepo repository.TokenUsageRepository
|
||||
cryptoHelper *crypto.Crypto
|
||||
}
|
||||
|
||||
type UserInfo struct {
|
||||
@@ -27,11 +29,17 @@ type Statistics struct {
|
||||
CreatedTZ int
|
||||
}
|
||||
|
||||
func NewUserService(userRepo repository.UserRepository, requestRepo repository.RequestRepository, cryptoSecret string) UserService {
|
||||
type BalanceStatistics struct {
|
||||
AverageCost float64
|
||||
WriteOffHistory []*model.WriteOffHistory
|
||||
}
|
||||
|
||||
func NewUserService(userRepo repository.UserRepository, requestRepo repository.RequestRepository, tokenUsageRepo repository.TokenUsageRepository, cryptoSecret string) UserService {
|
||||
return &userService{
|
||||
userRepo: userRepo,
|
||||
requestRepo: requestRepo,
|
||||
cryptoHelper: crypto.NewCrypto(cryptoSecret),
|
||||
userRepo: userRepo,
|
||||
requestRepo: requestRepo,
|
||||
tokenUsageRepo: tokenUsageRepo,
|
||||
cryptoHelper: crypto.NewCrypto(cryptoSecret),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,3 +89,15 @@ func (s *userService) GetStatistics(ctx context.Context, userID int) (*Statistic
|
||||
CreatedTZ: createdTZ,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *userService) GetBalanceStatistics(ctx context.Context, userID int) (*BalanceStatistics, error) {
|
||||
averageCost, history, err := s.tokenUsageRepo.GetBalanceStatistics(ctx, userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &BalanceStatistics{
|
||||
AverageCost: averageCost,
|
||||
WriteOffHistory: history,
|
||||
}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user