mock mode: database queries implemented and checkbox on account page built
This commit is contained in:
@@ -27,6 +27,72 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
func (db *Store) SetMockMode(ctx context.Context, acctID int64, on bool) error {
|
||||
_, err := db.db.Exec(
|
||||
ctx,
|
||||
`
|
||||
INSERT INTO
|
||||
mock_mode (
|
||||
account_id,
|
||||
mock_mode
|
||||
)
|
||||
VALUES (
|
||||
@account_id,
|
||||
@mock_mode
|
||||
)
|
||||
ON CONFLICT (account_id) DO UPDATE
|
||||
SET
|
||||
mock_mode = @mock_mode
|
||||
`,
|
||||
pgx.NamedArgs{
|
||||
"account_id": acctID,
|
||||
"mock_mode": on,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to perform query: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (db *Store) GetMockMode(ctx context.Context, acctID int64) (on bool, err error) {
|
||||
rows, err := db.db.Query(
|
||||
ctx,
|
||||
`
|
||||
WITH account_query AS (
|
||||
SELECT
|
||||
account_id
|
||||
FROM
|
||||
accounts
|
||||
WHERE
|
||||
account_id = @account_id
|
||||
)
|
||||
SELECT
|
||||
COALESCE(mm.mock_mode, false)
|
||||
FROM
|
||||
account_query AS aq
|
||||
LEFT JOIN
|
||||
mock_mode AS mm
|
||||
USING
|
||||
(account_id)
|
||||
`,
|
||||
pgx.NamedArgs{
|
||||
"account_id": acctID,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("failed to perform query: %w", err)
|
||||
}
|
||||
|
||||
on, err = pgx.CollectExactlyOneRow(rows, pgx.RowTo[bool])
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("failed to scan rows: %w", err)
|
||||
}
|
||||
|
||||
return on, nil
|
||||
}
|
||||
|
||||
func (db *Store) CreateMockShop(ctx context.Context, acctID int64, platform Platform, name string) (shopID uuid.UUID, err error) {
|
||||
shopTableName, err := getMockShopTableName(platform)
|
||||
if err != nil {
|
||||
|
||||
@@ -69,6 +69,10 @@ func (v_ctx *StoreWithContext) StartEditingMockSyncGroup(acctID int64, syncGroup
|
||||
return v_ctx.Store.StartEditingMockSyncGroup(v_ctx.ctx, acctID, syncGroupID)
|
||||
}
|
||||
|
||||
func (v_ctx *StoreWithContext) SaveMockSyncGroupBeingEdited(acctID int64) (int64, error) {
|
||||
return v_ctx.Store.SaveMockSyncGroupBeingEdited(v_ctx.ctx, acctID)
|
||||
}
|
||||
|
||||
func (v_ctx *StoreWithContext) CancelEditingOfMockSyncGroupForAccount(acctID int64) (int64, bool, error) {
|
||||
return v_ctx.Store.CancelEditingOfMockSyncGroupForAccount(v_ctx.ctx, acctID)
|
||||
}
|
||||
@@ -85,10 +89,22 @@ func (v_ctx *StoreWithContext) GetMockSyncGroupEditingListing(acctID int64, sync
|
||||
return v_ctx.Store.GetMockSyncGroupEditingListing(v_ctx.ctx, acctID, syncGroupID, orderIndex)
|
||||
}
|
||||
|
||||
func (v_ctx *StoreWithContext) AddListingToMockSyncGroupBeingEdited(acctID int64) (int64, int, error) {
|
||||
return v_ctx.Store.AddListingToMockSyncGroupBeingEdited(v_ctx.ctx, acctID)
|
||||
}
|
||||
|
||||
func (v_ctx *StoreWithContext) SetShopInListingInMockSyncGroupBeingEdited(acctID int64, syncGroupID int64, orderIndex int, platform Platform, shopID string) error {
|
||||
return v_ctx.Store.SetShopInListingInMockSyncGroupBeingEdited(v_ctx.ctx, acctID, syncGroupID, orderIndex, platform, shopID)
|
||||
}
|
||||
|
||||
func (v_ctx *StoreWithContext) SetListingInListingInMockSyncGroupBeingEdited(acctID int64, syncGroupID int64, orderIndex int, listingID string) error {
|
||||
return v_ctx.Store.SetListingInListingInMockSyncGroupBeingEdited(v_ctx.ctx, acctID, syncGroupID, orderIndex, listingID)
|
||||
}
|
||||
|
||||
func (v_ctx *StoreWithContext) DeleteListingInListingInMockSyncGroupBeingEdited(acctID int64, orderIndex int) error {
|
||||
return v_ctx.Store.DeleteListingInListingInMockSyncGroupBeingEdited(v_ctx.ctx, acctID, orderIndex)
|
||||
}
|
||||
|
||||
func (v_ctx *StoreWithContext) GetAccountPointerByUserID(userID string) (*Account, error) {
|
||||
return v_ctx.Store.GetAccountPointerByUserID(v_ctx.ctx, userID)
|
||||
}
|
||||
@@ -97,6 +113,18 @@ func (v_ctx *StoreWithContext) beginReadonlyTxn(cb func(pgx.Tx) error) error {
|
||||
return v_ctx.Store.beginReadonlyTxn(v_ctx.ctx, cb)
|
||||
}
|
||||
|
||||
func (v_ctx *StoreWithContext) beginTxn(cb func(pgx.Tx) error) error {
|
||||
return v_ctx.Store.beginTxn(v_ctx.ctx, cb)
|
||||
}
|
||||
|
||||
func (v_ctx *StoreWithContext) SetMockMode(acctID int64, on bool) error {
|
||||
return v_ctx.Store.SetMockMode(v_ctx.ctx, acctID, on)
|
||||
}
|
||||
|
||||
func (v_ctx *StoreWithContext) GetMockMode(acctID int64) (bool, error) {
|
||||
return v_ctx.Store.GetMockMode(v_ctx.ctx, acctID)
|
||||
}
|
||||
|
||||
func (v_ctx *StoreWithContext) CreateMockShop(acctID int64, platform Platform, name string) (uuid.UUID, error) {
|
||||
return v_ctx.Store.CreateMockShop(v_ctx.ctx, acctID, platform, name)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user