feat(create_note): minimal handler
This commit is contained in:
parent
843b840583
commit
722b1dbbe7
2 changed files with 10 additions and 2 deletions
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
"github.com/KristianJBorgwarth/dendrite.daemon/core/rpc"
|
"github.com/KristianJBorgwarth/dendrite.daemon/core/rpc"
|
||||||
|
"github.com/KristianJBorgwarth/dendrite.daemon/persistence/repositories"
|
||||||
)
|
)
|
||||||
|
|
||||||
type createNoteCommand struct {
|
type createNoteCommand struct {
|
||||||
|
|
@ -14,7 +15,7 @@ type createNoteCommand struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type CreateNoteHandler struct{
|
type CreateNoteHandler struct{
|
||||||
repository NoteRepository
|
repository repositories.NoteRepository
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h CreateNoteHandler) Handle(params []byte) (any, *rpc.Error) {
|
func (h CreateNoteHandler) Handle(params []byte) (any, *rpc.Error) {
|
||||||
|
|
@ -23,4 +24,11 @@ func (h CreateNoteHandler) Handle(params []byte) (any, *rpc.Error) {
|
||||||
return nil, &rpc.Error{Code: -32602, Message: "invalid params"}
|
return nil, &rpc.Error{Code: -32602, Message: "invalid params"}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err := h.repository.Upsert(cmd.Title, cmd.TemplatePath, cmd.Path)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, &rpc.Error{Code: -1, Message: err.Error()}
|
||||||
|
}
|
||||||
|
|
||||||
|
return map[string]any{"status": "ok"}, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ package repositories
|
||||||
import "database/sql"
|
import "database/sql"
|
||||||
|
|
||||||
type NoteRepository interface {
|
type NoteRepository interface {
|
||||||
CreateNote(title string, path string, slug string) error
|
Upsert(title string, path string, slug string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type noteRepository struct {
|
type noteRepository struct {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue