2025-07-26 23:31:00 +02:00
|
|
|
package common
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"fmt"
|
2025-08-23 19:14:16 +02:00
|
|
|
"strings"
|
2025-07-26 23:31:00 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func (todo Todo) Store(store *BoltStore, user string) error {
|
|
|
|
|
if todo.Owner != user {
|
|
|
|
|
return fmt.Errorf("unauthorized user")
|
|
|
|
|
}
|
|
|
|
|
todoJson, err := json.Marshal(todo)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
return store.SaveValueToBucket(user, todo.Name, string(todoJson))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (todoRequest StoreTodoRequest) Store(store *BoltStore, user string) error {
|
|
|
|
|
todo := Todo{
|
|
|
|
|
Name: todoRequest.Name,
|
|
|
|
|
Description: todoRequest.Description,
|
|
|
|
|
Status: todoRequest.Status,
|
|
|
|
|
Owner: user,
|
|
|
|
|
}
|
|
|
|
|
todoJson, err := json.Marshal(todo)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
return store.SaveValueToBucket(user, todo.Name, string(todoJson))
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-23 19:14:16 +02:00
|
|
|
func (todoList TodoList) FindByName(name string) (Todo, bool) {
|
|
|
|
|
for _, todo := range todoList.Todos {
|
2025-07-26 23:31:00 +02:00
|
|
|
if todo.Name == name {
|
|
|
|
|
return todo, true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return Todo{}, false
|
|
|
|
|
}
|
2025-08-23 19:14:16 +02:00
|
|
|
|
|
|
|
|
func (todo Todo) PrintIndexed(index int) {
|
|
|
|
|
var statusColor string
|
|
|
|
|
|
|
|
|
|
// Select color based on the status (case-insensitive)
|
|
|
|
|
switch strings.ToLower(todo.Status) {
|
|
|
|
|
case Done:
|
|
|
|
|
statusColor = ColorGreen
|
|
|
|
|
case WIP:
|
|
|
|
|
statusColor = ColorYellow
|
|
|
|
|
case Pending:
|
|
|
|
|
statusColor = ColorBlue
|
|
|
|
|
case Blocked, Failed:
|
|
|
|
|
statusColor = ColorRed
|
|
|
|
|
default:
|
|
|
|
|
statusColor = ColorReset // No color for unknown statuses
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fmt.Printf("%d) %s - %s%s%s\n", index, todo.Name, statusColor, strings.ToUpper(todo.Status), ColorReset)
|
|
|
|
|
|
|
|
|
|
fmt.Printf("\t%s\n", todo.Description)
|
|
|
|
|
}
|