From 984441d03359c8669fede95d4fb8c89ced644ca3 Mon Sep 17 00:00:00 2001 From: Administrator Date: Thu, 25 Aug 2022 11:45:48 +0300 Subject: [PATCH] get field --- battleship/views.py | 12 ++++++++++++ battleship_back/urls.py | 3 ++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/battleship/views.py b/battleship/views.py index 1b7ca34..ce87eaf 100644 --- a/battleship/views.py +++ b/battleship/views.py @@ -143,3 +143,15 @@ def check_field_correct(request): return JsonResponse({ 'correct': correct }) + + +def get_field(request): + if request.method == 'OPTIONS': + return JsonResponse({}) + data = json.loads(request.body.decode('utf-8')) + player = Player.objects.get(game_id=data['gam_id'], token=data['token']).one() + cells = list(player.field) + cells = [cells[x * 10: (x + 1) * 10] for x in range(0, 10)] + return JsonResponse({ + 'field': cells + }) diff --git a/battleship_back/urls.py b/battleship_back/urls.py index db009bd..fc0bc19 100644 --- a/battleship_back/urls.py +++ b/battleship_back/urls.py @@ -26,5 +26,6 @@ urlpatterns = [ path('api/attend_game', views.attend_game), path('api/place_ships', views.place_ships), path('api/shoot', views.shoot), - path('api/check_field_correct', views.check_field_correct) + path('api/check_field_correct', views.check_field_correct), + path('api/get_field', views.get_field) ]