Figured out how to check if Int32 values from the ObjectWrapper have any values. Just get the pointer of it and see if it is a nullptr
This commit is contained in:
@@ -155,12 +155,13 @@ namespace controller
|
|||||||
// TODO: create endpoint for updating songs
|
// TODO: create endpoint for updating songs
|
||||||
ENDPOINT("UPDATE", "/api/v1/song/{id}", songUpdate,
|
ENDPOINT("UPDATE", "/api/v1/song/{id}", songUpdate,
|
||||||
BODY_DTO(dto::SongDto::ObjectWrapper, songDto), PATH(Int32, id)) {
|
BODY_DTO(dto::SongDto::ObjectWrapper, songDto), PATH(Int32, id)) {
|
||||||
model::Song song(id);
|
|
||||||
songDto->id = id;
|
songDto->id = id;
|
||||||
|
|
||||||
auto updatedSong = manager::SongManager::songDtoConv(songDto);
|
auto updatedSong = manager::SongManager::songDtoConv(songDto);
|
||||||
std::cout << "printing updated song" << std::endl;
|
std::cout << "printing updated song" << std::endl;
|
||||||
manager::SongManager::printSong(updatedSong);
|
manager::SongManager::printSong(updatedSong);
|
||||||
|
manager::SongManager songMgr(m_bConf);
|
||||||
|
songMgr.updateSong(updatedSong);
|
||||||
|
|
||||||
return createResponse(Status::CODE_200, "OK");
|
return createResponse(Status::CODE_200, "OK");
|
||||||
}
|
}
|
||||||
|
|||||||
+34
-17
@@ -5,6 +5,8 @@
|
|||||||
#include <random>
|
#include <random>
|
||||||
|
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
|
#include "oatpp/web/protocol/http/outgoing/ChunkedBody.hpp"
|
||||||
|
#include "oatpp/web/server/api/ApiController.hpp"
|
||||||
|
|
||||||
#include "database/CoverArtRepository.h"
|
#include "database/CoverArtRepository.h"
|
||||||
#include "database/SongRepository.h"
|
#include "database/SongRepository.h"
|
||||||
@@ -68,36 +70,51 @@ void manager::SongManager::deleteSong(model::Song& song)
|
|||||||
manager::DirectoryManager::deleteDirectories(song, paths["root_music_path"].get<std::string>());
|
manager::DirectoryManager::deleteDirectories(song, paths["root_music_path"].get<std::string>());
|
||||||
}
|
}
|
||||||
|
|
||||||
void manager::SongManager::updateSong(model::Song& song)
|
void manager::SongManager::updateSong(model::Song& updatedSong)
|
||||||
{
|
{
|
||||||
// TODO: update song metadata
|
database::SongRepository songRepo(m_bConf);
|
||||||
|
|
||||||
|
OATPP_ASSERT_HTTP(songRepo.doesSongExist(updatedSong, type::SongFilter::id) , oatpp::web::protocol::http::Status::CODE_404, "song does not exist");
|
||||||
|
|
||||||
|
auto currSong = songRepo.retrieveRecord(updatedSong, type::SongFilter::id);
|
||||||
|
utility::MetadataRetriever meta;
|
||||||
|
meta.updateMetadata(updatedSong, currSong);
|
||||||
|
|
||||||
|
// TODO:
|
||||||
|
// 1. depending on what metadata was changed there might be a need to
|
||||||
|
// change where the song is stored on the filesystem, deleting empty
|
||||||
|
// directories in the process
|
||||||
|
// 2. create or delete necessary records
|
||||||
}
|
}
|
||||||
|
|
||||||
model::Song manager::SongManager::songDtoConv(dto::SongDto::ObjectWrapper& songDto)
|
model::Song manager::SongManager::songDtoConv(dto::SongDto::ObjectWrapper& songDto)
|
||||||
{
|
{
|
||||||
// TODO: figure out how to determine if a non-character sequence
|
|
||||||
// field is empty. Will be necessary for updating the
|
|
||||||
// song based on what the HTTP request body is
|
|
||||||
std::cout << "coverting dto::SongDto to model::Song" << std::endl;
|
std::cout << "coverting dto::SongDto to model::Song" << std::endl;
|
||||||
model::Song song;
|
model::Song song;
|
||||||
song.id = songDto->id;
|
song.id = songDto->id;
|
||||||
song.album = (songDto->album == nullptr) ? "" : songDto->album->c_str();
|
song.album = (songDto->album == nullptr) ? "" : songDto->album->c_str();
|
||||||
song.artist = (songDto->artist == nullptr) ? "" : songDto->artist->c_str();
|
song.artist = (songDto->artist == nullptr) ? "" : songDto->artist->c_str();
|
||||||
song.genre = (songDto->genre == nullptr) ? "" : songDto->genre->c_str();
|
song.genre = (songDto->genre == nullptr) ? "" : songDto->genre->c_str();
|
||||||
auto s = songDto->year.empty();
|
auto year = songDto->year.getPtr();
|
||||||
std::cout << s << std::endl;
|
auto track = songDto->track.getPtr();
|
||||||
auto sy = &songDto->year;
|
auto disc = songDto->track.getPtr();
|
||||||
if (sy->empty()) {
|
auto duration = songDto->track.getPtr();
|
||||||
//}
|
if (year != nullptr) {
|
||||||
//if (true) {
|
std::cout << "not null" << std::endl;
|
||||||
std::cout << "year is null" << std::endl;
|
song.year = songDto->year;
|
||||||
} else {
|
} else {
|
||||||
std::cout << "year is not null" << std::endl;
|
year = 0;
|
||||||
|
}
|
||||||
|
if (track != nullptr) {
|
||||||
|
song.track = songDto->track;
|
||||||
|
} else {
|
||||||
|
track = 0;
|
||||||
|
}
|
||||||
|
if (disc != nullptr) {
|
||||||
|
song.disc = songDto->disc;
|
||||||
|
} else {
|
||||||
|
disc = 0;
|
||||||
}
|
}
|
||||||
song.title = (songDto->title == nullptr) ? "" : songDto->title->c_str();
|
|
||||||
//song.track = songDto->track;
|
|
||||||
//song.duration = songDto->duration;
|
|
||||||
//song.disc = songDto->disc;
|
|
||||||
|
|
||||||
return song;
|
return song;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user