Refactoring
This commit is contained in:
@@ -48,14 +48,6 @@ namespace Icarus.Controllers.Managers
|
||||
|
||||
|
||||
#region Constructors
|
||||
/**
|
||||
public SongManager()
|
||||
{
|
||||
Initialize();
|
||||
InitializeConnection();
|
||||
}
|
||||
*/
|
||||
|
||||
public SongManager(IConfiguration config)
|
||||
{
|
||||
_config = config;
|
||||
@@ -71,8 +63,7 @@ namespace Icarus.Controllers.Managers
|
||||
|
||||
|
||||
#region Methods
|
||||
public SongResult UpdateSong(Song song)/**, SongRepository songStore, AlbumRepository albumStore,
|
||||
ArtistRepository artistStore, GenreRepository genreStore, YearRepository yearStore)*/
|
||||
public SongResult UpdateSong(Song song)
|
||||
{
|
||||
var result = new SongResult();
|
||||
|
||||
@@ -133,10 +124,7 @@ namespace Icarus.Controllers.Managers
|
||||
return successful;
|
||||
}
|
||||
|
||||
public void DeleteSong(Song song)/**, SongRepository songStore,
|
||||
AlbumRepository albumStore, ArtistRepository artistStore,
|
||||
GenreRepository genreStore, YearRepository yearStore,
|
||||
CoverArtRepository coverStore)*/
|
||||
public void DeleteSong(Song song)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -149,13 +137,12 @@ namespace Icarus.Controllers.Managers
|
||||
_logger.Info("Song deleted from the filesystem");
|
||||
|
||||
var coverMgr = new CoverArtManager(_config);
|
||||
// var coverArt = coverStore.GetCoverArt(song);
|
||||
|
||||
var coverArt = coverMgr.GetCoverArt(song);
|
||||
coverMgr.DeleteCoverArt(coverArt);
|
||||
|
||||
coverMgr.DeleteCoverArtFromDatabase(coverArt);
|
||||
DeleteSongFromDatabase(song/**, songStore, albumStore, artistStore,
|
||||
genreStore, yearStore*/);
|
||||
DeleteSongFromDatabase(song);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -306,8 +293,7 @@ namespace Icarus.Controllers.Managers
|
||||
|
||||
|
||||
|
||||
private void SaveSongToDatabase(Song song)/**, SongRepository songStore, AlbumRepository albumStore,
|
||||
ArtistRepository artistStore, GenreRepository genreStore, YearRepository yearStore)*/
|
||||
private void SaveSongToDatabase(Song song)
|
||||
{
|
||||
_logger.Info("Starting process to save the song to the database");
|
||||
|
||||
@@ -320,7 +306,7 @@ namespace Icarus.Controllers.Managers
|
||||
_logger.Info(info);
|
||||
_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");
|
||||
|
||||
@@ -349,7 +335,7 @@ namespace Icarus.Controllers.Managers
|
||||
|
||||
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");
|
||||
|
||||
@@ -378,7 +364,7 @@ namespace Icarus.Controllers.Managers
|
||||
|
||||
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");
|
||||
|
||||
@@ -450,7 +436,7 @@ namespace Icarus.Controllers.Managers
|
||||
return true;
|
||||
}
|
||||
|
||||
private Album UpdateAlbumInDatabase(Song oldSongRecord, Song newSongRecord)//, AlbumRepository albumStore)
|
||||
private Album UpdateAlbumInDatabase(Song oldSongRecord, Song newSongRecord)
|
||||
{
|
||||
var albumContext = new AlbumContext(_connectionString);
|
||||
|
||||
@@ -504,7 +490,7 @@ namespace Icarus.Controllers.Managers
|
||||
return existingAlbumRecord;
|
||||
}
|
||||
}
|
||||
private Artist UpdateArtistInDatabase(Song oldSongRecord, Song newSongRecord)//, ArtistRepository artistStore)
|
||||
private Artist UpdateArtistInDatabase(Song oldSongRecord, Song newSongRecord)
|
||||
{
|
||||
var artistContext = new ArtistContext(_connectionString);
|
||||
|
||||
@@ -553,7 +539,7 @@ namespace Icarus.Controllers.Managers
|
||||
return existingArtistRecord;
|
||||
}
|
||||
}
|
||||
private Genre UpdateGenreInDatabase(Song oldSongRecord, Song newSongRecord)//, GenreRepository genreStore)
|
||||
private Genre UpdateGenreInDatabase(Song oldSongRecord, Song newSongRecord)
|
||||
{
|
||||
var genreContext = new GenreContext(_connectionString);
|
||||
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,*/
|
||||
ref SongResult result)
|
||||
private void UpdateSongInDatabase(ref Song oldSongRecord, ref Song newSongRecord, ref SongResult result)
|
||||
{
|
||||
var updatedSongRecord = new Song
|
||||
{
|
||||
@@ -705,20 +690,19 @@ namespace Icarus.Controllers.Managers
|
||||
result.SongTitle = updatedSongRecord.Title;
|
||||
}
|
||||
|
||||
private void DeleteSongFromDatabase(Song song)/**, SongRepository songStore, AlbumRepository albumStore,
|
||||
ArtistRepository artistStore, GenreRepository genreStore, YearRepository yearStore)*/
|
||||
private void DeleteSongFromDatabase(Song song)
|
||||
{
|
||||
_logger.Info("Starting process to delete records related to the song from the database");
|
||||
|
||||
DeleteAlbumFromDatabase(song);//, albumStore);
|
||||
DeleteArtistFromDatabase(song);//, artistStore);
|
||||
DeleteGenreFromDatabase(song);//, genreStore);
|
||||
DeleteAlbumFromDatabase(song);
|
||||
DeleteArtistFromDatabase(song);
|
||||
DeleteGenreFromDatabase(song);
|
||||
|
||||
var sngContext = new SongContext(_connectionString);
|
||||
sngContext.Songs.Remove(song);
|
||||
sngContext.SaveChanges();
|
||||
}
|
||||
private void DeleteAlbumFromDatabase(Song song)// AlbumRepository albumStore)
|
||||
private void DeleteAlbumFromDatabase(Song song)
|
||||
{
|
||||
var albumContext = new AlbumContext(_connectionString);
|
||||
|
||||
@@ -736,7 +720,7 @@ namespace Icarus.Controllers.Managers
|
||||
albumContext.SaveChanges();
|
||||
}
|
||||
}
|
||||
private void DeleteArtistFromDatabase(Song song)//, ArtistRepository artistStore)
|
||||
private void DeleteArtistFromDatabase(Song song)
|
||||
{
|
||||
var artistContext = new ArtistContext(_connectionString);
|
||||
|
||||
@@ -754,7 +738,7 @@ namespace Icarus.Controllers.Managers
|
||||
artistContext.SaveChanges();
|
||||
}
|
||||
}
|
||||
private void DeleteGenreFromDatabase(Song song)//, GenreRepository genreStore)
|
||||
private void DeleteGenreFromDatabase(Song song)
|
||||
{
|
||||
var genreContext = new GenreContext(_connectionString);
|
||||
|
||||
|
||||
@@ -70,11 +70,12 @@ namespace Icarus.Controllers.Utilities
|
||||
try
|
||||
{
|
||||
using (ZipFile zip = new ZipFile())
|
||||
{
|
||||
zip.AddFile(songDetails.SongPath);
|
||||
zip.Save(tmpZipFilePath);
|
||||
}
|
||||
Console.WriteLine("Successfully compressed");
|
||||
{
|
||||
zip.AddFile(songDetails.SongPath());
|
||||
zip.Save(tmpZipFilePath);
|
||||
}
|
||||
|
||||
Console.WriteLine("Successfully compressed");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
+11
-11
@@ -9,17 +9,17 @@ namespace Icarus.Models
|
||||
public class Album
|
||||
{
|
||||
[JsonProperty("album_id")]
|
||||
public int AlbumID { get; set; }
|
||||
[JsonProperty("title")]
|
||||
public string Title { get; set; }
|
||||
[JsonProperty("album_artist")]
|
||||
public string AlbumArtist { get; set; }
|
||||
[JsonProperty("song_count")]
|
||||
[NotMapped]
|
||||
public int SongCount { get; set; }
|
||||
public int AlbumID { get; set; }
|
||||
[JsonProperty("title")]
|
||||
public string Title { get; set; }
|
||||
[JsonProperty("album_artist")]
|
||||
public string AlbumArtist { get; set; }
|
||||
[JsonProperty("song_count")]
|
||||
[NotMapped]
|
||||
public int SongCount { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
[NotMapped]
|
||||
public List<Song> Songs { get; set; }
|
||||
[JsonIgnore]
|
||||
[NotMapped]
|
||||
public List<Song> Songs { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
+9
-9
@@ -9,15 +9,15 @@ namespace Icarus.Models
|
||||
public class Artist
|
||||
{
|
||||
[JsonProperty("artist_id")]
|
||||
public int ArtistID { get; set; }
|
||||
[JsonProperty("name")]
|
||||
public string Name { get; set; }
|
||||
[JsonProperty("song_count")]
|
||||
[NotMapped]
|
||||
public int SongCount { get; set; }
|
||||
public int ArtistID { get; set; }
|
||||
[JsonProperty("name")]
|
||||
public string Name { get; set; }
|
||||
[JsonProperty("song_count")]
|
||||
[NotMapped]
|
||||
public int SongCount { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
[NotMapped]
|
||||
public List<Song> Songs { get; set; }
|
||||
[JsonIgnore]
|
||||
[NotMapped]
|
||||
public List<Song> Songs { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,6 @@ namespace Icarus.Models
|
||||
public class BaseResult
|
||||
{
|
||||
[JsonProperty("message")]
|
||||
public string Message { get; set; }
|
||||
public string Message { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -12,12 +12,12 @@ namespace Icarus.Models
|
||||
[JsonProperty("cover_art_id")]
|
||||
public int CoverArtID { get; set; }
|
||||
[JsonProperty("title")]
|
||||
public string SongTitle { get; set; }
|
||||
public string SongTitle { get; set; }
|
||||
[JsonIgnore]
|
||||
public string ImagePath { get; set; }
|
||||
public string ImagePath { get; set; }
|
||||
[JsonProperty("song_id")]
|
||||
public int SongId { get; set; }
|
||||
[JsonIgnore]
|
||||
[JsonIgnore]
|
||||
[NotMapped]
|
||||
public List<Song> Songs { get; set; }
|
||||
}
|
||||
|
||||
+9
-10
@@ -9,15 +9,14 @@ namespace Icarus.Models
|
||||
public class Genre
|
||||
{
|
||||
[JsonProperty("genre_id")]
|
||||
public int GenreID { get; set; }
|
||||
[JsonProperty("genre")]
|
||||
public string GenreName { get; set; }
|
||||
[JsonProperty("song_count")]
|
||||
[NotMapped]
|
||||
public int SongCount { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
[NotMapped]
|
||||
public List<Song> Songs { get; set; }
|
||||
public int GenreID { get; set; }
|
||||
[JsonProperty("genre")]
|
||||
public string GenreName { get; set; }
|
||||
[JsonProperty("song_count")]
|
||||
[NotMapped]
|
||||
public int SongCount { get; set; }
|
||||
[JsonIgnore]
|
||||
[NotMapped]
|
||||
public List<Song> Songs { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,14 +7,14 @@ namespace Icarus.Models
|
||||
public class LoginResult : BaseResult
|
||||
{
|
||||
[JsonProperty("user_id")]
|
||||
public int UserID { get; set; }
|
||||
[JsonProperty("username")]
|
||||
public string Username { get; set; }
|
||||
[JsonProperty("token")]
|
||||
public string Token { get; set; }
|
||||
[JsonProperty("token_type")]
|
||||
public string TokenType { get; set; }
|
||||
[JsonProperty("expiration")]
|
||||
public int Expiration { get; set; }
|
||||
public int UserID { get; set; }
|
||||
[JsonProperty("username")]
|
||||
public string Username { get; set; }
|
||||
[JsonProperty("token")]
|
||||
public string Token { get; set; }
|
||||
[JsonProperty("token_type")]
|
||||
public string TokenType { get; set; }
|
||||
[JsonProperty("expiration")]
|
||||
public int Expiration { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@ namespace Icarus.Models
|
||||
public class RegisterResult : BaseResult
|
||||
{
|
||||
[JsonProperty("username")]
|
||||
public string Username { get; set; }
|
||||
[JsonProperty("successfully_registered")]
|
||||
public bool SuccessfullyRegistered { get; set; }
|
||||
public string Username { get; set; }
|
||||
[JsonProperty("successfully_registered")]
|
||||
public bool SuccessfullyRegistered { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
+47
-50
@@ -7,60 +7,57 @@ namespace Icarus.Models
|
||||
{
|
||||
public class Song
|
||||
{
|
||||
#region Properties
|
||||
[JsonProperty("song_id")]
|
||||
public int SongID { get; set; }
|
||||
[JsonProperty("title")]
|
||||
public string Title { get; set; }
|
||||
[JsonProperty("album")]
|
||||
[Column("Album")]
|
||||
public string AlbumTitle { get; set; }
|
||||
[JsonProperty("artist")]
|
||||
public string Artist { get; set; }
|
||||
[JsonProperty("year")]
|
||||
public int? Year { get; set; }
|
||||
[JsonProperty("genre")]
|
||||
public string Genre { get; set; }
|
||||
[JsonProperty("duration")]
|
||||
public int Duration { get; set; }
|
||||
[JsonProperty("filename")]
|
||||
public string Filename { get; set; }
|
||||
[JsonProperty("song_path")]
|
||||
public string SongPath { get; set; }
|
||||
[JsonProperty("track")]
|
||||
public int Track { get; set; } = 0;
|
||||
[JsonProperty("disc")]
|
||||
public int Disc { get; set; } = 0;
|
||||
public int SongID { get; set; }
|
||||
[JsonProperty("title")]
|
||||
public string Title { get; set; }
|
||||
[JsonProperty("album")]
|
||||
[Column("Album")]
|
||||
public string AlbumTitle { get; set; }
|
||||
[JsonProperty("artist")]
|
||||
public string Artist { get; set; }
|
||||
[JsonProperty("year")]
|
||||
public int? Year { get; set; }
|
||||
[JsonProperty("genre")]
|
||||
public string Genre { get; set; }
|
||||
[JsonProperty("duration")]
|
||||
public int Duration { get; set; }
|
||||
[JsonProperty("filename")]
|
||||
public string Filename { get; set; }
|
||||
[JsonIgnore]
|
||||
public string SongDirectory { get; set; }
|
||||
[JsonProperty("track")]
|
||||
public int Track { get; set; } = 0;
|
||||
[JsonProperty("disc")]
|
||||
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; }
|
||||
|
||||
/**
|
||||
[JsonIgnore]
|
||||
public Artist SongArtist { get; set; }
|
||||
*/
|
||||
[JsonIgnore]
|
||||
public int? ArtistID { get; set; }
|
||||
/**
|
||||
[JsonIgnore]
|
||||
public Genre SongGenre { get; set; }
|
||||
*/
|
||||
[JsonIgnore]
|
||||
public int? GenreID { get; set; }
|
||||
#region Methods
|
||||
public string SongPath()
|
||||
{
|
||||
var fullPath = SongDirectory;
|
||||
|
||||
// [JsonIgnore]
|
||||
// public Year SongYear { get; set; }
|
||||
// [JsonIgnore]
|
||||
// public int? YearId { get; set; }
|
||||
if (fullPath[fullPath.Length -1] != '/')
|
||||
{
|
||||
fullPath += "/";
|
||||
}
|
||||
|
||||
/**
|
||||
[JsonIgnore]
|
||||
public CoverArt SongCoverArt { get; set; }
|
||||
*/
|
||||
[JsonIgnore]
|
||||
public int? CoverArtID { get; set; }
|
||||
[JsonProperty("date_created")]
|
||||
public DateTime DateCreated { get; set; }
|
||||
fullPath += Filename;
|
||||
|
||||
return fullPath;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -6,7 +6,7 @@ namespace Icarus.Models
|
||||
public class SongData
|
||||
{
|
||||
public int ID { get; set; }
|
||||
public byte[] Data { get; set; }
|
||||
public int SongID { get; set; }
|
||||
public byte[] Data { get; set; }
|
||||
public int SongID { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
+25
-25
@@ -6,34 +6,34 @@ using Newtonsoft.Json;
|
||||
|
||||
namespace Icarus.Models
|
||||
{
|
||||
[Table("User")]
|
||||
[Table("User")]
|
||||
public class User
|
||||
{
|
||||
[JsonProperty("user_id")]
|
||||
[Column("UserID")]
|
||||
[Key]
|
||||
public int UserID { get; set; }
|
||||
[JsonProperty("username")]
|
||||
public string Username { get; set; }
|
||||
[JsonProperty("password")]
|
||||
public string Password { get; set; }
|
||||
[JsonProperty("email")]
|
||||
public string Email { get; set; }
|
||||
[JsonProperty("phone")]
|
||||
[Column("Phone")]
|
||||
public string Phone { get; set; }
|
||||
[JsonProperty("first_name")]
|
||||
public string Firstname { get; set; }
|
||||
[JsonProperty("last_name")]
|
||||
public string Lastname { get; set; }
|
||||
[JsonProperty("email_verified")]
|
||||
[NotMapped]
|
||||
public bool EmailVerified { get; set; }
|
||||
[Column("UserID")]
|
||||
[Key]
|
||||
public int UserID { get; set; }
|
||||
[JsonProperty("username")]
|
||||
public string Username { get; set; }
|
||||
[JsonProperty("password")]
|
||||
public string Password { get; set; }
|
||||
[JsonProperty("email")]
|
||||
public string Email { get; set; }
|
||||
[JsonProperty("phone")]
|
||||
[Column("Phone")]
|
||||
public string Phone { get; set; }
|
||||
[JsonProperty("first_name")]
|
||||
public string Firstname { get; set; }
|
||||
[JsonProperty("last_name")]
|
||||
public string Lastname { get; set; }
|
||||
[JsonProperty("email_verified")]
|
||||
[NotMapped]
|
||||
public bool EmailVerified { get; set; }
|
||||
[JsonProperty("date_created")]
|
||||
public DateTime DateCreated { get; set; }
|
||||
[JsonProperty("status")]
|
||||
public string Status { get; set; }
|
||||
[JsonProperty("last_login")]
|
||||
public DateTime? LastLogin { get; set; }
|
||||
public DateTime DateCreated { get; set; }
|
||||
[JsonProperty("status")]
|
||||
public string Status { get; set; }
|
||||
[JsonProperty("last_login")]
|
||||
public DateTime? LastLogin { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,8 @@ CREATE TABLE Song (
|
||||
Duration INT NOT NULL,
|
||||
Track INT NOT NULL,
|
||||
Disc INT NOT NULL,
|
||||
SongPath TEXT NOT NULL,
|
||||
SongDirectory TEXT NOT NULL,
|
||||
Filename TEXT NOT NULL,
|
||||
CoverArtID INT NOT NULL,
|
||||
ArtistID INT NOT NULL,
|
||||
AlbumID INT NOT NULL,
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
drop database Icarus;
|
||||
Reference in New Issue
Block a user