chore: implement reaction service

This commit is contained in:
Steven
2024-02-08 11:54:59 +08:00
parent a4fa67cd18
commit 3a5bc82d39
20 changed files with 2565 additions and 841 deletions

View File

@ -8,18 +8,18 @@ import (
"github.com/usememos/memos/store"
)
func (d *DB) CreateReaction(ctx context.Context, create *storepb.Reaction) (*storepb.Reaction, error) {
func (d *DB) UpsertReaction(ctx context.Context, upsert *storepb.Reaction) (*storepb.Reaction, error) {
fields := []string{"creator_id", "content_id", "reaction_type"}
args := []interface{}{create.CreatorId, create.ContentId, create.ReactionType.String()}
args := []interface{}{upsert.CreatorId, upsert.ContentId, upsert.ReactionType.String()}
stmt := "INSERT INTO reaction (" + strings.Join(fields, ", ") + ") VALUES (" + placeholders(len(args)) + ") RETURNING id, created_ts"
if err := d.db.QueryRowContext(ctx, stmt, args...).Scan(
&create.Id,
&create.CreatedTs,
&upsert.Id,
&upsert.CreatedTs,
); err != nil {
return nil, err
}
reaction := create
reaction := upsert
return reaction, nil
}