|
| 1 | +from typing import Any |
| 2 | + |
| 3 | +from ...models.project_templates import ( |
| 4 | + CreateWorkItemTemplate, |
| 5 | + UpdateWorkItemTemplate, |
| 6 | + WorkItemTemplate, |
| 7 | +) |
| 8 | +from ..base_resource import BaseResource |
| 9 | + |
| 10 | + |
| 11 | +class ProjectWorkItemTemplates(BaseResource): |
| 12 | + """API client for managing work item templates within a project.""" |
| 13 | + |
| 14 | + def __init__(self, config: Any) -> None: |
| 15 | + super().__init__(config, "/workspaces/") |
| 16 | + |
| 17 | + def list(self, workspace_slug: str, project_id: str) -> list[WorkItemTemplate]: |
| 18 | + """List all work item templates for a project. |
| 19 | +
|
| 20 | + Args: |
| 21 | + workspace_slug: The workspace slug identifier |
| 22 | + project_id: UUID of the project |
| 23 | +
|
| 24 | + Returns: |
| 25 | + List of work item templates |
| 26 | + """ |
| 27 | + data = self._get(f"{workspace_slug}/projects/{project_id}/workitems/templates/") |
| 28 | + items = data.get("results", data) if isinstance(data, dict) else data |
| 29 | + return [WorkItemTemplate.model_validate(item) for item in items] |
| 30 | + |
| 31 | + def create( |
| 32 | + self, |
| 33 | + workspace_slug: str, |
| 34 | + project_id: str, |
| 35 | + data: CreateWorkItemTemplate, |
| 36 | + ) -> WorkItemTemplate: |
| 37 | + """Create a new work item template for a project. |
| 38 | +
|
| 39 | + Args: |
| 40 | + workspace_slug: The workspace slug identifier |
| 41 | + project_id: UUID of the project |
| 42 | + data: Template data |
| 43 | +
|
| 44 | + Returns: |
| 45 | + The created work item template |
| 46 | + """ |
| 47 | + response = self._post( |
| 48 | + f"{workspace_slug}/projects/{project_id}/workitems/templates/", |
| 49 | + data.model_dump(exclude_none=True), |
| 50 | + ) |
| 51 | + return WorkItemTemplate.model_validate(response) |
| 52 | + |
| 53 | + def update( |
| 54 | + self, |
| 55 | + workspace_slug: str, |
| 56 | + project_id: str, |
| 57 | + template_id: str, |
| 58 | + data: UpdateWorkItemTemplate, |
| 59 | + ) -> WorkItemTemplate: |
| 60 | + """Update a work item template by ID. |
| 61 | +
|
| 62 | + Args: |
| 63 | + workspace_slug: The workspace slug identifier |
| 64 | + project_id: UUID of the project |
| 65 | + template_id: UUID of the template |
| 66 | + data: Updated template data |
| 67 | +
|
| 68 | + Returns: |
| 69 | + The updated work item template |
| 70 | + """ |
| 71 | + response = self._patch( |
| 72 | + f"{workspace_slug}/projects/{project_id}/workitems/templates/{template_id}", |
| 73 | + data.model_dump(exclude_none=True), |
| 74 | + ) |
| 75 | + return WorkItemTemplate.model_validate(response) |
| 76 | + |
| 77 | + def delete( |
| 78 | + self, |
| 79 | + workspace_slug: str, |
| 80 | + project_id: str, |
| 81 | + template_id: str, |
| 82 | + ) -> None: |
| 83 | + """Delete a work item template by ID. |
| 84 | +
|
| 85 | + Args: |
| 86 | + workspace_slug: The workspace slug identifier |
| 87 | + project_id: UUID of the project |
| 88 | + template_id: UUID of the template |
| 89 | + """ |
| 90 | + self._delete(f"{workspace_slug}/projects/{project_id}/workitems/templates/{template_id}/") |
0 commit comments