-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add owner/name filter to list clients #2637
Changes from 3 commits
ffb8604
2252759
66699f0
a4492df
3953547
7c86062
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,13 +76,21 @@ func (p *Persister) DeleteClient(ctx context.Context, id string) error { | |
return sqlcon.HandleError(p.Connection(ctx).Destroy(&client.Client{ID: cl.ID})) | ||
} | ||
|
||
func (p *Persister) GetClients(ctx context.Context, limit, offset int) ([]client.Client, error) { | ||
func (p *Persister) GetClients(ctx context.Context, filters client.ClientFilters) ([]client.Client, error) { | ||
cs := make([]client.Client, 0) | ||
return cs, sqlcon.HandleError( | ||
p.Connection(ctx). | ||
Paginate(offset/limit+1, limit). | ||
Order("id"). | ||
All(&cs)) | ||
|
||
query := p.Connection(ctx). | ||
Paginate(filters.Offset/filters.Limit+1, filters.Limit). | ||
Order("id") | ||
|
||
if filters.Name != "" { | ||
query.Where("client_name = ?", filters.Name) | ||
} | ||
if filters.Owner != "" { | ||
query.Where("owner = ?", filters.Owner) | ||
} | ||
Comment on lines
+86
to
+91
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This probably means that we need to index these fields? Otherwise this will get very slow when you have lots of clients. Then again, if we just have like 1000 clients, it probably wouldn't matter too much (maybe 5ms with index, 200ms without). What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For our use case, the index won't make much of a difference There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, we can keep the filter omitted for now and add it later. |
||
|
||
return cs, sqlcon.HandleError(query.All(&cs)) | ||
} | ||
|
||
func (p *Persister) CountClients(ctx context.Context) (int, error) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be added to the swagger spec:
hydra/client/doc.go
Line 90 in b597c88
You can also probably re-use / re-purpose that struct as
ClientFilter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the name/owner params to that struct, is that all that needs done?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's all that's needed - I think this can be removed then!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ClientFilters struct is used internally to get passed to the client manager, so new filers could be easily added...