Adding storage to our data

This commit is contained in:
2026-09-14 10:58:24 -04:00
parent b85c4c805a
commit 97ef735fc8
5 changed files with 93 additions and 23 deletions
+15 -15
View File
@@ -10,20 +10,20 @@ import (
)
type Todo struct {
Title string
Completed bool
CreatedAt time.Time
CompletedAt *time.Time
Title string
Status bool
CreatedAt time.Time
StatusAt *time.Time
}
type Todos []Todo
func (todos *Todos) add(title string) {
todo := Todo{
Title: title,
Completed: false,
CompletedAt: nil,
CreatedAt: time.Now(),
Title: title,
Status: false,
StatusAt: nil,
CreatedAt: time.Now(),
}
*todos = append(*todos, todo)
@@ -55,12 +55,12 @@ func (todos *Todos) toggle(index int) error {
return err
}
isCompeleted := t[index].Completed
isCompeleted := t[index].Status
if !isCompeleted {
completionTime := time.Now()
t[index].CompletedAt = &completionTime
t[index].StatusAt = &completionTime
}
t[index].Completed = !isCompeleted
t[index].Status = !isCompeleted
return nil
}
@@ -77,15 +77,15 @@ func (todos *Todos) edit(index int, newTitle string) error {
func (todos *Todos) print() {
table := table.New(os.Stdout)
table.SetRowLines(false)
table.SetHeaders("Index", "Titile", "Completed", "Created at", "Completed at")
table.SetHeaders("Index", "Title", "Status", "Created at", "Status at")
for index, t := range *todos {
completed := "❌"
completedAt := ""
if t.Completed {
if t.Status {
completed = "✅"
if t.CompletedAt != nil {
completedAt = t.CompletedAt.Format(time.RFC1123)
if t.StatusAt != nil {
completedAt = t.StatusAt.Format(time.RFC1123)
}
}
table.AddRow(strconv.Itoa(index), t.Title, completed, t.CreatedAt.Format(time.RFC1123), completedAt)