feat: extend equipment and workout models with service tracking
This commit is contained in:
@@ -71,6 +71,12 @@ func (s *Service) UpdateEquipment(id, userID uint, updates map[string]interface{
|
||||
if active, ok := updates["active"].(bool); ok {
|
||||
equipment.Active = active
|
||||
}
|
||||
if v, ok := updates["service_interval_distance"].(float64); ok {
|
||||
equipment.ServiceIntervalDistance = v
|
||||
}
|
||||
if v, ok := updates["service_interval_duration"].(float64); ok {
|
||||
equipment.ServiceIntervalDuration = int(v)
|
||||
}
|
||||
|
||||
if err := s.repo.UpdateEquipment(equipment); err != nil {
|
||||
return nil, err
|
||||
@@ -83,6 +89,29 @@ func (s *Service) DeleteEquipment(id, userID uint) error {
|
||||
return s.repo.DeleteEquipment(id, userID)
|
||||
}
|
||||
|
||||
// IncrementMileage adds distance (km) and duration (seconds) to equipment totals.
|
||||
func (s *Service) IncrementMileage(equipmentID, userID uint, distance float64, duration int) error {
|
||||
return s.repo.IncrementMileage(equipmentID, userID, distance, duration)
|
||||
}
|
||||
|
||||
// RecordService resets the service counters and records the service date.
|
||||
func (s *Service) RecordService(equipmentID, userID uint) (*Equipment, error) {
|
||||
if err := s.repo.ResetServiceCounters(equipmentID, userID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return s.repo.GetEquipmentByID(equipmentID, userID)
|
||||
}
|
||||
|
||||
// GetServiceStatus returns the service status for a piece of equipment.
|
||||
func (s *Service) GetServiceStatus(equipmentID, userID uint) (*ServiceStatus, error) {
|
||||
eq, err := s.repo.GetEquipmentByID(equipmentID, userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
status := eq.GetServiceStatus()
|
||||
return &status, nil
|
||||
}
|
||||
|
||||
// Training Zones calculation
|
||||
func (s *Service) CalculateHRZones(maxHR, restingHR int) *HRZones {
|
||||
if maxHR <= 0 {
|
||||
|
||||
Reference in New Issue
Block a user