Commit c1498a18 authored by johnnyjoy's avatar johnnyjoy

chore: retire webhook state

parent 2a861ea4
...@@ -53,11 +53,9 @@ message Webhook { ...@@ -53,11 +53,9 @@ message Webhook {
google.protobuf.Timestamp update_time = 4; google.protobuf.Timestamp update_time = 4;
State state = 5; string name = 5;
string name = 6; string url = 6;
string url = 7;
} }
message CreateWebhookRequest { message CreateWebhookRequest {
......
This diff is collapsed.
...@@ -630,8 +630,6 @@ paths: ...@@ -630,8 +630,6 @@ paths:
updateTime: updateTime:
type: string type: string
format: date-time format: date-time
state:
$ref: '#/definitions/v1State'
name: name:
type: string type: string
url: url:
...@@ -3056,8 +3054,6 @@ definitions: ...@@ -3056,8 +3054,6 @@ definitions:
updateTime: updateTime:
type: string type: string
format: date-time format: date-time
state:
$ref: '#/definitions/v1State'
name: name:
type: string type: string
url: url:
......
...@@ -103,7 +103,6 @@ func convertWebhookFromStore(webhook *store.Webhook) *v1pb.Webhook { ...@@ -103,7 +103,6 @@ func convertWebhookFromStore(webhook *store.Webhook) *v1pb.Webhook {
Id: webhook.ID, Id: webhook.ID,
CreateTime: timestamppb.New(time.Unix(webhook.CreatedTs, 0)), CreateTime: timestamppb.New(time.Unix(webhook.CreatedTs, 0)),
UpdateTime: timestamppb.New(time.Unix(webhook.UpdatedTs, 0)), UpdateTime: timestamppb.New(time.Unix(webhook.UpdatedTs, 0)),
State: convertStateFromStore(webhook.RowStatus),
CreatorId: webhook.CreatorID, CreatorId: webhook.CreatorID,
Name: webhook.Name, Name: webhook.Name,
Url: webhook.URL, Url: webhook.URL,
......
...@@ -36,7 +36,7 @@ func (d *DB) ListWebhooks(ctx context.Context, find *store.FindWebhook) ([]*stor ...@@ -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) 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..., args...,
) )
if err != nil { if err != nil {
...@@ -47,19 +47,16 @@ func (d *DB) ListWebhooks(ctx context.Context, find *store.FindWebhook) ([]*stor ...@@ -47,19 +47,16 @@ func (d *DB) ListWebhooks(ctx context.Context, find *store.FindWebhook) ([]*stor
list := []*store.Webhook{} list := []*store.Webhook{}
for rows.Next() { for rows.Next() {
webhook := &store.Webhook{} webhook := &store.Webhook{}
var rowStatus string
if err := rows.Scan( if err := rows.Scan(
&webhook.ID, &webhook.ID,
&webhook.CreatedTs, &webhook.CreatedTs,
&webhook.UpdatedTs, &webhook.UpdatedTs,
&rowStatus,
&webhook.CreatorID, &webhook.CreatorID,
&webhook.Name, &webhook.Name,
&webhook.URL, &webhook.URL,
); err != nil { ); err != nil {
return nil, err return nil, err
} }
webhook.RowStatus = store.RowStatus(rowStatus)
list = append(list, webhook) list = append(list, webhook)
} }
...@@ -83,9 +80,6 @@ func (d *DB) GetWebhook(ctx context.Context, find *store.FindWebhook) (*store.We ...@@ -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) { func (d *DB) UpdateWebhook(ctx context.Context, update *store.UpdateWebhook) (*store.Webhook, error) {
set, args := []string{}, []any{} set, args := []string{}, []any{}
if update.RowStatus != nil {
set, args = append(set, "`row_status` = ?"), append(args, update.RowStatus.String())
}
if update.Name != nil { if update.Name != nil {
set, args = append(set, "`name` = ?"), append(args, *update.Name) set, args = append(set, "`name` = ?"), append(args, *update.Name)
} }
......
...@@ -10,18 +10,14 @@ import ( ...@@ -10,18 +10,14 @@ import (
func (d *DB) CreateWebhook(ctx context.Context, create *store.Webhook) (*store.Webhook, error) { func (d *DB) CreateWebhook(ctx context.Context, create *store.Webhook) (*store.Webhook, error) {
fields := []string{"name", "url", "creator_id"} fields := []string{"name", "url", "creator_id"}
args := []any{create.Name, create.URL, create.CreatorID} 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" stmt := "INSERT INTO webhook (" + strings.Join(fields, ", ") + ") VALUES (" + placeholders(len(args)) + ") RETURNING id, created_ts, updated_ts"
var rowStatus string
if err := d.db.QueryRowContext(ctx, stmt, args...).Scan( if err := d.db.QueryRowContext(ctx, stmt, args...).Scan(
&create.ID, &create.ID,
&create.CreatedTs, &create.CreatedTs,
&create.UpdatedTs, &create.UpdatedTs,
&rowStatus,
); err != nil { ); err != nil {
return nil, err return nil, err
} }
create.RowStatus = store.RowStatus(rowStatus)
webhook := create webhook := create
return webhook, nil return webhook, nil
} }
...@@ -40,7 +36,6 @@ func (d *DB) ListWebhooks(ctx context.Context, find *store.FindWebhook) ([]*stor ...@@ -40,7 +36,6 @@ func (d *DB) ListWebhooks(ctx context.Context, find *store.FindWebhook) ([]*stor
id, id,
created_ts, created_ts,
updated_ts, updated_ts,
row_status,
creator_id, creator_id,
name, name,
url url
...@@ -57,19 +52,16 @@ func (d *DB) ListWebhooks(ctx context.Context, find *store.FindWebhook) ([]*stor ...@@ -57,19 +52,16 @@ func (d *DB) ListWebhooks(ctx context.Context, find *store.FindWebhook) ([]*stor
list := []*store.Webhook{} list := []*store.Webhook{}
for rows.Next() { for rows.Next() {
webhook := &store.Webhook{} webhook := &store.Webhook{}
var rowStatus string
if err := rows.Scan( if err := rows.Scan(
&webhook.ID, &webhook.ID,
&webhook.CreatedTs, &webhook.CreatedTs,
&webhook.UpdatedTs, &webhook.UpdatedTs,
&rowStatus,
&webhook.CreatorID, &webhook.CreatorID,
&webhook.Name, &webhook.Name,
&webhook.URL, &webhook.URL,
); err != nil { ); err != nil {
return nil, err return nil, err
} }
webhook.RowStatus = store.RowStatus(rowStatus)
list = append(list, webhook) list = append(list, webhook)
} }
...@@ -82,9 +74,6 @@ func (d *DB) ListWebhooks(ctx context.Context, find *store.FindWebhook) ([]*stor ...@@ -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) { func (d *DB) UpdateWebhook(ctx context.Context, update *store.UpdateWebhook) (*store.Webhook, error) {
set, args := []string{}, []any{} 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 { if update.Name != nil {
set, args = append(set, "name = "+placeholder(len(args)+1)), append(args, *update.Name) 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 ...@@ -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) 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) args = append(args, update.ID)
webhook := &store.Webhook{} webhook := &store.Webhook{}
var rowStatus string
if err := d.db.QueryRowContext(ctx, stmt, args...).Scan( if err := d.db.QueryRowContext(ctx, stmt, args...).Scan(
&webhook.ID, &webhook.ID,
&webhook.CreatedTs, &webhook.CreatedTs,
&webhook.UpdatedTs, &webhook.UpdatedTs,
&rowStatus,
&webhook.CreatorID, &webhook.CreatorID,
&webhook.Name, &webhook.Name,
&webhook.URL, &webhook.URL,
); err != nil { ); err != nil {
return nil, err return nil, err
} }
webhook.RowStatus = store.RowStatus(rowStatus)
return webhook, nil return webhook, nil
} }
......
...@@ -11,18 +11,14 @@ func (d *DB) CreateWebhook(ctx context.Context, create *store.Webhook) (*store.W ...@@ -11,18 +11,14 @@ func (d *DB) CreateWebhook(ctx context.Context, create *store.Webhook) (*store.W
fields := []string{"`name`", "`url`", "`creator_id`"} fields := []string{"`name`", "`url`", "`creator_id`"}
placeholder := []string{"?", "?", "?"} placeholder := []string{"?", "?", "?"}
args := []any{create.Name, create.URL, create.CreatorID} 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`" stmt := "INSERT INTO `webhook` (" + strings.Join(fields, ", ") + ") VALUES (" + strings.Join(placeholder, ", ") + ") RETURNING `id`, `created_ts`, `updated_ts`"
var rowStatus string
if err := d.db.QueryRowContext(ctx, stmt, args...).Scan( if err := d.db.QueryRowContext(ctx, stmt, args...).Scan(
&create.ID, &create.ID,
&create.CreatedTs, &create.CreatedTs,
&create.UpdatedTs, &create.UpdatedTs,
&rowStatus,
); err != nil { ); err != nil {
return nil, err return nil, err
} }
create.RowStatus = store.RowStatus(rowStatus)
webhook := create webhook := create
return webhook, nil return webhook, nil
} }
...@@ -41,7 +37,6 @@ func (d *DB) ListWebhooks(ctx context.Context, find *store.FindWebhook) ([]*stor ...@@ -41,7 +37,6 @@ func (d *DB) ListWebhooks(ctx context.Context, find *store.FindWebhook) ([]*stor
id, id,
created_ts, created_ts,
updated_ts, updated_ts,
row_status,
creator_id, creator_id,
name, name,
url url
...@@ -58,19 +53,16 @@ func (d *DB) ListWebhooks(ctx context.Context, find *store.FindWebhook) ([]*stor ...@@ -58,19 +53,16 @@ func (d *DB) ListWebhooks(ctx context.Context, find *store.FindWebhook) ([]*stor
list := []*store.Webhook{} list := []*store.Webhook{}
for rows.Next() { for rows.Next() {
webhook := &store.Webhook{} webhook := &store.Webhook{}
var rowStatus string
if err := rows.Scan( if err := rows.Scan(
&webhook.ID, &webhook.ID,
&webhook.CreatedTs, &webhook.CreatedTs,
&webhook.UpdatedTs, &webhook.UpdatedTs,
&rowStatus,
&webhook.CreatorID, &webhook.CreatorID,
&webhook.Name, &webhook.Name,
&webhook.URL, &webhook.URL,
); err != nil { ); err != nil {
return nil, err return nil, err
} }
webhook.RowStatus = store.RowStatus(rowStatus)
list = append(list, webhook) list = append(list, webhook)
} }
...@@ -83,9 +75,6 @@ func (d *DB) ListWebhooks(ctx context.Context, find *store.FindWebhook) ([]*stor ...@@ -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) { func (d *DB) UpdateWebhook(ctx context.Context, update *store.UpdateWebhook) (*store.Webhook, error) {
set, args := []string{}, []any{} set, args := []string{}, []any{}
if update.RowStatus != nil {
set, args = append(set, "row_status = ?"), append(args, update.RowStatus.String())
}
if update.Name != nil { if update.Name != nil {
set, args = append(set, "name = ?"), append(args, *update.Name) set, args = append(set, "name = ?"), append(args, *update.Name)
} }
...@@ -94,21 +83,18 @@ func (d *DB) UpdateWebhook(ctx context.Context, update *store.UpdateWebhook) (*s ...@@ -94,21 +83,18 @@ func (d *DB) UpdateWebhook(ctx context.Context, update *store.UpdateWebhook) (*s
} }
args = append(args, update.ID) 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{} webhook := &store.Webhook{}
var rowStatus string
if err := d.db.QueryRowContext(ctx, stmt, args...).Scan( if err := d.db.QueryRowContext(ctx, stmt, args...).Scan(
&webhook.ID, &webhook.ID,
&webhook.CreatedTs, &webhook.CreatedTs,
&webhook.UpdatedTs, &webhook.UpdatedTs,
&rowStatus,
&webhook.CreatorID, &webhook.CreatorID,
&webhook.Name, &webhook.Name,
&webhook.URL, &webhook.URL,
); err != nil { ); err != nil {
return nil, err return nil, err
} }
webhook.RowStatus = store.RowStatus(rowStatus)
return webhook, nil return webhook, nil
} }
......
...@@ -9,7 +9,6 @@ type Webhook struct { ...@@ -9,7 +9,6 @@ type Webhook struct {
CreatedTs int64 CreatedTs int64
UpdatedTs int64 UpdatedTs int64
CreatorID int32 CreatorID int32
RowStatus RowStatus
Name string Name string
URL string URL string
} }
...@@ -21,7 +20,6 @@ type FindWebhook struct { ...@@ -21,7 +20,6 @@ type FindWebhook struct {
type UpdateWebhook struct { type UpdateWebhook struct {
ID int32 ID int32
RowStatus *RowStatus
Name *string Name *string
URL *string URL *string
} }
......
...@@ -18,7 +18,6 @@ func TestWebhookStore(t *testing.T) { ...@@ -18,7 +18,6 @@ func TestWebhookStore(t *testing.T) {
CreatorID: user.ID, CreatorID: user.ID,
Name: "test_webhook", Name: "test_webhook",
URL: "https://example.com", URL: "https://example.com",
RowStatus: store.Normal,
}) })
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, "test_webhook", webhook.Name) 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