diff --git a/core/dtos/backlink.go b/core/dtos/backlink_dto.go similarity index 85% rename from core/dtos/backlink.go rename to core/dtos/backlink_dto.go index c2201b1..1adbf65 100644 --- a/core/dtos/backlink.go +++ b/core/dtos/backlink_dto.go @@ -1,6 +1,6 @@ package dtos -type Backlink struct { +type BacklinkDto struct { ID string `json:"id"` Title string `json:"title"` Slug string `json:"slug"` @@ -10,8 +10,8 @@ type Backlink struct { Col int `json:"col"` } -func NewBacklink(id, title, slug, path, raw string, col, line int) *Backlink { - return &Backlink{ +func NewBacklink(id, title, slug, path, raw string, col, line int) *BacklinkDto { + return &BacklinkDto{ ID: id, Title: title, Slug: slug, diff --git a/core/dtos/note_dto.go b/core/dtos/note_dto.go new file mode 100644 index 0000000..df4ce80 --- /dev/null +++ b/core/dtos/note_dto.go @@ -0,0 +1,19 @@ +package dtos + +import "github.com/KristianJBorgwarth/dendrite.daemon/core/models" + +type NoteDto struct { + ID string `json:"id"` + Path string `json:"path"` + Title string `json:"title"` + Slug string `json:"slug"` +} + +func NewNoteDto(note *models.Note) *NoteDto { + return &NoteDto{ + ID: note.ID(), + Path: note.Path(), + Title: note.Title(), + Slug: note.Slug(), + } +} diff --git a/core/handlers/note/get_notes_by_tag_handler.go b/core/handlers/note/get_notes_by_tag_handler.go index 8c97caf..ebc9b5a 100644 --- a/core/handlers/note/get_notes_by_tag_handler.go +++ b/core/handlers/note/get_notes_by_tag_handler.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" + "github.com/KristianJBorgwarth/dendrite.daemon/core/dtos" "github.com/KristianJBorgwarth/dendrite.daemon/persistence/repositories" ) type getNotesByTagCommand struct { @@ -29,5 +30,10 @@ func (h *GetNotesByTagHandler) Handle(ctx context.Context, raw json.RawMessage) return nil, err } - return notes, nil + noteDtos := make([]*dtos.NoteDto, len(notes)) + for i, note := range notes { + noteDtos[i] = dtos.NewNoteDto(note) + } + + return noteDtos, nil } diff --git a/dendrite b/dendrite index 4b61683..8b8430b 100755 Binary files a/dendrite and b/dendrite differ diff --git a/persistence/repositories/link_repository.go b/persistence/repositories/link_repository.go index 6e20053..fc9a407 100644 --- a/persistence/repositories/link_repository.go +++ b/persistence/repositories/link_repository.go @@ -15,7 +15,7 @@ type ILinkRepository interface { 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.Backlink, error) + GetBacklinks(ctx context.Context, slug string) ([]*dtos.BacklinkDto, error) Delete(ctx context.Context, dbContext persistence.IDbContext, fromNoteID string) error } @@ -125,7 +125,7 @@ func (r *linkRepository) Search(ctx context.Context, query string) ([]*models.Li return links, nil } -func (r *linkRepository) GetBacklinks(ctx context.Context, slug string) ([]*dtos.Backlink, error) { +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 FROM link l @@ -138,7 +138,7 @@ func (r *linkRepository) GetBacklinks(ctx context.Context, slug string) ([]*dtos } defer rows.Close() - backlinks := make([]*dtos.Backlink, 0) + backlinks := make([]*dtos.BacklinkDto, 0) for rows.Next() { var noteID, noteSlug, noteTitle, notePath, raw string var line, col int