mirror of
https://github.com/clangen/musikcube.git
synced 2025-01-05 12:54:02 +00:00
Fix SavePlaylistQuery
This commit is contained in:
parent
37d7acb147
commit
c88942569b
@ -344,9 +344,6 @@ bool SavePlaylistQuery::CreatePlaylist(musik::core::db::Connection &db) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this->library->GetMessageQueue().Broadcast(
|
|
||||||
Message::Create(nullptr, message::PlaylistCreated, playlistId));
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -354,14 +351,7 @@ bool SavePlaylistQuery::RenamePlaylist(musik::core::db::Connection &db) {
|
|||||||
Statement renamePlaylist(RENAME_PLAYLIST_QUERY.c_str(), db);
|
Statement renamePlaylist(RENAME_PLAYLIST_QUERY.c_str(), db);
|
||||||
renamePlaylist.BindText(0, this->playlistName);
|
renamePlaylist.BindText(0, this->playlistName);
|
||||||
renamePlaylist.BindInt64(1, this->playlistId);
|
renamePlaylist.BindInt64(1, this->playlistId);
|
||||||
bool result = (renamePlaylist.Step() != db::Error);
|
return (renamePlaylist.Step() != db::Error);
|
||||||
|
|
||||||
if (result) {
|
|
||||||
this->library->GetMessageQueue().Broadcast(
|
|
||||||
Message::Create(nullptr, message::PlaylistRenamed, playlistId));
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SavePlaylistQuery::ReplacePlaylist(musik::core::db::Connection &db) {
|
bool SavePlaylistQuery::ReplacePlaylist(musik::core::db::Connection &db) {
|
||||||
@ -382,9 +372,6 @@ bool SavePlaylistQuery::ReplacePlaylist(musik::core::db::Connection &db) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->library->GetMessageQueue().Broadcast(
|
|
||||||
Message::Create(nullptr, message::PlaylistModified, playlistId));
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -399,9 +386,6 @@ bool SavePlaylistQuery::AppendToPlaylist(musik::core::db::Connection& db) {
|
|||||||
transaction.Cancel();
|
transaction.Cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
this->library->GetMessageQueue().Broadcast(
|
|
||||||
Message::Create(nullptr, message::PlaylistModified, playlistId));
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -413,9 +397,33 @@ bool SavePlaylistQuery::OnRun(musik::core::db::Connection &db) {
|
|||||||
case Operation::Create: this->result = this->CreatePlaylist(db); break;
|
case Operation::Create: this->result = this->CreatePlaylist(db); break;
|
||||||
case Operation::Append: this->result = this->AppendToPlaylist(db); break;
|
case Operation::Append: this->result = this->AppendToPlaylist(db); break;
|
||||||
}
|
}
|
||||||
|
if (this->result) {
|
||||||
|
this->SendPlaylistMutationBroadcast();
|
||||||
|
}
|
||||||
return this->result;
|
return this->result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SavePlaylistQuery::SendPlaylistMutationBroadcast() {
|
||||||
|
switch (this->op) {
|
||||||
|
case Operation::Rename:
|
||||||
|
this->library->GetMessageQueue().Broadcast(
|
||||||
|
Message::Create(nullptr, message::PlaylistRenamed, playlistId));
|
||||||
|
break;
|
||||||
|
case Operation::Replace:
|
||||||
|
this->library->GetMessageQueue().Broadcast(
|
||||||
|
Message::Create(nullptr, message::PlaylistModified, playlistId));
|
||||||
|
break;
|
||||||
|
case Operation::Create:
|
||||||
|
this->library->GetMessageQueue().Broadcast(
|
||||||
|
Message::Create(nullptr, message::PlaylistCreated, playlistId));
|
||||||
|
break;
|
||||||
|
case Operation::Append:
|
||||||
|
this->library->GetMessageQueue().Broadcast(
|
||||||
|
Message::Create(nullptr, message::PlaylistModified, playlistId));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* SUPPORTING TYPES */
|
/* SUPPORTING TYPES */
|
||||||
|
|
||||||
SavePlaylistQuery::TrackListWrapper::TrackListWrapper() {
|
SavePlaylistQuery::TrackListWrapper::TrackListWrapper() {
|
||||||
@ -469,15 +477,18 @@ ITrackList* SavePlaylistQuery::TrackListWrapper::Get() {
|
|||||||
/* ISerializableQuery */
|
/* ISerializableQuery */
|
||||||
|
|
||||||
std::string SavePlaylistQuery::SerializeQuery() {
|
std::string SavePlaylistQuery::SerializeQuery() {
|
||||||
|
nlohmann::json tracksJson = tracks.Get()
|
||||||
|
? ITrackListToJsonIdList(*tracks.Get())
|
||||||
|
: nlohmann::json();
|
||||||
nlohmann::json output = {
|
nlohmann::json output = {
|
||||||
{ "name", kQueryName },
|
{ "name", kQueryName },
|
||||||
{ "options", {
|
{ "options", {
|
||||||
{ "op", this->op },
|
{ "op", this->op },
|
||||||
{ "playlistName", this->playlistName },
|
{ "playlistName", this->playlistName },
|
||||||
{ "categoryType", this->categoryType },
|
{ "categoryType", this->categoryType },
|
||||||
{ "playlistId", this->playlistId },
|
{ "playlistId", this->playlistId },
|
||||||
{ "categoryId", this->categoryId },
|
{ "categoryId", this->categoryId },
|
||||||
{ "tracks", ITrackListToJsonIdList(*tracks.Get()) }
|
{ "tracks", tracksJson }
|
||||||
}}
|
}}
|
||||||
};
|
};
|
||||||
return output.dump();
|
return output.dump();
|
||||||
@ -490,8 +501,11 @@ std::string SavePlaylistQuery::SerializeResult() {
|
|||||||
|
|
||||||
void SavePlaylistQuery::DeserializeResult(const std::string& data) {
|
void SavePlaylistQuery::DeserializeResult(const std::string& data) {
|
||||||
auto input = nlohmann::json::parse(data);
|
auto input = nlohmann::json::parse(data);
|
||||||
this->SetStatus(input["result"].get<bool>() == true
|
this->result = input["result"].get<bool>();
|
||||||
? IQuery::Finished : IQuery::Failed);
|
this->SetStatus(result ? IQuery::Finished : IQuery::Failed);
|
||||||
|
if (result) {
|
||||||
|
SendPlaylistMutationBroadcast();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<SavePlaylistQuery> SavePlaylistQuery::DeserializeQuery(
|
std::shared_ptr<SavePlaylistQuery> SavePlaylistQuery::DeserializeQuery(
|
||||||
|
@ -144,6 +144,8 @@ namespace musik { namespace core { namespace library { namespace query {
|
|||||||
|
|
||||||
SavePlaylistQuery(musik::core::ILibraryPtr library); /* for query (de)serialization */
|
SavePlaylistQuery(musik::core::ILibraryPtr library); /* for query (de)serialization */
|
||||||
|
|
||||||
|
void SendPlaylistMutationBroadcast();
|
||||||
|
|
||||||
struct TrackListWrapper {
|
struct TrackListWrapper {
|
||||||
TrackListWrapper();
|
TrackListWrapper();
|
||||||
TrackListWrapper(std::shared_ptr<musik::core::TrackList> shared);
|
TrackListWrapper(std::shared_ptr<musik::core::TrackList> shared);
|
||||||
|
Loading…
Reference in New Issue
Block a user