summaryrefslogtreecommitdiff
path: root/internal/api/trello.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/api/trello.go')
-rw-r--r--internal/api/trello.go38
1 files changed, 28 insertions, 10 deletions
diff --git a/internal/api/trello.go b/internal/api/trello.go
index 5b87e30..9c18ade 100644
--- a/internal/api/trello.go
+++ b/internal/api/trello.go
@@ -128,9 +128,12 @@ func (c *TrelloClient) GetCards(ctx context.Context, boardID string) ([]models.C
// Fetch lists to get list names
lists, err := c.getLists(ctx, boardID)
- if err != nil {
- // If we can't get lists, continue with empty list names
- lists = make(map[string]string)
+ listMap := make(map[string]string)
+ if err == nil {
+ // Build map of list ID to name
+ for _, list := range lists {
+ listMap[list.ID] = list.Name
+ }
}
// Convert to our model
@@ -140,7 +143,7 @@ func (c *TrelloClient) GetCards(ctx context.Context, boardID string) ([]models.C
ID: apiCard.ID,
Name: apiCard.Name,
ListID: apiCard.IDList,
- ListName: lists[apiCard.IDList],
+ ListName: listMap[apiCard.IDList],
URL: apiCard.URL,
}
@@ -158,8 +161,8 @@ func (c *TrelloClient) GetCards(ctx context.Context, boardID string) ([]models.C
return cards, nil
}
-// getLists fetches lists for a board and returns a map of list ID to name
-func (c *TrelloClient) getLists(ctx context.Context, boardID string) (map[string]string, error) {
+// getLists fetches lists for a board
+func (c *TrelloClient) getLists(ctx context.Context, boardID string) ([]models.List, error) {
url := fmt.Sprintf("%s/boards/%s/lists?key=%s&token=%s", c.baseURL, boardID, c.apiKey, c.token)
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
@@ -183,15 +186,23 @@ func (c *TrelloClient) getLists(ctx context.Context, boardID string) (map[string
return nil, fmt.Errorf("failed to decode response: %w", err)
}
- // Convert to map
- lists := make(map[string]string, len(apiLists))
- for _, list := range apiLists {
- lists[list.ID] = list.Name
+ // Convert to model
+ lists := make([]models.List, 0, len(apiLists))
+ for _, apiList := range apiLists {
+ lists = append(lists, models.List{
+ ID: apiList.ID,
+ Name: apiList.Name,
+ })
}
return lists, nil
}
+// GetLists fetches lists for a specific board
+func (c *TrelloClient) GetLists(ctx context.Context, boardID string) ([]models.List, error) {
+ return c.getLists(ctx, boardID)
+}
+
// GetBoardsWithCards fetches all boards and their cards in one call
func (c *TrelloClient) GetBoardsWithCards(ctx context.Context) ([]models.Board, error) {
boards, err := c.GetBoards(ctx)
@@ -211,11 +222,18 @@ func (c *TrelloClient) GetBoardsWithCards(ctx context.Context) ([]models.Board,
sem <- struct{}{}
defer func() { <-sem }()
+ // Fetch cards
cards, err := c.GetCards(ctx, boards[i].ID)
if err == nil {
// It is safe to write to specific indices of the slice concurrently
boards[i].Cards = cards
}
+
+ // Fetch lists
+ lists, err := c.getLists(ctx, boards[i].ID)
+ if err == nil {
+ boards[i].Lists = lists
+ }
}(i)
}