Mercurial > minori
comparison src/services/anilist.cpp @ 77:6f7385bd334c
*: update
formatted all source files, no more subclassing QThread... many other
changes :)
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Fri, 06 Oct 2023 06:18:53 -0400 |
parents | 3364fadc8a36 |
children |
comparison
equal
deleted
inserted
replaced
76:3364fadc8a36 | 77:6f7385bd334c |
---|---|
5 #include "core/http.h" | 5 #include "core/http.h" |
6 #include "core/json.h" | 6 #include "core/json.h" |
7 #include "core/session.h" | 7 #include "core/session.h" |
8 #include "core/strings.h" | 8 #include "core/strings.h" |
9 #include "gui/translate/anilist.h" | 9 #include "gui/translate/anilist.h" |
10 #include <QByteArray> | |
10 #include <QDesktopServices> | 11 #include <QDesktopServices> |
11 #include <QInputDialog> | 12 #include <QInputDialog> |
12 #include <QLineEdit> | 13 #include <QLineEdit> |
13 #include <QMessageBox> | 14 #include <QMessageBox> |
14 #include <QUrl> | 15 #include <QUrl> |
38 static Account account; | 39 static Account account; |
39 | 40 |
40 std::string SendRequest(std::string data) { | 41 std::string SendRequest(std::string data) { |
41 std::vector<std::string> headers = {"Authorization: Bearer " + account.AuthToken(), "Accept: application/json", | 42 std::vector<std::string> headers = {"Authorization: Bearer " + account.AuthToken(), "Accept: application/json", |
42 "Content-Type: application/json"}; | 43 "Content-Type: application/json"}; |
43 return HTTP::PerformBasicPostRequest("https://graphql.anilist.co", data, headers); | 44 return Strings::ToUtf8String(HTTP::Post("https://graphql.anilist.co", data, headers)); |
44 } | 45 } |
45 | 46 |
46 void ParseListStatus(std::string status, Anime::Anime& anime) { | 47 void ParseListStatus(std::string status, Anime::Anime& anime) { |
47 std::unordered_map<std::string, Anime::ListStatus> map = { | 48 std::unordered_map<std::string, Anime::ListStatus> map = { |
48 {"CURRENT", Anime::ListStatus::CURRENT }, | 49 {"CURRENT", Anime::ListStatus::CURRENT }, |
253 * float[] advancedScores, | 254 * float[] advancedScores, |
254 * Date startedAt, | 255 * Date startedAt, |
255 * Date completedAt | 256 * Date completedAt |
256 **/ | 257 **/ |
257 Anime::Anime& anime = Anime::db.items[id]; | 258 Anime::Anime& anime = Anime::db.items[id]; |
258 const std::string query = | 259 const std::string query = "mutation ($media_id: Int, $progress: Int, $status: MediaListStatus, $score: Int, " |
259 "mutation ($media_id: Int, $progress: Int, $status: MediaListStatus, $score: Int, $notes: String) {\n" | 260 "$notes: String, $start: FuzzyDateInput, $comp: FuzzyDateInput) {\n" |
260 " SaveMediaListEntry (mediaId: $media_id, progress: $progress, status: $status, scoreRaw: $score, notes: " | 261 " SaveMediaListEntry (mediaId: $media_id, progress: $progress, status: $status, " |
261 "$notes) {\n" | 262 "scoreRaw: $score, notes: $notes, startedAt: $start, completedAt: $comp) {\n" |
262 " id\n" | 263 " id\n" |
263 " }\n" | 264 " }\n" |
264 "}\n"; | 265 "}\n"; |
265 // clang-format off | 266 // clang-format off |
266 nlohmann::json json = { | 267 nlohmann::json json = { |
267 {"query", query}, | 268 {"query", query}, |
268 {"variables", { | 269 {"variables", { |
269 {"media_id", anime.GetId()}, | 270 {"media_id", anime.GetId()}, |
270 {"progress", anime.GetUserProgress()}, | 271 {"progress", anime.GetUserProgress()}, |
271 {"status", ListStatusToString(anime)}, | 272 {"status", ListStatusToString(anime)}, |
272 {"score", anime.GetUserScore()}, | 273 {"score", anime.GetUserScore()}, |
273 {"notes", anime.GetUserNotes()} | 274 {"notes", anime.GetUserNotes()}, |
275 {"start", anime.GetUserDateStarted().GetAsAniListJson()}, | |
276 {"comp", anime.GetUserDateCompleted().GetAsAniListJson()} | |
274 }} | 277 }} |
275 }; | 278 }; |
276 // clang-format on | 279 // clang-format on |
277 auto ret = nlohmann::json::parse(SendRequest(json.dump())); | 280 auto ret = nlohmann::json::parse(SendRequest(json.dump())); |
278 return JSON::GetInt(ret, "/data/SaveMediaListEntry/id"_json_pointer); | 281 return JSON::GetInt(ret, "/data/SaveMediaListEntry/id"_json_pointer); |