Code cleanup
This commit is contained in:
@@ -7,75 +7,70 @@
|
||||
|
||||
namespace manager {
|
||||
|
||||
ArtistManager::ArtistManager(const model::BinaryPath& bConf) : m_bConf(bConf) { }
|
||||
ArtistManager::ArtistManager(const model::BinaryPath& bConf) : m_bConf(bConf) { }
|
||||
|
||||
|
||||
model::Artist ArtistManager::retrieveArtist(model::Artist& artist)
|
||||
{
|
||||
std::cout << "retrieving artist record" << std::endl;
|
||||
database::ArtistRepository artRepo(m_bConf);
|
||||
std::cout << "initialized artist repo" << std::endl;
|
||||
std::cout << artist.artist << std::endl;
|
||||
artist = artRepo.retrieveRecord(artist, type::ArtistFilter::artist);
|
||||
model::Artist ArtistManager::retrieveArtist(model::Artist& artist) {
|
||||
std::cout << "retrieving artist record\n";
|
||||
database::ArtistRepository artRepo(m_bConf);
|
||||
std::cout << "initialized artist repo\n";
|
||||
std::cout << artist.artist << "\n";
|
||||
artist = artRepo.retrieveRecord(artist, type::ArtistFilter::artist);
|
||||
|
||||
return artist;
|
||||
}
|
||||
|
||||
model::Artist ArtistManager::saveArtist(const model::Song& song)
|
||||
{
|
||||
model::Artist artist;
|
||||
artist.artist = song.artist;
|
||||
|
||||
database::ArtistRepository artRepo(m_bConf);
|
||||
if (!artRepo.doesArtistExist(artist, type::ArtistFilter::artist)) {
|
||||
artRepo.saveRecord(artist);
|
||||
} else {
|
||||
std::cout << "artist already exists" << std::endl;
|
||||
return artist;
|
||||
}
|
||||
|
||||
return artist;
|
||||
}
|
||||
model::Artist ArtistManager::saveArtist(const model::Song& song) {
|
||||
model::Artist artist;
|
||||
artist.artist = song.artist;
|
||||
|
||||
database::ArtistRepository artRepo(m_bConf);
|
||||
if (!artRepo.doesArtistExist(artist, type::ArtistFilter::artist)) {
|
||||
artRepo.saveRecord(artist);
|
||||
} else {
|
||||
std::cout << "artist already exists\n";
|
||||
}
|
||||
|
||||
return artist;
|
||||
}
|
||||
|
||||
|
||||
void ArtistManager::deleteArtist(const model::Song& song)
|
||||
{
|
||||
model::Artist artist(song);
|
||||
void ArtistManager::deleteArtist(const model::Song& song) {
|
||||
model::Artist artist(song);
|
||||
|
||||
database::ArtistRepository artRepo(m_bConf);
|
||||
auto artWSC = artRepo.retrieveRecordWithSongCount(artist, type::ArtistFilter::id);
|
||||
database::ArtistRepository artRepo(m_bConf);
|
||||
auto artWSC = artRepo.retrieveRecordWithSongCount(artist, type::ArtistFilter::id);
|
||||
|
||||
if (artWSC.second > 1) {
|
||||
std::cout << "artist still contain songs related to it";
|
||||
std::cout << ", not delete" << std::endl;
|
||||
return;
|
||||
if (artWSC.second > 1) {
|
||||
std::cout << "artist still contain songs related to it";
|
||||
std::cout << ", not delete\n";
|
||||
return;
|
||||
}
|
||||
|
||||
std::cout << "safe to delete the artist record\n";
|
||||
artRepo.deleteArtist(artist, type::ArtistFilter::id);
|
||||
}
|
||||
|
||||
std::cout << "safe to delete the artist record" << std::endl;
|
||||
artRepo.deleteArtist(artist, type::ArtistFilter::id);
|
||||
}
|
||||
void ArtistManager::updateArtist(model::Song& updatedSong,
|
||||
const model::Song& currSong) {
|
||||
model::Artist artist;
|
||||
artist.artist = updatedSong.artist;
|
||||
|
||||
void ArtistManager::updateArtist(model::Song& updatedSong,
|
||||
const model::Song& currSong)
|
||||
{
|
||||
model::Artist artist;
|
||||
artist.artist = updatedSong.artist;
|
||||
database::ArtistRepository artRepo(m_bConf);
|
||||
if (!artRepo.doesArtistExist(artist, type::ArtistFilter::artist)) {
|
||||
std::cout << "artist record does not exist\n";
|
||||
artRepo.saveRecord(artist);
|
||||
} else {
|
||||
std::cout << "artist record already exists\n";
|
||||
}
|
||||
|
||||
database::ArtistRepository artRepo(m_bConf);
|
||||
if (!artRepo.doesArtistExist(artist, type::ArtistFilter::artist)) {
|
||||
std::cout << "artist record does not exist" << std::endl;
|
||||
artRepo.saveRecord(artist);
|
||||
} else {
|
||||
std::cout << "artist record already exists" << std::endl;
|
||||
artist = artRepo.retrieveRecord(artist, type::ArtistFilter::artist);
|
||||
updatedSong.artistId = artist.id;
|
||||
}
|
||||
|
||||
artist = artRepo.retrieveRecord(artist, type::ArtistFilter::artist);
|
||||
updatedSong.artistId = artist.id;
|
||||
}
|
||||
|
||||
void ArtistManager::printArtist(const model::Artist& artist)
|
||||
{
|
||||
std::cout << "\nartist record" << std::endl;
|
||||
std::cout << "id: " << artist.id << std::endl;
|
||||
std::cout << "artist: " << artist.artist << std::endl;
|
||||
}
|
||||
void ArtistManager::printArtist(const model::Artist& artist) {
|
||||
std::cout << "\nartist record" << "\n";
|
||||
std::cout << "id: " << artist.id << "\n";
|
||||
std::cout << "artist: " << artist.artist << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user