mirror of
https://ids-dev.idsbuybuybuy.com/ids-ecommerce/ids-svc-product.git
synced 2026-11-29 16:57:41 +08:00
feat: update batch delete logic to use product ID placeholders
This commit is contained in:
parent
6074355b39
commit
7ce922d440
@ -242,12 +242,13 @@ WHERE store_id = $1
|
||||
return ErrProductNotFound
|
||||
}
|
||||
|
||||
skuPH, skuArgs := productIDPlaceholders(parsed, 1)
|
||||
if _, err := tx.ExecContext(ctx, fmt.Sprintf(`
|
||||
UPDATE product.product_items
|
||||
SET deleted_at = COALESCE(deleted_at, NOW()), updated_at = NOW()
|
||||
WHERE deleted_at IS NULL
|
||||
AND product_id IN (%s)
|
||||
`, ph), args...); err != nil {
|
||||
`, skuPH), skuArgs...); err != nil {
|
||||
return fmt.Errorf("batch delete product skus: %w", err)
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,9 @@
|
||||
package repository
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestParseBatchProductIDs(t *testing.T) {
|
||||
parsed, unique, err := parseBatchProductIDs([]string{" 11111 ", "11111", "22222"})
|
||||
@ -18,3 +21,20 @@ func TestParseBatchProductIDs(t *testing.T) {
|
||||
t.Fatal("parseBatchProductIDs(nil) error = nil, want required")
|
||||
}
|
||||
}
|
||||
|
||||
func TestProductIDPlaceholders(t *testing.T) {
|
||||
ids := []int64{11111, 22222}
|
||||
|
||||
gotPlaceholders, gotArgs := productIDPlaceholders(ids, 1)
|
||||
if gotPlaceholders != "$1, $2" {
|
||||
t.Fatalf("placeholders starting at 1 = %q, want %q", gotPlaceholders, "$1, $2")
|
||||
}
|
||||
if !reflect.DeepEqual(gotArgs, []any{int64(11111), int64(22222)}) {
|
||||
t.Fatalf("args = %v, want [11111 22222]", gotArgs)
|
||||
}
|
||||
|
||||
gotPlaceholders, _ = productIDPlaceholders(ids, 2)
|
||||
if gotPlaceholders != "$2, $3" {
|
||||
t.Fatalf("placeholders starting at 2 = %q, want %q", gotPlaceholders, "$2, $3")
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user