-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui): first shitty content-type graph
- Loading branch information
1 parent
7f2cf63
commit 2f1f647
Showing
17 changed files
with
628 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package analytics | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/bacalhau-project/amplify/pkg/db" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
var ( | ||
ErrAnalyticsErr = fmt.Errorf("analytics error") | ||
ErrInvalidPageSize = errors.Wrap(ErrAnalyticsErr, "invalid page size") | ||
ErrInvalidKey = errors.Wrap(ErrAnalyticsErr, "invalid key") | ||
) | ||
|
||
type analyticsRepository struct { | ||
database db.Analytics | ||
} | ||
type AnalyticsRepository interface { | ||
QueryTopResultsByKey(ctx context.Context, params QueryTopResultsByKeyParams) (map[string]interface{}, error) | ||
} | ||
|
||
func NewAnalyticsRepository(d db.Analytics) AnalyticsRepository { | ||
return &analyticsRepository{ | ||
database: d, | ||
} | ||
} | ||
|
||
type QueryTopResultsByKeyParams struct { | ||
Key string | ||
PageSize int | ||
} | ||
|
||
func (r *analyticsRepository) QueryTopResultsByKey(ctx context.Context, params QueryTopResultsByKeyParams) (map[string]interface{}, error) { | ||
if params.PageSize <= 0 { | ||
return nil, ErrInvalidPageSize | ||
} | ||
if params.Key == "" { | ||
return nil, ErrInvalidKey | ||
} | ||
rows, err := r.database.QueryTopResultsByKey(ctx, db.QueryTopResultsByKeyParams{ | ||
Key: params.Key, | ||
PageSize: int32(params.PageSize), | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
results := make(map[string]interface{}, params.PageSize) | ||
for _, row := range rows { | ||
results[row.Value] = row.Count | ||
} | ||
return results, nil | ||
} |
Oops, something went wrong.