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) ]