Skip to content

[API-69] Implement managed users endpoint#69

Merged
schottra merged 7 commits intomainfrom
grants-endpoints-2
May 6, 2025
Merged

[API-69] Implement managed users endpoint#69
schottra merged 7 commits intomainfrom
grants-endpoints-2

Conversation

@schottra
Copy link
Copy Markdown
Contributor

@schottra schottra commented May 5, 2025

Follow on to #65 which implements the managed users endpoint.

The query is very similar but it needs to select the user by id and join grants by their wallet address. And the resulting JSON for each record uses { user, grant } instead of { manager, grant }.

Fun thing: My original queries were missing parens around the OR clause at the end and that duped me into thinking things were really broken...

I also learned that if you put the IS NULL check first on a sqlc.narg() param, it won't generate the correct type (will give you an interface {} instead of a nullable boolean). But if it's last, things work correctly 🤷

Copy link
Copy Markdown
Member

@raymondjacobson raymondjacobson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not blocking, but code could be a little tighter I think

Comment thread api/dbv1/queries/get_grants.sql Outdated
Comment thread api/v1_users_managed_users.go Outdated
Comment thread api/v1_users_managed_users_test.go
@schottra schottra merged commit a736ae3 into main May 6, 2025
2 checks passed
@schottra schottra deleted the grants-endpoints-2 branch May 6, 2025 14:31
Comment thread api/request_helpers.go
value = &parsed
}
return pgtype.Bool{Bool: value != nil && *value, Valid: value != nil}, nil
}
Copy link
Copy Markdown
Contributor

@stereosteve stereosteve May 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be written more simple like:

func getOptionalBool(c *fiber.Ctx, key string) (pgtype.Bool, error) {
	if valueStr := c.Query(key); valueStr != "" {
		parsed, err := strconv.ParseBool(c.Query(key))
		if err != nil {
			return pgtype.Bool{}, err
		}
		return pgtype.Bool{Bool: parsed, Valid: true}, nil
	}
	return pgtype.Bool{}, nil
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants