Added functionality to check if the song already exists when uploading
This commit is contained in:
@@ -27,6 +27,7 @@
|
||||
#include "model/Models.h"
|
||||
#include "type/Scopes.h"
|
||||
#include "type/SongFilter.h"
|
||||
#include "type/SongUpload.h"
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
@@ -74,7 +75,16 @@ public:
|
||||
sng.data = std::move(data);
|
||||
|
||||
manager::SongManager songMgr(m_bConf);
|
||||
songMgr.saveSong(sng);
|
||||
const auto result = songMgr.saveSong(sng);
|
||||
if (!result.first) {
|
||||
switch (result.second) {
|
||||
case type::SongUpload::AlreadyExist:
|
||||
return createResponse(Status::CODE_400, "Song already exists");
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
auto songDto = dto::conversion::DtoConversions::toSongDto(sng);
|
||||
|
||||
return createDtoResponse(Status::CODE_200, songDto);
|
||||
|
||||
@@ -4,12 +4,14 @@
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include "dto/SongDto.hpp"
|
||||
#include "model/Models.h"
|
||||
#include "type/SongChanged.h"
|
||||
#include "type/SongUpload.h"
|
||||
|
||||
namespace manager {
|
||||
class SongManager
|
||||
@@ -17,14 +19,13 @@ namespace manager {
|
||||
public:
|
||||
SongManager(const model::BinaryPath&);
|
||||
|
||||
std::pair<bool, type::SongUpload> saveSong(model::Song&);
|
||||
|
||||
bool didSongChange(const model::Song&, const model::Song&);
|
||||
bool requiresFilesystemChange(const model::Song&, const model::Song&);
|
||||
bool deleteSong(model::Song&);
|
||||
bool updateSong(model::Song&);
|
||||
|
||||
void saveSong(model::Song&);
|
||||
|
||||
static void printSong(const model::Song&);
|
||||
private:
|
||||
std::map<type::SongChanged, bool> changesInSong(const model::Song&, const model::Song&);
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
#ifndef SONGUPLOAD_H_
|
||||
#define SONGUPLOAD_H_
|
||||
|
||||
namespace type
|
||||
{
|
||||
enum class SongUpload
|
||||
{
|
||||
Successful = 0,
|
||||
AlreadyExist = 1,
|
||||
Failed = 2
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user