Skip to content

Conversation

@zaydaanjahangir
Copy link
Contributor

Description

Added PUT endpoint for guests as the last part of the whole guest entity integration #68

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactoring (code improvement without changing functionality)
  • Documentation update
  • Configuration/infrastructure change
  • Performance improvement
  • Test coverage improvement

Related Issue(s)

Closes #68

What Changed?

  • Adds PUT /api/v1/guests/:id endpoint for guest updates
  • Includes unit tests for the guest update handler

Testing & Validation

How this was tested

  1. Tested locally in Supabase
  2. Unit tests

Screenshots/Recordings

Screenshot 2026-01-25 at 11 52 41 PM Screenshot 2026-01-25 at 11 53 06 PM

Unfinished Work & Known Issues

  • None, this PR is complete and production-ready

Notes & Nuances

  • N/A

Pre-Merge Checklist

Code Quality

  • Code follows the project's style guidelines and conventions
  • Self-review completed (I've reviewed my own code for obvious issues)
  • No debugging code, console logs, or commented-out code left behind
  • No merge conflicts with the base branch
  • Meaningful commit messages that explain the "why"

Testing & CI

  • All CI checks are passing
  • All new and existing tests pass locally
  • Test coverage hasn't decreased (or decrease is justified)
  • Linting passes without errors

Documentation

  • Code is self-documenting or includes helpful comments for complex logic
  • API documentation updated (if backend endpoints changed)
  • Type definitions are accurate and up-to-date

Reviewer Notes

  • Areas needing extra attention: ...
  • Questions for reviewers: ...

@zaydaanjahangir zaydaanjahangir marked this pull request as ready for review January 27, 2026 11:03
Copy link
Contributor

@danctila danctila left a comment

Choose a reason for hiding this comment

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

very solid implementation and testing just requersted one change to think about in the SQL update and one other small thing

Comment on lines +77 to +98
func (r *GuestsRepository) UpdateGuest(ctx context.Context, id string, update *models.UpdateGuest) (*models.Guest, error) {
var guest models.Guest

row := r.db.QueryRow(ctx, `
UPDATE guests
SET
first_name = COALESCE($2, first_name),
last_name = COALESCE($3, last_name),
profile_picture = COALESCE($4, profile_picture),
timezone = COALESCE($5, timezone),
updated_at = NOW()
WHERE id = $1
RETURNING
id, created_at, updated_at,
first_name, last_name, profile_picture, timezone`,
id,
update.FirstName,
update.LastName,
update.ProfilePicture,
update.Timezone,
)

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the COALESCE approach in the UPDATE query might have a flaw bc you can't intentionally set the fields to NULL.

For ex if a client wants to remove their profile picture or timezone they won't be able to do it with this implementation

Might want to just add more to the pattern to distinguish between "not provided" and "set to null/empty/etc." OR document that the endpoint specifically doesn't support clearing optional fields

Comment on lines +168 to +200
func validateUpdateGuest(update *models.UpdateGuest) error {
errors := make(map[string]string)

if update.FirstName != nil && strings.TrimSpace(*update.FirstName) == "" {
errors["first_name"] = "must not be an empty string"
}

if update.LastName != nil && strings.TrimSpace(*update.LastName) == "" {
errors["last_name"] = "must not be an empty string"
}

if update.Timezone != nil {
if _, err := time.LoadLocation(*update.Timezone); err != nil {
errors["timezone"] = "invalid IANA timezone"
}
}

if len(errors) > 0 {
var keys []string
for k := range errors {
keys = append(keys, k)
}
sort.Strings(keys)

var parts []string
for _, k := range keys {
parts = append(parts, k+": "+errors[k])
}
return errs.BadRequest(strings.Join(parts, ", "))
}

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.

this is small but in validateUpdateGuest there is no check for an empty update where all fields are nil so a PUT request with {} would succeed but not do anything except update the timestamp -> so it mightb e good to have some validation that requires at least one field to be updated

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.

feat: integrate guest entity

3 participants