new database

This commit is contained in:
2021-04-19 09:15:15 +02:00
parent 24663071e6
commit 22a431da07
43 changed files with 423 additions and 302 deletions
+9 -10
View File
@@ -2,21 +2,20 @@
require_once "../../../bootstrap.php";
require_once "../Admin/Admin.php";
use Backend\Models\Group;
use \Backend\Models\KeyWord;
use \Backend\Models\GameJam;
use \Illuminate\Support\Collection;
use Backend\Models\Registration;
if (!isAdmin()){
if(isset($_GET['genKeyWord'])){
if (!isAdmin()) {
if (isset($_GET['genKeyWord'])) {
$gameJamId = $_GET['gameJamId'];
$game_jam = GameJam::find($gameJamId);
$all_group_in_game_jam_id = Group::where("game_jam_id", $game_jam->id)->pluck("id")->toArray();
$find_all_keywords = KeyWord::whereIn("group_id", $all_group_in_game_jam_id)->inRandomOrder()->take(6)->get();
$all_registration_in_game_jam_id = Registration::where("game_jam_id", $game_jam->id)->pluck("id")->toArray();
$find_all_keywords = KeyWord::whereIn("group_id", $all_registration_in_game_jam_id)->inRandomOrder()->take(6)->get();
$game_jam->key_word = $find_all_keywords->first()->key_word;
if(!$game_jam->save()){
if (!$game_jam->save()) {
http_response_code(500);
}else{
} else {
http_response_code(201);
}
@@ -24,10 +23,10 @@ if (!isAdmin()){
header("Access-Control-Allow-Headers: X-Requested-With, Content-Type, Accept");
header('Content-Type: application/json;charset=UTF-8');
echo json_encode(array('data' => $find_all_keywords->jsonSerialize()));
}else{
} else {
http_response_code(400);
}
}else{
} else {
http_response_code(401);
echo json_encode(["message" => "is not admin"]);
}
+24 -9
View File
@@ -1,18 +1,33 @@
<?php
require_once "../../../bootstrap.php";
require_once "../Group/Group.php";
use Backend\Models\GameJam;
use Backend\Models\Registration;
use Backend\Models\Group;
use Backend\Models\KeyWord;
session_start();
if (isLogin()) {
if(isset($_POST['submitKeyWord'])){
//Find the group id
if (isset($_POST['submitKeyWord'])) {
//Find the group
$group = groupViaToken($_SESSION['token']);
if($gameJam = GameJam::find($_POST["gameJamId"]) === null){
http_response_code(400);
echo json_encode(["message" => "gameJam not found"]);
exit();
}
$registration = Registration::where('game_jam_id', $gameJam->id)->where("group_id", $group->id)->frist();
if ($registration === null) {
http_response_code(401);
echo json_encode(["message" => "group not registered for that game jam"]);
exit();
}
//if statement to find out if the group have use all their keyWords
if(KeyWord::where('group_id', $group->id)->count()<$group->group_amount){
if (KeyWord::where('registration_id', $registration->id)->count() < $registration->group_amount) {
//Make a new keyword[Only to be used if you need to make a new of something]
$keyword = new KeyWord();
@@ -21,23 +36,23 @@ if (isLogin()) {
$keyword->key_word = $_POST['key_word'];
//Make foreign key from the groups table to the keyWords table
$keyword->group()->associate($group);
$keyword->registration()->associate($registration);
//Try to save it
if(!$keyword->save()){
if (!$keyword->save()) {
http_response_code(500);
}else{
} else {
http_response_code(201);
}
}else{
} else {
http_response_code(400);
echo json_encode(["message" => "limited upload reached"]);
}
}else{
} else {
http_response_code(400);
}
}else{
} else {
http_response_code(401);
echo json_encode(["message" => "not login"]);
}