Game-Jaming/Backend/Controllers/Polls/1vote.php

39 lines
793 B
PHP

<?php
use Backend\Models\GameData;
use Backend\Models\Vote;
require_once "../../../bootstrap.php";
require_once "Vote.php";
if (isset($_POST['1Vote'])) {
if (VoteCheck($_POST['gameDataId'])) {
$vote = new Vote();
$vote->gameDate()->associate(GameData::find($_POST['gameDataId']));
$vote->points += 1;
if (!empty($_POST['comment'])) {
$vote->comment = $_POST['comment'];
}
if (!$vote->save()) {
http_response_code(500);
} else {
http_response_code(201);
}
} else {
http_response_code(403);
echo json_encode(["message" => "you have already voted"]);
}
} else {
http_response_code(400);
echo json_encode(["message" => "you have already voted"]);
}