Commit e3df21c7 authored by Zohten's avatar Zohten

basic getter

parent aa453f50
<?php
class GameController extends Controller
{
public function __construct($name, $request)
{
parent::__construct($name, $request);
}
/**
* Process incoming request for the /game endpoint
*
* @return Response
*/
public function processRequest()
{
$httpMethod=$this->request->getHttpMethod();
$uriParams=$this->request->getUriParams();
switch ($httpMethod) {
case 'GET':
// If there is a uriParams, it is the /game/{id} endpoint
if ($uriParams) {
return $this->getGame($uriParams[0]);
}
// Else, it is the /game endpoint
return $this->getAllGames();
break;
}
$message = json_encode(["message" => "unsupported parameters or method in game"]);
return Response::errorResponse($message);
}
/**
* (GET) Get all games in Game table
*
* @return Response
*/
protected function getAllGames()
{
$games = Game::getList();
$response = Response::okResponse(json_encode($games, JSON_PRETTY_PRINT));
return $response;
}
/**
* (GET) Get a specific game in Game table based
*
* @return Response
*/
protected function getGame($id)
{
$games = Game::getRow($id);
$response = Response::okResponse(json_encode($games, JSON_PRETTY_PRINT));
return $response;
}
}
\ No newline at end of file
<?php
class Game extends Model
{
// ===========
// = Statics =
// ===========
protected static $table_name = 'MJ_GAME';
public static function getList()
{
$stm = parent::exec('GAME_LIST');
return $stm->fetchAll();
}
public static function getRow($id)
{
$stm = parent::exec('GAME_GET_WITH_ID', ['id' => $id]);
return $stm->fetchAll();
}
}
\ No newline at end of file
<?php
Game::addSqlQuery(
'GAME_LIST',
'SELECT * FROM MJ_GAME'
);
Game::addSqlQuery(
'GAME_GET_WITH_ID',
'SELECT * FROM MJ_GAME WHERE ID_GAME=:id'
);
\ 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