Version 5.1 - All the GraphQL #32

Closed
timw4mail wants to merge 1160 commits from develop into master
6 changed files with 47 additions and 56 deletions
Showing only changes of commit def424da72 - Show all commits

View File

@ -75,6 +75,15 @@ class Controller {
$this->urlGenerator = $urlGenerator; $this->urlGenerator = $urlGenerator;
} }
/**
* Redirect to the default controller/url from an empty path
*/
public function redirect_to_default()
{
$default_type = $this->config->get(['routing','default_list']);
$this->redirect($this->urlGenerator->default_url($default_type), 303);
}
/** /**
* Get a class member * Get a class member
* *
@ -169,16 +178,13 @@ class Controller {
/** /**
* Redirect to the selected page * Redirect to the selected page
* *
* @param string $path * @param string $url
* @param int $code * @param int $code
* @param string $type
* @return void * @return void
*/ */
public function redirect($path, $code, $type = "anime") public function redirect($url, $code)
{ {
$url = $this->urlGenerator->full_url($path, $type);
$http = new HttpView($this->container); $http = new HttpView($this->container);
$http->redirect($url, $code); $http->redirect($url, $code);
} }
} }

View File

@ -54,29 +54,6 @@ class Anime extends BaseController {
* @return void * @return void
*/ */
public function index($type = "watching", $view = '') public function index($type = "watching", $view = '')
{
return $this->anime_list($type, $view);
}
/**
* Search for anime
*
* @return void
*/
public function search()
{
$query = $this->request->query->get('query');
$this->outputJSON($this->model->search($query));
}
/**
* Show a portion, or all of the anime list
*
* @param string $type - The section of the list
* @param string $view - List or cover view
* @return void
*/
protected function anime_list($type, $view)
{ {
$type_title_map = [ $type_title_map = [
'all' => 'All', 'all' => 'All',
@ -114,6 +91,17 @@ class Anime extends BaseController {
]); ]);
} }
/**
* Search for anime
*
* @return void
*/
public function search()
{
$query = $this->request->query->get('query');
$this->outputJSON($this->model->search($query));
}
/** /**
* Update an anime item * Update an anime item
* *

View File

@ -34,6 +34,7 @@ class Manga extends Controller {
public function __construct(ContainerInterface $container) public function __construct(ContainerInterface $container)
{ {
parent::__construct($container); parent::__construct($container);
$this->model = new MangaModel($container); $this->model = new MangaModel($container);
$this->base_data = array_merge($this->base_data, [ $this->base_data = array_merge($this->base_data, [
'menu_name' => 'manga_list', 'menu_name' => 'manga_list',
@ -51,28 +52,6 @@ class Manga extends Controller {
* @return void * @return void
*/ */
public function index($status = "all", $view = "") public function index($status = "all", $view = "")
{
return $this->manga_list($status, $view);
}
/**
* Update an anime item
*
* @return boolean|null
*/
public function update()
{
$this->outputJSON($this->model->update($this->request->post->get()));
}
/**
* Get a section of the manga list
*
* @param string $status
* @param string $view
* @return void
*/
protected function manga_list($status, $view)
{ {
$map = [ $map = [
'all' => 'All', 'all' => 'All',
@ -99,5 +78,15 @@ class Manga extends Controller {
'sections' => $data, 'sections' => $data,
]); ]);
} }
/**
* Update an anime item
*
* @return boolean|null
*/
public function update()
{
$this->outputJSON($this->model->update($this->request->post->get()));
}
} }
// End of MangaController.php // End of MangaController.php

View File

@ -54,6 +54,12 @@ class Dispatcher extends RoutingBase {
*/ */
protected function generate_convention_routes() protected function generate_convention_routes()
{ {
$this->output_routes[] = $this->router->add('index_redirect', '/')
->setValues([
'controller' => 'Aviat\\AnimeClient\\Controller',
'action' => 'redirect_to_default'
]);
$this->output_routes[] = $this->router->add('list', '/{controller}/{type}{/view}') $this->output_routes[] = $this->router->add('list', '/{controller}/{type}{/view}')
->setValues([ ->setValues([
'controller' => $this->routes['convention']['default_controller'], 'controller' => $this->routes['convention']['default_controller'],

View File

@ -106,7 +106,7 @@ class UrlGenerator extends RoutingBase {
return $this->url("{$type}/{$default_path}"); return $this->url("{$type}/{$default_path}");
} }
return ""; throw new \InvalidArgumentException("Invalid default type: '{$type}'");
} }
/** /**

View File

@ -177,8 +177,8 @@ class DispatcherTest extends AnimeClient_TestCase {
'routing' => [ 'routing' => [
'anime_path' => 'anime', 'anime_path' => 'anime',
'manga_path' => 'manga', 'manga_path' => 'manga',
'default_anime_path' => "/anime/watching", 'default_anime_list_path' => "watching",
'default_manga_path' => '/manga/all', 'default_manga_list_path' => 'all',
'default_list' => 'manga' 'default_list' => 'manga'
], ],
'routes' => [ 'routes' => [
@ -221,7 +221,9 @@ class DispatcherTest extends AnimeClient_TestCase {
$this->_set_up($config, "/", "localhost"); $this->_set_up($config, "/", "localhost");
$this->assertEquals('//localhost/manga/all', $this->urlGenerator->default_url('manga'), "Incorrect default url"); $this->assertEquals('//localhost/manga/all', $this->urlGenerator->default_url('manga'), "Incorrect default url");
$this->assertEquals('//localhost/anime/watching', $this->urlGenerator->default_url('anime'), "Incorrect default url"); $this->assertEquals('//localhost/anime/watching', $this->urlGenerator->default_url('anime'), "Incorrect default url");
$this->assertEquals('', $this->urlGenerator->default_url('foo'), "Incorrect default url");
$this->setExpectedException('\InvalidArgumentException');
$this->urlGenerator->default_url('foo');
} }
public function dataGetControllerList() public function dataGetControllerList()
@ -232,8 +234,8 @@ class DispatcherTest extends AnimeClient_TestCase {
'routing' => [ 'routing' => [
'anime_path' => 'anime', 'anime_path' => 'anime',
'manga_path' => 'manga', 'manga_path' => 'manga',
'default_anime_path' => "/anime/watching", 'default_anime_list_path' => "watching",
'default_manga_path' => '/manga/all', 'default_manga_list_path' => 'all',
'default_list' => 'manga' 'default_list' => 'manga'
], ],
'routes' => [ 'routes' => [