moved mock syn group list item to component
This commit is contained in:
@@ -61,6 +61,10 @@ func (v_ctx *StoreWithContext) GetMockListing(acctID int64, platform Platform, s
|
||||
return v_ctx.Store.GetMockListing(v_ctx.ctx, acctID, platform, shopID, listingID)
|
||||
}
|
||||
|
||||
func (v_ctx *StoreWithContext) DeleteMockSyncGroup(acctID int64, syncGroupID int64) error {
|
||||
return v_ctx.Store.DeleteMockSyncGroup(v_ctx.ctx, acctID, syncGroupID)
|
||||
}
|
||||
|
||||
func (v_ctx *StoreWithContext) GetAccountPointerByUserID(userID string) (*Account, error) {
|
||||
return v_ctx.Store.GetAccountPointerByUserID(v_ctx.ctx, userID)
|
||||
}
|
||||
@@ -165,6 +169,10 @@ func (v_ctx *StoreWithContext) ListMockSyncGroups(acctID int64) ([]SyncGroup, er
|
||||
return v_ctx.Store.ListMockSyncGroups(v_ctx.ctx, acctID)
|
||||
}
|
||||
|
||||
func (v_ctx *StoreWithContext) GetMockSyncGroup(acctID int64, syncGroupID int64) (*SyncGroup, error) {
|
||||
return v_ctx.Store.GetMockSyncGroup(v_ctx.ctx, acctID, syncGroupID)
|
||||
}
|
||||
|
||||
func (v_ctx *StoreWithContext) listMockSyncGroupListings(tx pgx.Tx, acctID int64, syncGroupID int64) ([]SyncGroupListing, error) {
|
||||
return v_ctx.Store.listMockSyncGroupListings(v_ctx.ctx, tx, acctID, syncGroupID)
|
||||
}
|
||||
|
||||
@@ -1110,6 +1110,64 @@ func (db *Store) ListMockSyncGroups(ctx context.Context, acctID int64) ([]SyncGr
|
||||
return grps, nil
|
||||
}
|
||||
|
||||
func (db *Store) GetMockSyncGroup(ctx context.Context, acctID, syncGroupID int64) (*SyncGroup, error) {
|
||||
tx, err := db.db.BeginTx(ctx, pgx.TxOptions{
|
||||
AccessMode: pgx.ReadOnly,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to begin transaction: %w", err)
|
||||
}
|
||||
defer tx.Rollback(ctx)
|
||||
|
||||
rows, err := tx.Query(
|
||||
ctx,
|
||||
`
|
||||
SELECT
|
||||
name
|
||||
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 nil, fmt.Errorf("failed to perform query: %w", err)
|
||||
}
|
||||
|
||||
name, err := pgx.CollectExactlyOneRow(rows, pgx.RowTo[string])
|
||||
if err != nil {
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return nil, consts.ErrNotFound
|
||||
}
|
||||
return nil, fmt.Errorf("failed to scan rows: %w", err)
|
||||
}
|
||||
|
||||
listings, err := db.listMockSyncGroupListings(ctx, tx, acctID, syncGroupID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to load listings: %w", err)
|
||||
}
|
||||
|
||||
if err := tx.Commit(ctx); err != nil {
|
||||
return nil, fmt.Errorf("failed to commit transaction: %w", err)
|
||||
}
|
||||
|
||||
return &SyncGroup{
|
||||
SyncGroupIDs: SyncGroupIDs{
|
||||
AccountIDs: AccountIDs{
|
||||
AccountID: acctID,
|
||||
},
|
||||
SyncGroupID: syncGroupID,
|
||||
},
|
||||
Name: name,
|
||||
Listings: listings,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// listMockSyncGroupListings will sort the returned listings by order_index.
|
||||
func (db *Store) listMockSyncGroupListings(ctx context.Context, tx pgx.Tx, acctID, syncGroupID int64) ([]SyncGroupListing, error) {
|
||||
var listings []SyncGroupListing
|
||||
|
||||
Reference in New Issue
Block a user