Merge pull request #486 from s-Joshua-s/feat/usage-filter-by-apikey
feat(gateway): filter /v1/usage stats by API Key instead of UserID
This commit is contained in:
@@ -41,6 +41,7 @@ type UsageLogRepository interface {
|
||||
|
||||
// User dashboard stats
|
||||
GetUserDashboardStats(ctx context.Context, userID int64) (*usagestats.UserDashboardStats, error)
|
||||
GetAPIKeyDashboardStats(ctx context.Context, apiKeyID int64) (*usagestats.UserDashboardStats, error)
|
||||
GetUserUsageTrendByUserID(ctx context.Context, userID int64, startTime, endTime time.Time, granularity string) ([]usagestats.TrendDataPoint, error)
|
||||
GetUserModelStats(ctx context.Context, userID int64, startTime, endTime time.Time) ([]usagestats.ModelStat, error)
|
||||
|
||||
|
||||
@@ -288,6 +288,15 @@ func (s *UsageService) GetUserDashboardStats(ctx context.Context, userID int64)
|
||||
return stats, nil
|
||||
}
|
||||
|
||||
// GetAPIKeyDashboardStats returns dashboard summary stats filtered by API Key.
|
||||
func (s *UsageService) GetAPIKeyDashboardStats(ctx context.Context, apiKeyID int64) (*usagestats.UserDashboardStats, error) {
|
||||
stats, err := s.usageRepo.GetAPIKeyDashboardStats(ctx, apiKeyID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("get api key dashboard stats: %w", err)
|
||||
}
|
||||
return stats, nil
|
||||
}
|
||||
|
||||
// GetUserUsageTrendByUserID returns per-user usage trend.
|
||||
func (s *UsageService) GetUserUsageTrendByUserID(ctx context.Context, userID int64, startTime, endTime time.Time, granularity string) ([]usagestats.TrendDataPoint, error) {
|
||||
trend, err := s.usageRepo.GetUserUsageTrendByUserID(ctx, userID, startTime, endTime, granularity)
|
||||
|
||||
Reference in New Issue
Block a user