diff --git a/internal/repository/post_repo.go b/internal/repository/post_repo.go index 2cd1bad..cb67888 100644 --- a/internal/repository/post_repo.go +++ b/internal/repository/post_repo.go @@ -254,7 +254,7 @@ func (r *PostRepo) PostCountsByDate(ctx context.Context, userID string, since ti tz = "UTC" } rows, err := r.pg.Pool.Query(ctx, ` - SELECT (created_at AT TIME ZONE $3)::date AS d, count(*) AS n + SELECT (created_at AT TIME ZONE $3::text)::date AS d, count(*) AS n FROM posts WHERE user_id = $1 AND created_at >= $2 GROUP BY d`, diff --git a/internal/service/sadhna_service.go b/internal/service/sadhna_service.go index 2aee9db..abff115 100644 --- a/internal/service/sadhna_service.go +++ b/internal/service/sadhna_service.go @@ -148,11 +148,18 @@ func (s *SadhnaService) Dashboard(ctx context.Context, userID string) (*model.Sa logs, err := s.logs.ListSince(ctx, userID, since) if err != nil { + s.logger.Error("sadhna dashboard: list logs failed", + zap.String("user", userID), zap.Error(err)) return nil, err } + // The quote half is non-critical: if it fails (e.g. an unrecognized + // timezone in the AT TIME ZONE bucketing), log it and degrade to "no + // quotes" rather than 500-ing the whole dashboard. postsByDay, err := s.posts.PostCountsByDate(ctx, userID, since, tz) if err != nil { - return nil, err + s.logger.Error("sadhna dashboard: post counts failed", + zap.String("user", userID), zap.String("tz", tz), zap.Error(err)) + postsByDay = map[string]int{} } // Index the chanting half by day. @@ -398,11 +405,15 @@ func (s *SadhnaService) History(ctx context.Context, userID string, from, to tim tz, _ := s.resolveTZ(ctx, userID) logs, err := s.logs.ListSince(ctx, userID, from) if err != nil { + s.logger.Error("sadhna history: list logs failed", + zap.String("user", userID), zap.Error(err)) return nil, err } postsByDay, err := s.posts.PostCountsByDate(ctx, userID, from, tz) if err != nil { - return nil, err + s.logger.Error("sadhna history: post counts failed", + zap.String("user", userID), zap.String("tz", tz), zap.Error(err)) + postsByDay = map[string]int{} } chantByDay := make(map[string]bool, len(logs))