lots of stuff, don't truly remember
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
package stats
|
||||
|
||||
import (
|
||||
"rideaware/pkg/database"
|
||||
)
|
||||
|
||||
type Service struct {
|
||||
repo *Repository
|
||||
}
|
||||
@@ -31,3 +35,37 @@ func (s *Service) GetMonthlyStats(userID uint, months int) ([]PeriodStats, error
|
||||
func (s *Service) GetPersonalBests(userID uint) ([]PersonalBest, error) {
|
||||
return s.repo.GetPersonalBests(userID)
|
||||
}
|
||||
|
||||
// getUserFTP retrieves the user's FTP from the user_profiles table.
|
||||
func (s *Service) getUserFTP(userID uint) int {
|
||||
var ftp int
|
||||
database.DB.Table("user_profiles").
|
||||
Where("user_id = ?", userID).
|
||||
Select("ftp").
|
||||
Scan(&ftp)
|
||||
return ftp
|
||||
}
|
||||
|
||||
// GetTrainingLoad returns daily TSS data and the user's FTP.
|
||||
func (s *Service) GetTrainingLoad(userID uint, days int) ([]DailyTSS, int, error) {
|
||||
if days <= 0 || days > 730 {
|
||||
days = 180
|
||||
}
|
||||
|
||||
ftp := s.getUserFTP(userID)
|
||||
|
||||
data, err := s.repo.GetDailyTSS(userID, ftp, days)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
return data, ftp, nil
|
||||
}
|
||||
|
||||
// GetPowerHistory returns power data points for completed workouts.
|
||||
func (s *Service) GetPowerHistory(userID uint, days int) ([]PowerPoint, error) {
|
||||
if days <= 0 || days > 730 {
|
||||
days = 365
|
||||
}
|
||||
return s.repo.GetPowerHistory(userID, days)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user