registration controllers update
This commit is contained in:
@@ -1,13 +1,29 @@
|
||||
<?php
|
||||
|
||||
use Backend\Models\GameData;
|
||||
use Backend\Models\Vote;
|
||||
use \Backend\Models\Registration;
|
||||
|
||||
require_once "../../../bootstrap.php";
|
||||
require_once "../Group/Group.php";
|
||||
|
||||
if (isLogin()) {
|
||||
|
||||
$gameDate = GameData::find($_GET[]);
|
||||
if(!$gameDate){
|
||||
http_response_code(400);
|
||||
echo json_encode(["message" => "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);
|
||||
|
||||
@@ -1 +1,32 @@
|
||||
<?php
|
||||
require_once "../../../bootstrap.php";
|
||||
require_once "../Group/Group.php";
|
||||
|
||||
use Backend\Models\Registration;
|
||||
|
||||
if(isLogin()){
|
||||
if(isset($_POST['newReg'])){
|
||||
$group = groupViaToken($_SESSION['token']);
|
||||
$gameJam = \Backend\Models\GameJam::find($_POST["gameJamId"]);
|
||||
if(Registration::where("group_id", $group->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"]);
|
||||
}
|
||||
|
||||
|
||||
@@ -1 +1,27 @@
|
||||
<?php
|
||||
require_once "../../../bootstrap.php";
|
||||
require_once "../Group/Group.php";
|
||||
|
||||
use Backend\Models\Registration;
|
||||
|
||||
if(isLogin()){
|
||||
if(isset($_POST['updateReg'])){
|
||||
if($reg = Registration::where("group_id", $_POST["groupId"])->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"]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user