Skip to content
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

Add a partial update User endpoint #108

Merged
merged 5 commits into from
Mar 4, 2025
Merged

Add a partial update User endpoint #108

merged 5 commits into from
Mar 4, 2025

Conversation

calebbourg
Copy link
Collaborator

Description

This PR introduces a pattern for providing partial updates to database tables via our API.
By partial updates I mean that we are able to modify a subset of columns for any given table without having to provide values for the the other columns. The pattern is somewhat based on the pattern for filtering queries as introduced in #102

Note: This new endpoint assumes that the user being updated will always be the current user (as noted inline in comments). At some point we will likely want a user to be able to make updates to another user. We can decide how the code diverges at that point when we know more about how we want that to work.

Changes

  • Adds generic update function
  • Updates user updating to use new function
  • Adds PUT /users update endpoint
  • Fixes a small issue with the Rapidoc for login

Testing Strategy

I was able to test partially updating a user in Rapidoc

Screenshot 2025-03-04 at 1 18 55 PM

Coming Up

  • Adding New Users
  • Updating Coaching Sessions
  • Stricter validations

@calebbourg calebbourg self-assigned this Mar 4, 2025
@calebbourg calebbourg added the enhancement Improves existing functionality or feature label Mar 4, 2025
@calebbourg calebbourg added this to the 1.0-beta1 milestone Mar 4, 2025
@calebbourg calebbourg requested review from jhodapp and zgavin1 March 4, 2025 18:36
Copy link
Member

@jhodapp jhodapp left a comment

Choose a reason for hiding this comment

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

@calebbourg Looks really great, I like the new UpdateMap pattern and IntoUpdateMap trait a lot.

One question I'm curious for your thoughts on inline.

) -> Result<users::Model, Error> {
let existing_user = find_by_id(db, user_id).await?;
let active_model = existing_user.into_active_model();
Ok(mutate::update::<users::ActiveModel, users::Column>(
Copy link
Member

Choose a reason for hiding this comment

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

Nice, we're consistent in our verbiage of mutate in both the backend here and the frontend with my recent API refactoring work. And they hold very similar meanings. This is a very good thing.

pub github_profile_url: Option<String>,
}

impl IntoUpdateMap for UpdateUserParams {
Copy link
Member

Choose a reason for hiding this comment

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

I love this pattern for updating just the right fields - it's extremely clean, easy to understand and effective.

@jhodapp jhodapp changed the title Update User Endpoint Add a partial update User endpoint Mar 4, 2025
@calebbourg calebbourg merged commit 48746c5 into main Mar 4, 2025
4 checks passed
@calebbourg calebbourg deleted the update_user_endpoint branch March 4, 2025 19:36
@github-project-automation github-project-automation bot moved this from Review to ✅ Done in Refactor Coaching Platform Mar 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improves existing functionality or feature
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

2 participants