Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/dbv1/db.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions api/dbv1/full_managers.go
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
}
2 changes: 1 addition & 1 deletion api/dbv1/get_account_playlists.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/dbv1/get_connected_wallets.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions api/dbv1/get_developer_apps.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/dbv1/get_extended_account_fields.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

138 changes: 138 additions & 0 deletions api/dbv1/get_grants.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/dbv1/get_playlist_ids_by_permalink.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/dbv1/get_playlists.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/dbv1/get_track_ids_by_permalink.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/dbv1/get_tracks.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/dbv1/get_undisbursed_challenges.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/dbv1/get_user_for_handle.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/dbv1/get_user_for_wallet.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/dbv1/get_users.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions api/dbv1/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions api/dbv1/queries/get_grants.sql
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')
Copy link
Copy Markdown
Contributor

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?

Copy link
Copy Markdown
Contributor Author

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)

ORDER BY g.created_at DESC;
1 change: 1 addition & 0 deletions api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ func NewApiServer(config config.Config) *ApiServer {
g.Get("/users/:userId/following", app.v1UsersFollowing)
g.Get("/users/:userId/library/tracks", app.v1UsersLibraryTracks)
g.Get("/users/:userId/library/:playlistType", app.v1UsersLibraryPlaylists)
g.Get("/users/:userId/managers", app.v1UsersManagers)
g.Get("/users/:userId/mutuals", app.v1UsersMutuals)
g.Get("/users/:userId/reposts", app.v1UsersReposts)
g.Get("/users/:userId/related", app.v1UsersRelated)
Expand Down
Loading
Loading