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 (
|
import (
|
||||||
"api_bb/internal/models"
|
"api_bb/internal/models"
|
||||||
"api_bb/internal/repository"
|
"api_bb/internal/repository"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
type PersonalBestService struct {
|
type PersonalBestService struct {
|
||||||
pbRepo repository.PersonalBestRepository
|
pbRepo repository.PersonalBestRepository
|
||||||
|
userStatsService UserStatsService
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPersonalBestService(pbRepo repository.PersonalBestRepository) *PersonalBestService {
|
func NewPersonalBestService(pbRepo repository.PersonalBestRepository, userStatsService UserStatsService) *PersonalBestService {
|
||||||
return &PersonalBestService{
|
return &PersonalBestService{
|
||||||
pbRepo: pbRepo,
|
pbRepo: pbRepo,
|
||||||
|
userStatsService: userStatsService,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,9 +54,11 @@ func (s *PersonalBestService) CreatePersonalBest(userID uint, req models.Persona
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Если это лучший результат, можно обновить статистику пользователя
|
|
||||||
if !isBest {
|
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
|
return personalBest, nil
|
||||||
@@ -83,4 +88,4 @@ func (s *PersonalBestService) VerifyPersonalBest(id uint, userID uint) error {
|
|||||||
|
|
||||||
pb.Verified = true
|
pb.Verified = true
|
||||||
return s.pbRepo.Update(pb)
|
return s.pbRepo.Update(pb)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user