feat(note/dto): add note dto for return obj

This commit is contained in:
Kristian Borgwarth 2026-04-26 17:02:17 +02:00
parent ce21a7fc9b
commit 262f320077
5 changed files with 32 additions and 7 deletions

View file

@ -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,

19
core/dtos/note_dto.go Normal file
View file

@ -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(),
}
}

View file

@ -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
}

BIN
dendrite

Binary file not shown.

View file

@ -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