draft shits
This commit is contained in:
42
internal/scanner/handler.go
Normal file
42
internal/scanner/handler.go
Normal file
@ -0,0 +1,42 @@
|
||||
package scanner
|
||||
|
||||
import (
|
||||
"donniemarko/internal/note"
|
||||
"donniemarko/internal/storage"
|
||||
"os"
|
||||
)
|
||||
|
||||
type NotesHandler struct {
|
||||
storage storage.Storage
|
||||
}
|
||||
|
||||
func (h *NotesHandler) HandleCreate(path string) error {
|
||||
note, err := ParseNoteFile(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
h.storage.Create(note)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *NotesHandler) HandleModify(path string) error {
|
||||
return h.HandleCreate(path)
|
||||
}
|
||||
|
||||
func (h *NotesHandler) HandleDelete(path string) error {
|
||||
id := note.GenerateNoteID(path)
|
||||
h.storage.Delete(id)
|
||||
return nil
|
||||
}
|
||||
|
||||
func ParseNoteFile(path string) (*note.Note, error) {
|
||||
content, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
id := note.GenerateNoteID(path)
|
||||
nn := note.NewNote()
|
||||
nn.ID = id
|
||||
nn.Content = string(content)
|
||||
return nn, nil
|
||||
}
|
||||
Reference in New Issue
Block a user