diff --git a/app/views/anime/add.php b/app/views/anime/add.php index 9224905d..fac82700 100644 --- a/app/views/anime/add.php +++ b/app/views/anime/add.php @@ -28,6 +28,7 @@
= print_r($data, TRUE) ?>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); diff --git a/src/Controller/Anime.php b/src/Controller/Anime.php index 4809e21e..a9746973 100644 --- a/src/Controller/Anime.php +++ b/src/Controller/Anime.php @@ -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(); diff --git a/src/Controller/Manga.php b/src/Controller/Manga.php index a0113207..d2b47ee4 100644 --- a/src/Controller/Manga.php +++ b/src/Controller/Manga.php @@ -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 { diff --git a/src/Model/Anime.php b/src/Model/Anime.php index 553d18e8..6b5453d4 100644 --- a/src/Model/Anime.php +++ b/src/Model/Anime.php @@ -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 * diff --git a/src/Model/Manga.php b/src/Model/Manga.php index 7df7a4c3..420948a2 100644 --- a/src/Model/Manga.php +++ b/src/Model/Manga.php @@ -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 *