From 48b9f532a40a475ec2125fe599b4da760e62a135 Mon Sep 17 00:00:00 2001 From: Jonas Date: Wed, 21 Apr 2021 10:26:04 +0200 Subject: [PATCH] registration controllers update --- Backend/Controllers/Polls/GetVote.php | 18 +++++++- .../Registration/NewRegistration.php | 31 ++++++++++++++ .../Registration/UpdateRegistration.php | 26 ++++++++++++ composer.json | 1 + composer.lock | 41 ++++++++++--------- 5 files changed, 96 insertions(+), 21 deletions(-) diff --git a/Backend/Controllers/Polls/GetVote.php b/Backend/Controllers/Polls/GetVote.php index 14e1497..3b7a72c 100644 --- a/Backend/Controllers/Polls/GetVote.php +++ b/Backend/Controllers/Polls/GetVote.php @@ -1,13 +1,29 @@ "game data not found"]); + exit(); + } + $reg = Registration::where("game_data_id", $gameDate->id)->first(); + $group = groupViaToken($_SESSION['token']); + if($reg->group_id !== $group->id){ + http_response_code(401); + echo json_encode(["message" => "group not own game data"]); + } + header('Content-Type: application/json;charset=UTF-8'); - echo json_encode(array('data' => Vote::where('group_id', groupViaToken($_SESSION['token'])->id)->get()->jsonSerialize())); + echo json_encode(array('data' => Vote::where('game_data_id',$gameDate->id)->get()->jsonSerialize())); } else { http_response_code(401); diff --git a/Backend/Controllers/Registration/NewRegistration.php b/Backend/Controllers/Registration/NewRegistration.php index b3d9bbc..7ce8c47 100644 --- a/Backend/Controllers/Registration/NewRegistration.php +++ b/Backend/Controllers/Registration/NewRegistration.php @@ -1 +1,32 @@ id)->where("game_jam_id", $gameJam->id)->count() === 0){ + $reg = new Registration(); + $reg->group_amount = $_POST["groupAmount"]; + $reg->group()->associate($group); + $reg->gameJam()->associate($gameJam); + if($reg->save()){ + http_response_code(201); + }else{ + http_response_code(500); + } + }else { + http_response_code(400); + echo json_encode(["message" => "already registered"]); + } + }else { + http_response_code(400); + } +}else{ + http_response_code(401); + echo json_encode(["message" => "is not login"]); +} + diff --git a/Backend/Controllers/Registration/UpdateRegistration.php b/Backend/Controllers/Registration/UpdateRegistration.php index b3d9bbc..4c2451f 100644 --- a/Backend/Controllers/Registration/UpdateRegistration.php +++ b/Backend/Controllers/Registration/UpdateRegistration.php @@ -1 +1,27 @@ where("game_jam_id", $_POST["gameJamId"])->first()){ + $reg->group_amount = $_POST["groupAmount"]; + if($reg->save()){ + http_response_code(200); + }else{ + http_response_code(500); + } + }else{ + http_response_code(400); + echo json_encode(["message" => "registration does not exits"]); + } + + }else{ + http_response_code(400); + } +}else{ + http_response_code(401); + echo json_encode(["message" => "is not login"]); +} diff --git a/composer.json b/composer.json index 5eeebd5..2cbb74c 100755 --- a/composer.json +++ b/composer.json @@ -4,6 +4,7 @@ "ext-mysqli": "*", "ext-sqlite3": "*", "ext-fileinfo": "*", + "ext-json": "*", "twbs/bootstrap": "5.0.0-beta3" }, "autoload": { diff --git a/composer.lock b/composer.lock index 1f7eb62..71153e6 100755 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "a595c493fc068e54510775d5cd53d649", + "content-hash": "e0289598393b91834d5fbd72b92a029a", "packages": [ { "name": "doctrine/inflector", @@ -103,16 +103,16 @@ }, { "name": "illuminate/collections", - "version": "v8.37.0", + "version": "v8.38.0", "source": { "type": "git", "url": "https://github.com/illuminate/collections.git", - "reference": "591e31015a8b0731708c54411cb52d50a00b2bc3" + "reference": "21690cd5591f2d42d792e5e4a687f9beba829f1d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/illuminate/collections/zipball/591e31015a8b0731708c54411cb52d50a00b2bc3", - "reference": "591e31015a8b0731708c54411cb52d50a00b2bc3", + "url": "https://api.github.com/repos/illuminate/collections/zipball/21690cd5591f2d42d792e5e4a687f9beba829f1d", + "reference": "21690cd5591f2d42d792e5e4a687f9beba829f1d", "shasum": "" }, "require": { @@ -153,11 +153,11 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2021-04-01T13:26:52+00:00" + "time": "2021-04-14T11:48:08+00:00" }, { "name": "illuminate/container", - "version": "v8.37.0", + "version": "v8.38.0", "source": { "type": "git", "url": "https://github.com/illuminate/container.git", @@ -208,7 +208,7 @@ }, { "name": "illuminate/contracts", - "version": "v8.37.0", + "version": "v8.38.0", "source": { "type": "git", "url": "https://github.com/illuminate/contracts.git", @@ -256,16 +256,16 @@ }, { "name": "illuminate/database", - "version": "v8.37.0", + "version": "v8.38.0", "source": { "type": "git", "url": "https://github.com/illuminate/database.git", - "reference": "a9d9c78c705bc64e92a61c33453ebbcad6dd5f29" + "reference": "03c0525b693587f877f4d80dcc55597528c98fc0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/illuminate/database/zipball/a9d9c78c705bc64e92a61c33453ebbcad6dd5f29", - "reference": "a9d9c78c705bc64e92a61c33453ebbcad6dd5f29", + "url": "https://api.github.com/repos/illuminate/database/zipball/03c0525b693587f877f4d80dcc55597528c98fc0", + "reference": "03c0525b693587f877f4d80dcc55597528c98fc0", "shasum": "" }, "require": { @@ -320,11 +320,11 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2021-04-13T13:40:36+00:00" + "time": "2021-04-17T17:53:05+00:00" }, { "name": "illuminate/macroable", - "version": "v8.37.0", + "version": "v8.38.0", "source": { "type": "git", "url": "https://github.com/illuminate/macroable.git", @@ -370,16 +370,16 @@ }, { "name": "illuminate/support", - "version": "v8.37.0", + "version": "v8.38.0", "source": { "type": "git", "url": "https://github.com/illuminate/support.git", - "reference": "074a9b7adefcdd7108e19faa96bc9dacfe922062" + "reference": "735391f31e145aad4f7aff3d9736ef70452dd1fe" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/illuminate/support/zipball/074a9b7adefcdd7108e19faa96bc9dacfe922062", - "reference": "074a9b7adefcdd7108e19faa96bc9dacfe922062", + "url": "https://api.github.com/repos/illuminate/support/zipball/735391f31e145aad4f7aff3d9736ef70452dd1fe", + "reference": "735391f31e145aad4f7aff3d9736ef70452dd1fe", "shasum": "" }, "require": { @@ -434,7 +434,7 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2021-04-11T23:26:41+00:00" + "time": "2021-04-15T11:51:39+00:00" }, { "name": "nesbot/carbon", @@ -1686,7 +1686,8 @@ "platform": { "ext-mysqli": "*", "ext-sqlite3": "*", - "ext-fileinfo": "*" + "ext-fileinfo": "*", + "ext-json": "*" }, "platform-dev": [], "plugin-api-version": "2.0.0"