chore: remove link completionn redudant
This commit is contained in:
parent
257ed48602
commit
04dd864db1
4 changed files with 0 additions and 67 deletions
|
|
@ -40,7 +40,6 @@ func main() {
|
|||
server.RegisterHandler("note/backlinks", note.NewGetBackLinksHandler(linkRepo, noteRepo))
|
||||
server.RegisterHandler("note/search_by_tag", note.NewGetNotesByTagHandler(noteRepo))
|
||||
|
||||
server.RegisterHandler("completion/link", completion.NewCompleteLinkHandler(linkRepo))
|
||||
server.RegisterHandler("completion/tag", completion.NewCompleteTagHandler(tagRepo))
|
||||
server.RegisterHandler("completion/slug", completion.NewCompleteSlugHandler(noteRepo))
|
||||
|
||||
|
|
|
|||
|
|
@ -1,45 +0,0 @@
|
|||
package completion
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"log/slog"
|
||||
|
||||
"github.com/KristianJBorgwarth/dendrite.daemon/persistence/repositories"
|
||||
)
|
||||
|
||||
type completeLinkCommand struct {
|
||||
Query string `json:"query"`
|
||||
}
|
||||
|
||||
type completeLinkResult struct {
|
||||
Slug string `json:"slug"`
|
||||
Display string `json:"display"`
|
||||
}
|
||||
|
||||
type CompleteLinkHandler struct {
|
||||
linkRepo repositories.ILinkRepository
|
||||
}
|
||||
|
||||
func NewCompleteLinkHandler(lr repositories.ILinkRepository) *CompleteLinkHandler {
|
||||
return &CompleteLinkHandler{linkRepo: lr}
|
||||
}
|
||||
|
||||
func (h *CompleteLinkHandler) Handle(ctx context.Context, raw json.RawMessage) (any, error) {
|
||||
var cmd completeLinkCommand
|
||||
if err := json.Unmarshal(raw, &cmd); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
links, err := h.linkRepo.Search(ctx, cmd.Query)
|
||||
if err != nil {
|
||||
slog.Error("Failed to search links", "error", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
items := make([]completeLinkResult, len(links))
|
||||
for i, link := range links {
|
||||
items[i] = completeLinkResult{Slug: link.TargetSlug(), Display: link.Display()}
|
||||
}
|
||||
|
||||
return items, nil
|
||||
}
|
||||
BIN
dendrite
BIN
dendrite
Binary file not shown.
|
|
@ -14,7 +14,6 @@ type ILinkRepository interface {
|
|||
InsertRange(ctx context.Context, dbContext persistence.IDbContext, links []*models.Link) error
|
||||
GetByNoteID(ctx context.Context, dbContext persistence.IDbContext, fromNoteID string) ([]*models.Link, error)
|
||||
GetBySlug(ctx context.Context, dbContext persistence.IDbContext, targetSlug string) ([]*models.Link, error)
|
||||
Search(ctx context.Context, query string) ([]*models.Link, error)
|
||||
GetBacklinks(ctx context.Context, slug string) ([]*dtos.BacklinkDto, error)
|
||||
Delete(ctx context.Context, dbContext persistence.IDbContext, fromNoteID string) error
|
||||
}
|
||||
|
|
@ -105,26 +104,6 @@ func (r *linkRepository) GetBySlug(ctx context.Context, dbContext persistence.ID
|
|||
return links, nil
|
||||
}
|
||||
|
||||
func (r *linkRepository) Search(ctx context.Context, query string) ([]*models.Link, error) {
|
||||
rows, err := r.readDBContext.QueryContext(ctx, `SELECT id, from_note_id, target_slug, raw, display, line, col FROM link WHERE raw LIKE ?`, "%"+query+"%")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var links []*models.Link
|
||||
for rows.Next() {
|
||||
var id, fromNoteID, targetSlug, raw, display string
|
||||
var line, col int
|
||||
if err := rows.Scan(&id, &fromNoteID, &targetSlug, &raw, &display, &line, &col); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
links = append(links, models.NewLink(id, fromNoteID, targetSlug, raw, display, line, col))
|
||||
}
|
||||
|
||||
return links, nil
|
||||
}
|
||||
|
||||
func (r *linkRepository) GetBacklinks(ctx context.Context, slug string) ([]*dtos.BacklinkDto, error) {
|
||||
query := `
|
||||
SELECT n.id, n.slug, n.title, n.path, l.raw, l.line, l.col
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue