Delete song endpoint Bug fix (#111)
* Bug fix * Removed some code * Simplifying method
This commit was merged in pull request #111.
This commit is contained in:
@@ -92,29 +92,6 @@ public class DirectoryManager : BaseManager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteEmptyDirectories()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var albumDirectory = AlbumDirectory();
|
|
||||||
var artistDirectory = ArtistDirectory();
|
|
||||||
if (IsDirectoryEmpty(albumDirectory))
|
|
||||||
{
|
|
||||||
Directory.Delete(albumDirectory);
|
|
||||||
Console.WriteLine($"directory {albumDirectory} deleted");
|
|
||||||
}
|
|
||||||
if (IsDirectoryEmpty(artistDirectory))
|
|
||||||
{
|
|
||||||
Directory.Delete(artistDirectory);
|
|
||||||
Console.WriteLine($"directory {artistDirectory} deleted");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
var exMsg = ex.Message;
|
|
||||||
Console.WriteLine($"An error occurred {exMsg}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int DeleteEmptyDirectories(string? directory, int level)
|
public int DeleteEmptyDirectories(string? directory, int level)
|
||||||
{
|
{
|
||||||
@@ -157,12 +134,12 @@ public class DirectoryManager : BaseManager
|
|||||||
var albumDirectory = AlbumDirectory(song);
|
var albumDirectory = AlbumDirectory(song);
|
||||||
var artistDirectory = ArtistDirectory(song);
|
var artistDirectory = ArtistDirectory(song);
|
||||||
|
|
||||||
if (IsDirectoryEmpty(albumDirectory))
|
if (Directory.Exists(albumDirectory) && IsDirectoryEmpty(albumDirectory))
|
||||||
{
|
{
|
||||||
Directory.Delete(albumDirectory);
|
Directory.Delete(albumDirectory);
|
||||||
_logger.Info("Album directory deleted");
|
_logger.Info("Album directory deleted");
|
||||||
}
|
}
|
||||||
if (IsDirectoryEmpty(artistDirectory))
|
if (Directory.Exists(artistDirectory) && IsDirectoryEmpty(artistDirectory))
|
||||||
{
|
{
|
||||||
Directory.Delete(artistDirectory);
|
Directory.Delete(artistDirectory);
|
||||||
_logger.Info("Artist directory deleted");
|
_logger.Info("Artist directory deleted");
|
||||||
@@ -175,66 +152,7 @@ public class DirectoryManager : BaseManager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string RetrieveAlbumPath(Song song)
|
|
||||||
{
|
|
||||||
_logger.Info("Retrieving album song path");
|
|
||||||
|
|
||||||
var albumPath = string.Empty;
|
|
||||||
albumPath = AlbumDirectory(song);
|
|
||||||
|
|
||||||
return albumPath;
|
|
||||||
}
|
|
||||||
public string RetrieveArtistPath(Song song)
|
|
||||||
{
|
|
||||||
_logger.Info("Retrieving artist path");
|
|
||||||
|
|
||||||
var artistPath = string.Empty;
|
|
||||||
artistPath = ArtistDirectory(song);
|
|
||||||
|
|
||||||
return artistPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string GenerateSongPath(Song song)
|
|
||||||
{
|
|
||||||
_logger.Info("Generating song path");
|
|
||||||
|
|
||||||
var artistPath = ArtistDirectory(song);
|
|
||||||
var albumPath = AlbumDirectory(song);
|
|
||||||
|
|
||||||
GenerateDirectories(new List<DirEnt>{
|
|
||||||
new DirEnt
|
|
||||||
{
|
|
||||||
Pre = "Artist path does not exist",
|
|
||||||
Path = artistPath,
|
|
||||||
Post = "Creating artist path"
|
|
||||||
},
|
|
||||||
new DirEnt
|
|
||||||
{
|
|
||||||
Pre = "Album path does not exist",
|
|
||||||
Path = albumPath,
|
|
||||||
Post = "Created album path"
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return albumPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
private class DirEnt
|
|
||||||
{
|
|
||||||
public string? Pre { get; set; }
|
|
||||||
public string? Path { get; set; }
|
|
||||||
public string? Post { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
private void GenerateDirectories(List<DirEnt> dirs)
|
|
||||||
{
|
|
||||||
foreach (var di in dirs)
|
|
||||||
{
|
|
||||||
_logger.Info(di.Pre);
|
|
||||||
Directory.CreateDirectory(di.Path!);
|
|
||||||
_logger.Info(di.Post);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Initialize(DirectoryType dirTypes = DirectoryType.Music)
|
private void Initialize(DirectoryType dirTypes = DirectoryType.Music)
|
||||||
{
|
{
|
||||||
@@ -249,10 +167,8 @@ public class DirectoryManager : BaseManager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool IsDirectoryEmpty(string path)
|
private bool IsDirectoryEmpty(string path) =>
|
||||||
{
|
!(Directory.EnumerateFileSystemEntries(path).Any());
|
||||||
return !Directory.EnumerateFileSystemEntries(path).Any();
|
|
||||||
}
|
|
||||||
|
|
||||||
private string AlbumDirectory()
|
private string AlbumDirectory()
|
||||||
{
|
{
|
||||||
@@ -267,10 +183,6 @@ public class DirectoryManager : BaseManager
|
|||||||
|
|
||||||
return directory;
|
return directory;
|
||||||
}
|
}
|
||||||
private string ArtistDirectory()
|
|
||||||
{
|
|
||||||
return ArtistDirectory(_song!);
|
|
||||||
}
|
|
||||||
private string ArtistDirectory(Song song)
|
private string ArtistDirectory(Song song)
|
||||||
{
|
{
|
||||||
var directory = _rootSongDirectory;
|
var directory = _rootSongDirectory;
|
||||||
|
|||||||
Reference in New Issue
Block a user