feat: move reaction type to setting

This commit is contained in:
Steven
2024-10-10 21:06:32 +08:00
parent 1f9d657065
commit e527b6a878
41 changed files with 927 additions and 3467 deletions

View File

@@ -6,14 +6,13 @@ import (
"github.com/pkg/errors"
storepb "github.com/usememos/memos/proto/gen/store"
"github.com/usememos/memos/store"
)
func (d *DB) UpsertReaction(ctx context.Context, upsert *store.Reaction) (*store.Reaction, error) {
fields := []string{"`creator_id`", "`content_id`", "`reaction_type`"}
placeholder := []string{"?", "?", "?"}
args := []interface{}{upsert.CreatorID, upsert.ContentID, upsert.ReactionType.String()}
args := []interface{}{upsert.CreatorID, upsert.ContentID, upsert.ReactionType}
stmt := "INSERT INTO `reaction` (" + strings.Join(fields, ", ") + ") VALUES (" + strings.Join(placeholder, ", ") + ")"
result, err := d.db.ExecContext(ctx, stmt, args...)
if err != nil {
@@ -67,17 +66,15 @@ func (d *DB) ListReactions(ctx context.Context, find *store.FindReaction) ([]*st
list := []*store.Reaction{}
for rows.Next() {
reaction := &store.Reaction{}
var reactionType string
if err := rows.Scan(
&reaction.ID,
&reaction.CreatedTs,
&reaction.CreatorID,
&reaction.ContentID,
&reactionType,
&reaction.ReactionType,
); err != nil {
return nil, err
}
reaction.ReactionType = storepb.ReactionType(storepb.ReactionType_value[reactionType])
list = append(list, reaction)
}