58 lines
1.5 KiB
Go
58 lines
1.5 KiB
Go
package main
|
|
|
|
import (
|
|
"time"
|
|
|
|
"verstak/internal/core/activity"
|
|
"verstak/internal/core/nodes"
|
|
syncsvc "verstak/internal/core/sync"
|
|
)
|
|
|
|
func (a *App) ListNotes(nodeID string) ([]NodeDTO, error) {
|
|
children, err := a.nodes.ListChildren(nodeID, false)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var result []NodeDTO
|
|
for i := range children {
|
|
if children[i].Type == nodes.TypeNote {
|
|
result = append(result, toNodeDTO(&children[i]))
|
|
}
|
|
}
|
|
return result, nil
|
|
}
|
|
|
|
func (a *App) CreateNote(parentID, title string) (*NodeDTO, error) {
|
|
node, fileRec, err := a.notes.Create(parentID, title, "")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
_ = a.activity.Record(parentID, activity.TargetNote, node.ID, "", activity.TypeNoteCreated, title, "")
|
|
_ = a.sync.RecordOp(syncsvc.EntityNote, node.ID, syncsvc.OpCreate, notePayload(node, fileRec, ""))
|
|
dto := toNodeDTO(node)
|
|
return &dto, nil
|
|
}
|
|
|
|
func (a *App) ReadNote(noteID string) (string, error) {
|
|
return a.notes.Read(noteID)
|
|
}
|
|
|
|
func (a *App) SaveNote(noteID, content string) error {
|
|
if err := a.notes.Save(noteID, content); err != nil {
|
|
return err
|
|
}
|
|
if n, err := a.nodes.GetActive(noteID); err == nil {
|
|
pid := ""
|
|
if n.ParentID != nil {
|
|
pid = *n.ParentID
|
|
}
|
|
_ = a.activity.Record(pid, activity.TargetNote, noteID, "", activity.TypeNoteUpdated, n.Title, "")
|
|
_ = a.sync.RecordOp(syncsvc.EntityNote, noteID, syncsvc.OpUpdate, map[string]interface{}{
|
|
"node_id": noteID,
|
|
"content": content,
|
|
"updated_at": time.Now().UTC().Format(time.RFC3339),
|
|
})
|
|
}
|
|
return nil
|
|
}
|