-
Notifications
You must be signed in to change notification settings - Fork 0
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
Change /groups/{group id}/users route #115
Conversation
a userId could have multiple roles, if it is present in the usergroups table in multiple rows (with different groupId). however, since we specify the groupId in the /group/{groupId}/users route, it makes sense that we only retrieve users that have that groupId. - in controller, get groupId from context - for each user obtained from the users table, call GetUserRoleByID function from usergroups model - store the roles obtained in an array - pass array to updated ListFrom function from users view, which now include a role attribute in its JSON response
previously, the DeleteUser function was not working as it chained `.Delete(&user)` after `.First(&user)`. this resulted in a query as shown, and its corresponding error: * `ERROR: table name "users" specified more than once (SQLSTATE 42712) [8.059ms] [rows:1] UPDATE "users" SET "deleted_at"='2024-02-12 20:52:41.02' FROM "users" WHERE id = 4 AND "users"."deleted_at" IS NULL AND "users"."id" = 4` the intent of `.First(&user)` was likely to store the user to be deleted first in the `user` variable with the use of a `SELECT` SQL statement. however, chaining another method at the end of a finisher method likely led to some errors (see chaining [here](https://gorm.io/docs/method_chaining.html)). thus, this commit attempts to separate the two statements, preserving the initial intent of storing the user to be deleted before deleting, and then returning this user.
missing validation for parameters, but seemed unnecessary since there is only one route with parameter validation (creating user)
Relevant frontend PR: source-academy/frontend#2763 |
for i, user := range users { | ||
roles[i], err = model.GetUserRoleByID(db, user.ID, *groupId) | ||
if err != nil { | ||
logrus.Error(err) | ||
return err | ||
} | ||
} |
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.
N + 1 query problem
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.
Filed as an issue: #121.
We can just merge first as it's not critical at the moment.
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.
Hi, sorry for the delayed review, LGTM, thanks! Just waiting for the frontend PR to also pass review before merging at the same time.
Editing existing routes and adding routes for stories user and add stories user panels on the frontend
Corresponding frontend PR: source-academy/frontend#2763