-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First pass at getting Playlists working again
- Loading branch information
Showing
20 changed files
with
977 additions
and
641 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
|
||
#include <vector> | ||
#include <string> | ||
|
||
#include <oatpp/core/Types.hpp> | ||
|
||
#include "model/Playlist.h" | ||
#include "model/PlaylistItem.h" | ||
|
||
namespace creatures { | ||
|
||
|
||
std::vector<std::string> playlist_required_fields = { | ||
"id", "number_of_items", "items" | ||
}; | ||
|
||
std::vector<std::string> playlistitems_required_fields = { | ||
"animation_id", "weight" | ||
}; | ||
|
||
|
||
oatpp::Object<PlaylistDto> convertToDto(const Playlist &playlist) { | ||
auto playlistDto = PlaylistDto::createShared(); | ||
playlistDto->id = playlist.id; | ||
playlistDto->name = playlist.name; | ||
playlistDto->number_of_items = playlist.number_of_items; | ||
playlistDto->items = oatpp::List<oatpp::Object<PlaylistItemDto>>::createShared(); | ||
|
||
// Now do the items | ||
for (const auto &item: playlist.items) { | ||
playlistDto->items->emplace_back(convertToDto(item)); | ||
} | ||
|
||
return playlistDto; | ||
} | ||
|
||
Playlist convertFromDto(const std::shared_ptr<PlaylistDto> &playlistDto) { | ||
Playlist playlist; | ||
playlist.id = playlistDto->id; | ||
playlist.name = playlistDto->name; | ||
playlist.number_of_items = playlistDto->number_of_items; | ||
|
||
// Ensure the list is initialized before iterating | ||
playlist.items = std::vector<PlaylistItem>(); | ||
for (const auto &listItem: *playlistDto->items.getPtr()) { | ||
playlist.items.push_back(convertFromDto(listItem.getPtr())); | ||
} | ||
|
||
return playlist; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
|
||
#pragma once | ||
|
||
#include <vector> | ||
#include <string> | ||
|
||
#include <oatpp/core/Types.hpp> | ||
#include <oatpp/core/macro/codegen.hpp> | ||
|
||
#include "server/namespace-stuffs.h" | ||
|
||
#include "model/PlaylistItem.h" | ||
|
||
|
||
namespace creatures { | ||
|
||
struct Playlist { | ||
playlistId_t id; | ||
std::string name; | ||
std::vector<PlaylistItem> items; | ||
uint32_t number_of_items; | ||
}; | ||
|
||
|
||
#include OATPP_CODEGEN_BEGIN(DTO) | ||
|
||
class PlaylistDto : public oatpp::DTO { | ||
|
||
DTO_INIT(PlaylistDto, DTO /* extends */) | ||
|
||
DTO_FIELD_INFO(id) { | ||
info->description = "The ID of this playlist in the form of an UUID"; | ||
} | ||
|
||
DTO_FIELD(String, id); | ||
|
||
DTO_FIELD_INFO(name) { | ||
info->description = "The name of this playlist in the UI"; | ||
} | ||
|
||
DTO_FIELD(String, name); | ||
|
||
DTO_FIELD_INFO(items) { | ||
info->description = "The items in the playlist"; | ||
} | ||
|
||
DTO_FIELD(List < Object < PlaylistItemDto >>, items); | ||
|
||
DTO_FIELD_INFO(number_of_items) { | ||
info->description = "The number of items in this playlist"; | ||
} | ||
|
||
DTO_FIELD(UInt32, number_of_items); | ||
|
||
|
||
}; | ||
|
||
#include OATPP_CODEGEN_END(DTO) | ||
|
||
oatpp::Object<PlaylistDto> convertToDto(const Playlist &playlist); | ||
|
||
Playlist convertFromDto(const std::shared_ptr<PlaylistDto> &playlistDto); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
|
||
|
||
#include <string> | ||
|
||
#include <spdlog/spdlog.h> | ||
#include <oatpp/core/Types.hpp> | ||
|
||
#include "model/PlaylistItem.h" | ||
|
||
namespace creatures { | ||
|
||
std::vector<std::string> playlistitem_required_fields = { | ||
"animation_id", "weight" | ||
}; | ||
|
||
|
||
// Convert a DTO to the real thing | ||
PlaylistItem convertFromDto(const std::shared_ptr<PlaylistItemDto> &playlistItemDto) { | ||
|
||
trace("Converting PlaylistItemDto to PlaylistItem"); | ||
|
||
PlaylistItem playlistItem; | ||
playlistItem.animation_id = playlistItemDto->animation_id; | ||
playlistItem.weight = playlistItemDto->weight; | ||
trace("animation_id: {}, weight: {}", playlistItem.animation_id, playlistItem.weight); | ||
|
||
return playlistItem; | ||
} | ||
|
||
oatpp::Object<PlaylistItemDto> convertToDto(const PlaylistItem &playlistItem) { | ||
auto playlistItemDto = PlaylistItemDto::createShared(); | ||
playlistItemDto->animation_id = playlistItem.animation_id; | ||
playlistItemDto->weight = playlistItem.weight; | ||
return playlistItemDto; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
|
||
#pragma once | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
#include <oatpp/core/Types.hpp> | ||
#include <oatpp/core/macro/codegen.hpp> | ||
|
||
#include "server/namespace-stuffs.h" | ||
|
||
|
||
namespace creatures { | ||
|
||
/* | ||
* This is one item in a playlist | ||
*/ | ||
|
||
|
||
struct PlaylistItem { | ||
|
||
/** | ||
* The ID of the playlist | ||
*/ | ||
animationId_t animation_id; | ||
|
||
/** | ||
* The weight of the item | ||
*/ | ||
uint32_t weight; | ||
|
||
}; | ||
|
||
|
||
#include OATPP_CODEGEN_BEGIN(DTO) | ||
|
||
class PlaylistItemDto : public oatpp::DTO { | ||
|
||
DTO_INIT(PlaylistItemDto, DTO /* extends */) | ||
|
||
DTO_FIELD_INFO(animation_id) { | ||
info->description = "The ID of the animation for this entry"; | ||
} | ||
DTO_FIELD(String, animation_id); | ||
|
||
DTO_FIELD_INFO(weight) { | ||
info->description = "This item's weight"; | ||
} | ||
DTO_FIELD(UInt32 , weight); | ||
|
||
}; | ||
|
||
#include OATPP_CODEGEN_END(DTO) | ||
|
||
oatpp::Object<PlaylistItemDto> convertToDto(const PlaylistItem &playlistItem); | ||
creatures::PlaylistItem convertFromDto(const std::shared_ptr<PlaylistItemDto> &playlistItemDto); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.