Skip to content

Commit

Permalink
Merge pull request #74 from KnightHacks/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
LockedThread committed Jan 4, 2023
2 parents feb7d35 + a332728 commit 578abb5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
5 changes: 1 addition & 4 deletions integration_tests/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,7 @@ create table users
phone_number varchar,
last_name varchar not null,
age integer,
pronoun_id integer
constraint users_pronouns_id_fk
references pronouns
deferrable initially deferred,
pronoun_id integer,
first_name varchar not null,
role varchar not null,
oauth_uid varchar not null
Expand Down
16 changes: 9 additions & 7 deletions repository/database/create_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import (
// lot of pointers for nil safety purposes
func (r *DatabaseRepository) CreateUser(ctx context.Context, oAuth *model.OAuth, input *model.NewUser) (*model.User, error) {
var userId string
var pronouns model.Pronouns
var pronouns *model.Pronouns = nil
if input.Pronouns != nil {
// input.Pronouns is a PronounsInput struct which a direct copy of the Pronouns struct, so we need to copy its fields
pronouns = model.Pronouns{
pronouns = &model.Pronouns{
Subjective: input.Pronouns.Subjective,
Objective: input.Pronouns.Objective,
}
Expand All @@ -33,7 +33,7 @@ func (r *DatabaseRepository) CreateUser(ctx context.Context, oAuth *model.OAuth,
LastName: input.LastName,
Email: input.Email,
PhoneNumber: input.PhoneNumber,
Pronouns: &pronouns,
Pronouns: pronouns,
Age: input.Age,
Role: sharedModels.RoleNormal,
OAuth: oAuth,
Expand All @@ -57,11 +57,13 @@ func (r *DatabaseRepository) CreateUser(ctx context.Context, oAuth *model.OAuth,
}

// Get pronouns
pronounIdPtr, err := r.GetOrCreatePronoun(ctx, tx, pronouns, input)
if err != nil {
return err
var pronounIdPtr *int
if pronouns != nil {
pronounIdPtr, err = r.GetOrCreatePronoun(ctx, tx, *pronouns, input)
if err != nil {
return err
}
}

// Insert new user into database
userIdInt, err := r.InsertUser(ctx, tx, input, pronounIdPtr, oAuth)
if err != nil {
Expand Down

0 comments on commit 578abb5

Please sign in to comment.