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 {
|
||||
|
||||
Reference in New Issue
Block a user