chore: refactor audit page to use window function for count (#5133)

* Move count query to window function

* Unpack count and update types

* Remove count endpoint

* Update tests, wip

* Fix tests

* Update frontend, wip

* Remove space

* Fix frontend test

* Don't hang on error

* Handle no results

* Don't omit count

* Fix frontend tests
This commit is contained in:
Presley Pizzo
2022-11-21 11:30:41 -05:00
committed by GitHub
parent 7a369e0a30
commit 67941b4f80
15 changed files with 54 additions and 347 deletions
+1 -37
View File
@@ -113,14 +113,7 @@ type AuditLogsRequest struct {
type AuditLogResponse struct {
AuditLogs []AuditLog `json:"audit_logs"`
}
type AuditLogCountRequest struct {
SearchQuery string `json:"q,omitempty"`
}
type AuditLogCountResponse struct {
Count int64 `json:"count"`
Count int64 `json:"count"`
}
type CreateTestAuditLogRequest struct {
@@ -159,35 +152,6 @@ func (c *Client) AuditLogs(ctx context.Context, req AuditLogsRequest) (AuditLogR
return logRes, nil
}
// AuditLogCount returns the count of all audit logs in the product.
func (c *Client) AuditLogCount(ctx context.Context, req AuditLogCountRequest) (AuditLogCountResponse, error) {
res, err := c.Request(ctx, http.MethodGet, "/api/v2/audit/count", nil, func(r *http.Request) {
q := r.URL.Query()
var params []string
if req.SearchQuery != "" {
params = append(params, req.SearchQuery)
}
q.Set("q", strings.Join(params, " "))
r.URL.RawQuery = q.Encode()
})
if err != nil {
return AuditLogCountResponse{}, err
}
defer res.Body.Close()
if res.StatusCode != http.StatusOK {
return AuditLogCountResponse{}, readBodyAsError(res)
}
var logRes AuditLogCountResponse
err = json.NewDecoder(res.Body).Decode(&logRes)
if err != nil {
return AuditLogCountResponse{}, err
}
return logRes, nil
}
func (c *Client) CreateTestAuditLog(ctx context.Context, req CreateTestAuditLogRequest) error {
res, err := c.Request(ctx, http.MethodPost, "/api/v2/audit/testgenerate", req)
if err != nil {