File size: 4,917 Bytes
7360460 a65e06d 7360460 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
import logging
from typing import Dict, List, Optional
from pmcp.mcp_server.trello_server.utils.trello_api import TrelloClient
class ChecklistService:
"""
Service class for handling Trello checklist operations.
"""
def __init__(self, client: TrelloClient):
self.client = client
async def get_checklist(self, checklist_id: str) -> Dict:
"""
Get a specific checklist by ID.
Args:
checklist_id (str): The ID of the checklist to retrieve
Returns:
Dict: The checklist data
"""
return await self.client.GET(f"/checklists/{checklist_id}")
async def get_card_checklists(self, card_id: str) -> List[Dict]:
"""
Get all checklists for a specific card.
Args:
card_id (str): The ID of the card to get checklists for
Returns:
List[Dict]: List of checklists on the card
"""
return await self.client.GET(f"/cards/{card_id}/checklists")
async def create_checklist(
self, card_id: str, name: str, pos: Optional[str] = None
) -> Dict:
"""
Create a new checklist on a card.
Args:
card_id (str): The ID of the card to create the checklist on
name (str): The name of the checklist
pos (Optional[str]): The position of the checklist (top, bottom, or a positive number)
Returns:
Dict: The created checklist data
"""
data = {"name": name}
if pos:
data["pos"] = pos
return await self.client.POST(f"/checklists", data={"idCard": card_id, **data})
async def update_checklist(
self, checklist_id: str, name: Optional[str] = None, pos: Optional[str] = None
) -> Dict:
"""
Update an existing checklist.
Args:
checklist_id (str): The ID of the checklist to update
name (Optional[str]): New name for the checklist
pos (Optional[str]): New position for the checklist
Returns:
Dict: The updated checklist data
"""
data = {}
if name:
data["name"] = name
if pos:
data["pos"] = pos
return await self.client.PUT(f"/checklists/{checklist_id}", data=data)
async def delete_checklist(self, checklist_id: str) -> Dict:
"""
Delete a checklist.
Args:
checklist_id (str): The ID of the checklist to delete
Returns:
Dict: The response from the delete operation
"""
return await self.client.DELETE(f"/checklists/{checklist_id}")
async def add_checkitem(
self,
checklist_id: str,
name: str,
checked: bool = False,
pos: Optional[str] = None,
) -> Dict:
"""
Add a new item to a checklist.
Args:
checklist_id (str): The ID of the checklist to add the item to
name (str): The name of the checkitem
checked (bool): Whether the item is checked
pos (Optional[str]): The position of the item
Returns:
Dict: The created checkitem data
"""
data = {"name": name, "checked": checked}
if pos:
data["pos"] = pos
return await self.client.POST(
f"/checklists/{checklist_id}/checkItems", data=data
)
async def update_checkitem(
self,
checklist_id: str,
checkitem_id: str,
name: Optional[str] = None,
checked: Optional[bool] = None,
pos: Optional[str] = None,
) -> Dict:
"""
Update a checkitem in a checklist.
Args:
checklist_id (str): The ID of the checklist containing the item
checkitem_id (str): The ID of the checkitem to update
name (Optional[str]): New name for the checkitem
checked (Optional[bool]): New checked state
pos (Optional[str]): New position for the item
Returns:
Dict: The updated checkitem data
"""
data = {}
if name:
data["name"] = name
if checked is not None:
data["checked"] = checked
if pos:
data["pos"] = pos
return await self.client.PUT(
f"/checklists/{checklist_id}/checkItems/{checkitem_id}", data=data
)
async def delete_checkitem(self, checklist_id: str, checkitem_id: str) -> Dict:
"""
Delete a checkitem from a checklist.
Args:
checklist_id (str): The ID of the checklist containing the item
checkitem_id (str): The ID of the checkitem to delete
Returns:
Dict: The response from the delete operation
"""
return await self.client.DELETE(
f"/checklists/{checklist_id}/checkItems/{checkitem_id}"
)
|