Include TotalSummary in CRUD responses to eliminate redundant API calls

Backend changes:
- Add WithSummaryResponse wrappers for Task, TaskCompletion, and Residence CRUD
- Update services to return summary with all mutations (create, update, delete)
- Update handlers to pass through new response types
- Add getSummaryForUser helper for fetching summary in CRUD operations
- Wire ResidenceService into TaskService for summary access
- Add summary field to JoinResidenceResponse

This optimization eliminates the need for a separate getSummary() call after
every task/residence mutation, reducing network calls from 2 to 1.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Trey t
2025-12-08 10:39:33 -06:00
parent f88409cfb4
commit 1a48fbfb20
9 changed files with 351 additions and 134 deletions

View File

@@ -69,6 +69,18 @@ type MyResidencesResponse struct {
Summary TotalSummary `json:"summary"`
}
// ResidenceWithSummaryResponse wraps ResidenceResponse with TotalSummary for CRUD operations
type ResidenceWithSummaryResponse struct {
Data ResidenceResponse `json:"data"`
Summary TotalSummary `json:"summary"`
}
// ResidenceDeleteWithSummaryResponse for delete operations
type ResidenceDeleteWithSummaryResponse struct {
Data string `json:"data"`
Summary TotalSummary `json:"summary"`
}
// ShareCodeResponse represents a share code in the API response
type ShareCodeResponse struct {
ID uint `json:"id"`
@@ -84,6 +96,7 @@ type ShareCodeResponse struct {
type JoinResidenceResponse struct {
Message string `json:"message"`
Residence ResidenceResponse `json:"residence"`
Summary TotalSummary `json:"summary"`
}
// GenerateShareCodeResponse represents the response after generating a share code

View File

@@ -371,3 +371,24 @@ func NewTaskCompletionWithTaskResponse(c *models.TaskCompletion, task *models.Ta
func DetermineKanbanColumn(task *models.Task, daysThreshold int) string {
return categorization.DetermineKanbanColumn(task, daysThreshold)
}
// === Response Wrappers with Summary ===
// These wrap CRUD responses with TotalSummary to eliminate extra API calls
// TaskWithSummaryResponse wraps TaskResponse with TotalSummary
type TaskWithSummaryResponse struct {
Data TaskResponse `json:"data"`
Summary TotalSummary `json:"summary"`
}
// TaskCompletionWithSummaryResponse wraps TaskCompletionResponse with TotalSummary
type TaskCompletionWithSummaryResponse struct {
Data TaskCompletionResponse `json:"data"`
Summary TotalSummary `json:"summary"`
}
// DeleteWithSummaryResponse for delete operations
type DeleteWithSummaryResponse struct {
Data string `json:"data"`
Summary TotalSummary `json:"summary"`
}