Commit c1498a18 authored by johnnyjoy's avatar johnnyjoy

chore: retire webhook state

parent 2a861ea4
......@@ -53,11 +53,9 @@ message Webhook {
google.protobuf.Timestamp update_time = 4;
State state = 5;
string name = 5;
string name = 6;
string url = 7;
string url = 6;
}
message CreateWebhookRequest {
......
This diff is collapsed.
......@@ -630,8 +630,6 @@ paths:
updateTime:
type: string
format: date-time
state:
$ref: '#/definitions/v1State'
name:
type: string
url:
......@@ -3056,8 +3054,6 @@ definitions:
updateTime:
type: string
format: date-time
state:
$ref: '#/definitions/v1State'
name:
type: string
url:
......
......@@ -103,7 +103,6 @@ func convertWebhookFromStore(webhook *store.Webhook) *v1pb.Webhook {
Id: webhook.ID,
CreateTime: timestamppb.New(time.Unix(webhook.CreatedTs, 0)),
UpdateTime: timestamppb.New(time.Unix(webhook.UpdatedTs, 0)),
State: convertStateFromStore(webhook.RowStatus),
CreatorId: webhook.CreatorID,
Name: webhook.Name,
Url: webhook.URL,
......
......@@ -36,7 +36,7 @@ func (d *DB) ListWebhooks(ctx context.Context, find *store.FindWebhook) ([]*stor
where, args = append(where, "`creator_id` = ?"), append(args, *find.CreatorID)
}
rows, err := d.db.QueryContext(ctx, "SELECT `id`, UNIX_TIMESTAMP(`created_ts`), UNIX_TIMESTAMP(`updated_ts`), `row_status`, `creator_id`, `name`, `url` FROM `webhook` WHERE "+strings.Join(where, " AND ")+" ORDER BY `id` DESC",
rows, err := d.db.QueryContext(ctx, "SELECT `id`, UNIX_TIMESTAMP(`created_ts`), UNIX_TIMESTAMP(`updated_ts`), `creator_id`, `name`, `url` FROM `webhook` WHERE "+strings.Join(where, " AND ")+" ORDER BY `id` DESC",
args...,
)
if err != nil {
......@@ -47,19 +47,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)
}
......@@ -83,9 +80,6 @@ func (d *DB) GetWebhook(ctx context.Context, find *store.FindWebhook) (*store.We
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` = ?"), append(args, update.RowStatus.String())
}
if update.Name != nil {
set, args = append(set, "`name` = ?"), append(args, *update.Name)
}
......
......@@ -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
}
......
......@@ -11,18 +11,14 @@ func (d *DB) CreateWebhook(ctx context.Context, create *store.Webhook) (*store.W
fields := []string{"`name`", "`url`", "`creator_id`"}
placeholder := []string{"?", "?", "?"}
args := []any{create.Name, create.URL, create.CreatorID}
stmt := "INSERT INTO `webhook` (" + strings.Join(fields, ", ") + ") VALUES (" + strings.Join(placeholder, ", ") + ") RETURNING `id`, `created_ts`, `updated_ts`, `row_status`"
var rowStatus string
stmt := "INSERT INTO `webhook` (" + strings.Join(fields, ", ") + ") VALUES (" + strings.Join(placeholder, ", ") + ") 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
}
......@@ -41,7 +37,6 @@ func (d *DB) ListWebhooks(ctx context.Context, find *store.FindWebhook) ([]*stor
id,
created_ts,
updated_ts,
row_status,
creator_id,
name,
url
......@@ -58,19 +53,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)
}
......@@ -83,9 +75,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 = ?"), append(args, update.RowStatus.String())
}
if update.Name != nil {
set, args = append(set, "name = ?"), append(args, *update.Name)
}
......@@ -94,21 +83,18 @@ func (d *DB) UpdateWebhook(ctx context.Context, update *store.UpdateWebhook) (*s
}
args = append(args, update.ID)
stmt := "UPDATE `webhook` SET " + strings.Join(set, ", ") + " WHERE `id` = ? RETURNING `id`, `created_ts`, `updated_ts`, `row_status`, `creator_id`, `name`, `url`"
stmt := "UPDATE `webhook` SET " + strings.Join(set, ", ") + " WHERE `id` = ? RETURNING `id`, `created_ts`, `updated_ts`, `creator_id`, `name`, `url`"
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
}
......
......@@ -9,7 +9,6 @@ type Webhook struct {
CreatedTs int64
UpdatedTs int64
CreatorID int32
RowStatus RowStatus
Name string
URL string
}
......@@ -20,10 +19,9 @@ type FindWebhook struct {
}
type UpdateWebhook struct {
ID int32
RowStatus *RowStatus
Name *string
URL *string
ID int32
Name *string
URL *string
}
type DeleteWebhook struct {
......
......@@ -18,7 +18,6 @@ func TestWebhookStore(t *testing.T) {
CreatorID: user.ID,
Name: "test_webhook",
URL: "https://example.com",
RowStatus: store.Normal,
})
require.NoError(t, err)
require.Equal(t, "test_webhook", webhook.Name)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment