Commit 08e3e181 authored by Zohten's avatar Zohten

can add round

parent a92a0e42
...@@ -32,6 +32,10 @@ class RoundController extends Controller ...@@ -32,6 +32,10 @@ class RoundController extends Controller
// If there is no uriParams, it is the /round endpoint // If there is no uriParams, it is the /round endpoint
return $this->getAllRounds(); return $this->getAllRounds();
break; break;
case 'POST':
$body = $this->request->getData();
return $this->newRound($body);
break;
} }
$message = json_encode(["message" => "unsupported parameters or method in round"]); $message = json_encode(["message" => "unsupported parameters or method in round"]);
return Response::errorResponse($message); return Response::errorResponse($message);
...@@ -72,4 +76,20 @@ class RoundController extends Controller ...@@ -72,4 +76,20 @@ class RoundController extends Controller
$response = Response::okResponse(json_encode($rounds, JSON_PRETTY_PRINT)); $response = Response::okResponse(json_encode($rounds, JSON_PRETTY_PRINT));
return $response; return $response;
} }
/**
* (POST) Add a new round in Round table
*
* @param array $array array containing ID_GAME, PREVAILING_WIND ,SEED
* @return Response
*/
protected function newRound($array)
{
Round::createRound($array);
$message = json_encode(["message" => 'Round succesfully created!']);
$response = Response::createdResponse($message);
return $response;
}
} }
\ No newline at end of file
...@@ -26,4 +26,12 @@ class Round extends Model ...@@ -26,4 +26,12 @@ class Round extends Model
$stm = parent::exec('ROUND_GET_USERS', ['id' => $id]); $stm = parent::exec('ROUND_GET_USERS', ['id' => $id]);
return $stm->fetchAll(); return $stm->fetchAll();
} }
public static function createRound($array)
{
$begin_date = date('Y-m-d H:i:s');
$pimped_array = array_merge($array, ['begin_date'=>$begin_date]);
$stm = parent::exec('ROUND_CREATE', $pimped_array);
}
} }
\ No newline at end of file
...@@ -25,4 +25,10 @@ Game::addSqlQuery( ...@@ -25,4 +25,10 @@ Game::addSqlQuery(
JOIN MJ_PLAY as p on p.ID_USER = usr.ID_USER JOIN MJ_PLAY as p on p.ID_USER = usr.ID_USER
JOIN MJ_ROUND as r on r.ID_ROUND = p.ID_ROUND JOIN MJ_ROUND as r on r.ID_ROUND = p.ID_ROUND
WHERE r.ID_ROUND=:id' WHERE r.ID_ROUND=:id'
);
User::addSqlQuery(
'ROUND_CREATE',
'INSERT INTO MJ_ROUND (ID_ROUND ,ID_GAME ,PREVAILING_WIND ,SEED ,BEGINING ,ENDING ,ACTIONS)
VALUES (NULL, :id_game, :prevailing_wind, :seed, :begin_date, NULL, NULL)'
); );
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment