style: fix linting issues

- Fix SQLite GetReaction to use standard List pattern (consistent with MySQL/PostgreSQL)
- Add periods to comment endings (godot linter requirement)
- Simplify GetReaction implementation to avoid sql.ErrNoRows handling
This commit is contained in:
Claude 2025-11-06 12:14:30 +00:00
parent 1a3298554b
commit 64ef80a21c
No known key found for this signature in database
2 changed files with 8 additions and 33 deletions

View File

@ -68,7 +68,7 @@ func (s *APIV1Service) DeleteMemoReaction(ctx context.Context, request *v1pb.Del
return nil, status.Errorf(codes.InvalidArgument, "invalid reaction name: %v", err) return nil, status.Errorf(codes.InvalidArgument, "invalid reaction name: %v", err)
} }
// Get reaction and check ownership // Get reaction and check ownership.
reaction, err := s.Store.GetReaction(ctx, &store.FindReaction{ reaction, err := s.Store.GetReaction(ctx, &store.FindReaction{
ID: &reactionID, ID: &reactionID,
}) })
@ -76,7 +76,7 @@ func (s *APIV1Service) DeleteMemoReaction(ctx context.Context, request *v1pb.Del
return nil, status.Errorf(codes.Internal, "failed to get reaction") return nil, status.Errorf(codes.Internal, "failed to get reaction")
} }
if reaction == nil { if reaction == nil {
// Return permission denied to avoid revealing if reaction exists // Return permission denied to avoid revealing if reaction exists.
return nil, status.Errorf(codes.PermissionDenied, "permission denied") return nil, status.Errorf(codes.PermissionDenied, "permission denied")
} }

View File

@ -88,40 +88,15 @@ func (d *DB) ListReactions(ctx context.Context, find *store.FindReaction) ([]*st
} }
func (d *DB) GetReaction(ctx context.Context, find *store.FindReaction) (*store.Reaction, error) { func (d *DB) GetReaction(ctx context.Context, find *store.FindReaction) (*store.Reaction, error) {
where, args := []string{"1 = 1"}, []any{} list, err := d.ListReactions(ctx, find)
if err != nil {
if find.ID != nil {
where, args = append(where, "id = ?"), append(args, *find.ID)
}
if find.CreatorID != nil {
where, args = append(where, "creator_id = ?"), append(args, *find.CreatorID)
}
if find.ContentID != nil {
where, args = append(where, "content_id = ?"), append(args, *find.ContentID)
}
reaction := &store.Reaction{}
if err := d.db.QueryRowContext(ctx, `
SELECT
id,
created_ts,
creator_id,
content_id,
reaction_type
FROM reaction
WHERE `+strings.Join(where, " AND ")+`
LIMIT 1`,
args...,
).Scan(
&reaction.ID,
&reaction.CreatedTs,
&reaction.CreatorID,
&reaction.ContentID,
&reaction.ReactionType,
); err != nil {
return nil, err return nil, err
} }
if len(list) == 0 {
return nil, nil
}
reaction := list[0]
return reaction, nil return reaction, nil
} }