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);
+6 -5
View File
@@ -70,11 +70,12 @@ namespace Icarus.Controllers.Utilities
try try
{ {
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)
{ {
+11 -11
View File
@@ -9,17 +9,17 @@ namespace Icarus.Models
public class Album public class Album
{ {
[JsonProperty("album_id")] [JsonProperty("album_id")]
public int AlbumID { get; set; } public int AlbumID { get; set; }
[JsonProperty("title")] [JsonProperty("title")]
public string Title { get; set; } public string Title { get; set; }
[JsonProperty("album_artist")] [JsonProperty("album_artist")]
public string AlbumArtist { get; set; } public string AlbumArtist { get; set; }
[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; }
} }
} }
+9 -9
View File
@@ -9,15 +9,15 @@ namespace Icarus.Models
public class Artist public class Artist
{ {
[JsonProperty("artist_id")] [JsonProperty("artist_id")]
public int ArtistID { get; set; } public int ArtistID { get; set; }
[JsonProperty("name")] [JsonProperty("name")]
public string Name { get; set; } public string Name { get; set; }
[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; }
} }
} }
+1 -1
View File
@@ -7,6 +7,6 @@ namespace Icarus.Models
public class BaseResult public class BaseResult
{ {
[JsonProperty("message")] [JsonProperty("message")]
public string Message { get; set; } public string Message { get; set; }
} }
} }
+3 -3
View File
@@ -12,12 +12,12 @@ namespace Icarus.Models
[JsonProperty("cover_art_id")] [JsonProperty("cover_art_id")]
public int CoverArtID { get; set; } public int CoverArtID { get; set; }
[JsonProperty("title")] [JsonProperty("title")]
public string SongTitle { get; set; } public string SongTitle { get; set; }
[JsonIgnore] [JsonIgnore]
public string ImagePath { get; set; } public string ImagePath { get; set; }
[JsonProperty("song_id")] [JsonProperty("song_id")]
public int SongId { get; set; } public int SongId { get; set; }
[JsonIgnore] [JsonIgnore]
[NotMapped] [NotMapped]
public List<Song> Songs { get; set; } public List<Song> Songs { get; set; }
} }
+9 -10
View File
@@ -9,15 +9,14 @@ namespace Icarus.Models
public class Genre public class Genre
{ {
[JsonProperty("genre_id")] [JsonProperty("genre_id")]
public int GenreID { get; set; } public int GenreID { get; set; }
[JsonProperty("genre")] [JsonProperty("genre")]
public string GenreName { get; set; } public string GenreName { get; set; }
[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; }
} }
} }
+9 -9
View File
@@ -7,14 +7,14 @@ namespace Icarus.Models
public class LoginResult : BaseResult public class LoginResult : BaseResult
{ {
[JsonProperty("user_id")] [JsonProperty("user_id")]
public int UserID { get; set; } public int UserID { get; set; }
[JsonProperty("username")] [JsonProperty("username")]
public string Username { get; set; } public string Username { get; set; }
[JsonProperty("token")] [JsonProperty("token")]
public string Token { get; set; } public string Token { get; set; }
[JsonProperty("token_type")] [JsonProperty("token_type")]
public string TokenType { get; set; } public string TokenType { get; set; }
[JsonProperty("expiration")] [JsonProperty("expiration")]
public int Expiration { get; set; } public int Expiration { get; set; }
} }
} }
+3 -3
View File
@@ -7,8 +7,8 @@ namespace Icarus.Models
public class RegisterResult : BaseResult public class RegisterResult : BaseResult
{ {
[JsonProperty("username")] [JsonProperty("username")]
public string Username { get; set; } public string Username { get; set; }
[JsonProperty("successfully_registered")] [JsonProperty("successfully_registered")]
public bool SuccessfullyRegistered { get; set; } public bool SuccessfullyRegistered { get; set; }
} }
} }
+47 -50
View File
@@ -7,60 +7,57 @@ 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")]
public string Title { get; set; } public string Title { get; set; }
[JsonProperty("album")] [JsonProperty("album")]
[Column("Album")] [Column("Album")]
public string AlbumTitle { get; set; } public string AlbumTitle { get; set; }
[JsonProperty("artist")] [JsonProperty("artist")]
public string Artist { get; set; } public string Artist { get; set; }
[JsonProperty("year")] [JsonProperty("year")]
public int? Year { get; set; } public int? Year { get; set; }
[JsonProperty("genre")] [JsonProperty("genre")]
public string Genre { get; set; } public string Genre { get; set; }
[JsonProperty("duration")] [JsonProperty("duration")]
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 int? AlbumID { get; set; }
[JsonIgnore]
public int? ArtistID { get; set; }
[JsonIgnore]
public int? GenreID { get; set; }
[JsonIgnore]
public int? CoverArtID { get; set; }
[JsonProperty("date_created")]
public DateTime DateCreated { get; set; }
#endregion
// [JsonIgnore]
// public Album Album { get; set; }
[JsonIgnore]
public int? AlbumID { get; set; }
/** #region Methods
[JsonIgnore] public string SongPath()
public Artist SongArtist { get; set; } {
*/ var fullPath = SongDirectory;
[JsonIgnore]
public int? ArtistID { get; set; }
/**
[JsonIgnore]
public Genre SongGenre { get; set; }
*/
[JsonIgnore]
public int? GenreID { get; set; }
// [JsonIgnore] if (fullPath[fullPath.Length -1] != '/')
// public Year SongYear { get; set; } {
// [JsonIgnore] fullPath += "/";
// public int? YearId { get; set; } }
/** fullPath += Filename;
[JsonIgnore]
public CoverArt SongCoverArt { get; set; } return fullPath;
*/ }
[JsonIgnore] #endregion
public int? CoverArtID { get; set; }
[JsonProperty("date_created")]
public DateTime DateCreated { get; set; }
} }
} }
+2 -2
View File
@@ -6,7 +6,7 @@ namespace Icarus.Models
public class SongData public class SongData
{ {
public int ID { get; set; } public int ID { get; set; }
public byte[] Data { get; set; } public byte[] Data { get; set; }
public int SongID { get; set; } public int SongID { get; set; }
} }
} }
+25 -25
View File
@@ -6,34 +6,34 @@ using Newtonsoft.Json;
namespace Icarus.Models namespace Icarus.Models
{ {
[Table("User")] [Table("User")]
public class User public class User
{ {
[JsonProperty("user_id")] [JsonProperty("user_id")]
[Column("UserID")] [Column("UserID")]
[Key] [Key]
public int UserID { get; set; } public int UserID { get; set; }
[JsonProperty("username")] [JsonProperty("username")]
public string Username { get; set; } public string Username { get; set; }
[JsonProperty("password")] [JsonProperty("password")]
public string Password { get; set; } public string Password { get; set; }
[JsonProperty("email")] [JsonProperty("email")]
public string Email { get; set; } public string Email { get; set; }
[JsonProperty("phone")] [JsonProperty("phone")]
[Column("Phone")] [Column("Phone")]
public string Phone { get; set; } public string Phone { get; set; }
[JsonProperty("first_name")] [JsonProperty("first_name")]
public string Firstname { get; set; } public string Firstname { get; set; }
[JsonProperty("last_name")] [JsonProperty("last_name")]
public string Lastname { get; set; } public string Lastname { get; set; }
[JsonProperty("email_verified")] [JsonProperty("email_verified")]
[NotMapped] [NotMapped]
public bool EmailVerified { get; set; } public bool EmailVerified { get; set; }
[JsonProperty("date_created")] [JsonProperty("date_created")]
public DateTime DateCreated { get; set; } public DateTime DateCreated { get; set; }
[JsonProperty("status")] [JsonProperty("status")]
public string Status { get; set; } public string Status { get; set; }
[JsonProperty("last_login")] [JsonProperty("last_login")]
public DateTime? LastLogin { get; set; } public DateTime? LastLogin { get; set; }
} }
} }
+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;