mock shop page allows updating of listings
This commit is contained in:
@@ -309,7 +309,7 @@ func (db *Store) CreateMockListing(ctx context.Context, listing MockListing) (Mo
|
||||
"sku": listing.SKU,
|
||||
"name": listing.Name,
|
||||
"description": listing.Description,
|
||||
"count": listing.Count + 5,
|
||||
"count": listing.Count,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
@@ -322,6 +322,49 @@ func (db *Store) CreateMockListing(ctx context.Context, listing MockListing) (Mo
|
||||
return listing, nil
|
||||
}
|
||||
|
||||
// UpdateMockListing updates a mock listing, but not it's count
|
||||
func (db *Store) UpdateMockListing(ctx context.Context, listing MockListing) error {
|
||||
_, listingTableName, err := getMockShopAndListingsTableNames(listing.Platform)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
tag, err := db.db.Exec(
|
||||
ctx,
|
||||
fmt.Sprintf(
|
||||
`
|
||||
UPDATE
|
||||
%s
|
||||
SET
|
||||
sku = @sku,
|
||||
name = @name,
|
||||
description = @description
|
||||
WHERE
|
||||
account_id = @account_id
|
||||
AND shop_id = @shop_id
|
||||
AND listing_id = @listing_id
|
||||
`,
|
||||
listingTableName,
|
||||
),
|
||||
pgx.NamedArgs{
|
||||
"account_id": listing.AccountID,
|
||||
"shop_id": listing.ShopID,
|
||||
"listing_id": listing.ListingID,
|
||||
"sku": listing.SKU,
|
||||
"name": listing.Name,
|
||||
"description": listing.Description,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to perform query: %w", err)
|
||||
}
|
||||
if tag.RowsAffected() == 0 {
|
||||
return fmt.Errorf("%w: listing not found", consts.ErrNotFound)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (db *Store) ListMockListingsForShop(ctx context.Context, acctID int64, platform Platform, shopID string) ([]MockListing, error) {
|
||||
shopTableName, listingsTableName, err := getMockShopAndListingsTableNames(platform)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user