pelican/status.go

83 lines
1.4 KiB
Go
Raw Normal View History

package main
2021-09-15 10:23:19 +01:00
import (
"fmt"
"sort"
bolt "go.etcd.io/bbolt"
)
// Status represents the status of the Kanban board.
type Status struct {
ID int
Name string
CardIds []int
2021-09-15 10:23:19 +01:00
Order int
}
2021-09-15 10:23:19 +01:00
// ByStatusOrder implements sort.Interface for []Status based on the Order field.
type ByStatusOrder []Status
func (s ByStatusOrder) Len() int {
return len(s)
}
func (s ByStatusOrder) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}
func (s ByStatusOrder) Less(i, j int) bool {
return s[i].Order < s[j].Order
}
2021-09-16 06:51:21 +01:00
// readStatuses returns an ordered list of statuses from the database.
2021-09-15 10:23:19 +01:00
// TODO: function needs to be unit tested.
func readStatuses(db *bolt.DB) ([]Status, error) {
statuses, err := loadAllStatuses(db)
if err != nil {
return statuses, fmt.Errorf("unable to read statuses, %w", err)
}
sort.Sort(ByStatusOrder(statuses))
return statuses, nil
}
2021-09-16 06:51:21 +01:00
func readStatus(db *bolt.DB) (Status, error) {
return Status{}, nil
}
func createStatus(db *bolt.DB) error {
return nil
}
func updateStatus(db *bolt.DB) error {
return nil
}
func deleteStatus(db *bolt.DB) error {
return nil
}
// newDefaultStatusList creates the default list of statuses and saves the statuses to the database.
// TODO: function needs to be unit tested.
func newDefaultStatusList() []Status {
return []Status{
2021-09-15 10:23:19 +01:00
{
2021-09-16 06:51:21 +01:00
ID: -1,
2021-09-15 10:23:19 +01:00
Name: "To Do",
Order: 1,
},
{
2021-09-16 06:51:21 +01:00
ID: -1,
2021-09-15 10:23:19 +01:00
Name: "Doing",
Order: 2,
},
{
2021-09-16 06:51:21 +01:00
ID: -1,
2021-09-15 10:23:19 +01:00
Name: "Done",
Order: 3,
},
}
}