mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
refactor: Refactor audit logs count to support filtering (#4113)
This commit is contained in:
+14
-2
@@ -103,6 +103,10 @@ type AuditLogResponse struct {
|
||||
AuditLogs []AuditLog `json:"audit_logs"`
|
||||
}
|
||||
|
||||
type AuditLogCountRequest struct {
|
||||
SearchQuery string `json:"q,omitempty"`
|
||||
}
|
||||
|
||||
type AuditLogCountResponse struct {
|
||||
Count int64 `json:"count"`
|
||||
}
|
||||
@@ -142,8 +146,16 @@ func (c *Client) AuditLogs(ctx context.Context, req AuditLogsRequest) (AuditLogR
|
||||
}
|
||||
|
||||
// AuditLogCount returns the count of all audit logs in the product.
|
||||
func (c *Client) AuditLogCount(ctx context.Context) (AuditLogCountResponse, error) {
|
||||
res, err := c.Request(ctx, http.MethodGet, "/api/v2/audit/count", nil)
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user