Add lightweight summary endpoint for task statistics
- Add GET /api/residences/summary/ endpoint - Returns task statistics without full residence data - Enables efficient refresh of home screen summary counts 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -120,6 +120,40 @@ func (s *ResidenceService) GetMyResidences(userID uint) (*responses.MyResidences
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GetSummary returns just the task summary statistics for a user's residences
|
||||
// This is a lightweight endpoint for refreshing summary counts without full residence data
|
||||
func (s *ResidenceService) GetSummary(userID uint) (*responses.TotalSummary, error) {
|
||||
residences, err := s.residenceRepo.FindByUser(userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
summary := &responses.TotalSummary{
|
||||
TotalResidences: len(residences),
|
||||
}
|
||||
|
||||
// Get task statistics if task repository is available
|
||||
if s.taskRepo != nil && len(residences) > 0 {
|
||||
// Collect residence IDs
|
||||
residenceIDs := make([]uint, len(residences))
|
||||
for i, r := range residences {
|
||||
residenceIDs[i] = r.ID
|
||||
}
|
||||
|
||||
// Get aggregated statistics
|
||||
stats, err := s.taskRepo.GetTaskStatistics(residenceIDs)
|
||||
if err == nil && stats != nil {
|
||||
summary.TotalTasks = stats.TotalTasks
|
||||
summary.TotalPending = stats.TotalPending
|
||||
summary.TotalOverdue = stats.TotalOverdue
|
||||
summary.TasksDueNextWeek = stats.TasksDueNextWeek
|
||||
summary.TasksDueNextMonth = stats.TasksDueNextMonth
|
||||
}
|
||||
}
|
||||
|
||||
return summary, nil
|
||||
}
|
||||
|
||||
// CreateResidence creates a new residence
|
||||
func (s *ResidenceService) CreateResidence(req *requests.CreateResidenceRequest, ownerID uint) (*responses.ResidenceResponse, error) {
|
||||
// TODO: Check subscription tier limits
|
||||
|
||||
Reference in New Issue
Block a user