Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

Added endpoint to patch attendee registration #407

Open
wants to merge 5 commits into
base: staging
Choose a base branch
from

Conversation

kgukevin
Copy link

@kgukevin kgukevin commented Sep 7, 2021

Implements patch endpoint for attendee registration. Adds parameter to validate to allow override of form field requirements. Removes default value population from model conversions.

@kgukevin kgukevin changed the title Feat/patch registration attendee Adds patch registration attendee Sep 7, 2021
@kgukevin kgukevin changed the title Adds patch registration attendee Added patch registration attendee Sep 7, 2021
@kgukevin kgukevin changed the title Added patch registration attendee Added attendee registration patching Sep 7, 2021
@kgukevin kgukevin changed the title Added attendee registration patching Added endpoint to patch attendee registration Sep 7, 2021
Copy link
Contributor

@heesooy heesooy left a comment

Choose a reason for hiding this comment

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

Good start! I think we might need to change our strategy here a bit, so gonna nack it but let me know if you disagree/have a different approach. Sorry for the back and forth.

Some general tips regarding PRs:

  1. I noticed your second commit 0cc6c76 has the same commit message as the first commit. I would either squash all the commits into one commit or make sure that your second commit has a different, useful message
  2. No need to change the PR titles to make it perfect. As you can see every edit leaves an edit history in the PR and it makes the PR a little messy, and as long as the title makes general sense it's fine
  3. If the PR addresses/fixes an issue then you can reference that issue number from anywhere in this PR, whether it's the original PR message or any comments. For example, this PR is related to Add endpoint to patch user registration #234

Comment on lines 10 to 12
if len(params) == 1{
return nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you explain what this change does?

Edit: ah I see you made this flag to skip the validation. I think we can avoid having to do this since we might need to change our strategy for this PR. See my other comment below

}
// else {
// data[field.Name] = getDefaultValue(field.Type) //removed for registration/attendee patch function
// }
Copy link
Contributor

@heesooy heesooy Sep 7, 2021

Choose a reason for hiding this comment

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

Hm. Now that I think about it, I think we actually don't want to do this. Users currently expect the API to always return all fields, even if their value is empty/default. 1. We wouldn't want to introduce a change to this behavior without thinking about its implications on the user and 2. I think it is better to have an API that returns a consistent format.

So as for how to get around this issue: we can try to manually strip off fields from the user_registration when we pass it into the database patch function

Comment on lines 289 to 298
original_registration, err := service.GetUserRegistration(id)

if err != nil {
errors.WriteError(w, r, errors.DatabaseError(err.Error(), "Could not get user's original registration."))
return
}

user_registration.Data["github"] = user_info.Username

user_registration.Data["createdAt"] = original_registration.Data["createdAt"]
Copy link
Contributor

Choose a reason for hiding this comment

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

We shouldn't need to re-insert the "github" or "createdAt" fields. We only need to change the "updatedAt" field + the fields the user provided in the request.

@kgukevin
Copy link
Author

kgukevin commented Sep 9, 2021

Per offline discussion with @heesooy, the current strategy for the patch endpoint implementation was to use the raw request body as a map and compare it to the registration definition to prune unwanted excess fields before patching it to the database. This prevents default value population in the patch datastore to combat "erasing" unpopulated fields after patching while preserving the functionality for better consistency. ValidateNonEmpty was also created to accommodate for validating a patch (which is a subset of fields in the registration definition). Other strategies were discussed to combat default values (such as getting original registration from the database and updating it with the new data before patching back to the database) but the implemented strategy was preferred for database operation atomicity.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants