forked from github/plane
feat: add endpoint for draft cycles and add validation for creating draft cycles (#355)
* feat: add endpoint for draft cycles and add validation for creating draft cycles * fix: key error in cycle create endpoint
This commit is contained in:
parent
27653907f9
commit
3a81a6c186
@ -83,6 +83,7 @@ from plane.api.views import (
|
|||||||
CycleDateCheckEndpoint,
|
CycleDateCheckEndpoint,
|
||||||
CurrentUpcomingCyclesEndpoint,
|
CurrentUpcomingCyclesEndpoint,
|
||||||
CompletedCyclesEndpoint,
|
CompletedCyclesEndpoint,
|
||||||
|
DraftCyclesEndpoint,
|
||||||
## End Cycles
|
## End Cycles
|
||||||
# Modules
|
# Modules
|
||||||
ModuleViewSet,
|
ModuleViewSet,
|
||||||
@ -503,12 +504,17 @@ urlpatterns = [
|
|||||||
path(
|
path(
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/cycles/current-upcoming-cycles/",
|
"workspaces/<str:slug>/projects/<uuid:project_id>/cycles/current-upcoming-cycles/",
|
||||||
CurrentUpcomingCyclesEndpoint.as_view(),
|
CurrentUpcomingCyclesEndpoint.as_view(),
|
||||||
name="project-cycle",
|
name="project-cycle-upcoming",
|
||||||
),
|
),
|
||||||
path(
|
path(
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/cycles/completed-cycles/",
|
"workspaces/<str:slug>/projects/<uuid:project_id>/cycles/completed-cycles/",
|
||||||
CompletedCyclesEndpoint.as_view(),
|
CompletedCyclesEndpoint.as_view(),
|
||||||
name="project-cycle",
|
name="project-cycle-completed",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/cycles/draft-cycles/",
|
||||||
|
DraftCyclesEndpoint.as_view(),
|
||||||
|
name="project-cycle-draft",
|
||||||
),
|
),
|
||||||
## End Cycles
|
## End Cycles
|
||||||
# Issue
|
# Issue
|
||||||
|
@ -45,6 +45,7 @@ from .cycle import (
|
|||||||
CycleDateCheckEndpoint,
|
CycleDateCheckEndpoint,
|
||||||
CurrentUpcomingCyclesEndpoint,
|
CurrentUpcomingCyclesEndpoint,
|
||||||
CompletedCyclesEndpoint,
|
CompletedCyclesEndpoint,
|
||||||
|
DraftCyclesEndpoint,
|
||||||
)
|
)
|
||||||
from .asset import FileAssetEndpoint
|
from .asset import FileAssetEndpoint
|
||||||
from .issue import (
|
from .issue import (
|
||||||
|
@ -45,6 +45,37 @@ class CycleViewSet(BaseViewSet):
|
|||||||
.distinct()
|
.distinct()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def create(self, request, slug, project_id):
|
||||||
|
try:
|
||||||
|
if (
|
||||||
|
request.data.get("start_date", None) is None
|
||||||
|
and request.data.get("end_date", None) is None
|
||||||
|
) or (
|
||||||
|
request.data.get("start_date", None) is not None
|
||||||
|
and request.data.get("end_date", None) is not None
|
||||||
|
):
|
||||||
|
serializer = CycleSerializer(data=request.data)
|
||||||
|
if serializer.is_valid():
|
||||||
|
serializer.save(
|
||||||
|
project_id=project_id,
|
||||||
|
owned_by=request.user,
|
||||||
|
)
|
||||||
|
return Response(serializer.data, status=status.HTTP_201_CREATED)
|
||||||
|
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
else:
|
||||||
|
return Response(
|
||||||
|
{
|
||||||
|
"error": "Both start date and end date are either required or are to be null"
|
||||||
|
},
|
||||||
|
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,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class CycleIssueViewSet(BaseViewSet):
|
class CycleIssueViewSet(BaseViewSet):
|
||||||
serializer_class = CycleIssueSerializer
|
serializer_class = CycleIssueSerializer
|
||||||
@ -275,7 +306,7 @@ class CurrentUpcomingCyclesEndpoint(BaseAPIView):
|
|||||||
class CompletedCyclesEndpoint(BaseAPIView):
|
class CompletedCyclesEndpoint(BaseAPIView):
|
||||||
def get(self, request, slug, project_id):
|
def get(self, request, slug, project_id):
|
||||||
try:
|
try:
|
||||||
past_cycles = Cycle.objects.filter(
|
completed_cycles = Cycle.objects.filter(
|
||||||
workspace__slug=slug,
|
workspace__slug=slug,
|
||||||
project_id=project_id,
|
project_id=project_id,
|
||||||
end_date__lte=timezone.now(),
|
end_date__lte=timezone.now(),
|
||||||
@ -283,7 +314,9 @@ class CompletedCyclesEndpoint(BaseAPIView):
|
|||||||
|
|
||||||
return Response(
|
return Response(
|
||||||
{
|
{
|
||||||
"past_cycles": CycleSerializer(past_cycles, many=True).data,
|
"completed_cycles": CycleSerializer(
|
||||||
|
completed_cycles, many=True
|
||||||
|
).data,
|
||||||
},
|
},
|
||||||
status=status.HTTP_200_OK,
|
status=status.HTTP_200_OK,
|
||||||
)
|
)
|
||||||
@ -294,3 +327,25 @@ class CompletedCyclesEndpoint(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 DraftCyclesEndpoint(BaseAPIView):
|
||||||
|
def get(self, request, slug, project_id):
|
||||||
|
try:
|
||||||
|
draft_cycles = Cycle.objects.filter(
|
||||||
|
workspace__slug=slug,
|
||||||
|
project_id=project_id,
|
||||||
|
end_date=None,
|
||||||
|
start_date=None,
|
||||||
|
)
|
||||||
|
|
||||||
|
return Response(
|
||||||
|
{"draft_cycles": CycleSerializer(draft_cycles, many=True).data},
|
||||||
|
status=status.HTTP_200_OK,
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
capture_exception(e)
|
||||||
|
return Response(
|
||||||
|
{"error": "Something went wrong please try again later"},
|
||||||
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user