| 57 | } |
| 58 | |
| 59 | func (s *Store) GetUsageSummary(ctx context.Context, userID, bucketDate string) (*UsageSummary, error) { |
| 60 | sum := &UsageSummary{} |
| 61 | var bucketTime time.Time |
| 62 | err := s.pool.QueryRow(ctx, |
| 63 | `SELECT user_id, bucket_date, inbound_count, outbound_count, total_count |
| 64 | FROM usage_summaries WHERE user_id = $1 AND bucket_date = $2`, userID, bucketDate, |
| 65 | ).Scan(&sum.UserID, &bucketTime, &sum.InboundCount, &sum.OutboundCount, &sum.TotalCount) |
| 66 | if err != nil { |
| 67 | return nil, err |
| 68 | } |
| 69 | sum.BucketDate = bucketTime.Format("2006-01-02") |
| 70 | return sum, nil |
| 71 | } |
| 72 | |
| 73 | func (s *Store) IncrementUsageSummary(ctx context.Context, userID, bucketDate, direction string) error { |
| 74 | inbound, outbound := 0, 0 |