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:
@@ -59,7 +59,7 @@ func NewHandlers(pool *pgxpool.Pool, jwtSecret, cryptoSecret, openAIKey, perplex
|
||||
perplexityClient := ai.NewPerplexityClient(perplexityKey)
|
||||
|
||||
authService := service.NewAuthService(userRepo, sessionRepo, inviteRepo, txManager, jwtSecret, cryptoSecret)
|
||||
userService := service.NewUserService(userRepo, requestRepo, cryptoSecret)
|
||||
userService := service.NewUserService(userRepo, requestRepo, tokenUsageRepo, cryptoSecret)
|
||||
inviteService := service.NewInviteService(inviteRepo, userRepo, txManager)
|
||||
requestService := service.NewRequestService(requestRepo, supplierRepo, tokenUsageRepo, userRepo, openAIClient, perplexityClient, txManager)
|
||||
supplierService := service.NewSupplierService(supplierRepo, requestRepo)
|
||||
|
||||
@@ -48,19 +48,22 @@ func (h *UserHandler) GetStatistics(ctx context.Context, req *pb.GetStatisticsRe
|
||||
}
|
||||
|
||||
func (h *UserHandler) GetBalanceStatistics(ctx context.Context, req *pb.GetBalanceStatisticsRequest) (*pb.GetBalanceStatisticsResponse, error) {
|
||||
balance, err := h.userService.GetBalance(ctx, int(req.UserId))
|
||||
stats, err := h.userService.GetBalanceStatistics(ctx, int(req.UserId))
|
||||
if err != nil {
|
||||
return nil, errors.ToGRPCError(err, h.logger, "UserService.GetBalanceStatistics")
|
||||
}
|
||||
|
||||
stats, err := h.userService.GetStatistics(ctx, int(req.UserId))
|
||||
if err != nil {
|
||||
return nil, errors.ToGRPCError(err, h.logger, "UserService.GetBalanceStatistics")
|
||||
history := make([]*pb.WriteOffHistoryItem, 0, len(stats.WriteOffHistory))
|
||||
for _, item := range stats.WriteOffHistory {
|
||||
history = append(history, &pb.WriteOffHistoryItem{
|
||||
OperationId: item.OperationID,
|
||||
Data: item.Data,
|
||||
Amount: item.Amount,
|
||||
})
|
||||
}
|
||||
|
||||
return &pb.GetBalanceStatisticsResponse{
|
||||
Balance: balance,
|
||||
TotalRequests: int32(stats.RequestsCount),
|
||||
TotalSpent: 0,
|
||||
AverageCost: stats.AverageCost,
|
||||
WriteOffHistory: history,
|
||||
}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user