Skip to content

Commit

Permalink
Merge pull request #36 from QRTaxi/yj
Browse files Browse the repository at this point in the history
feat: success 후 cancel 시 메시지 전송
  • Loading branch information
leehjhjhj authored Aug 15, 2023
2 parents 1237171 + f3c4f73 commit 2b3fd80
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
3 changes: 3 additions & 0 deletions call/consumers/receive_consumers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ def send_message(self, event):
'driver_id': driver_id,
'assign_id': assign_id,
})

def cancel(self, event_dict):
self.send_json(event_dict)
13 changes: 12 additions & 1 deletion call/models/assign.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,18 @@ def websocket_message(instance: Assign, created: bool):
"type": message_type,
"assign_id": assign_pk,
})


if instance.status == 'cancel' and instance.driver_id:
message_type = "cancel"
instance.channel_layer_group_send(
"drivers",
{
"assign_id": assign_pk,
"driver_id": instance.driver_id.id,
"type": message_type,
}
)

def call__on_post_save(instance: Assign, created: bool, **kwargs):
websocket_message(instance, created)

Expand Down
9 changes: 7 additions & 2 deletions call/services/call_cancel_service.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from call.models import Assign
from driver.models import CustomDriver
from rest_framework import exceptions

def cancel_call(cancel_call_data):
Expand All @@ -10,6 +11,10 @@ def cancel_call(cancel_call_data):
get_assign_info = Assign.objects.get(id=assign_id)
get_assign_info.status = 'cancel'
get_assign_info.save(update_fields=['status'])
if get_assign_info.driver_id is not None:
driver = get_assign_info.driver_id
get_driver_info = CustomDriver.objects.get(id=driver.id)
get_driver_info.is_able = True
get_driver_info.save(update_fields=['is_able'])
except Assign.DoesNotExist:
raise exceptions.NotFound("해당 데이터를 찾을 수 없습니다.")

raise exceptions.NotFound("해당 데이터를 찾을 수 없습니다.")

0 comments on commit 2b3fd80

Please sign in to comment.