-
Notifications
You must be signed in to change notification settings - Fork 9
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
TreatmentPrescription bulk delete endpoint + tests (PLAN-1504) #1670
Changes from all commits
bc7d70b
1209303
0cae3cf
008f2ab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
TreatmentPlanSerializer, | ||
TreatmentPrescriptionSerializer, | ||
TreatmentPrescriptionListSerializer, | ||
TreatmentPrescriptionBatchDeleteSerializer, | ||
UpsertTreamentPrescriptionSerializer, | ||
) | ||
from impacts.services import ( | ||
|
@@ -191,3 +192,20 @@ def create(self, request, *args, **kwargs): | |
|
||
def perform_create(self, serializer): | ||
return upsert_treatment_prescriptions(**serializer.validated_data) | ||
|
||
@action(detail=False, methods=["post"]) | ||
def delete_prescriptions(self, request, tx_plan_pk=None): | ||
serializer = TreatmentPrescriptionBatchDeleteSerializer(data=request.data) | ||
|
||
if not serializer.is_valid(): | ||
return response.Response( | ||
serializer.errors, status=status.HTTP_400_BAD_REQUEST | ||
) | ||
|
||
stand_ids = serializer.validated_data.get("stand_ids", []) | ||
|
||
delete_result = TreatmentPrescription.objects.filter( | ||
stand_id__in=stand_ids, treatment_plan_id=tx_plan_pk | ||
).delete() | ||
Comment on lines
+207
to
+209
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a product question to do to Jordan: in other endpoints we record an actstream about deletions. Should we log this interaction as well? If the answer is yes, then the actstrem format is a bit different, but it should be possible to log it with a method on our service module. |
||
|
||
return response.Response({"result": delete_result}, status=status.HTTP_200_OK) |
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.
Much nicer!