ability to delete mock sync groups
This commit is contained in:
@@ -410,6 +410,96 @@ func (db *Store) GetMockListingsForShop(ctx context.Context, acctID int64, platf
|
||||
return listings, nil
|
||||
}
|
||||
|
||||
func (db *Store) GetMockListing(ctx context.Context, acctID int64, platform Platform, shopID, listingID string) (*Listing, error) {
|
||||
in, ok := getMockShopSchemaInfo(platform)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("%w: unrecognized platform: %s", consts.ErrNotFound, platform)
|
||||
}
|
||||
|
||||
rows, err := db.db.Query(
|
||||
ctx,
|
||||
fmt.Sprintf(
|
||||
`
|
||||
SELECT
|
||||
name,
|
||||
count,
|
||||
sku,
|
||||
description
|
||||
FROM
|
||||
%s
|
||||
WHERE
|
||||
account_id = @account_id
|
||||
AND shop_id = @shop_id
|
||||
AND listing_id = @listing_id
|
||||
`,
|
||||
in.listingsTable,
|
||||
),
|
||||
pgx.NamedArgs{
|
||||
"account_id": acctID,
|
||||
"shop_id": shopID,
|
||||
"listing_id": listingID,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to perform query: %w", err)
|
||||
}
|
||||
|
||||
v, err := pgx.CollectExactlyOneRow(rows, pgx.RowToStructByNameLax[struct {
|
||||
Name string
|
||||
Count int64
|
||||
Sku string
|
||||
Description string
|
||||
}])
|
||||
if err != nil {
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return nil, consts.ErrNotFound
|
||||
}
|
||||
return nil, fmt.Errorf("failed to scan row: %w", err)
|
||||
}
|
||||
|
||||
return &Listing{
|
||||
AccountShopListingIDs: AccountShopListingIDs{
|
||||
AccountShopIDs: AccountShopIDs{
|
||||
AccountIDs: AccountIDs{
|
||||
AccountID: acctID,
|
||||
},
|
||||
Platform: platform,
|
||||
ShopID: shopID,
|
||||
},
|
||||
ListingID: listingID,
|
||||
},
|
||||
SKU: v.Sku,
|
||||
Name: v.Name,
|
||||
Description: v.Name,
|
||||
Count: v.Count,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (db *Store) DeleteMockSyncGroup(ctx context.Context, acctID, syncGroupID int64) error {
|
||||
tag, err := db.db.Exec(
|
||||
ctx,
|
||||
`
|
||||
DELETE FROM
|
||||
mock.sync_groups
|
||||
WHERE
|
||||
account_id = @account_id
|
||||
AND sync_group_id = @sync_group_id
|
||||
`,
|
||||
pgx.NamedArgs{
|
||||
"account_id": acctID,
|
||||
"sync_group_id": syncGroupID,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to perform query: %w", err)
|
||||
}
|
||||
if tag.RowsAffected() == 0 {
|
||||
return consts.ErrNotFound
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// additional context
|
||||
|
||||
func (db *Store) GetAccountPointerByUserID(ctx context.Context, userID string) (*Account, error) {
|
||||
|
||||
Reference in New Issue
Block a user