Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
projet-cdaw
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Quentin Vrel
projet-cdaw
Commits
e3df21c7
Commit
e3df21c7
authored
Nov 27, 2020
by
Zohten
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
basic getter
parent
aa453f50
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
92 additions
and
0 deletions
+92
-0
GameController.class.php
BackEnd/src/controller/GameController.class.php
+57
-0
Game.class.php
BackEnd/src/model/Game.class.php
+24
-0
Game.sql.php
BackEnd/src/sql/Game.sql.php
+11
-0
No files found.
BackEnd/src/controller/GameController.class.php
0 → 100644
View file @
e3df21c7
<?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
BackEnd/src/model/Game.class.php
0 → 100644
View file @
e3df21c7
<?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
BackEnd/src/sql/Game.sql.php
0 → 100644
View file @
e3df21c7
<?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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment