Working on updating a song's metadata
This commit is contained in:
@@ -153,8 +153,19 @@ namespace controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: create endpoint for updating songs
|
// TODO: create endpoint for updating songs
|
||||||
|
ENDPOINT("UPDATE", "/api/v1/song/{id}", songUpdate,
|
||||||
|
BODY_DTO(dto::SongDto::ObjectWrapper, songDto), PATH(Int32, id)) {
|
||||||
|
model::Song song(id);
|
||||||
|
songDto->id = id;
|
||||||
|
|
||||||
// TODO: work on this to handle the database records
|
auto updatedSong = manager::SongManager::songDtoConv(songDto);
|
||||||
|
std::cout << "printing updated song" << std::endl;
|
||||||
|
manager::SongManager::printSong(updatedSong);
|
||||||
|
|
||||||
|
return createResponse(Status::CODE_200, "OK");
|
||||||
|
}
|
||||||
|
|
||||||
|
// endpoint to delete a song
|
||||||
ENDPOINT("DELETE", "api/v1/song/data/{id}", songDelete, PATH(Int32, id)) {
|
ENDPOINT("DELETE", "api/v1/song/data/{id}", songDelete, PATH(Int32, id)) {
|
||||||
model::Song song(id);
|
model::Song song(id);
|
||||||
|
|
||||||
@@ -164,7 +175,7 @@ namespace controller
|
|||||||
return createResponse(Status::CODE_200, "OK");
|
return createResponse(Status::CODE_200, "OK");
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: create endpoint for streaming songs
|
// endpoint for streaming a song
|
||||||
ENDPOINT("GET", "/api/v1/song/stream/{id}", streamSong,
|
ENDPOINT("GET", "/api/v1/song/stream/{id}", streamSong,
|
||||||
PATH(Int32, id)) {
|
PATH(Int32, id)) {
|
||||||
database::SongRepository songRepo(m_bConf);
|
database::SongRepository songRepo(m_bConf);
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
#include "dto/SongDto.hpp"
|
||||||
#include "model/Models.h"
|
#include "model/Models.h"
|
||||||
|
|
||||||
namespace manager
|
namespace manager
|
||||||
@@ -18,6 +19,9 @@ namespace manager
|
|||||||
|
|
||||||
void saveSong(model::Song&);
|
void saveSong(model::Song&);
|
||||||
void deleteSong(model::Song&);
|
void deleteSong(model::Song&);
|
||||||
|
void updateSong(model::Song&);
|
||||||
|
|
||||||
|
static model::Song songDtoConv(dto::SongDto::ObjectWrapper&);
|
||||||
|
|
||||||
static void printSong(const model::Song&);
|
static void printSong(const model::Song&);
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -45,9 +45,6 @@ void manager::SongManager::saveSong(model::Song& song)
|
|||||||
|
|
||||||
void manager::SongManager::deleteSong(model::Song& song)
|
void manager::SongManager::deleteSong(model::Song& song)
|
||||||
{
|
{
|
||||||
// TODO: handle what happens to miscellanes records
|
|
||||||
// like Album, Artist, Genre, etc. when a song
|
|
||||||
// is deleted
|
|
||||||
database::SongRepository songRepo(m_bConf);
|
database::SongRepository songRepo(m_bConf);
|
||||||
|
|
||||||
if (!songRepo.doesSongExist(song, type::SongFilter::id)) {
|
if (!songRepo.doesSongExist(song, type::SongFilter::id)) {
|
||||||
@@ -71,6 +68,40 @@ 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)
|
||||||
|
{
|
||||||
|
// TODO: update song metadata
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
model::Song song;
|
||||||
|
song.id = songDto->id;
|
||||||
|
song.album = (songDto->album == nullptr) ? "" : songDto->album->c_str();
|
||||||
|
song.artist = (songDto->artist == nullptr) ? "" : songDto->artist->c_str();
|
||||||
|
song.genre = (songDto->genre == nullptr) ? "" : songDto->genre->c_str();
|
||||||
|
auto s = songDto->year.empty();
|
||||||
|
std::cout << s << std::endl;
|
||||||
|
auto sy = &songDto->year;
|
||||||
|
if (sy->empty()) {
|
||||||
|
//}
|
||||||
|
//if (true) {
|
||||||
|
std::cout << "year is null" << std::endl;
|
||||||
|
} else {
|
||||||
|
std::cout << "year is not null" << std::endl;
|
||||||
|
}
|
||||||
|
song.title = (songDto->title == nullptr) ? "" : songDto->title->c_str();
|
||||||
|
//song.track = songDto->track;
|
||||||
|
//song.duration = songDto->duration;
|
||||||
|
//song.disc = songDto->disc;
|
||||||
|
|
||||||
|
return song;
|
||||||
|
}
|
||||||
|
|
||||||
void manager::SongManager::printSong(const model::Song& song)
|
void manager::SongManager::printSong(const model::Song& song)
|
||||||
{
|
{
|
||||||
std::cout << "\nsong" << std::endl;
|
std::cout << "\nsong" << std::endl;
|
||||||
|
|||||||
Reference in New Issue
Block a user