use beads service
use pointes for comments use htmx routing
This commit is contained in:
@@ -51,48 +51,3 @@ func (s *BeadsService) DeleteIssues() error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *BeadsService) GetComments(ctx context.Context, issueID string) ([]models.Comment, error) {
|
||||
query := `SELECT id, issue_id, author, text, created_at FROM comments WHERE issue_id = ? ORDER BY created_at ASC LIMIT 100`
|
||||
|
||||
rows, err := s.UnderlyingDB().QueryContext(ctx, query, issueID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(commentsPtr) == 0 {
|
||||
return []models.Comment{}, nil
|
||||
}
|
||||
|
||||
comments := make([]models.Comment, 0, len(commentsPtr))
|
||||
for _, c := range commentsPtr {
|
||||
if c != nil {
|
||||
comments = append(comments, *c)
|
||||
}
|
||||
}
|
||||
|
||||
return comments, nil
|
||||
}
|
||||
|
||||
func (s *BeadsService) AddComment(ctx context.Context, issueID, author, text string) (*models.Comment, error) {
|
||||
query := `INSERT INTO comments (issue_id, author, text, created_at) VALUES (?, ?, ?, ?)`
|
||||
|
||||
createdAt := time.Now().UTC()
|
||||
result, err := s.UnderlyingDB().ExecContext(ctx, query, issueID, author, text, createdAt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
id, err := result.LastInsertId()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &models.Comment{
|
||||
ID: id,
|
||||
IssueID: issueID,
|
||||
Author: author,
|
||||
Text: text,
|
||||
CreatedAt: createdAt,
|
||||
}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user