feat: database method to move wish to another list
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
--: }}}
|
||||
|
||||
Reference in New Issue
Block a user