forked from github/plane
feat: bulk create endpoint for estimate points (#708)
* feat: bulk create endpoint for estimate points * dev: remove integrity logic and update url
This commit is contained in:
parent
105428894f
commit
6a579f85ad
@ -83,6 +83,7 @@ from plane.api.views import (
|
|||||||
EstimateViewSet,
|
EstimateViewSet,
|
||||||
EstimatePointViewSet,
|
EstimatePointViewSet,
|
||||||
ProjectEstimatePointEndpoint,
|
ProjectEstimatePointEndpoint,
|
||||||
|
BulkCreateEstimatePointEndpoint,
|
||||||
## End Estimates
|
## End Estimates
|
||||||
# Shortcuts
|
# Shortcuts
|
||||||
ShortCutViewSet,
|
ShortCutViewSet,
|
||||||
@ -534,6 +535,11 @@ urlpatterns = [
|
|||||||
ProjectEstimatePointEndpoint.as_view(),
|
ProjectEstimatePointEndpoint.as_view(),
|
||||||
name="project-estimate-points",
|
name="project-estimate-points",
|
||||||
),
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/estimates/<uuid:estimate_id>/bulk-create-estimate-points/",
|
||||||
|
BulkCreateEstimatePointEndpoint.as_view(),
|
||||||
|
name="bulk-create-estimate-points",
|
||||||
|
),
|
||||||
# End States ##
|
# End States ##
|
||||||
# Shortcuts
|
# Shortcuts
|
||||||
path(
|
path(
|
||||||
@ -753,7 +759,7 @@ urlpatterns = [
|
|||||||
name="project-issue-labels",
|
name="project-issue-labels",
|
||||||
),
|
),
|
||||||
path(
|
path(
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/bulk-create-labels/",
|
"workspaces/<str:slug>/projects/<uuid:project_id>/lk-create-labels/",
|
||||||
BulkCreateIssueLabelsEndpoint.as_view(),
|
BulkCreateIssueLabelsEndpoint.as_view(),
|
||||||
name="project-bulk-labels",
|
name="project-bulk-labels",
|
||||||
),
|
),
|
||||||
|
@ -135,4 +135,5 @@ from .estimate import (
|
|||||||
EstimateViewSet,
|
EstimateViewSet,
|
||||||
EstimatePointViewSet,
|
EstimatePointViewSet,
|
||||||
ProjectEstimatePointEndpoint,
|
ProjectEstimatePointEndpoint,
|
||||||
|
BulkCreateEstimatePointEndpoint,
|
||||||
)
|
)
|
||||||
|
@ -135,3 +135,50 @@ class ProjectEstimatePointEndpoint(BaseAPIView):
|
|||||||
{"error": "Something went wrong please try again later"},
|
{"error": "Something went wrong please try again later"},
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class BulkCreateEstimatePointEndpoint(BaseAPIView):
|
||||||
|
def post(self, request, slug, project_id, estimate_id):
|
||||||
|
try:
|
||||||
|
estimate = Estimate.objects.get(
|
||||||
|
pk=estimate_id, workspace__slug=slug, project=project_id
|
||||||
|
)
|
||||||
|
|
||||||
|
estimate_points = request.data.get("estimate_points", [])
|
||||||
|
|
||||||
|
if not len(estimate_points) or len(estimate_points) > 8:
|
||||||
|
return Response(
|
||||||
|
{"error": "Estimate points are required"},
|
||||||
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
|
)
|
||||||
|
|
||||||
|
estimate_points = EstimatePoint.objects.bulk_create(
|
||||||
|
[
|
||||||
|
EstimatePoint(
|
||||||
|
estimate=estimate,
|
||||||
|
key=estimate_point.get("key", 0),
|
||||||
|
value=estimate_point.get("value", ""),
|
||||||
|
description=estimate_point.get("description", ""),
|
||||||
|
project_id=project_id,
|
||||||
|
workspace_id=estimate.workspace_id,
|
||||||
|
)
|
||||||
|
for estimate_point in estimate_points
|
||||||
|
],
|
||||||
|
batch_size=10,
|
||||||
|
ignore_conflicts=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
serializer = EstimatePointSerializer(estimate_points, many=True)
|
||||||
|
|
||||||
|
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||||
|
except Estimate.DoesNotExist:
|
||||||
|
return Response(
|
||||||
|
{"error": "Estimate does not exist"},
|
||||||
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
capture_exception(e)
|
||||||
|
return Response(
|
||||||
|
{"error": "Something went wrong please try again later"},
|
||||||
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
|
)
|
||||||
|
@ -27,7 +27,6 @@ class EstimatePoint(ProjectBaseModel):
|
|||||||
"db.Estimate",
|
"db.Estimate",
|
||||||
on_delete=models.CASCADE,
|
on_delete=models.CASCADE,
|
||||||
related_name="points",
|
related_name="points",
|
||||||
limit_choices_to={"estimate__points__count__lt": 10},
|
|
||||||
)
|
)
|
||||||
key = models.IntegerField(
|
key = models.IntegerField(
|
||||||
default=0, validators=[MinValueValidator(0), MaxValueValidator(7)]
|
default=0, validators=[MinValueValidator(0), MaxValueValidator(7)]
|
||||||
|
Loading…
Reference in New Issue
Block a user