Files
resolutionflow/backend/app/services/psa/connectwise/provider.py
Michael Chihlas 2a53f48d69 feat(psa): implement get_ticket in ConnectWise provider
Replace NotImplementedError stub with real implementation that fetches
a ticket by ID via CW REST API and maps it to PSATicket.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 22:44:58 -04:00

94 lines
3.3 KiB
Python

"""ConnectWise implementation of PSAProvider."""
from __future__ import annotations
from app.services.psa.base import PSAProvider
from app.services.psa.types import (
ConnectionTestResult,
PSATicket,
PSANote,
PSAStatus,
PSACompany,
PSAMember,
PSAConfiguration,
)
from .client import ConnectWiseClient
class ConnectWiseProvider(PSAProvider):
"""ConnectWise PSA provider implementation."""
def __init__(self, client: ConnectWiseClient):
self.client = client
async def test_connection(self) -> ConnectionTestResult:
"""Test the CW connection by fetching system info."""
try:
info = await self.client.get("/system/info")
return ConnectionTestResult(
success=True,
message="Connected successfully.",
server_version=info.get("version", None),
)
except Exception as e:
return ConnectionTestResult(
success=False,
message=str(e),
server_version=None,
)
# ── Stubs for Phase A slices 2-5 ─────────────────────────────────
async def get_ticket(self, ticket_id: str) -> PSATicket:
"""Fetch a single ticket by ID from ConnectWise."""
data = await self.client.get(
f"/service/tickets/{ticket_id}",
params={"fields": "id,summary,company,board,status,priority,closedFlag"},
)
return PSATicket(
id=str(data["id"]),
summary=data.get("summary", ""),
company_name=data.get("company", {}).get("name"),
company_id=str(data["company"]["id"]) if data.get("company") else None,
board_name=data.get("board", {}).get("name"),
board_id=data.get("board", {}).get("id"),
status_name=data.get("status", {}).get("name"),
status_id=data.get("status", {}).get("id"),
priority_name=data.get("priority", {}).get("name"),
priority_id=data.get("priority", {}).get("id"),
closed=data.get("closedFlag", False),
)
async def search_tickets(self, query: str, **filters) -> list[PSATicket]:
raise NotImplementedError("Implemented in Slice 3")
async def post_note(
self,
ticket_id: str,
text: str,
note_type: str,
member_id: str | None = None,
) -> PSANote:
raise NotImplementedError("Implemented in Slice 4")
async def update_ticket_status(
self, ticket_id: str, status_id: int
) -> PSATicket:
raise NotImplementedError("Implemented in Slice 4")
async def get_ticket_statuses(self, board_id: int) -> list[PSAStatus]:
raise NotImplementedError("Implemented in Slice 3")
async def list_companies(self, **filters) -> list[PSACompany]:
raise NotImplementedError("Implemented in Slice 3")
async def get_company(self, company_id: str) -> PSACompany:
raise NotImplementedError("Implemented in Slice 3")
async def list_members(self) -> list[PSAMember]:
raise NotImplementedError("Implemented in Slice 5")
async def get_ticket_configurations(
self, ticket_id: str
) -> list[PSAConfiguration]:
raise NotImplementedError("Implemented in Slice 3")