modified: serv_nginx/api_bb/internal/service/personal_best_service.go
add update stats
This commit is contained in:
@@ -4,17 +4,20 @@ package service
|
||||
import (
|
||||
"api_bb/internal/models"
|
||||
"api_bb/internal/repository"
|
||||
"fmt"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type PersonalBestService struct {
|
||||
pbRepo repository.PersonalBestRepository
|
||||
userStatsService UserStatsService
|
||||
}
|
||||
|
||||
func NewPersonalBestService(pbRepo repository.PersonalBestRepository) *PersonalBestService {
|
||||
func NewPersonalBestService(pbRepo repository.PersonalBestRepository, userStatsService UserStatsService) *PersonalBestService {
|
||||
return &PersonalBestService{
|
||||
pbRepo: pbRepo,
|
||||
userStatsService: userStatsService,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,9 +54,11 @@ func (s *PersonalBestService) CreatePersonalBest(userID uint, req models.Persona
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Если это лучший результат, можно обновить статистику пользователя
|
||||
if !isBest {
|
||||
// Здесь можно вызвать метод для обновления UserStats
|
||||
if err := s.userStatsService.UpdatePersonalBest(userID, string(req.DistanceType), req.Time); err != nil {
|
||||
// Логируем ошибку, но не прерываем выполнение
|
||||
fmt.Printf("Failed to update user stats: %v\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
return personalBest, nil
|
||||
|
||||
Reference in New Issue
Block a user