bedder feedback on http response
This commit is contained in:
@@ -5,30 +5,39 @@ use Backend\Models\Group;
|
||||
use Backend\Models\Vote;
|
||||
use \Illuminate\Support\Collection;
|
||||
|
||||
if(isAdmin() && isset($_GET['gameJamId'])){
|
||||
$groups = Group::where('game_jam_id',$_GET['gameJamId'])->get();
|
||||
$winningGroups = new Collection();
|
||||
$i = -1;
|
||||
foreach ($groups as $group){
|
||||
$x = Vote::where('group_id', $group->id)->count();
|
||||
if($x>$i){
|
||||
if(isAdmin()){
|
||||
if(isset($_GET['gameJamId'])) {
|
||||
$groups = Group::where('game_jam_id', $_GET['gameJamId'])->get();
|
||||
if($groups) {
|
||||
$winningGroups = new Collection();
|
||||
$winningGroups->push($group);
|
||||
$i = -1;
|
||||
foreach ($groups as $group) {
|
||||
$x = Vote::where('group_id', $group->id)->count();
|
||||
if ($x > $i) {
|
||||
$winningGroups = new Collection();
|
||||
$winningGroups->push($group);
|
||||
|
||||
$i = $x;
|
||||
$i = $x;
|
||||
} elseif ($i === $x) {
|
||||
$winningGroups->push($group);
|
||||
}
|
||||
}
|
||||
|
||||
header("Access-Control-Allow-Methods: GET");
|
||||
header("Access-Control-Allow-Headers: X-Requested-With, Content-Type, Accept");
|
||||
header('Content-Type: application/json;charset=UTF-8');
|
||||
echo json_encode(array('data' => $winningGroups->jsonSerialize()));
|
||||
}
|
||||
elseif ($i === $x){
|
||||
$winningGroups->push($group);
|
||||
else{
|
||||
http_response_code(400);
|
||||
echo json_encode(["message" => "game jam not found"]);
|
||||
}
|
||||
}else{
|
||||
http_response_code(400);
|
||||
}
|
||||
|
||||
header("Access-Control-Allow-Methods: GET");
|
||||
header("Access-Control-Allow-Headers: X-Requested-With, Content-Type, Accept");
|
||||
header('Content-Type: application/json;charset=UTF-8');
|
||||
echo json_encode(array('data' => $winningGroups->jsonSerialize()));
|
||||
|
||||
|
||||
}else{
|
||||
echo http_response_code(401);
|
||||
http_response_code(401);
|
||||
echo json_encode(["message" => "not admin"]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user