comparison 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
comparison
equal deleted inserted replaced
51:75c804f713b2 52:0c4138de2ea7
6 #include "core/session.h" 6 #include "core/session.h"
7 #include "core/strings.h" 7 #include "core/strings.h"
8 #include "gui/translate/anilist.h" 8 #include "gui/translate/anilist.h"
9 #include <QDesktopServices> 9 #include <QDesktopServices>
10 #include <QInputDialog> 10 #include <QInputDialog>
11 #include <QDebug>
11 #include <QLineEdit> 12 #include <QLineEdit>
12 #include <QMessageBox> 13 #include <QMessageBox>
13 #include <QUrl> 14 #include <QUrl>
14 #include <chrono> 15 #include <chrono>
15 #include <curl/curl.h> 16 #include <curl/curl.h>
258 ParseList(list.value()); 259 ParseList(list.value());
259 } 260 }
260 return 1; 261 return 1;
261 } 262 }
262 263
263 int UpdateAnimeEntry(const Anime::Anime& anime) { 264 int UpdateAnimeEntry(int id) {
264 /** 265 /**
265 * possible values: 266 * possible values:
266 * 267 *
267 * int mediaId, 268 * int mediaId,
268 * MediaListStatus status, 269 * MediaListStatus status,
278 * string[] customLists, 279 * string[] customLists,
279 * float[] advancedScores, 280 * float[] advancedScores,
280 * Date startedAt, 281 * Date startedAt,
281 * Date completedAt 282 * Date completedAt
282 **/ 283 **/
283 const std::string query = "mutation ($media_id: Int, $progress: Int, $status: MediaListStatus, " 284 Anime::Anime& anime = Anime::db.items[id];
284 "$score: Int, $notes: String) {\n" 285 const std::string query = "mutation ($media_id: Int, $progress: Int, $status: MediaListStatus, $score: Int, $notes: String) {\n"
285 " SaveMediaListEntry (mediaId: $media_id, progress: $progress, " 286 " SaveMediaListEntry (mediaId: $media_id, progress: $progress, status: $status, scoreRaw: $score, notes: $notes) {\n"
286 "status: $status, scoreRaw: $score, notes: "
287 "$notes) {\n"
288 " id\n" 287 " id\n"
289 " }\n" 288 " }\n"
290 "}\n"; 289 "}\n";
291 // clang-format off 290 // clang-format off
292 nlohmann::json json = { 291 nlohmann::json json = {
298 {"score", anime.GetUserScore()}, 297 {"score", anime.GetUserScore()},
299 {"notes", anime.GetUserNotes()} 298 {"notes", anime.GetUserNotes()}
300 }} 299 }}
301 }; 300 };
302 // clang-format on 301 // clang-format on
303 SendRequest(json.dump()); 302 auto ret = nlohmann::json::parse(SendRequest(json.dump()));
304 return 1; 303 return JSON::GetInt(ret, "/data/SaveMediaListEntry/id"_json_pointer);
305 } 304 }
306 305
307 int ParseUser(const nlohmann::json& json) { 306 int ParseUser(const nlohmann::json& json) {
308 account.SetUsername(JSON::GetString(json, "/name"_json_pointer)); 307 account.SetUsername(JSON::GetString(json, "/name"_json_pointer));
309 account.SetUserId(JSON::GetInt(json, "/id"_json_pointer)); 308 account.SetUserId(JSON::GetInt(json, "/id"_json_pointer));