ops design and app
add more comments feature, more tags feature, and other frontend updates
This commit is contained in:
@@ -109,6 +109,38 @@ func (r *Repository) GetDocumentByPathIncludingArchived(ctx context.Context, pat
|
||||
return r.getDocumentByPath(ctx, path, true)
|
||||
}
|
||||
|
||||
func (r *Repository) GetDocumentByID(ctx context.Context, id string) (*DocumentRecord, error) {
|
||||
var (
|
||||
record DocumentRecord
|
||||
tagsJSON string
|
||||
created string
|
||||
updated string
|
||||
archived sql.NullString
|
||||
)
|
||||
err := r.db.QueryRowContext(ctx, `
|
||||
SELECT id, path, current_hash, title, tags, created_at, updated_at, archived_at
|
||||
FROM documents
|
||||
WHERE id = ? AND archived_at IS NULL
|
||||
`, id).Scan(&record.ID, &record.Path, &record.CurrentHash, &record.Title, &tagsJSON, &created, &updated, &archived)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := parseDocumentTimes(&record, created, updated); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if archived.Valid && archived.String != "" {
|
||||
t, err := time.Parse(time.RFC3339, archived.String)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("parse document archived_at: %w", err)
|
||||
}
|
||||
record.ArchivedAt = &t
|
||||
}
|
||||
if err := json.Unmarshal([]byte(tagsJSON), &record.Tags); err != nil {
|
||||
return nil, fmt.Errorf("unmarshal document tags: %w", err)
|
||||
}
|
||||
return &record, nil
|
||||
}
|
||||
|
||||
func (r *Repository) getDocumentByPath(ctx context.Context, path string, includeArchived bool) (*DocumentRecord, error) {
|
||||
var (
|
||||
record DocumentRecord
|
||||
@@ -416,6 +448,32 @@ func (r *Repository) SearchDocuments(ctx context.Context, query string) ([]Searc
|
||||
return results, rows.Err()
|
||||
}
|
||||
|
||||
func (r *Repository) SearchDocumentsByTag(ctx context.Context, tag string) ([]SearchResult, error) {
|
||||
rows, err := r.db.QueryContext(ctx, `
|
||||
SELECT d.path, d.title
|
||||
FROM documents d
|
||||
WHERE EXISTS (
|
||||
SELECT 1 FROM json_each(d.tags) WHERE json_each.value = ?
|
||||
) AND d.archived_at IS NULL
|
||||
ORDER BY d.path
|
||||
`, tag)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("search documents by tag: %w", err)
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var results []SearchResult
|
||||
for rows.Next() {
|
||||
var result SearchResult
|
||||
if err := rows.Scan(&result.Path, &result.Title); err != nil {
|
||||
return nil, fmt.Errorf("scan tag search result: %w", err)
|
||||
}
|
||||
results = append(results, result)
|
||||
}
|
||||
|
||||
return results, rows.Err()
|
||||
}
|
||||
|
||||
func (r *Repository) UpdateSearchContent(ctx context.Context, path string, content string) error {
|
||||
if _, err := r.db.ExecContext(ctx, `
|
||||
UPDATE document_search SET content = ?
|
||||
|
||||
Reference in New Issue
Block a user