diff --git a/backend/internal/database/query.sql.go b/backend/internal/database/query.sql.go index 45c75a3..f5dabea 100644 --- a/backend/internal/database/query.sql.go +++ b/backend/internal/database/query.sql.go @@ -1013,6 +1013,34 @@ func (q *Queries) GetWishlistsByUsernameWithPrivacy(ctx context.Context, arg Get return items, nil } +const moveWishToWishListWithGuid = `-- name: MoveWishToWishListWithGuid :one +WITH updated AS ( + UPDATE wishes w + SET + wish_list_id = wl.id, + wish_list_guid = ($1::text)::uuid + FROM wish_lists wl + WHERE + wl.guid = ($1::text)::uuid AND + wl.profile_id = ( -- Make sure the wish is not moved to another profile + SELECT profile_id + FROM wish_lists + WHERE wish_lists.id = w.wish_list_id + ) + RETURNING w.id +) +SELECT + COUNT(*) > 0 AS target_found +FROM updated +` + +func (q *Queries) MoveWishToWishListWithGuid(ctx context.Context, wishListGuid string) (bool, error) { + row := q.db.QueryRow(ctx, moveWishToWishListWithGuid, wishListGuid) + var target_found bool + err := row.Scan(&target_found) + return target_found, err +} + const pruneExpiredConfirmationCodes = `-- name: PruneExpiredConfirmationCodes :exec DELETE FROM confirmation_codes WHERE expires_at < CURRENT_TIMESTAMP diff --git a/sqlc/query.sql b/sqlc/query.sql index a312f5a..88e3a25 100644 --- a/sqlc/query.sql +++ b/sqlc/query.sql @@ -435,4 +435,23 @@ SET deleted = COALESCE(@deleted::boolean, w.deleted) WHERE w.guid = (@guid::text)::uuid; +;-- name: MoveWishToWishListWithGuid :one +WITH updated AS ( + UPDATE wishes w + SET + wish_list_id = wl.id, + wish_list_guid = (@wish_list_guid::text)::uuid + FROM wish_lists wl + WHERE + wl.guid = (@wish_list_guid::text)::uuid AND + wl.profile_id = ( -- Make sure the wish is not moved to another profile + SELECT profile_id + FROM wish_lists + WHERE wish_lists.id = w.wish_list_id + ) + RETURNING w.id +) +SELECT + COUNT(*) > 0 AS target_found +FROM updated; --: }}}