diff --git a/Backend/Database/GameData.php b/Backend/Database/GameData.php index e16e107..62062e3 100644 --- a/Backend/Database/GameData.php +++ b/Backend/Database/GameData.php @@ -10,6 +10,7 @@ Capsule::schema()->create("game_data", function (Blueprint $table){ $table->id(); $table->string("gameLink"); $table->boolean("isWebBased"); + $table->string("img"); $table->timestamps(); }); diff --git a/Backend/Database/Group.php b/Backend/Database/Group.php index ee1e9a0..95d10b9 100644 --- a/Backend/Database/Group.php +++ b/Backend/Database/Group.php @@ -11,8 +11,6 @@ Capsule::schema()->create("groups", function (Blueprint $table){ $table->string("groupName"); $table->integer("groupAmount"); $table->foreignId("game_jam_id")->constrained("game_jams"); - $table->integer("votes")->nullable(); - $table->foreignId("password_id")->constrained("passwords"); $table->foreignId("game_data_id")->nullable()->constrained("game_data"); $table->timestamps(); }); diff --git a/Backend/Database/Password.php b/Backend/Database/Password.php index f3b480f..faa35a5 100644 --- a/Backend/Database/Password.php +++ b/Backend/Database/Password.php @@ -8,6 +8,7 @@ use Illuminate\Support\Facades\Schema; //Create password table with the rows as id, password, rememberToken and timestamps Capsule::schema()->create("passwords", function (Blueprint $table){ $table->id(); + $table->foreignId("group_id")->constrained("groups"); $table->string('password'); $table->rememberToken(); $table->timestamps(); diff --git a/Backend/Database/Vote.php b/Backend/Database/Vote.php new file mode 100644 index 0000000..c2cc3e9 --- /dev/null +++ b/Backend/Database/Vote.php @@ -0,0 +1,14 @@ +create("votes", function (Blueprint $table){ + $table->id(); + $table->foreignId("group_id")->constrained("groups"); + $table->tinyInteger("points"); + $table->text("comment")->nullable(); + $table->timestamps(); +}); \ No newline at end of file diff --git a/Backend/Database/databaseMigration.php b/Backend/Database/databaseMigration.php index 3cc96f1..2009635 100644 --- a/Backend/Database/databaseMigration.php +++ b/Backend/Database/databaseMigration.php @@ -15,6 +15,7 @@ require "GameJam.php"; //GameJam has no foreign key require "GameData.php"; //GameData has no foreign key -require "Password.php"; //Password has no foreign key require "Group.php"; //Group has foreign keys to the GameJam, GameData and Password tables hence we create it as one of the last tables in the database +require "Password.php"; //Password has no foreign key require "KeyWord.php"; //Group has foreign keys to the Group +require "Vote.php"; diff --git a/Backend/Database/hasVoted.php b/Backend/Database/hasVoted.php deleted file mode 100644 index 1b49242..0000000 --- a/Backend/Database/hasVoted.php +++ /dev/null @@ -1,23 +0,0 @@ -create("has_voted", function (Blueprint $table){ - $table->id(); - $table->timestamps(); -}); - - -/* -Syntex to create table in database - -$table->string("texts"); - -$table => valuable; -string => datatype; -("texts") => name for the row in the database -*/ \ No newline at end of file diff --git a/Backend/Models/Group.php b/Backend/Models/Group.php index 13fd160..dd0df3f 100644 --- a/Backend/Models/Group.php +++ b/Backend/Models/Group.php @@ -17,6 +17,6 @@ class Group extends Eloquent return $this->belongsTo(GameData::class); } public function password(){ - return $this->belongsTo(Password::class); + return $this->hasOne(Password::class); } } diff --git a/Backend/Models/Password.php b/Backend/Models/Password.php index 10d78da..58e9b42 100644 --- a/Backend/Models/Password.php +++ b/Backend/Models/Password.php @@ -8,7 +8,7 @@ class Password extends Eloquent{ public function group(){ - return $this->hasOne(Group::class); + return $this->belongsTo(Group::class); } } \ No newline at end of file diff --git a/Backend/Models/hasVoted.php b/Backend/Models/hasVoted.php deleted file mode 100644 index 7f8a903..0000000 --- a/Backend/Models/hasVoted.php +++ /dev/null @@ -1,12 +0,0 @@ -belongsTo(GameData::class); - } -} \ No newline at end of file diff --git a/Backend/SigningUp.php b/Backend/SigningUp.php index 0503989..9813dee 100644 --- a/Backend/SigningUp.php +++ b/Backend/SigningUp.php @@ -14,29 +14,28 @@ $errors = array(); if(isset($_POST['reg_group'])){ - $password = New Password(); - $password->password = password_hash($_POST['password'] ,PASSWORD_DEFAULT); - - if(!$password->save()){ - return; - } $group = new Group(); - $group->password()->associate($password); - $group->gameJam()->associate(GameJam::find($_POST['gameJamId'])); $group->groupName = $groupName = $_POST['groupName']; $group->groupAmount = $_POST['groupAmount']; - $group->votes = 0; - if(!$group->save()){ return; } + $password = New Password(); + + $password->group()->associate($group); + + $password->password = password_hash($_POST['password'] ,PASSWORD_DEFAULT); + + if(!$password->save()){ + return; + } $_SESSION['groupName'] = $groupName; $_SESSION['success'] = "You are now logged in";