Game-Jaming/Backend/Controllers/Registration/NewRegistration.php

33 lines
1003 B
PHP

<?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"]);
}