All basic API functionality:
* Anime List Item: * Creation * Updating * Retreiving * Deletion * Manga List Item: * Creation * Updating * Retreiving * Deletion * Anime detail page * Manga detail page
This commit is contained in:
parent
9f048b739e
commit
39118d63e5
@ -28,6 +28,7 @@
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>
|
||||
<input type="hidden" name="type" value="anime" />
|
||||
<button type="submit">Save</button>
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -17,13 +17,13 @@
|
||||
[<a href="<?= $urlGenerator->default_url('manga') ?>">Manga List</a>]
|
||||
<?php endif ?>
|
||||
</span>
|
||||
<?php if ($auth->is_authenticated()): ?>
|
||||
<?php /* if ($auth->is_authenticated()): ?>
|
||||
<span class="flex-no-wrap"> </span>
|
||||
<span class="flex-no-wrap small-font">
|
||||
<button type="button" class="js-clear-cache user-btn">Clear API Cache</button>
|
||||
</span>
|
||||
<span class="flex-no-wrap"> </span>
|
||||
<?php endif ?>
|
||||
<?php endif */ ?>
|
||||
<span class="flex-no-wrap small-font">
|
||||
<?php if ($auth->is_authenticated()): ?>
|
||||
<a class="bracketed" href="<?= $url->generate('logout') ?>">Logout</a>
|
||||
@ -41,4 +41,4 @@
|
||||
<li class="<?= Util::is_selected('list', $urlGenerator->last_segment()) ?>"><a href="<?= $urlGenerator->url("{$route_path}/list") ?>">List View</a></li>
|
||||
</ul>
|
||||
<?php endif ?>
|
||||
</nav>
|
||||
</nav>
|
||||
|
@ -28,6 +28,7 @@
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>
|
||||
<input type="hidden" name="type" value="manga" />
|
||||
<button type="submit">Save</button>
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -21,7 +21,7 @@
|
||||
});
|
||||
|
||||
// Clear the api cache
|
||||
ac.on('.js-clear-cache', 'click', function (event) {
|
||||
ac.on('.js-clear-cache', 'click', function () {
|
||||
ac.get('/cache_purge', () => {
|
||||
ac.showMessage('success', `Sucessfully purged api cache`);
|
||||
});
|
||||
|
@ -38,7 +38,7 @@
|
||||
}
|
||||
|
||||
// Update the total count
|
||||
data['data']['progress'] = ++completed;
|
||||
data.data.progress = ++completed;
|
||||
|
||||
_.ajax(_.url('/manga/update'), {
|
||||
data: data,
|
||||
|
@ -16,7 +16,6 @@
|
||||
|
||||
namespace Aviat\AnimeClient\API\Kitsu;
|
||||
|
||||
use Aviat\AnimeClient\AnimeClient;
|
||||
use Aviat\AnimeClient\API\Kitsu as K;
|
||||
use Aviat\AnimeClient\API\Kitsu\Transformer\{
|
||||
AnimeTransformer, AnimeListTransformer, MangaTransformer, MangaListTransformer
|
||||
@ -24,7 +23,6 @@ use Aviat\AnimeClient\API\Kitsu\Transformer\{
|
||||
use Aviat\Ion\Di\ContainerAware;
|
||||
use Aviat\Ion\Json;
|
||||
use GuzzleHttp\Exception\ClientException;
|
||||
use PHP_CodeSniffer\Tokenizers\JS;
|
||||
|
||||
/**
|
||||
* Kitsu API Model
|
||||
@ -77,6 +75,12 @@ class KitsuModel {
|
||||
$this->mangaListTransformer = new MangaListTransformer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the userid for a username from Kitsu
|
||||
*
|
||||
* @param string $username
|
||||
* @return string
|
||||
*/
|
||||
public function getUserIdByUsername(string $username)
|
||||
{
|
||||
$data = $this->getRequest('users', [
|
||||
@ -154,7 +158,7 @@ class KitsuModel {
|
||||
'include' => 'media,media.genres',
|
||||
'page' => [
|
||||
'offset' => 0,
|
||||
'limit' => 200
|
||||
'limit' => 1000
|
||||
],
|
||||
'sort' => '-updated_at'
|
||||
]
|
||||
@ -251,6 +255,12 @@ class KitsuModel {
|
||||
}
|
||||
}
|
||||
|
||||
public function createListItem(array $data): bool
|
||||
{
|
||||
$data['user_id'] = $this->getUserIdByUsername($this->getUsername());
|
||||
return $this->listItem->create($data);
|
||||
}
|
||||
|
||||
public function updateListItem(array $data)
|
||||
{
|
||||
try
|
||||
|
@ -37,24 +37,31 @@ class ListItem extends AbstractListItem {
|
||||
|
||||
public function create(array $data): bool
|
||||
{
|
||||
$response = $this->getResponse('post', 'library-entries', [
|
||||
'body' => [
|
||||
'type' => 'libraryEntries',
|
||||
'attributes' => [
|
||||
'status' => $data['status'],
|
||||
'progress' => $data['progress'] ?? 0
|
||||
],
|
||||
'relationships' => [
|
||||
'user' => [
|
||||
'id' => $data['user_id'],
|
||||
'type' => 'users'
|
||||
/*?><pre><?= print_r($data, TRUE) ?></pre><?php */
|
||||
$response = $this->getResponse('POST', 'library-entries', [
|
||||
'body' => Json::encode([
|
||||
'data' => [
|
||||
'type' => 'libraryEntries',
|
||||
'attributes' => [
|
||||
'status' => $data['status'],
|
||||
'progress' => $data['progress'] ?? 0
|
||||
],
|
||||
'media' => [
|
||||
'id' => $data['id'],
|
||||
'type' => $data['type']
|
||||
'relationships' => [
|
||||
'user' => [
|
||||
'data' => [
|
||||
'id' => $data['user_id'],
|
||||
'type' => 'users'
|
||||
]
|
||||
],
|
||||
'media' => [
|
||||
'data' => [
|
||||
'id' => $data['id'],
|
||||
'type' => $data['type']
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
])
|
||||
]);
|
||||
|
||||
return ($response->getStatusCode() === 201);
|
||||
|
@ -154,9 +154,9 @@ class Anime extends BaseController {
|
||||
$this->redirect("anime/add", 303);
|
||||
}
|
||||
|
||||
$result = $this->model->update($data);
|
||||
$result = $this->model->createLibraryItem($data);
|
||||
|
||||
if (intval($result['statusCode']) === 201)
|
||||
if ($result)
|
||||
{
|
||||
$this->set_flash_message('Added new anime to list', 'success');
|
||||
// $this->cache->purge();
|
||||
|
@ -137,12 +137,12 @@ class Manga extends Controller {
|
||||
$this->redirect("manga/add", 303);
|
||||
}
|
||||
|
||||
$result = $this->model->add($data);
|
||||
$result = $this->model->createLibraryItem($data);
|
||||
|
||||
if ($result['statusCode'] >= 200 && $result['statusCode'] < 300)
|
||||
if ($result)
|
||||
{
|
||||
$this->set_flash_message('Added new manga to list', 'success');
|
||||
$this->cache->purge();
|
||||
// $this->cache->purge();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -243,12 +243,14 @@ class Manga extends Controller {
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$response = $this->model->delete($this->request->getParsedBody());
|
||||
$body = $this->request->getParsedBody();
|
||||
$id = $body['id'];
|
||||
$response = $this->model->deleteLibraryItem($id);
|
||||
|
||||
if ((bool)$response['body'] === TRUE)
|
||||
if ($response)
|
||||
{
|
||||
$this->set_flash_message("Successfully deleted manga.", 'success');
|
||||
$this->cache->purge();
|
||||
//$this->cache->purge();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -105,6 +105,11 @@ class Anime extends API {
|
||||
return $this->kitsuModel->getListItem($itemId);
|
||||
}
|
||||
|
||||
public function createLibraryItem(array $data): bool
|
||||
{
|
||||
return $this->kitsuModel->createListItem($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a list entry
|
||||
*
|
||||
|
@ -52,6 +52,11 @@ class Manga extends API
|
||||
'dropped' => self::DROPPED
|
||||
];
|
||||
|
||||
/**
|
||||
* @var Aviat\AnimeClient\API\Kitsu\KitsuModel
|
||||
*/
|
||||
protected $kitsuModel;
|
||||
|
||||
public function __construct(ContainerInterface $container)
|
||||
{
|
||||
parent::__construct($container);
|
||||
@ -83,6 +88,17 @@ class Manga extends API
|
||||
return $this->kitsuModel->getManga($manga_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new manga list item
|
||||
*
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
public function createLibraryItem(array $data): bool
|
||||
{
|
||||
return $this->kitsuModel->createListItem($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get information about a specific list item
|
||||
* for editing/updating that item
|
||||
@ -106,6 +122,17 @@ class Manga extends API
|
||||
return $this->kitsuModel->updateListItem($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a list entry
|
||||
*
|
||||
* @param string $itemId
|
||||
* @return bool
|
||||
*/
|
||||
public function deleteLibraryItem(string $itemId): bool
|
||||
{
|
||||
return $this->kitsuModel->deleteListItem($itemId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for anime by name
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user