-
Notifications
You must be signed in to change notification settings - Fork 14
api methods for estimates feature #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,204 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from typing import Any | ||
|
|
||
| from ..models.estimates import ( | ||
| CreateEstimate, | ||
| CreateEstimatePoint, | ||
| Estimate, | ||
| EstimatePoint, | ||
| UpdateEstimate, | ||
| UpdateEstimatePoint, | ||
| ) | ||
| from .base_resource import BaseResource | ||
|
|
||
|
|
||
| class Estimates(BaseResource): | ||
| """Resource for managing project estimates and estimate points.""" | ||
|
|
||
| def __init__(self, config: Any) -> None: | ||
| super().__init__(config, "/workspaces/") | ||
|
|
||
| # ── Estimate CRUD ──────────────────────────────────────────── | ||
|
|
||
| def create( | ||
| self, | ||
| workspace_slug: str, | ||
| project_id: str, | ||
| data: CreateEstimate, | ||
| ) -> Estimate: | ||
| """Create a new estimate for a project. | ||
|
|
||
| Args: | ||
| workspace_slug: The workspace slug identifier. | ||
| project_id: UUID of the project. | ||
| data: Estimate creation data. | ||
| """ | ||
| response = self._post( | ||
| f"{workspace_slug}/projects/{project_id}/estimates", | ||
| data.model_dump(exclude_none=True), | ||
| ) | ||
| return Estimate.model_validate(response) | ||
|
|
||
| def link_to_project( | ||
| self, | ||
| workspace_slug: str, | ||
| project_id: str, | ||
| estimate_id: str, | ||
| ) -> Any: | ||
| """Link an estimate to a project so that it becomes the active estimate system. | ||
|
|
||
| Args: | ||
| workspace_slug: The workspace slug identifier. | ||
| project_id: UUID of the project. | ||
| estimate_id: UUID of the estimate to link. | ||
| """ | ||
| from ..models.projects import UpdateProject | ||
| from .projects import Projects | ||
|
|
||
| projects_client = Projects(self.config) | ||
| return projects_client.update( | ||
| workspace_slug, | ||
| project_id, | ||
| UpdateProject(estimate=estimate_id), | ||
| ) | ||
|
|
||
| def retrieve( | ||
| self, | ||
| workspace_slug: str, | ||
| project_id: str, | ||
| ) -> Estimate: | ||
| """Retrieve the estimate configured for a project. | ||
|
|
||
| Args: | ||
| workspace_slug: The workspace slug identifier. | ||
| project_id: UUID of the project. | ||
| """ | ||
| response = self._get( | ||
| f"{workspace_slug}/projects/{project_id}/estimates", | ||
| ) | ||
| return Estimate.model_validate(response) | ||
|
|
||
| def update( | ||
| self, | ||
| workspace_slug: str, | ||
| project_id: str, | ||
| data: UpdateEstimate, | ||
| ) -> Estimate: | ||
| """Update the estimate for a project. | ||
|
|
||
| Args: | ||
| workspace_slug: The workspace slug identifier. | ||
| project_id: UUID of the project. | ||
| data: Fields to update. | ||
| """ | ||
| response = self._patch( | ||
| f"{workspace_slug}/projects/{project_id}/estimates", | ||
| data.model_dump(exclude_none=True), | ||
| ) | ||
| return Estimate.model_validate(response) | ||
|
|
||
| def delete( | ||
| self, | ||
| workspace_slug: str, | ||
| project_id: str, | ||
| ) -> None: | ||
| """Delete the estimate for a project. | ||
|
|
||
| Args: | ||
| workspace_slug: The workspace slug identifier. | ||
| project_id: UUID of the project. | ||
| """ | ||
| return self._delete( | ||
| f"{workspace_slug}/projects/{project_id}/estimates", | ||
| ) | ||
|
|
||
| # ── Estimate Points ────────────────────────────────────────── | ||
|
|
||
| def list_points( | ||
| self, | ||
| workspace_slug: str, | ||
| project_id: str, | ||
| estimate_id: str, | ||
| ) -> list[EstimatePoint]: | ||
| """List all estimate points for a project estimate. | ||
|
|
||
| Args: | ||
| workspace_slug: The workspace slug identifier. | ||
| project_id: UUID of the project. | ||
| estimate_id: UUID of the estimate. | ||
| """ | ||
| response = self._get( | ||
| f"{workspace_slug}/projects/{project_id}" | ||
| f"/estimates/{estimate_id}/estimate-points", | ||
| ) | ||
| return [EstimatePoint.model_validate(item) for item in response] | ||
|
|
||
| def create_points( | ||
| self, | ||
| workspace_slug: str, | ||
| project_id: str, | ||
| estimate_id: str, | ||
| data: list[CreateEstimatePoint], | ||
| ) -> list[EstimatePoint]: | ||
| """Create estimate points for a project estimate. | ||
|
|
||
| The API accepts a JSON array directly as the request body. | ||
|
|
||
| Args: | ||
| workspace_slug: The workspace slug identifier. | ||
| project_id: UUID of the project. | ||
| estimate_id: UUID of the estimate. | ||
| data: List of estimate point creation data. | ||
| """ | ||
| payload = [item.model_dump(exclude_none=True) for item in data] | ||
| response = self._post( | ||
| f"{workspace_slug}/projects/{project_id}" | ||
| f"/estimates/{estimate_id}/estimate-points", | ||
| payload, | ||
| ) | ||
| return [EstimatePoint.model_validate(item) for item in response] | ||
|
|
||
| def update_point( | ||
| self, | ||
| workspace_slug: str, | ||
| project_id: str, | ||
| estimate_id: str, | ||
| estimate_point_id: str, | ||
| data: UpdateEstimatePoint, | ||
| ) -> EstimatePoint: | ||
| """Update a single estimate point. | ||
|
|
||
| Args: | ||
| workspace_slug: The workspace slug identifier. | ||
| project_id: UUID of the project. | ||
| estimate_id: UUID of the estimate. | ||
| estimate_point_id: UUID of the estimate point. | ||
| data: Fields to update. | ||
| """ | ||
| response = self._patch( | ||
| f"{workspace_slug}/projects/{project_id}" | ||
| f"/estimates/{estimate_id}/estimate-points/{estimate_point_id}", | ||
| data.model_dump(exclude_none=True), | ||
| ) | ||
| return EstimatePoint.model_validate(response) | ||
|
|
||
| def delete_point( | ||
| self, | ||
| workspace_slug: str, | ||
| project_id: str, | ||
| estimate_id: str, | ||
| estimate_point_id: str, | ||
| ) -> None: | ||
| """Delete a single estimate point. | ||
|
|
||
| Args: | ||
| workspace_slug: The workspace slug identifier. | ||
| project_id: UUID of the project. | ||
| estimate_id: UUID of the estimate. | ||
| estimate_point_id: UUID of the estimate point. | ||
| """ | ||
| return self._delete( | ||
| f"{workspace_slug}/projects/{project_id}" | ||
| f"/estimates/{estimate_id}/estimate-points/{estimate_point_id}", | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The estimate CRUD methods only address the active project estimate.
link_to_project(..., estimate_id)and all point operations already show that estimates are individual records, butretrieve(),update(), anddelete()only acceptproject_id. After more than one estimate exists, callers have no way to target a specific non-active estimate for read/update/delete.Also applies to: 66-114, 118-204
🤖 Prompt for AI Agents