Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move create wall API to new REST structure
- Loading branch information
Showing
11 changed files
with
154 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,59 @@ | |||
<?php | |||
/* This Source Code Form is subject to the terms of the Mozilla Public | |||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | |||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | |||
|
|||
require_once('../../lib/parapara.inc'); | |||
require_once('api.inc'); | |||
require_once('walls.inc'); | |||
|
|||
header('Content-Type: text/plain; charset=UTF-8'); | |||
|
|||
// Check we are logged in | |||
session_name(WALLMAKER_SESSION_NAME); | |||
session_start(); | |||
if (!isset($_SESSION['email'])) { | |||
bailWithError('logged-out'); | |||
} | |||
|
|||
// Prepare common parameters | |||
$wallId = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : null; | |||
|
|||
// Parse input | |||
$handle = fopen('php://input','r'); | |||
$jsonString = fgets($handle); | |||
$json = json_decode($jsonString,true); | |||
fclose($handle); | |||
|
|||
switch ($_SERVER['REQUEST_METHOD']) { | |||
case 'POST': | |||
$params = array('ownerEmail' => $_SESSION['email']); | |||
$params['design'] = @$json['design']; | |||
$params['title'] = @$json['title']; | |||
|
|||
// XXX Move the following to Walls::create | |||
// Run the query | |||
$wallId = createWall($params); | |||
|
|||
// Prepare result | |||
$result = array('wallId' => $wallId); | |||
// start session | |||
$currentdatetime = gmdate("Y-m-d H:i:s"); | |||
startNewSession($wallId, null, $currentdatetime); | |||
break; | |||
|
|||
case 'GET': | |||
if ($wallId === null) { | |||
// XXX Return the list of walls here | |||
bailWithError('bad-request'); | |||
} | |||
$result = getWallDetails($wallId, $_SESSION['email']); | |||
break; | |||
|
|||
default: | |||
bailWithError('bad-request'); | |||
} | |||
|
|||
// Return the result | |||
print json_encode($result); | |||
?> |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,54 @@ | |||
<?php | |||
/* This Source Code Form is subject to the terms of the Mozilla Public | |||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | |||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | |||
|
|||
require_once('../../lib/parapara.inc'); | |||
require_once('simpletest/autorun.php'); | |||
require_once('WallMakerTestCase.php'); | |||
|
|||
class CreateWallTestCase extends WallMakerTestCase { | |||
|
|||
function __construct($name = false) { | |||
parent::__construct($name); | |||
} | |||
|
|||
function testLoggedOut() { | |||
// Check it fails if we're logged out | |||
$wall = $this->_createWall( | |||
'Test wall', | |||
$this->testDesignId | |||
); | |||
$this->assertTrue(@$wall['error_key'] == 'logged-out', | |||
"Got wall whilst logged out."); | |||
} | |||
|
|||
function testCreate() { | |||
$this->login(); | |||
|
|||
// Create wall | |||
$wall = $this->_createWall( | |||
'Test wall', | |||
$this->testDesignId | |||
); | |||
$this->assertTrue(!array_key_exists('error_key', $wall), | |||
"Got error creating wall"); | |||
$this->assertTrue(is_int(@$wall['wallId']) && $wall['wallId'] > 0, | |||
"Unexpected wall ID: " . @$wall['wallId']); | |||
|
|||
// Tidy up | |||
$this->removeWall($wall['wallId']); | |||
} | |||
|
|||
// Test creating works (get ID) | |||
// Test PUT method doesn't work? | |||
// Test name | |||
// -- no name is error | |||
// -- whitespace | |||
// Test designId | |||
// Test session exists | |||
// Test wall name is set | |||
// (I think it should basically return the same as fetching the wall??) | |||
} | |||
|
|||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.