diff src/services/anilist.cpp @ 52:0c4138de2ea7

anime list: we are finally read-write
author Paper <mrpapersonic@gmail.com>
date Mon, 25 Sep 2023 22:49:42 -0400
parents e613772f41d5
children 3d2decf093bb
line wrap: on
line diff
--- a/src/services/anilist.cpp	Mon Sep 25 20:29:26 2023 -0400
+++ b/src/services/anilist.cpp	Mon Sep 25 22:49:42 2023 -0400
@@ -8,6 +8,7 @@
 #include "gui/translate/anilist.h"
 #include <QDesktopServices>
 #include <QInputDialog>
+#include <QDebug>
 #include <QLineEdit>
 #include <QMessageBox>
 #include <QUrl>
@@ -260,7 +261,7 @@
 	return 1;
 }
 
-int UpdateAnimeEntry(const Anime::Anime& anime) {
+int UpdateAnimeEntry(int id) {
 	/**
 	 * possible values:
 	 *
@@ -280,11 +281,9 @@
 	 * Date startedAt,
 	 * Date completedAt
 	 **/
-	const std::string query = "mutation ($media_id: Int, $progress: Int, $status: MediaListStatus, "
-	                          "$score: Int, $notes: String) {\n"
-	                          "  SaveMediaListEntry (mediaId: $media_id, progress: $progress, "
-	                          "status: $status, scoreRaw: $score, notes: "
-	                          "$notes) {\n"
+	Anime::Anime& anime = Anime::db.items[id];
+	const std::string query = "mutation ($media_id: Int, $progress: Int, $status: MediaListStatus, $score: Int, $notes: String) {\n"
+	                          "  SaveMediaListEntry (mediaId: $media_id, progress: $progress, status: $status, scoreRaw: $score, notes: $notes) {\n"
 	                          "    id\n"
 	                          "  }\n"
 	                          "}\n";
@@ -300,8 +299,8 @@
 		}}
 	};
 	// clang-format on
-	SendRequest(json.dump());
-	return 1;
+	auto ret = nlohmann::json::parse(SendRequest(json.dump()));
+	return JSON::GetInt(ret, "/data/SaveMediaListEntry/id"_json_pointer);
 }
 
 int ParseUser(const nlohmann::json& json) {