diff --git a/gulpfile.js b/gulpfile.js index df3d0bf..0951031 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -147,7 +147,7 @@ gulp.task('coverage', ['tsc', 'vendor'], () => { gulp.task('test-api', () => { return gulp.src('') - .pipe(phpunit('./src/api/vendor/phpunit/phpunit/phpunit test/api/*Test.php')); + .pipe(phpunit('./src/api/vendor/phpunit/phpunit/phpunit test/api/')); }); gulp.task('watch', () => { diff --git a/src/api/controllers/Attachments.php b/src/api/controllers/Attachments.php new file mode 100644 index 0000000..830cc5a --- /dev/null +++ b/src/api/controllers/Attachments.php @@ -0,0 +1,6 @@ +apiJson = new ApiJson(); $this->logger = $container->get('logger'); + $this->container = $container; } public function jsonResponse($response) { diff --git a/src/api/controllers/Boards.php b/src/api/controllers/Boards.php index c01ffa7..fa0423d 100644 --- a/src/api/controllers/Boards.php +++ b/src/api/controllers/Boards.php @@ -20,5 +20,32 @@ class Boards extends BaseController { return $this->jsonResponse($response); } + public function getBoard($request, $response, $args) { + $board = new Board($this->container, (int)$args['id']); + + if ($board->id === 0) { + $this->logger->addError('Attempt to load board ' . $args['id'] . + ' failed.'); + $this->apiJson->addAlert('error', 'No board found for ID ' . + $args['id'] . '.'); + + return $this->jsonResponse($response); + } + + $this->apiJson->setSuccess(); + $this->apiJson->addData($board); + + return $this->jsonResponse($response); + } + + public function addBoard($request, $response, $args) { + } + + public function updateBoard($request, $response, $args) { + } + + public function removeBoard($request, $response, $args) { + } + } diff --git a/src/api/controllers/Columns.php b/src/api/controllers/Columns.php new file mode 100644 index 0000000..d8f77d4 --- /dev/null +++ b/src/api/controllers/Columns.php @@ -0,0 +1,6 @@ +get('/', 'Invalid:noApi'); $app->get('/boards', 'Boards:getAllBoards'); +$app->get('/boards/{id}', 'Boards:getBoard'); +$app->post('/boards', 'Boards:addBoard'); +$app->post('/boards/{id}', 'Boards:updateBoard'); +$app->delete('/boards/{id}', 'Boards:removeBoard'); +/* +$app->get('/autoactions', 'AutoActions:getAllActions'); +$app->post('/autoactions', 'AutoActions:addAction'); +$app->delete('/autoactions/{id}', 'AutoActions:removeAction'); +$app->get('/columns/{id}', 'Columns:getColumn'); +$app->post('/columns', 'Columns:addColumn'); +$app->post('/columns/{id}', 'Columns:updateColumn'); +$app->delete('/columns/{id}', 'Columns:removeColumn'); + +$app->get('/items/{id}', 'Items:getItem'); +$app->post('/items', 'Items:addItem'); +$app->post('/items/{id}', 'Items:updateItem'); +$app->delete('/items/{id}', 'Items:removeItem'); + +$app->get('/comments/{id}', 'Comments:getComment'); +$app->post('/comments', 'Comments:addComment'); +$app->post('/comments/{id}', 'Comments:updateComment'); +$app->delete('/comments/{id}', 'Comments:removeComment'); + +$app->get('/attachments/{id}', 'Attachments:getAttachment'); +$app->post('/attachments', 'Attachments:addAttachment'); +$app->post('/attachments/{id}', 'Attachments:updateAttachment'); +$app->delete('/attachments/{id}', 'Attachments:removeAttachment'); + +$app->get('/users', 'Users:getAllUsers'); +$app->get('/users/{id}', 'Users:getUser'); +$app->post('/users', 'Users:addUser'); +$app->post('/users/{id}', 'Users:updateUser'); +$app->delete('/users/{id}', 'Users:removeUser'); + +$app->post('/authenticate', 'Users:authenticate'); +$app->post('/users/login', 'Users:login'); +$app->post('/users/logout', 'Users:logout'); +*/ $app->run(); R::close(); diff --git a/src/api/models/BaseModel.php b/src/api/models/BaseModel.php index 1a717b1..a3decca 100644 --- a/src/api/models/BaseModel.php +++ b/src/api/models/BaseModel.php @@ -5,10 +5,7 @@ abstract class BaseModel { protected $logger; protected $bean; - public function __construct($type, $id) { - global $app; - $container = $app->getContainer(); - + public function __construct($type, $id, $container) { $this->logger = $container->get('logger'); $this->bean = R::load($type, $id); } diff --git a/src/api/models/Board.php b/src/api/models/Board.php index 3176579..7594fd0 100644 --- a/src/api/models/Board.php +++ b/src/api/models/Board.php @@ -1,8 +1,12 @@ loadFromBean($this->bean); } - public static function fromBean($bean) { + public static function fromBean($container, $bean) { + $instance = new self($container, 0, true); + $instance->loadFromBean($bean); + + return $instance; } public function updateBean() { } - public function loadFromBean() { + public function loadFromBean($bean) { } } diff --git a/src/index.html b/src/index.html index 914417a..c3932a8 100644 --- a/src/index.html +++ b/src/index.html @@ -2,7 +2,7 @@ TaskBoard - + @@ -26,7 +26,9 @@
- Loading... + +
TaskBoard is Loading...
+
diff --git a/src/scss/_core.scss b/src/scss/_core.scss index ca01279..dbba1c2 100644 --- a/src/scss/_core.scss +++ b/src/scss/_core.scss @@ -18,3 +18,7 @@ h6 { margin: 0; } +.loading { + padding-top: 2em; + text-align: center; +} diff --git a/test/api/BoardTest.php b/test/api/BoardTest.php new file mode 100644 index 0000000..850c1b6 --- /dev/null +++ b/test/api/BoardTest.php @@ -0,0 +1,37 @@ +assertTrue($board->id === 0); + $this->assertTrue($board->name === ''); + $this->assertTrue($board->is_active === true); + $this->assertArraySubset($board->columns, []); + } + + public function testCreateFromBean() { + $board = Board::fromBean(new ContainerMock(), null); + + $this->assertTrue($board->id === 0); + $this->assertTrue($board->name === ''); + $this->assertTrue($board->is_active === true); + $this->assertArraySubset($board->columns, []); + } + +} + diff --git a/test/api/BoardsTest.php b/test/api/BoardsTest.php index 74f4bc1..394965e 100644 --- a/test/api/BoardsTest.php +++ b/test/api/BoardsTest.php @@ -1,18 +1,22 @@ addAlert('info', 'No boards in database.'); @@ -21,5 +25,18 @@ class BoardsTest extends PHPUnit_Framework_TestCase { $boards->getAllBoards(null, new ResponseMock(), null)); } + public function testGetBoard() { + $boards = new Boards(new ContainerMock()); + + $expected = new ApiJson(); + $expected->addAlert('error', 'No board found for ID 1.'); + + $args = []; + $args['id'] = '1'; + + $this->assertEquals($expected, + $boards->getBoard(null, new ResponseMock(), $args)); + } + } diff --git a/test/api/Mocks.php b/test/api/Mocks.php index 35be358..4d617a8 100644 --- a/test/api/Mocks.php +++ b/test/api/Mocks.php @@ -1,5 +1,14 @@