Skip to content

Commit

Permalink
Merge pull request #72 from go-park-mail-ru/task/sharing
Browse files Browse the repository at this point in the history
Task/sharing
  • Loading branch information
mevain authored Dec 20, 2024
2 parents 90ae75c + a88ddf0 commit cfbb07e
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion internal/pkg/trips/repo/trips_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,9 +417,18 @@ func (r *TripRepository) GetTripBySharingToken(ctx context.Context, token string
}

func (r *TripRepository) AddUserToTrip(ctx context.Context, tripId, userId uint) (bool, error) {
findOwnerQuery := `SELECT user_id FROM trip WHERE id = $1`
var ownerID int
err := r.db.QueryRowContext(ctx, findOwnerQuery, tripId).Scan(&ownerID)
if err != nil {
return false, fmt.Errorf("failed to find trip owner: %w", err)
}
if ownerID == int(userId) {
return false, nil
}
findOptionQuery := `SELECT sharing_option FROM sharing_token WHERE trip_id = $1`
var sharingOption string
err := r.db.QueryRowContext(ctx, findOptionQuery, tripId).Scan(&sharingOption)
err = r.db.QueryRowContext(ctx, findOptionQuery, tripId).Scan(&sharingOption)
if err != nil {
return false, fmt.Errorf("failed to find sharing option: %w", err)
}
Expand Down

0 comments on commit cfbb07e

Please sign in to comment.