Switching to C++ #60
@@ -14,6 +14,7 @@ public:
|
|||||||
|
|
||||||
Cover retrieveRecord(Cover&, coverFilter);
|
Cover retrieveRecord(Cover&, coverFilter);
|
||||||
|
|
||||||
|
void deleteRecord(const Cover&);
|
||||||
void saveRecord(const Cover&);
|
void saveRecord(const Cover&);
|
||||||
private:
|
private:
|
||||||
Cover parseRecord(MYSQL_RES*);
|
Cover parseRecord(MYSQL_RES*);
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ public:
|
|||||||
|
|
||||||
Song retrieveRecord(Song&, songFilter);
|
Song retrieveRecord(Song&, songFilter);
|
||||||
|
|
||||||
|
void deleteRecord(const Song&);
|
||||||
void saveRecord(const Song&);
|
void saveRecord(const Song&);
|
||||||
private:
|
private:
|
||||||
std::vector<Song> parseRecords(MYSQL_RES*);
|
std::vector<Song> parseRecords(MYSQL_RES*);
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ public:
|
|||||||
song_manager(std::string&);
|
song_manager(std::string&);
|
||||||
|
|
||||||
void saveSong(Song&);
|
void saveSong(Song&);
|
||||||
|
void deleteSong(Song&);
|
||||||
|
|
||||||
static void printSong(const Song&);
|
static void printSong(const Song&);
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -194,6 +194,17 @@ public:
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ENDPOINT("DELETE", "api/v1/song/data/{id}", songDelete, PATH(Int32, id)) {
|
||||||
|
|
||||||
|
Song song;
|
||||||
|
song.id = id;
|
||||||
|
|
||||||
|
song_manager sngMgr(exe_path);
|
||||||
|
sngMgr.deleteSong(song);
|
||||||
|
|
||||||
|
return createResponse(Status::CODE_200, "OK");
|
||||||
|
}
|
||||||
|
|
||||||
#include OATPP_CODEGEN_END(ApiController)
|
#include OATPP_CODEGEN_END(ApiController)
|
||||||
private:
|
private:
|
||||||
std::string exe_path;
|
std::string exe_path;
|
||||||
|
|||||||
@@ -45,6 +45,15 @@ Cover coverArtRepository::retrieveRecord(Cover& cov, coverFilter filter = coverF
|
|||||||
return covDb;
|
return covDb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void coverArtRepository::deleteRecord(const Cover& cov)
|
||||||
|
{
|
||||||
|
auto conn = setup_mysql_connection();
|
||||||
|
const std::string query("DELETE FROM CoverArt WHERE CoverArtId = " + std::to_string(cov.id));
|
||||||
|
|
||||||
|
auto result = perform_mysql_query(conn, query);
|
||||||
|
|
||||||
|
mysql_close(conn);
|
||||||
|
}
|
||||||
|
|
||||||
void coverArtRepository::saveRecord(const Cover& cov)
|
void coverArtRepository::saveRecord(const Cover& cov)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -57,6 +57,18 @@ Song songRepository::retrieveRecord(Song& song, songFilter filter)
|
|||||||
return song;
|
return song;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void songRepository::deleteRecord(const Song& song)
|
||||||
|
{
|
||||||
|
auto conn = setup_mysql_connection();
|
||||||
|
auto status = 0;
|
||||||
|
|
||||||
|
const std::string query("DELETE FROM Song WHERE SongId = " + std::to_string(song.id));
|
||||||
|
|
||||||
|
auto result = perform_mysql_query(conn, query);
|
||||||
|
|
||||||
|
mysql_close(conn);
|
||||||
|
}
|
||||||
|
|
||||||
void songRepository::saveRecord(const Song& song)
|
void songRepository::saveRecord(const Song& song)
|
||||||
{
|
{
|
||||||
auto conn = setup_mysql_connection();
|
auto conn = setup_mysql_connection();
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
#include "database/coverArtRepository.h"
|
||||||
#include "database/songRepository.h"
|
#include "database/songRepository.h"
|
||||||
#include "managers/coverArtManager.h"
|
#include "managers/coverArtManager.h"
|
||||||
#include "managers/directory_manager.h"
|
#include "managers/directory_manager.h"
|
||||||
@@ -53,6 +54,28 @@ void song_manager::saveSong(Song& song)
|
|||||||
songRepo.saveRecord(song);
|
songRepo.saveRecord(song);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void song_manager::deleteSong(Song& song)
|
||||||
|
{
|
||||||
|
coverArtRepository covRepo(exe_path);
|
||||||
|
songRepository songRepo(exe_path);
|
||||||
|
|
||||||
|
song = songRepo.retrieveRecord(song, songFilter::id);
|
||||||
|
songRepo.deleteRecord(song);
|
||||||
|
|
||||||
|
Cover cov;
|
||||||
|
cov.id = song.coverArtId;
|
||||||
|
cov = covRepo.retrieveRecord(cov, coverFilter::id);
|
||||||
|
covRepo.deleteRecord(cov);
|
||||||
|
|
||||||
|
|
||||||
|
// TODO: only delete coverArt that is not the stock cover
|
||||||
|
// path
|
||||||
|
fs::remove(cov.imagePath);
|
||||||
|
fs::remove(song.songPath);
|
||||||
|
|
||||||
|
// TODO: delete empty directories
|
||||||
|
}
|
||||||
|
|
||||||
void song_manager::printSong(const Song& song)
|
void song_manager::printSong(const Song& song)
|
||||||
{
|
{
|
||||||
std::cout << std::endl << "song" << std::endl;
|
std::cout << std::endl << "song" << std::endl;
|
||||||
|
|||||||
Reference in New Issue
Block a user