added Edit Group button to mock sync group accordion
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
|
||||
"ruben/inventory2/consts"
|
||||
@@ -500,6 +501,97 @@ func (db *Store) DeleteMockSyncGroup(ctx context.Context, acctID, syncGroupID in
|
||||
return nil
|
||||
}
|
||||
|
||||
func (db *Store) StartEditingMockSyncGroup(ctx context.Context, acctID, syncGroupID int64) (int64, bool, error) {
|
||||
rows, err := db.db.Query(
|
||||
ctx,
|
||||
`
|
||||
WITH deleted_row AS (
|
||||
DELETE FROM
|
||||
mock.sync_group_editing
|
||||
WHERE
|
||||
account_id = @account_id
|
||||
AND sync_group_id <> @sync_group_id
|
||||
RETURNING
|
||||
account_id,
|
||||
sync_group_id
|
||||
), new_row AS (
|
||||
INSERT INTO
|
||||
mock.sync_group_editing (
|
||||
account_id,
|
||||
sync_group_id
|
||||
)
|
||||
SELECT
|
||||
x.account_id,
|
||||
x.sync_group_id
|
||||
FROM (
|
||||
VALUES (
|
||||
@account_id,
|
||||
@sync_group_id
|
||||
)
|
||||
) AS x(account_id, sync_group_id)
|
||||
LEFT JOIN
|
||||
deleted_row
|
||||
ON
|
||||
TRUE
|
||||
ON CONFLICT
|
||||
DO NOTHING
|
||||
)
|
||||
SELECT
|
||||
sync_group_id
|
||||
FROM
|
||||
deleted_row
|
||||
`,
|
||||
pgx.NamedArgs{
|
||||
"account_id": acctID,
|
||||
"sync_group_id": syncGroupID,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return 0, false, fmt.Errorf("failed to perform query: %w", err)
|
||||
}
|
||||
|
||||
v, err := pgx.CollectExactlyOneRow(rows, pgx.RowTo[pgtype.Int8])
|
||||
if err != nil {
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return 0, false, nil
|
||||
}
|
||||
return 0, false, fmt.Errorf("failed to scan rows: %w", err)
|
||||
}
|
||||
|
||||
return v.Int64, v.Valid, nil
|
||||
}
|
||||
|
||||
func (db *Store) MockSyncGroupIsBeingEdited(ctx context.Context, acctID, syncGroupID int64) (bool, error) {
|
||||
rows, err := db.db.Query(
|
||||
ctx,
|
||||
`
|
||||
SELECT
|
||||
true
|
||||
FROM
|
||||
mock.sync_group_editing
|
||||
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 false, fmt.Errorf("failed to perform query: %w", err)
|
||||
}
|
||||
|
||||
if _, err = pgx.CollectExactlyOneRow(rows, pgx.RowTo[pgtype.Bool]); err != nil {
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return false, nil
|
||||
}
|
||||
return false, fmt.Errorf("failed to scan rows: %w", err)
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// additional context
|
||||
|
||||
func (db *Store) GetAccountPointerByUserID(ctx context.Context, userID string) (*Account, error) {
|
||||
|
||||
@@ -65,6 +65,14 @@ func (v_ctx *StoreWithContext) DeleteMockSyncGroup(acctID int64, syncGroupID int
|
||||
return v_ctx.Store.DeleteMockSyncGroup(v_ctx.ctx, acctID, syncGroupID)
|
||||
}
|
||||
|
||||
func (v_ctx *StoreWithContext) StartEditingMockSyncGroup(acctID int64, syncGroupID int64) (int64, bool, error) {
|
||||
return v_ctx.Store.StartEditingMockSyncGroup(v_ctx.ctx, acctID, syncGroupID)
|
||||
}
|
||||
|
||||
func (v_ctx *StoreWithContext) MockSyncGroupIsBeingEdited(acctID int64, syncGroupID int64) (bool, error) {
|
||||
return v_ctx.Store.MockSyncGroupIsBeingEdited(v_ctx.ctx, acctID, syncGroupID)
|
||||
}
|
||||
|
||||
func (v_ctx *StoreWithContext) GetAccountPointerByUserID(userID string) (*Account, error) {
|
||||
return v_ctx.Store.GetAccountPointerByUserID(v_ctx.ctx, userID)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user