Get manga updates working correctly with GraphQL, see #28

This commit is contained in:
Timothy Warren 2020-08-04 09:20:28 -04:00
parent 78b195f966
commit 1c3216e26a
4 changed files with 44 additions and 25 deletions

View File

@ -0,0 +1,32 @@
mutation(
$id: ID!,
$notes: String,
$private: Boolean,
$progress: Int,
$ratingTwenty: Int,
$reconsumeCount: Int!,
$reconsuming: Boolean,
$status: LibraryEntryStatus!,
) {
updateLibraryEntry(input: {
id: $id,
notes: $notes
private: $private
progress: $progress
rating: $ratingTwenty
reconsumeCount: $reconsumeCount
reconsuming: $reconsuming
status: $status
}) {
libraryEntry {
id
notes
private
progress
rating
reconsumeCount
reconsuming
status
}
}
}

View File

@ -151,29 +151,16 @@ final class ListItem extends AbstractListItem {
*/ */
public function update(string $id, FormItemData $data): Request public function update(string $id, FormItemData $data): Request
{ {
$authHeader = $this->getAuthHeader(); return $this->requestBuilder->mutateRequest('UpdateLibraryItem', [
$requestData = [
'data' => [
'id' => $id, 'id' => $id,
'type' => 'libraryEntries', 'notes' => $data['notes'],
'attributes' => $data 'private' => (bool)$data['private'],
] 'progress' => (int)$data['progress'],
]; 'ratingTwenty' => (int)$data['ratingTwenty'],
'reconsumeCount' => (int)$data['reconsumeCount'],
if (((int) $data->progress) === 0) 'reconsuming' => (bool)$data['reconsuming'],
{ 'status' => strtoupper($data['status']),
$data->progress = 0; ]);
}
$request = $this->requestBuilder->newRequest('PATCH', "library-entries/{$id}")
->setJsonBody($requestData);
if ($authHeader !== NULL)
{
$request = $request->setHeader('Authorization', $authHeader);
}
return $request->getFullRequest();
} }
/** /**

View File

@ -255,7 +255,7 @@ class Anime extends API {
$results = $requester->makeRequests(); $results = $requester->makeRequests();
$body = Json::decode($results['kitsu']); $body = Json::decode($results['kitsu']);
$statusCode = array_key_exists('error', $body) ? 400: 200; $statusCode = array_key_exists('errors', $body) ? 400: 200;
return [ return [
'body' => Json::decode($results['kitsu']), 'body' => Json::decode($results['kitsu']),

View File

@ -171,7 +171,7 @@ class Manga extends API {
$results = $requester->makeRequests(); $results = $requester->makeRequests();
$body = Json::decode($results['kitsu']); $body = Json::decode($results['kitsu']);
$statusCode = array_key_exists('error', $body) ? 400: 200; $statusCode = array_key_exists('errors', $body) ? 400: 200;
return [ return [
'body' => Json::decode($results['kitsu']), 'body' => Json::decode($results['kitsu']),