from dooray_mcp.services import template_api
from dooray_mcp.types.common import ControllerResponse
from dooray_mcp.types.template import CreateTemplateParams, UpdateTemplateParams
async def list_templates(project_id: str, page: int = 0, size: int = 20) -> ControllerResponse:
result = await template_api.list_templates(project_id, page, size)
if not result.contents:
return ControllerResponse(content="No templates found.")
lines = [f"Found {result.total_count} templates:\n"]
for tmpl in result.contents:
lines.append(f"- **{tmpl.name}** (ID: {tmpl.id})")
lines.append(f" - Created: {tmpl.created_at or 'N/A'}")
lines.append("")
return ControllerResponse(content="\n".join(lines))
async def get_template(project_id: str, template_id: str) -> ControllerResponse:
tmpl = await template_api.get_template(project_id, template_id)
body_content = ""
if tmpl.body:
body_content = tmpl.body.content
lines = [
f"# {tmpl.name}",
"",
f"- **ID**: {tmpl.id}",
f"- **Created**: {tmpl.created_at or 'N/A'}",
f"- **Updated**: {tmpl.updated_at or 'N/A'}",
]
if body_content:
lines.extend(["", "## Content", "", body_content])
return ControllerResponse(content="\n".join(lines))
async def create_template(
project_id: str, name: str, body: str, body_mime_type: str = "text/x-markdown"
) -> ControllerResponse:
params = CreateTemplateParams(name=name, body=body, body_mime_type=body_mime_type)
tmpl = await template_api.create_template(project_id, params)
return ControllerResponse(
content=f"Template created successfully. (ID: {tmpl.id}, Name: {tmpl.name})"
)
async def update_template(
project_id: str,
template_id: str,
name: str | None = None,
body: str | None = None,
body_mime_type: str = "text/x-markdown",
) -> ControllerResponse:
params = UpdateTemplateParams(name=name, body=body, body_mime_type=body_mime_type)
tmpl = await template_api.update_template(project_id, template_id, params)
return ControllerResponse(content=f"Template updated successfully. (ID: {tmpl.id})")
async def delete_template(project_id: str, template_id: str) -> ControllerResponse:
await template_api.delete_template(project_id, template_id)
return ControllerResponse(content=f"Template deleted successfully. (ID: {template_id})")