refactor: update resource id naming

This commit is contained in:
Steven
2024-03-20 20:39:16 +08:00
parent a3a4e37cb0
commit 7cc8b951a3
48 changed files with 704 additions and 693 deletions

View File

@@ -12,9 +12,9 @@ import (
)
func (d *DB) CreateMemo(ctx context.Context, create *store.Memo) (*store.Memo, error) {
fields := []string{"`resource_name`", "`creator_id`", "`content`", "`visibility`"}
fields := []string{"`uid`", "`creator_id`", "`content`", "`visibility`"}
placeholder := []string{"?", "?", "?", "?"}
args := []any{create.ResourceName, create.CreatorID, create.Content, create.Visibility}
args := []any{create.UID, create.CreatorID, create.Content, create.Visibility}
stmt := "INSERT INTO `memo` (" + strings.Join(fields, ", ") + ") VALUES (" + strings.Join(placeholder, ", ") + ")"
result, err := d.db.ExecContext(ctx, stmt, args...)
@@ -43,8 +43,8 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
if v := find.ID; v != nil {
where, args = append(where, "`memo`.`id` = ?"), append(args, *v)
}
if v := find.ResourceName; v != nil {
where, args = append(where, "`memo`.`resource_name` = ?"), append(args, *v)
if v := find.UID; v != nil {
where, args = append(where, "`memo`.`uid` = ?"), append(args, *v)
}
if v := find.CreatorID; v != nil {
where, args = append(where, "`memo`.`creator_id` = ?"), append(args, *v)
@@ -94,7 +94,7 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
fields := []string{
"`memo`.`id` AS `id`",
"`memo`.`resource_name` AS `resource_name`",
"`memo`.`uid` AS `uid`",
"`memo`.`creator_id` AS `creator_id`",
"UNIX_TIMESTAMP(`memo`.`created_ts`) AS `created_ts`",
"UNIX_TIMESTAMP(`memo`.`updated_ts`) AS `updated_ts`",
@@ -126,7 +126,7 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
var memo store.Memo
dests := []any{
&memo.ID,
&memo.ResourceName,
&memo.UID,
&memo.CreatorID,
&memo.CreatedTs,
&memo.UpdatedTs,
@@ -166,8 +166,8 @@ func (d *DB) GetMemo(ctx context.Context, find *store.FindMemo) (*store.Memo, er
func (d *DB) UpdateMemo(ctx context.Context, update *store.UpdateMemo) error {
set, args := []string{}, []any{}
if v := update.ResourceName; v != nil {
set, args = append(set, "`resource_name` = ?"), append(args, *v)
if v := update.UID; v != nil {
set, args = append(set, "`uid` = ?"), append(args, *v)
}
if v := update.CreatedTs; v != nil {
set, args = append(set, "`created_ts` = FROM_UNIXTIME(?)"), append(args, *v)