mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
chore: retire webhook state
This commit is contained in:
@ -10,18 +10,14 @@ import (
|
||||
func (d *DB) CreateWebhook(ctx context.Context, create *store.Webhook) (*store.Webhook, error) {
|
||||
fields := []string{"name", "url", "creator_id"}
|
||||
args := []any{create.Name, create.URL, create.CreatorID}
|
||||
stmt := "INSERT INTO webhook (" + strings.Join(fields, ", ") + ") VALUES (" + placeholders(len(args)) + ") RETURNING id, created_ts, updated_ts, row_status"
|
||||
var rowStatus string
|
||||
stmt := "INSERT INTO webhook (" + strings.Join(fields, ", ") + ") VALUES (" + placeholders(len(args)) + ") RETURNING id, created_ts, updated_ts"
|
||||
if err := d.db.QueryRowContext(ctx, stmt, args...).Scan(
|
||||
&create.ID,
|
||||
&create.CreatedTs,
|
||||
&create.UpdatedTs,
|
||||
&rowStatus,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
create.RowStatus = store.RowStatus(rowStatus)
|
||||
webhook := create
|
||||
return webhook, nil
|
||||
}
|
||||
@ -40,7 +36,6 @@ func (d *DB) ListWebhooks(ctx context.Context, find *store.FindWebhook) ([]*stor
|
||||
id,
|
||||
created_ts,
|
||||
updated_ts,
|
||||
row_status,
|
||||
creator_id,
|
||||
name,
|
||||
url
|
||||
@ -57,19 +52,16 @@ func (d *DB) ListWebhooks(ctx context.Context, find *store.FindWebhook) ([]*stor
|
||||
list := []*store.Webhook{}
|
||||
for rows.Next() {
|
||||
webhook := &store.Webhook{}
|
||||
var rowStatus string
|
||||
if err := rows.Scan(
|
||||
&webhook.ID,
|
||||
&webhook.CreatedTs,
|
||||
&webhook.UpdatedTs,
|
||||
&rowStatus,
|
||||
&webhook.CreatorID,
|
||||
&webhook.Name,
|
||||
&webhook.URL,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
webhook.RowStatus = store.RowStatus(rowStatus)
|
||||
list = append(list, webhook)
|
||||
}
|
||||
|
||||
@ -82,9 +74,6 @@ func (d *DB) ListWebhooks(ctx context.Context, find *store.FindWebhook) ([]*stor
|
||||
|
||||
func (d *DB) UpdateWebhook(ctx context.Context, update *store.UpdateWebhook) (*store.Webhook, error) {
|
||||
set, args := []string{}, []any{}
|
||||
if update.RowStatus != nil {
|
||||
set, args = append(set, "row_status = "+placeholder(len(args)+1)), append(args, update.RowStatus.String())
|
||||
}
|
||||
if update.Name != nil {
|
||||
set, args = append(set, "name = "+placeholder(len(args)+1)), append(args, *update.Name)
|
||||
}
|
||||
@ -92,22 +81,19 @@ func (d *DB) UpdateWebhook(ctx context.Context, update *store.UpdateWebhook) (*s
|
||||
set, args = append(set, "url = "+placeholder(len(args)+1)), append(args, *update.URL)
|
||||
}
|
||||
|
||||
stmt := "UPDATE webhook SET " + strings.Join(set, ", ") + " WHERE id = " + placeholder(len(args)+1) + " RETURNING id, created_ts, updated_ts, row_status, creator_id, name, url"
|
||||
stmt := "UPDATE webhook SET " + strings.Join(set, ", ") + " WHERE id = " + placeholder(len(args)+1) + " RETURNING id, created_ts, updated_ts, creator_id, name, url"
|
||||
args = append(args, update.ID)
|
||||
webhook := &store.Webhook{}
|
||||
var rowStatus string
|
||||
if err := d.db.QueryRowContext(ctx, stmt, args...).Scan(
|
||||
&webhook.ID,
|
||||
&webhook.CreatedTs,
|
||||
&webhook.UpdatedTs,
|
||||
&rowStatus,
|
||||
&webhook.CreatorID,
|
||||
&webhook.Name,
|
||||
&webhook.URL,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
webhook.RowStatus = store.RowStatus(rowStatus)
|
||||
return webhook, nil
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user