From c40a0fc690a94ab1e9f3253f4e85b394769b3617 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Fri, 4 Oct 2024 10:41:59 +0300 Subject: can read content and can mark as posted the entry --- internal/entry/entry.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/internal/entry/entry.go b/internal/entry/entry.go index 6934eba..7bb4930 100644 --- a/internal/entry/entry.go +++ b/internal/entry/entry.go @@ -1,7 +1,9 @@ package entry import ( + "errors" "fmt" + "os" "strings" "time" @@ -80,3 +82,22 @@ func New(filePath string) (Entry, error) { return e, nil } + +func (e Entry) Content() (string, error) { + bytes, err := os.ReadFile(e.Path) + return string(bytes), err +} + +func (e *Entry) MarkPosted() error { + if e.State != Queued { + return errors.New("entry is not queued") + } + if e.State == Posted { + return errors.New("entry is already posted") + } + if err := os.Rename(e.Path, strings.TrimSuffix(e.Path, ".queued")+".posted"); err != nil { + return err + } + e.State = Posted + return nil +} -- cgit v1.2.3