Commit 08e3e181 authored by Zohten's avatar Zohten

can add round

parent a92a0e42
......@@ -32,6 +32,10 @@ class RoundController extends Controller
// If there is no uriParams, it is the /round endpoint
return $this->getAllRounds();
break;
case 'POST':
$body = $this->request->getData();
return $this->newRound($body);
break;
}
$message = json_encode(["message" => "unsupported parameters or method in round"]);
return Response::errorResponse($message);
......@@ -72,4 +76,20 @@ class RoundController extends Controller
$response = Response::okResponse(json_encode($rounds, JSON_PRETTY_PRINT));
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
$stm = parent::exec('ROUND_GET_USERS', ['id' => $id]);
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
......@@ -26,3 +26,9 @@ Game::addSqlQuery(
JOIN MJ_ROUND as r on r.ID_ROUND = p.ID_ROUND
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