Adding storage to our data
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user