feat(note/dto): add note dto for return obj
This commit is contained in:
parent
ce21a7fc9b
commit
262f320077
5 changed files with 32 additions and 7 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
package dtos
|
package dtos
|
||||||
|
|
||||||
type Backlink struct {
|
type BacklinkDto struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Slug string `json:"slug"`
|
Slug string `json:"slug"`
|
||||||
|
|
@ -10,8 +10,8 @@ type Backlink struct {
|
||||||
Col int `json:"col"`
|
Col int `json:"col"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewBacklink(id, title, slug, path, raw string, col, line int) *Backlink {
|
func NewBacklink(id, title, slug, path, raw string, col, line int) *BacklinkDto {
|
||||||
return &Backlink{
|
return &BacklinkDto{
|
||||||
ID: id,
|
ID: id,
|
||||||
Title: title,
|
Title: title,
|
||||||
Slug: slug,
|
Slug: slug,
|
||||||
19
core/dtos/note_dto.go
Normal file
19
core/dtos/note_dto.go
Normal 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(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
|
"github.com/KristianJBorgwarth/dendrite.daemon/core/dtos"
|
||||||
"github.com/KristianJBorgwarth/dendrite.daemon/persistence/repositories"
|
"github.com/KristianJBorgwarth/dendrite.daemon/persistence/repositories"
|
||||||
)
|
)
|
||||||
type getNotesByTagCommand struct {
|
type getNotesByTagCommand struct {
|
||||||
|
|
@ -29,5 +30,10 @@ func (h *GetNotesByTagHandler) Handle(ctx context.Context, raw json.RawMessage)
|
||||||
return nil, err
|
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
BIN
dendrite
Binary file not shown.
|
|
@ -15,7 +15,7 @@ type ILinkRepository interface {
|
||||||
GetByNoteID(ctx context.Context, dbContext persistence.IDbContext, fromNoteID string) ([]*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)
|
GetBySlug(ctx context.Context, dbContext persistence.IDbContext, targetSlug string) ([]*models.Link, error)
|
||||||
Search(ctx context.Context, query 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
|
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
|
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 := `
|
query := `
|
||||||
SELECT n.id, n.slug, n.title, n.path, l.raw, l.line, l.col
|
SELECT n.id, n.slug, n.title, n.path, l.raw, l.line, l.col
|
||||||
FROM link l
|
FROM link l
|
||||||
|
|
@ -138,7 +138,7 @@ func (r *linkRepository) GetBacklinks(ctx context.Context, slug string) ([]*dtos
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
|
|
||||||
backlinks := make([]*dtos.Backlink, 0)
|
backlinks := make([]*dtos.BacklinkDto, 0)
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var noteID, noteSlug, noteTitle, notePath, raw string
|
var noteID, noteSlug, noteTitle, notePath, raw string
|
||||||
var line, col int
|
var line, col int
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue