-
Notifications
You must be signed in to change notification settings - Fork 1
[API-69] Add user managers endpoint #65
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| package dbv1 | ||
|
|
||
| import ( | ||
| "context" | ||
| ) | ||
|
|
||
| type FullGrant struct { | ||
| GetGrantsForUserIdRow | ||
| GranteeUserID *struct{} `json:"grantee_user_id,omitempty"` | ||
| } | ||
|
|
||
| type FullManager struct { | ||
| Manager FullUser `json:"manager"` | ||
| Grant FullGrant `json:"grant"` | ||
| } | ||
|
|
||
| func (q *Queries) FullManagers(ctx context.Context, params GetGrantsForUserIdParams) ([]FullManager, error) { | ||
|
|
||
| grants, err := q.GetGrantsForUserId(ctx, params) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| user_ids := make([]int32, len(grants)) | ||
| for i, grant := range grants { | ||
| user_ids[i] = int32(grant.GranteeUserID) | ||
| } | ||
|
|
||
| users, err := q.FullUsersKeyed(ctx, GetUsersParams{ | ||
| Ids: user_ids, | ||
| MyID: params.UserID, | ||
| }) | ||
|
|
||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| managers := make([]FullManager, len(grants)) | ||
| for i, grant := range grants { | ||
| managers[i] = FullManager{ | ||
| Manager: users[int32(grant.GranteeUserID)], | ||
| Grant: FullGrant{GetGrantsForUserIdRow: grant}, | ||
| } | ||
| } | ||
|
|
||
| return managers, nil | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| -- name: GetGrantsForUserId :many | ||
| SELECT | ||
| g.user_id, | ||
| g.grantee_address, | ||
| g.is_revoked, | ||
| g.is_approved, | ||
| g.created_at, | ||
| g.updated_at, | ||
| u.user_id as grantee_user_id | ||
| FROM grants g | ||
| JOIN users u ON u.wallet = g.grantee_address | ||
| WHERE g.user_id = @user_id::int | ||
| AND g.is_revoked = @is_revoked | ||
| AND g.is_current = true | ||
| AND sqlc.narg('is_approved')::boolean IS NULL OR g.is_approved = sqlc.narg('is_approved') | ||
| ORDER BY g.created_at DESC; | ||
|
|
||
| -- name: GetGrantsForGranteeAddress :many | ||
| SELECT | ||
| g.user_id, | ||
| g.grantee_address, | ||
| g.is_revoked, | ||
| g.is_approved, | ||
| g.created_at, | ||
| g.updated_at, | ||
| u.user_id as grantee_user_id | ||
| FROM grants g | ||
| JOIN users u ON u.wallet = g.grantee_address | ||
| WHERE g.grantee_address = @grantee_address | ||
| AND g.is_current = true | ||
| AND g.is_revoked = @is_revoked | ||
| AND sqlc.narg('is_approved')::boolean IS NULL OR g.is_approved = sqlc.narg('is_approved') | ||
| ORDER BY g.created_at DESC; | ||
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.
Does this work? If you're casting to a boolean will it ever be null?
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'm also confused by it, but it does appear to work (verified by tests)