Refactoring

This commit is contained in:
kdeng00
2021-12-24 20:51:15 -05:00
parent f8d9c8e4a7
commit 023298c6f8
14 changed files with 147 additions and 164 deletions
+19 -35
View File
@@ -48,14 +48,6 @@ namespace Icarus.Controllers.Managers
#region Constructors #region Constructors
/**
public SongManager()
{
Initialize();
InitializeConnection();
}
*/
public SongManager(IConfiguration config) public SongManager(IConfiguration config)
{ {
_config = config; _config = config;
@@ -71,8 +63,7 @@ namespace Icarus.Controllers.Managers
#region Methods #region Methods
public SongResult UpdateSong(Song song)/**, SongRepository songStore, AlbumRepository albumStore, public SongResult UpdateSong(Song song)
ArtistRepository artistStore, GenreRepository genreStore, YearRepository yearStore)*/
{ {
var result = new SongResult(); var result = new SongResult();
@@ -133,10 +124,7 @@ namespace Icarus.Controllers.Managers
return successful; return successful;
} }
public void DeleteSong(Song song)/**, SongRepository songStore, public void DeleteSong(Song song)
AlbumRepository albumStore, ArtistRepository artistStore,
GenreRepository genreStore, YearRepository yearStore,
CoverArtRepository coverStore)*/
{ {
try try
{ {
@@ -149,13 +137,12 @@ namespace Icarus.Controllers.Managers
_logger.Info("Song deleted from the filesystem"); _logger.Info("Song deleted from the filesystem");
var coverMgr = new CoverArtManager(_config); var coverMgr = new CoverArtManager(_config);
// var coverArt = coverStore.GetCoverArt(song);
var coverArt = coverMgr.GetCoverArt(song); var coverArt = coverMgr.GetCoverArt(song);
coverMgr.DeleteCoverArt(coverArt); coverMgr.DeleteCoverArt(coverArt);
coverMgr.DeleteCoverArtFromDatabase(coverArt); coverMgr.DeleteCoverArtFromDatabase(coverArt);
DeleteSongFromDatabase(song/**, songStore, albumStore, artistStore, DeleteSongFromDatabase(song);
genreStore, yearStore*/);
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -306,8 +293,7 @@ namespace Icarus.Controllers.Managers
private void SaveSongToDatabase(Song song)/**, SongRepository songStore, AlbumRepository albumStore, private void SaveSongToDatabase(Song song)
ArtistRepository artistStore, GenreRepository genreStore, YearRepository yearStore)*/
{ {
_logger.Info("Starting process to save the song to the database"); _logger.Info("Starting process to save the song to the database");
@@ -320,7 +306,7 @@ namespace Icarus.Controllers.Managers
_logger.Info(info); _logger.Info(info);
_songContext.Add(song); _songContext.Add(song);
} }
private void SaveAlbumToDatabase(ref Song song)//, AlbumRepository albumStore) private void SaveAlbumToDatabase(ref Song song)
{ {
_logger.Info("Starting process to save the album record of the song to the database"); _logger.Info("Starting process to save the album record of the song to the database");
@@ -349,7 +335,7 @@ namespace Icarus.Controllers.Managers
song.AlbumID = album.AlbumID; song.AlbumID = album.AlbumID;
} }
private void SaveArtistToDatabase(ref Song song)//, ArtistRepository artistStore) private void SaveArtistToDatabase(ref Song song)
{ {
_logger.Info("Starting process to save the artist record of the song to the database"); _logger.Info("Starting process to save the artist record of the song to the database");
@@ -378,7 +364,7 @@ namespace Icarus.Controllers.Managers
song.ArtistID = artist.ArtistID; song.ArtistID = artist.ArtistID;
} }
private void SaveGenreToDatabase(ref Song song)//, GenreRepository genreStore) private void SaveGenreToDatabase(ref Song song)
{ {
_logger.Info("Starting process to save the genre record of the song to the database"); _logger.Info("Starting process to save the genre record of the song to the database");
@@ -450,7 +436,7 @@ namespace Icarus.Controllers.Managers
return true; return true;
} }
private Album UpdateAlbumInDatabase(Song oldSongRecord, Song newSongRecord)//, AlbumRepository albumStore) private Album UpdateAlbumInDatabase(Song oldSongRecord, Song newSongRecord)
{ {
var albumContext = new AlbumContext(_connectionString); var albumContext = new AlbumContext(_connectionString);
@@ -504,7 +490,7 @@ namespace Icarus.Controllers.Managers
return existingAlbumRecord; return existingAlbumRecord;
} }
} }
private Artist UpdateArtistInDatabase(Song oldSongRecord, Song newSongRecord)//, ArtistRepository artistStore) private Artist UpdateArtistInDatabase(Song oldSongRecord, Song newSongRecord)
{ {
var artistContext = new ArtistContext(_connectionString); var artistContext = new ArtistContext(_connectionString);
@@ -553,7 +539,7 @@ namespace Icarus.Controllers.Managers
return existingArtistRecord; return existingArtistRecord;
} }
} }
private Genre UpdateGenreInDatabase(Song oldSongRecord, Song newSongRecord)//, GenreRepository genreStore) private Genre UpdateGenreInDatabase(Song oldSongRecord, Song newSongRecord)
{ {
var genreContext = new GenreContext(_connectionString); var genreContext = new GenreContext(_connectionString);
var oldGenreRecord = genreContext.Genres.FirstOrDefault(gnr => gnr.GenreName.Equals(oldSongRecord.Genre)); var oldGenreRecord = genreContext.Genres.FirstOrDefault(gnr => gnr.GenreName.Equals(oldSongRecord.Genre));
@@ -601,8 +587,7 @@ namespace Icarus.Controllers.Managers
} }
} }
private void UpdateSongInDatabase(ref Song oldSongRecord, ref Song newSongRecord, /**SongRepository songStore,*/ private void UpdateSongInDatabase(ref Song oldSongRecord, ref Song newSongRecord, ref SongResult result)
ref SongResult result)
{ {
var updatedSongRecord = new Song var updatedSongRecord = new Song
{ {
@@ -705,20 +690,19 @@ namespace Icarus.Controllers.Managers
result.SongTitle = updatedSongRecord.Title; result.SongTitle = updatedSongRecord.Title;
} }
private void DeleteSongFromDatabase(Song song)/**, SongRepository songStore, AlbumRepository albumStore, private void DeleteSongFromDatabase(Song song)
ArtistRepository artistStore, GenreRepository genreStore, YearRepository yearStore)*/
{ {
_logger.Info("Starting process to delete records related to the song from the database"); _logger.Info("Starting process to delete records related to the song from the database");
DeleteAlbumFromDatabase(song);//, albumStore); DeleteAlbumFromDatabase(song);
DeleteArtistFromDatabase(song);//, artistStore); DeleteArtistFromDatabase(song);
DeleteGenreFromDatabase(song);//, genreStore); DeleteGenreFromDatabase(song);
var sngContext = new SongContext(_connectionString); var sngContext = new SongContext(_connectionString);
sngContext.Songs.Remove(song); sngContext.Songs.Remove(song);
sngContext.SaveChanges(); sngContext.SaveChanges();
} }
private void DeleteAlbumFromDatabase(Song song)// AlbumRepository albumStore) private void DeleteAlbumFromDatabase(Song song)
{ {
var albumContext = new AlbumContext(_connectionString); var albumContext = new AlbumContext(_connectionString);
@@ -736,7 +720,7 @@ namespace Icarus.Controllers.Managers
albumContext.SaveChanges(); albumContext.SaveChanges();
} }
} }
private void DeleteArtistFromDatabase(Song song)//, ArtistRepository artistStore) private void DeleteArtistFromDatabase(Song song)
{ {
var artistContext = new ArtistContext(_connectionString); var artistContext = new ArtistContext(_connectionString);
@@ -754,7 +738,7 @@ namespace Icarus.Controllers.Managers
artistContext.SaveChanges(); artistContext.SaveChanges();
} }
} }
private void DeleteGenreFromDatabase(Song song)//, GenreRepository genreStore) private void DeleteGenreFromDatabase(Song song)
{ {
var genreContext = new GenreContext(_connectionString); var genreContext = new GenreContext(_connectionString);
+2 -1
View File
@@ -71,9 +71,10 @@ namespace Icarus.Controllers.Utilities
{ {
using (ZipFile zip = new ZipFile()) using (ZipFile zip = new ZipFile())
{ {
zip.AddFile(songDetails.SongPath); zip.AddFile(songDetails.SongPath());
zip.Save(tmpZipFilePath); zip.Save(tmpZipFilePath);
} }
Console.WriteLine("Successfully compressed"); Console.WriteLine("Successfully compressed");
} }
catch (Exception ex) catch (Exception ex)
-1
View File
@@ -15,7 +15,6 @@ namespace Icarus.Models
[JsonProperty("song_count")] [JsonProperty("song_count")]
[NotMapped] [NotMapped]
public int SongCount { get; set; } public int SongCount { get; set; }
[JsonIgnore] [JsonIgnore]
[NotMapped] [NotMapped]
public List<Song> Songs { get; set; } public List<Song> Songs { get; set; }
+21 -24
View File
@@ -7,6 +7,7 @@ namespace Icarus.Models
{ {
public class Song public class Song
{ {
#region Properties
[JsonProperty("song_id")] [JsonProperty("song_id")]
public int SongID { get; set; } public int SongID { get; set; }
[JsonProperty("title")] [JsonProperty("title")]
@@ -24,43 +25,39 @@ namespace Icarus.Models
public int Duration { get; set; } public int Duration { get; set; }
[JsonProperty("filename")] [JsonProperty("filename")]
public string Filename { get; set; } public string Filename { get; set; }
[JsonProperty("song_path")] [JsonIgnore]
public string SongPath { get; set; } public string SongDirectory { get; set; }
[JsonProperty("track")] [JsonProperty("track")]
public int Track { get; set; } = 0; public int Track { get; set; } = 0;
[JsonProperty("disc")] [JsonProperty("disc")]
public int Disc { get; set; } = 0; public int Disc { get; set; } = 0;
// [JsonIgnore]
// public Album Album { get; set; }
[JsonIgnore] [JsonIgnore]
public int? AlbumID { get; set; } public int? AlbumID { get; set; }
/**
[JsonIgnore]
public Artist SongArtist { get; set; }
*/
[JsonIgnore] [JsonIgnore]
public int? ArtistID { get; set; } public int? ArtistID { get; set; }
/**
[JsonIgnore]
public Genre SongGenre { get; set; }
*/
[JsonIgnore] [JsonIgnore]
public int? GenreID { get; set; } public int? GenreID { get; set; }
// [JsonIgnore]
// public Year SongYear { get; set; }
// [JsonIgnore]
// public int? YearId { get; set; }
/**
[JsonIgnore]
public CoverArt SongCoverArt { get; set; }
*/
[JsonIgnore] [JsonIgnore]
public int? CoverArtID { get; set; } public int? CoverArtID { get; set; }
[JsonProperty("date_created")] [JsonProperty("date_created")]
public DateTime DateCreated { get; set; } public DateTime DateCreated { get; set; }
#endregion
#region Methods
public string SongPath()
{
var fullPath = SongDirectory;
if (fullPath[fullPath.Length -1] != '/')
{
fullPath += "/";
}
fullPath += Filename;
return fullPath;
}
#endregion
} }
} }
+2 -1
View File
@@ -44,7 +44,8 @@ CREATE TABLE Song (
Duration INT NOT NULL, Duration INT NOT NULL,
Track INT NOT NULL, Track INT NOT NULL,
Disc INT NOT NULL, Disc INT NOT NULL,
SongPath TEXT NOT NULL, SongDirectory TEXT NOT NULL,
Filename TEXT NOT NULL,
CoverArtID INT NOT NULL, CoverArtID INT NOT NULL,
ArtistID INT NOT NULL, ArtistID INT NOT NULL,
AlbumID INT NOT NULL, AlbumID INT NOT NULL,
+1
View File
@@ -0,0 +1 @@
drop database Icarus;