diff options
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/api/trello.go | 11 | ||||
| -rw-r--r-- | internal/store/sqlite.go | 8 |
2 files changed, 17 insertions, 2 deletions
diff --git a/internal/api/trello.go b/internal/api/trello.go index cecf0dc..b9391d6 100644 --- a/internal/api/trello.go +++ b/internal/api/trello.go @@ -6,6 +6,7 @@ import ( "fmt" "io" "net/http" + "sort" "sync" "time" @@ -216,6 +217,16 @@ func (c *TrelloClient) GetBoardsWithCards(ctx context.Context) ([]models.Board, wg.Wait() + // Sort boards: Non-empty boards first, then alphabetical by name + sort.Slice(boards, func(i, j int) bool { + hasCardsI := len(boards[i].Cards) > 0 + hasCardsJ := len(boards[j].Cards) > 0 + if hasCardsI != hasCardsJ { + return hasCardsI // true (non-empty) comes before false + } + return boards[i].Name < boards[j].Name + }) + return boards, nil } diff --git a/internal/store/sqlite.go b/internal/store/sqlite.go index e2b0aee..5063336 100644 --- a/internal/store/sqlite.go +++ b/internal/store/sqlite.go @@ -424,9 +424,13 @@ func (s *Store) SaveBoards(boards []models.Board) error { // GetBoards retrieves all boards with their cards from the database func (s *Store) GetBoards() ([]models.Board, error) { - // Fetch boards + // Fetch boards, sorted by: non-empty boards first, then alphabetical boardRows, err := s.db.Query(` - SELECT id, name FROM boards ORDER BY name + SELECT b.id, b.name + FROM boards b + ORDER BY + CASE WHEN (SELECT COUNT(*) FROM cards c WHERE c.board_id = b.id) > 0 THEN 0 ELSE 1 END, + b.name `) if err != nil { return nil, err |
