Functional
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
using NLog;
|
using NLog;
|
||||||
|
|
||||||
namespace Icarus.Controllers.Managers
|
namespace Icarus.Controllers.Managers
|
||||||
@@ -8,6 +9,8 @@ namespace Icarus.Controllers.Managers
|
|||||||
{
|
{
|
||||||
#region Fields
|
#region Fields
|
||||||
protected static Logger _logger = NLog.Web.NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();
|
protected static Logger _logger = NLog.Web.NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();
|
||||||
|
protected IConfiguration _config;
|
||||||
|
protected string _connectionString;
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
using Icarus.Constants;
|
using Icarus.Constants;
|
||||||
using Icarus.Controllers.Utilities;
|
using Icarus.Controllers.Utilities;
|
||||||
|
using Icarus.Database.Contexts;
|
||||||
using Icarus.Models;
|
using Icarus.Models;
|
||||||
using Icarus.Types;
|
using Icarus.Types;
|
||||||
|
|
||||||
@@ -13,36 +16,39 @@ namespace Icarus.Controllers.Managers
|
|||||||
{
|
{
|
||||||
#region Fields
|
#region Fields
|
||||||
private string _rootCoverArtPath;
|
private string _rootCoverArtPath;
|
||||||
|
private CoverArtContext _coverArtContext;
|
||||||
private byte[] _stockCoverArt = null;
|
private byte[] _stockCoverArt = null;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
#region Constructors
|
#region Constructors
|
||||||
public CoverArtManager(string rootPath)
|
public CoverArtManager(IConfiguration config)
|
||||||
{
|
{
|
||||||
_rootCoverArtPath = rootPath;
|
_config = config;
|
||||||
|
_connectionString = _config.GetConnectionString("DefaultConnection");
|
||||||
|
_rootCoverArtPath = _config.GetValue<string>("CoverArtPath");
|
||||||
Initialize();
|
Initialize();
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
#region Methods
|
#region Methods
|
||||||
public void SaveCoverArtToDatabase(ref Song song, ref CoverArt coverArt,
|
public void SaveCoverArtToDatabase(ref Song song, ref CoverArt coverArt)
|
||||||
CoverArtRepository coverArtRepository)
|
|
||||||
{
|
{
|
||||||
_logger.Info("Saving cover art record to the database");
|
_logger.Info("Saving cover art record to the database");
|
||||||
coverArtRepository.SaveCoverArt(coverArt);
|
_coverArtContext.Add(coverArt);
|
||||||
|
var songTitle = coverArt.SongTitle;
|
||||||
|
|
||||||
coverArt = coverArtRepository.GetCoverArt(CoverArtField.SongTitle,
|
coverArt = _coverArtContext.CoverArtImages.FirstOrDefault(cov => cov.SongTitle.Equals(songTitle));
|
||||||
coverArt);
|
|
||||||
|
|
||||||
song.CoverArtId = coverArt.CoverArtId;
|
song.CoverArtID = coverArt.CoverArtID;
|
||||||
}
|
}
|
||||||
public void DeleteCoverArtFromDatabase(CoverArt coverArt,
|
public void DeleteCoverArtFromDatabase(CoverArt coverArt)
|
||||||
CoverArtRepository coverArtRepository)
|
|
||||||
{
|
{
|
||||||
_logger.Info("Attempting to delete cover art from the database");
|
_logger.Info("Attempting to delete cover art from the database");
|
||||||
coverArtRepository.DeleteCoverArt(coverArt);
|
|
||||||
|
_coverArtContext.Remove(coverArt);
|
||||||
|
_coverArtContext.SaveChanges();
|
||||||
}
|
}
|
||||||
public void DeleteCoverArt(CoverArt coverArt)
|
public void DeleteCoverArt(CoverArt coverArt)
|
||||||
{
|
{
|
||||||
@@ -109,8 +115,15 @@ namespace Icarus.Controllers.Managers
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CoverArt GetCoverArt(Song song)
|
||||||
|
{
|
||||||
|
return _coverArtContext.CoverArtImages.FirstOrDefault(cov => cov.SongTitle.Equals(song.Title));
|
||||||
|
}
|
||||||
|
|
||||||
private void Initialize()
|
private void Initialize()
|
||||||
{
|
{
|
||||||
|
_coverArtContext = new CoverArtContext(_connectionString);
|
||||||
|
|
||||||
if (System.IO.File.Exists(DirectoryPaths.CoverArtPath))
|
if (System.IO.File.Exists(DirectoryPaths.CoverArtPath))
|
||||||
_stockCoverArt = File.ReadAllBytes(DirectoryPaths.CoverArtPath);
|
_stockCoverArt = File.ReadAllBytes(DirectoryPaths.CoverArtPath);
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ namespace Icarus.Controllers.Managers
|
|||||||
public class DirectoryManager : BaseManager
|
public class DirectoryManager : BaseManager
|
||||||
{
|
{
|
||||||
#region Fields
|
#region Fields
|
||||||
private IConfiguration _config;
|
|
||||||
private Song _song;
|
private Song _song;
|
||||||
private string _rootSongDirectory;
|
private string _rootSongDirectory;
|
||||||
private string _songDirectory;
|
private string _songDirectory;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Configuration;
|
using System.Configuration;
|
||||||
|
using System.Linq;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@@ -19,12 +20,11 @@ namespace Icarus.Controllers.Managers
|
|||||||
public class SongManager : BaseManager
|
public class SongManager : BaseManager
|
||||||
{
|
{
|
||||||
#region Fields
|
#region Fields
|
||||||
private IConfiguration _config;
|
|
||||||
private string _connectionString;
|
|
||||||
private string _tempDirectoryRoot;
|
private string _tempDirectoryRoot;
|
||||||
private string _archiveDirectoryRoot;
|
private string _archiveDirectoryRoot;
|
||||||
private string _compressedSongFilename;
|
private string _compressedSongFilename;
|
||||||
private string _message;
|
private string _message;
|
||||||
|
private SongContext _songContext;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
@@ -78,7 +78,7 @@ namespace Icarus.Controllers.Managers
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var oldSongRecord = songStore.GetSong(song);
|
var oldSongRecord = _songContext.RetrieveRecord(song);
|
||||||
song.SongPath = oldSongRecord.SongPath;
|
song.SongPath = oldSongRecord.SongPath;
|
||||||
|
|
||||||
MetadataRetriever updateMetadata = new MetadataRetriever();
|
MetadataRetriever updateMetadata = new MetadataRetriever();
|
||||||
@@ -86,16 +86,16 @@ namespace Icarus.Controllers.Managers
|
|||||||
|
|
||||||
var updatedSong = updateMetadata.UpdatedSongRecord;
|
var updatedSong = updateMetadata.UpdatedSongRecord;
|
||||||
|
|
||||||
var updatedAlbum = UpdateAlbumInDatabase(oldSongRecord, updatedSong)
|
var updatedAlbum = UpdateAlbumInDatabase(oldSongRecord, updatedSong);
|
||||||
oldSongRecord.AlbumId = updatedAlbum.AlbumId;
|
oldSongRecord.AlbumID = updatedAlbum.AlbumID;
|
||||||
|
|
||||||
var updatedArtist = UpdateArtistInDatabase(oldSongRecord, updatedSong);
|
var updatedArtist = UpdateArtistInDatabase(oldSongRecord, updatedSong);
|
||||||
oldSongRecord.ArtistId = updatedArtist.ArtistId;
|
oldSongRecord.ArtistID = updatedArtist.ArtistID;
|
||||||
|
|
||||||
var updatedGenre = UpdateGenreInDatabase(oldSongRecord, updatedSong);
|
var updatedGenre = UpdateGenreInDatabase(oldSongRecord, updatedSong);
|
||||||
Console.WriteLine($"Old Genre Id {oldSongRecord.GenreId}");
|
Console.WriteLine($"Old Genre Id {oldSongRecord.GenreID}");
|
||||||
oldSongRecord.GenreId = updatedGenre.GenreId;
|
oldSongRecord.GenreID = updatedGenre.GenreID;
|
||||||
Console.WriteLine($"Updated Genre Id {updatedGenre.GenreId}");
|
Console.WriteLine($"Updated Genre ID {updatedGenre.GenreID}");
|
||||||
|
|
||||||
UpdateSongInDatabase(ref oldSongRecord, ref updatedSong, ref result);
|
UpdateSongInDatabase(ref oldSongRecord, ref updatedSong, ref result);
|
||||||
|
|
||||||
@@ -148,9 +148,9 @@ namespace Icarus.Controllers.Managers
|
|||||||
}
|
}
|
||||||
_logger.Info("Song deleted from the filesystem");
|
_logger.Info("Song deleted from the filesystem");
|
||||||
|
|
||||||
var coverMgr = new CoverArtManager(_config.GetValue<string>(
|
var coverMgr = new CoverArtManager(_config);
|
||||||
"CoverArtPath"));
|
// var coverArt = coverStore.GetCoverArt(song);
|
||||||
var coverArt = coverStore.GetCoverArt(song);
|
var coverArt = coverMgr.GetCoverArt(song);
|
||||||
coverMgr.DeleteCoverArt(coverArt);
|
coverMgr.DeleteCoverArt(coverArt);
|
||||||
|
|
||||||
coverMgr.DeleteCoverArtFromDatabase(coverArt);
|
coverMgr.DeleteCoverArtFromDatabase(coverArt);
|
||||||
@@ -205,7 +205,7 @@ namespace Icarus.Controllers.Managers
|
|||||||
_logger.Info("Song successfully saved to filesystem");
|
_logger.Info("Song successfully saved to filesystem");
|
||||||
}
|
}
|
||||||
|
|
||||||
var coverMgr = new CoverArtManager(_config.GetValue<string>("CoverArtPath"));
|
var coverMgr = new CoverArtManager(_config);
|
||||||
var coverArt = coverMgr.SaveCoverArt(song);
|
var coverArt = coverMgr.SaveCoverArt(song);
|
||||||
|
|
||||||
coverMgr.SaveCoverArtToDatabase(ref song, ref coverArt);//,
|
coverMgr.SaveCoverArtToDatabase(ref song, ref coverArt);//,
|
||||||
@@ -298,13 +298,13 @@ namespace Icarus.Controllers.Managers
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_connectionString = _config.GetConnectionString("IcarusDev");
|
_connectionString = _config.GetConnectionString("DefaultConnection");
|
||||||
|
_songContext = new SongContext(_connectionString);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Error Occurred: {ex.Message}");
|
Console.WriteLine($"Error Occurred: {ex.Message}");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -321,7 +321,7 @@ namespace Icarus.Controllers.Managers
|
|||||||
var info = "Saving Song to DB";
|
var info = "Saving Song to DB";
|
||||||
Console.WriteLine(info);
|
Console.WriteLine(info);
|
||||||
_logger.Info(info);
|
_logger.Info(info);
|
||||||
songStore.SaveSong(song);
|
_songContext.Add(song);
|
||||||
}
|
}
|
||||||
private void SaveAlbumToDatabase(ref Song song)//, AlbumRepository albumStore)
|
private void SaveAlbumToDatabase(ref Song song)//, AlbumRepository albumStore)
|
||||||
{
|
{
|
||||||
@@ -331,24 +331,26 @@ namespace Icarus.Controllers.Managers
|
|||||||
|
|
||||||
album.Title = song.AlbumTitle;
|
album.Title = song.AlbumTitle;
|
||||||
album.AlbumArtist = song.Artist;
|
album.AlbumArtist = song.Artist;
|
||||||
|
var albumTitle = song.AlbumTitle;
|
||||||
|
AlbumContext albumContext = new AlbumContext(_connectionString);
|
||||||
|
|
||||||
if (!albumStore.DoesAlbumExist(song))
|
if (!(albumContext.Albums.FirstOrDefault(alb => alb.Title.Equals(albumTitle)) != null))
|
||||||
{
|
{
|
||||||
album.SongCount = 1;
|
album.SongCount = 1;
|
||||||
albumStore.SaveAlbum(album);
|
albumContext.Add(album);
|
||||||
album = albumStore.GetAlbum(song);
|
album = albumContext.Albums.FirstOrDefault(alb => alb.Title.Equals(albumTitle));
|
||||||
Console.WriteLine($"Album Id {album.AlbumId}");
|
Console.WriteLine($"Album Id {album.AlbumID}");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var albumRetrieved = albumStore.GetAlbum(song);
|
var albumRetrieved = albumContext.Albums.FirstOrDefault(alb => alb.Title.Equals(albumTitle));
|
||||||
album.AlbumId = albumRetrieved.AlbumId;
|
album.AlbumID = albumRetrieved.AlbumID;
|
||||||
album.SongCount = albumRetrieved.SongCount + 1;
|
album.SongCount = albumRetrieved.SongCount + 1;
|
||||||
|
|
||||||
albumStore.UpdateAlbum(album);
|
albumContext.Update(album);
|
||||||
}
|
}
|
||||||
|
|
||||||
song.AlbumId = album.AlbumId;
|
song.AlbumID = album.AlbumID;
|
||||||
}
|
}
|
||||||
private void SaveArtistToDatabase(ref Song song)//, ArtistRepository artistStore)
|
private void SaveArtistToDatabase(ref Song song)//, ArtistRepository artistStore)
|
||||||
{
|
{
|
||||||
@@ -358,23 +360,26 @@ namespace Icarus.Controllers.Managers
|
|||||||
|
|
||||||
artist.Name = song.Artist;
|
artist.Name = song.Artist;
|
||||||
artist.SongCount = 1;
|
artist.SongCount = 1;
|
||||||
|
var artistTitle = artist.Name;
|
||||||
|
ArtistContext artistContext = new ArtistContext(_connectionString);
|
||||||
|
|
||||||
if (!artistStore.DoesArtistExist(song))
|
if (!(artistContext.Artists.FirstOrDefault(art => art.Name.Equals(artistTitle)) != null))
|
||||||
{
|
{
|
||||||
artist.SongCount = 1;
|
artist.SongCount = 1;
|
||||||
artistStore.SaveArtist(artist);
|
artistContext.Add(artist);
|
||||||
artist = artistStore.GetArtist(song);
|
artist = artistContext.Artists.FirstOrDefault(art => art.Name.Equals(artistTitle));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var artistRetrieved = artistStore.GetArtist(song);
|
var artistRetrieved = artistContext.Artists.FirstOrDefault(art => art.Name.Equals(artistTitle));
|
||||||
artist.ArtistId = artistRetrieved.ArtistId;
|
artist.ArtistID = artistRetrieved.ArtistID;
|
||||||
artist.SongCount = artistRetrieved.SongCount + 1;
|
artist.SongCount = artistRetrieved.SongCount + 1;
|
||||||
|
|
||||||
artistStore.UpdateArtist(artist);
|
artistContext.Update(artist);
|
||||||
|
artistContext.SaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
song.ArtistId = artist.ArtistId;
|
song.ArtistID = artist.ArtistID;
|
||||||
}
|
}
|
||||||
private void SaveGenreToDatabase(ref Song song)//, GenreRepository genreStore)
|
private void SaveGenreToDatabase(ref Song song)//, GenreRepository genreStore)
|
||||||
{
|
{
|
||||||
@@ -386,26 +391,30 @@ namespace Icarus.Controllers.Managers
|
|||||||
SongCount = 1
|
SongCount = 1
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!genreStore.DoesGenreExist(song))
|
var genreName = song.Genre;
|
||||||
|
var genreContext = new GenreContext(_connectionString);
|
||||||
|
|
||||||
|
if (! (genreContext.Genres.FirstOrDefault(gnr => gnr.GenreName.Equals(genreName)) != null))
|
||||||
{
|
{
|
||||||
genreStore.SaveGenre(genre);
|
genreContext.Add(genre);
|
||||||
Console.WriteLine("Going to find genre");
|
Console.WriteLine("Going to find genre");
|
||||||
genre = genreStore.GetGenre(song);
|
genre = genreContext.Genres.FirstOrDefault(gnr => gnr.GenreName.Equals(genreName));
|
||||||
var genreDump = $"Genre id {genre.GenreId} GenreName {genre.GenreName}" +
|
var genreDump = $"Genre ID {genre.GenreID} GenreName {genre.GenreName}" +
|
||||||
$" Genre song Count {genre.SongCount}";
|
$" Genre song Count {genre.SongCount}";
|
||||||
Console.WriteLine(genreDump);
|
Console.WriteLine(genreDump);
|
||||||
_logger.Info(genreDump);
|
_logger.Info(genreDump);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var genreRetrieved = genreStore.GetGenre(song);
|
var genreRetrieved = genreContext.Genres.FirstOrDefault(gnr => gnr.GenreName.Equals(genreName));
|
||||||
genre.GenreId = genreRetrieved.GenreId;
|
genre.GenreID = genreRetrieved.GenreID;
|
||||||
genre.SongCount = genreRetrieved.SongCount + 1;
|
genre.SongCount = genreRetrieved.SongCount + 1;
|
||||||
|
|
||||||
genreStore.UpdateGenre(genre);
|
genreContext.Update(genre);
|
||||||
|
genreContext.SaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
song.GenreId = genre.GenreId;
|
song.GenreID = genre.GenreID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -446,7 +455,9 @@ namespace Icarus.Controllers.Managers
|
|||||||
|
|
||||||
private Album UpdateAlbumInDatabase(Song oldSongRecord, Song newSongRecord)//, AlbumRepository albumStore)
|
private Album UpdateAlbumInDatabase(Song oldSongRecord, Song newSongRecord)//, AlbumRepository albumStore)
|
||||||
{
|
{
|
||||||
var albumRecord = albumStore.GetAlbum(oldSongRecord, true);
|
var albumContext = new AlbumContext(_connectionString);
|
||||||
|
|
||||||
|
var albumRecord = albumContext.Albums.FirstOrDefault(alb => alb.Title.Equals(oldSongRecord.AlbumTitle));
|
||||||
var oldAlbumTitle = oldSongRecord.AlbumTitle;
|
var oldAlbumTitle = oldSongRecord.AlbumTitle;
|
||||||
var oldAlbumArtist = oldSongRecord.Artist;
|
var oldAlbumArtist = oldSongRecord.Artist;
|
||||||
var newAlbumTitle = newSongRecord.AlbumTitle;
|
var newAlbumTitle = newSongRecord.AlbumTitle;
|
||||||
@@ -469,7 +480,7 @@ namespace Icarus.Controllers.Managers
|
|||||||
info = "Change to the song's album";
|
info = "Change to the song's album";
|
||||||
_logger.Info(info);
|
_logger.Info(info);
|
||||||
|
|
||||||
if (!albumStore.DoesAlbumExist(newSongRecord))
|
if (!(albumContext.Albums.FirstOrDefault(alb => alb.Title.Equals(newSongRecord.AlbumTitle)) != null))
|
||||||
{
|
{
|
||||||
_logger.Info("Creating new album record");
|
_logger.Info("Creating new album record");
|
||||||
|
|
||||||
@@ -479,25 +490,28 @@ namespace Icarus.Controllers.Managers
|
|||||||
AlbumArtist = newAlbumArtist
|
AlbumArtist = newAlbumArtist
|
||||||
};
|
};
|
||||||
|
|
||||||
albumStore.SaveAlbum(newAlbumRecord);
|
albumContext.Add(newAlbumRecord);
|
||||||
|
|
||||||
return albumStore.GetAlbum(newSongRecord, true);
|
return albumContext.Albums.FirstOrDefault(alb => alb.Title.Equals(oldSongRecord.AlbumTitle));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_logger.Info("Updating existing album record");
|
_logger.Info("Updating existing album record");
|
||||||
|
|
||||||
var existingAlbumRecord = albumStore.GetAlbum(newSongRecord);
|
var existingAlbumRecord = albumContext.Albums.FirstOrDefault(alb => alb.Title.Equals(newSongRecord.AlbumTitle));
|
||||||
existingAlbumRecord.AlbumArtist = newAlbumArtist;
|
existingAlbumRecord.AlbumArtist = newAlbumArtist;
|
||||||
|
|
||||||
albumStore.UpdateAlbum(existingAlbumRecord);
|
albumContext.Update(existingAlbumRecord);
|
||||||
|
albumContext.SaveChanges();
|
||||||
|
|
||||||
return existingAlbumRecord;
|
return existingAlbumRecord;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private Artist UpdateArtistInDatabase(Song oldSongRecord, Song newSongRecord)//, ArtistRepository artistStore)
|
private Artist UpdateArtistInDatabase(Song oldSongRecord, Song newSongRecord)//, ArtistRepository artistStore)
|
||||||
{
|
{
|
||||||
var oldArtistRecord = artistStore.GetArtist(oldSongRecord, true);
|
var artistContext = new ArtistContext(_connectionString);
|
||||||
|
|
||||||
|
var oldArtistRecord = artistContext.Artists.FirstOrDefault(art => art.Name.Equals(oldSongRecord.AlbumTitle));
|
||||||
var oldArtistName = oldArtistRecord.Name;
|
var oldArtistName = oldArtistRecord.Name;
|
||||||
var newArtistName = newSongRecord.Artist;
|
var newArtistName = newSongRecord.Artist;
|
||||||
|
|
||||||
@@ -513,10 +527,11 @@ namespace Icarus.Controllers.Managers
|
|||||||
{
|
{
|
||||||
_logger.Info("Deleting artist record that no longer has any songs");
|
_logger.Info("Deleting artist record that no longer has any songs");
|
||||||
|
|
||||||
artistStore.DeleteArtist(oldArtistRecord);
|
artistContext.Remove(oldArtistRecord);
|
||||||
|
artistContext.SaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!artistStore.DoesArtistExist(newSongRecord))
|
if (!(artistContext.Artists.FirstOrDefault(art => art.Name.Equals(oldSongRecord.AlbumTitle)) != null))
|
||||||
{
|
{
|
||||||
_logger.Info("Creating new artist record");
|
_logger.Info("Creating new artist record");
|
||||||
|
|
||||||
@@ -525,24 +540,26 @@ namespace Icarus.Controllers.Managers
|
|||||||
Name = newArtistName
|
Name = newArtistName
|
||||||
};
|
};
|
||||||
|
|
||||||
artistStore.SaveArtist(newArtistRecord);
|
artistContext.Add(newArtistRecord);
|
||||||
|
|
||||||
return artistStore.GetArtist(newSongRecord, true);
|
return artistContext.Artists.FirstOrDefault(art => art.Name.Equals(newSongRecord.AlbumTitle));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_logger.Info("Updating existing artist record");
|
_logger.Info("Updating existing artist record");
|
||||||
|
|
||||||
var existingArtistRecord = artistStore.GetArtist(newSongRecord);
|
var existingArtistRecord = artistContext.Artists.FirstOrDefault(art => art.Name.Equals(newSongRecord.AlbumTitle));
|
||||||
|
|
||||||
artistStore.UpdateArtist(existingArtistRecord);
|
artistContext.Update(existingArtistRecord);
|
||||||
|
artistContext.SaveChanges();
|
||||||
|
|
||||||
return existingArtistRecord;
|
return existingArtistRecord;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private Genre UpdateGenreInDatabase(Song oldSongRecord, Song newSongRecord)//, GenreRepository genreStore)
|
private Genre UpdateGenreInDatabase(Song oldSongRecord, Song newSongRecord)//, GenreRepository genreStore)
|
||||||
{
|
{
|
||||||
var oldGenreRecord = genreStore.GetGenre(oldSongRecord, true);
|
var genreContext = new GenreContext(_connectionString);
|
||||||
|
var oldGenreRecord = genreContext.Genres.FirstOrDefault(gnr => gnr.GenreName.Equals(oldSongRecord.Genre));
|
||||||
var oldGenreName = oldGenreRecord.GenreName;
|
var oldGenreName = oldGenreRecord.GenreName;
|
||||||
var newGenreName = newSongRecord.Genre;
|
var newGenreName = newSongRecord.Genre;
|
||||||
|
|
||||||
@@ -558,10 +575,11 @@ namespace Icarus.Controllers.Managers
|
|||||||
{
|
{
|
||||||
_logger.Info("Deleting genre record");
|
_logger.Info("Deleting genre record");
|
||||||
|
|
||||||
genreStore.DeleteGenre(oldGenreRecord);
|
genreContext.Remove(oldGenreRecord);
|
||||||
|
genreContext.SaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!genreStore.DoesGenreExist(newSongRecord))
|
if (!(genreContext.Genres.FirstOrDefault(gnr => gnr.GenreName.Equals(oldSongRecord.Genre)) != null))
|
||||||
{
|
{
|
||||||
_logger.Info("Creating new genre record");
|
_logger.Info("Creating new genre record");
|
||||||
|
|
||||||
@@ -570,18 +588,19 @@ namespace Icarus.Controllers.Managers
|
|||||||
GenreName = newGenreName
|
GenreName = newGenreName
|
||||||
};
|
};
|
||||||
|
|
||||||
genreStore.SaveGenre(newGenreRecord);
|
genreContext.Add(newGenreRecord);
|
||||||
|
|
||||||
return genreStore.GetGenre(newSongRecord, true);
|
return genreContext.Genres.FirstOrDefault(gnr => gnr.GenreName.Equals(newGenreRecord.GenreName));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_logger.Info("Updating existing genre record");
|
_logger.Info("Updating existing genre record");
|
||||||
|
|
||||||
var existingGenreRecord = genreStore.GetGenre(newSongRecord);
|
var existingGenreRecord = genreContext.Genres.FirstOrDefault(gnr => gnr.GenreName.Equals(oldGenreRecord.GenreName));
|
||||||
|
|
||||||
genreStore.UpdateGenre(existingGenreRecord);
|
genreContext.Update(existingGenreRecord);
|
||||||
return genreStore.GetGenre(existingGenreRecord);
|
genreContext.SaveChanges();
|
||||||
|
return genreContext.Genres.FirstOrDefault(gnr => gnr.GenreName.Equals(existingGenreRecord.GenreName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -598,14 +617,15 @@ namespace Icarus.Controllers.Managers
|
|||||||
Year = oldSongRecord.Year,
|
Year = oldSongRecord.Year,
|
||||||
Filename = oldSongRecord.Filename,
|
Filename = oldSongRecord.Filename,
|
||||||
SongPath = oldSongRecord.SongPath,
|
SongPath = oldSongRecord.SongPath,
|
||||||
ArtistId = oldSongRecord.ArtistId,
|
ArtistID = oldSongRecord.ArtistID,
|
||||||
AlbumId = oldSongRecord.AlbumId,
|
AlbumID = oldSongRecord.AlbumID,
|
||||||
GenreId = oldSongRecord.GenreId,
|
GenreID = oldSongRecord.GenreID
|
||||||
YearId = oldSongRecord.YearId
|
|
||||||
|
|
||||||
};
|
};
|
||||||
var artistOrAlbumChanged = false;
|
var artistOrAlbumChanged = false;
|
||||||
|
|
||||||
|
var songContext = new SongContext(_connectionString);
|
||||||
|
|
||||||
if (!SongRecordChanged(oldSongRecord, newSongRecord))
|
if (!SongRecordChanged(oldSongRecord, newSongRecord))
|
||||||
{
|
{
|
||||||
_logger.Info("No change to the song record");
|
_logger.Info("No change to the song record");
|
||||||
@@ -674,10 +694,13 @@ namespace Icarus.Controllers.Managers
|
|||||||
|
|
||||||
_logger.Info("Saving song metadata to the database");
|
_logger.Info("Saving song metadata to the database");
|
||||||
|
|
||||||
if (songStore.DoesSongExist(newSongRecord))
|
if (songContext.Songs.FirstOrDefault(sng => sng.Title.Equals(updatedSongRecord.Title)) != null)
|
||||||
songStore.UpdateSong(updatedSongRecord);
|
{
|
||||||
|
songContext.Update(updatedSongRecord);
|
||||||
|
songContext.SaveChanges();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
songStore.SaveSong(updatedSongRecord);
|
songContext.Add(updatedSongRecord);
|
||||||
|
|
||||||
newSongRecord = updatedSongRecord;
|
newSongRecord = updatedSongRecord;
|
||||||
|
|
||||||
@@ -700,42 +723,57 @@ namespace Icarus.Controllers.Managers
|
|||||||
}
|
}
|
||||||
private void DeleteAlbumFromDatabase(Song song)// AlbumRepository albumStore)
|
private void DeleteAlbumFromDatabase(Song song)// AlbumRepository albumStore)
|
||||||
{
|
{
|
||||||
if (!albumStore.DoesAlbumExist(song))
|
var albumContext = new AlbumContext(_connectionString);
|
||||||
|
|
||||||
|
if (!(albumContext.Albums.FirstOrDefault(alb => alb.Title.Equals(song.AlbumTitle)) != null))
|
||||||
{
|
{
|
||||||
_logger.Info("Cannot delete the album record because it does not exist");
|
_logger.Info("Cannot delete the album record because it does not exist");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var album = albumStore.GetAlbum(song, true);
|
var album = albumContext.Albums.FirstOrDefault(alb => alb.Title.Equals(song.AlbumTitle));
|
||||||
|
|
||||||
if (album.SongCount <= 1)
|
if (album.SongCount <= 1)
|
||||||
albumStore.DeleteAlbum(album);
|
{
|
||||||
|
albumContext.Remove(album);
|
||||||
|
albumContext.SaveChanges();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
private void DeleteArtistFromDatabase(Song song)//, ArtistRepository artistStore)
|
private void DeleteArtistFromDatabase(Song song)//, ArtistRepository artistStore)
|
||||||
{
|
{
|
||||||
if (!artistStore.DoesArtistExist(song))
|
var artistContext = new ArtistContext(_connectionString);
|
||||||
|
|
||||||
|
if (!(artistContext.Artists.FirstOrDefault(art => art.Name.Equals(song.Artist)) != null))
|
||||||
{
|
{
|
||||||
_logger.Info("Cannot delete the artist record because it does not exist");
|
_logger.Info("Cannot delete the artist record because it does not exist");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var artist = artistStore.GetArtist(song, true);
|
var artist = artistContext.Artists.FirstOrDefault(art => art.Name.Equals(song.Artist));
|
||||||
|
|
||||||
if (artist.SongCount <= 1)
|
if (artist.SongCount <= 1)
|
||||||
artistStore.DeleteArtist(artist);
|
{
|
||||||
|
artistContext.Remove(artist);
|
||||||
|
artistContext.SaveChanges();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
private void DeleteGenreFromDatabase(Song song)//, GenreRepository genreStore)
|
private void DeleteGenreFromDatabase(Song song)//, GenreRepository genreStore)
|
||||||
{
|
{
|
||||||
if (!genreStore.DoesGenreExist(song))
|
var genreContext = new GenreContext(_connectionString);
|
||||||
|
|
||||||
|
if (!(genreContext.Genres.FirstOrDefault(gnr => gnr.GenreName.Equals(song.Genre)) != null))
|
||||||
{
|
{
|
||||||
_logger.Info("Cannot delete the genre record because it does not exist");
|
_logger.Info("Cannot delete the genre record because it does not exist");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var genre = genreStore.GetGenre(song, true);
|
var genre = genreContext.Genres.FirstOrDefault(gnr => gnr.GenreName.Equals(song.Genre));
|
||||||
|
|
||||||
if (genre.SongCount <= 1)
|
if (genre.SongCount <= 1)
|
||||||
genreStore.DeleteGenre(genre);
|
{
|
||||||
|
genreContext.Remove(genre);
|
||||||
|
genreContext.SaveChanges();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ namespace Icarus.Controllers.Managers
|
|||||||
public class TokenManager : BaseManager
|
public class TokenManager : BaseManager
|
||||||
{
|
{
|
||||||
#region Fields
|
#region Fields
|
||||||
private IConfiguration _config;
|
|
||||||
private string _clientId;
|
private string _clientId;
|
||||||
private string _clientSecret;
|
private string _clientSecret;
|
||||||
private string _audience;
|
private string _audience;
|
||||||
@@ -64,7 +63,7 @@ namespace Icarus.Controllers.Managers
|
|||||||
|
|
||||||
return new LoginResult
|
return new LoginResult
|
||||||
{
|
{
|
||||||
UserId = user.Id, Username = user.Username, Token = tokenResult.AccessToken,
|
UserID = user.UserID, Username = user.Username, Token = tokenResult.AccessToken,
|
||||||
TokenType = tokenResult.TokenType, Expiration = tokenResult.Expiration,
|
TokenType = tokenResult.TokenType, Expiration = tokenResult.Expiration,
|
||||||
Message = "Successfully retrieved token"
|
Message = "Successfully retrieved token"
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -46,17 +46,16 @@ namespace Icarus.Controllers.Utilities
|
|||||||
public static void PrintMetadata(Song song)
|
public static void PrintMetadata(Song song)
|
||||||
{
|
{
|
||||||
Console.WriteLine("\n\nMetadata of the song:");
|
Console.WriteLine("\n\nMetadata of the song:");
|
||||||
Console.WriteLine($"Id: {song.Id}");
|
Console.WriteLine($"ID: {song.SongID}");
|
||||||
Console.WriteLine($"Title: {song.Title}");
|
Console.WriteLine($"Title: {song.Title}");
|
||||||
Console.WriteLine($"Artist: {song.Artist}");
|
Console.WriteLine($"Artist: {song.Artist}");
|
||||||
Console.WriteLine($"Album: {song.AlbumTitle}");
|
Console.WriteLine($"Album: {song.AlbumTitle}");
|
||||||
Console.WriteLine($"Genre: {song.Genre}");
|
Console.WriteLine($"Genre: {song.Genre}");
|
||||||
Console.WriteLine($"Year: {song.Year}");
|
Console.WriteLine($"Year: {song.Year}");
|
||||||
Console.WriteLine($"Duration: {song.Duration}");
|
Console.WriteLine($"Duration: {song.Duration}");
|
||||||
Console.WriteLine($"AlbumId: {song.AlbumId}");
|
Console.WriteLine($"AlbumID: {song.AlbumID}");
|
||||||
Console.WriteLine($"ArtistId: {song.ArtistId}");
|
Console.WriteLine($"ArtistID: {song.ArtistID}");
|
||||||
Console.WriteLine($"GenreId: {song.GenreId}");
|
Console.WriteLine($"GenreID: {song.GenreID}");
|
||||||
Console.WriteLine($"YearId: {song.YearId}");
|
|
||||||
Console.WriteLine($"Song Path: {song.SongPath}");
|
Console.WriteLine($"Song Path: {song.SongPath}");
|
||||||
Console.WriteLine($"Filename: {song.Filename}");
|
Console.WriteLine($"Filename: {song.Filename}");
|
||||||
Console.WriteLine("\n");
|
Console.WriteLine("\n");
|
||||||
@@ -237,7 +236,7 @@ namespace Icarus.Controllers.Utilities
|
|||||||
{
|
{
|
||||||
_updatedSong = new Song
|
_updatedSong = new Song
|
||||||
{
|
{
|
||||||
Id = song.Id,
|
SongID = song.SongID,
|
||||||
Title = song.Title,
|
Title = song.Title,
|
||||||
AlbumTitle = song.AlbumTitle,
|
AlbumTitle = song.AlbumTitle,
|
||||||
Artist = song.Artist,
|
Artist = song.Artist,
|
||||||
@@ -271,7 +270,7 @@ namespace Icarus.Controllers.Utilities
|
|||||||
Console.WriteLine($"\n\n{message}");
|
Console.WriteLine($"\n\n{message}");
|
||||||
Console.WriteLine($"Title: {song.Title}");
|
Console.WriteLine($"Title: {song.Title}");
|
||||||
Console.WriteLine($"Artist: {song.Artist}");
|
Console.WriteLine($"Artist: {song.Artist}");
|
||||||
Console.WriteLine($"Album: {song.Album}");
|
Console.WriteLine($"Album: {song.AlbumTitle}");
|
||||||
Console.WriteLine($"Genre: {song.Genre}");
|
Console.WriteLine($"Genre: {song.Genre}");
|
||||||
Console.WriteLine($"Year: {song.Year}");
|
Console.WriteLine($"Year: {song.Year}");
|
||||||
Console.WriteLine($"Duration: {song.Duration}\n\n");
|
Console.WriteLine($"Duration: {song.Duration}\n\n");
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Configuration;
|
using System.Configuration;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
@@ -19,6 +20,8 @@ namespace Icarus.Controllers.V1
|
|||||||
{
|
{
|
||||||
#region Fields
|
#region Fields
|
||||||
private readonly ILogger<AlbumController> _logger;
|
private readonly ILogger<AlbumController> _logger;
|
||||||
|
private string _connectionString;
|
||||||
|
private IConfiguration _config;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
@@ -27,9 +30,11 @@ namespace Icarus.Controllers.V1
|
|||||||
|
|
||||||
|
|
||||||
#region Constructors
|
#region Constructors
|
||||||
public AlbumController(ILogger<AlbumController> logger)
|
public AlbumController(ILogger<AlbumController> logger, IConfiguration config)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
_config = config;
|
||||||
|
_connectionString = _config.GetConnectionString("DefaultConnection");
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -41,10 +46,9 @@ namespace Icarus.Controllers.V1
|
|||||||
{
|
{
|
||||||
List<Album> albums = new List<Album>();
|
List<Album> albums = new List<Album>();
|
||||||
|
|
||||||
AlbumRepository albumStoreContext = HttpContext.RequestServices
|
var albumContext = new AlbumContext(_connectionString);
|
||||||
.GetService(typeof(AlbumRepository)) as AlbumRepository;
|
|
||||||
|
|
||||||
albums = albumStoreContext.GetAlbums();
|
albums = albumContext.Albums.ToList();
|
||||||
|
|
||||||
if (albums.Count > 0)
|
if (albums.Count > 0)
|
||||||
return Ok(albums);
|
return Ok(albums);
|
||||||
@@ -58,15 +62,14 @@ namespace Icarus.Controllers.V1
|
|||||||
{
|
{
|
||||||
Album album = new Album
|
Album album = new Album
|
||||||
{
|
{
|
||||||
AlbumId = id
|
AlbumID = id
|
||||||
};
|
};
|
||||||
|
|
||||||
AlbumRepository albumStoreContext = HttpContext.RequestServices
|
var albumContext = new AlbumContext(_connectionString);
|
||||||
.GetService(typeof(AlbumRepository)) as AlbumRepository;
|
|
||||||
|
|
||||||
if (albumStoreContext.DoesAlbumExist(album))
|
if (albumContext.DoesRecordExist(album))
|
||||||
{
|
{
|
||||||
album = albumStoreContext.GetAlbum(album);
|
album = albumContext.RetrieveRecord(album);
|
||||||
|
|
||||||
return Ok(album);
|
return Ok(album);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ using Microsoft.Extensions.Configuration;
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
using Icarus.Models;
|
using Icarus.Models;
|
||||||
using Icarus.Database.Repositories;
|
using Icarus.Database.Contexts;
|
||||||
|
|
||||||
namespace Icarus.Controllers.V1
|
namespace Icarus.Controllers.V1
|
||||||
{
|
{
|
||||||
@@ -19,6 +19,8 @@ namespace Icarus.Controllers.V1
|
|||||||
{
|
{
|
||||||
#region Fields
|
#region Fields
|
||||||
private readonly ILogger<ArtistController> _logger;
|
private readonly ILogger<ArtistController> _logger;
|
||||||
|
private string _connectionString;
|
||||||
|
private IConfiguration _config;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
@@ -27,9 +29,11 @@ namespace Icarus.Controllers.V1
|
|||||||
|
|
||||||
|
|
||||||
#region Constructors
|
#region Constructors
|
||||||
public ArtistController(ILogger<ArtistController> logger)
|
public ArtistController(ILogger<ArtistController> logger, IConfiguration config)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
_config = config;
|
||||||
|
_connectionString = _config.GetConnectionString("DefaultConnection");
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -39,10 +43,9 @@ namespace Icarus.Controllers.V1
|
|||||||
[Authorize("read:artists")]
|
[Authorize("read:artists")]
|
||||||
public IActionResult Get()
|
public IActionResult Get()
|
||||||
{
|
{
|
||||||
ArtistRepository artistStoreContext = HttpContext.RequestServices
|
var artistContext = new ArtistContext(_connectionString);
|
||||||
.GetService(typeof(ArtistRepository)) as ArtistRepository;
|
|
||||||
|
|
||||||
var artists = artistStoreContext.GetArtists();
|
var artists = artistContext.Artists.ToList();
|
||||||
|
|
||||||
if (artists.Count > 0)
|
if (artists.Count > 0)
|
||||||
return Ok(artists);
|
return Ok(artists);
|
||||||
@@ -56,15 +59,14 @@ namespace Icarus.Controllers.V1
|
|||||||
{
|
{
|
||||||
Artist artist = new Artist
|
Artist artist = new Artist
|
||||||
{
|
{
|
||||||
ArtistId = id
|
ArtistID = id
|
||||||
};
|
};
|
||||||
|
|
||||||
ArtistRepository artistStoreContext = HttpContext.RequestServices
|
var artistContext = new ArtistContext(_connectionString);
|
||||||
.GetService(typeof(ArtistRepository)) as ArtistRepository;
|
|
||||||
|
|
||||||
if (artistStoreContext.DoesArtistExist(artist))
|
if (artistContext.DoesRecordExist(artist))
|
||||||
{
|
{
|
||||||
artist = artistStoreContext.GetArtist(artist);
|
artist = artistContext.RetrieveRecord(artist);
|
||||||
|
|
||||||
return Ok(artist);
|
return Ok(artist);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
@@ -9,7 +10,7 @@ using Microsoft.Extensions.Configuration;
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
using Icarus.Controllers.Managers;
|
using Icarus.Controllers.Managers;
|
||||||
using Icarus.Database.Repositories;
|
using Icarus.Database.Contexts;
|
||||||
using Icarus.Models;
|
using Icarus.Models;
|
||||||
|
|
||||||
namespace Icarus.Controllers.V1
|
namespace Icarus.Controllers.V1
|
||||||
@@ -20,26 +21,27 @@ namespace Icarus.Controllers.V1
|
|||||||
{
|
{
|
||||||
#region Fields
|
#region Fields
|
||||||
private readonly ILogger<CoverArtController> _logger;
|
private readonly ILogger<CoverArtController> _logger;
|
||||||
|
private string _connectionString;
|
||||||
|
private IConfiguration _config;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
#region Constructors
|
#region Constructors
|
||||||
public CoverArtController(ILogger<CoverArtController> logger)
|
public CoverArtController(ILogger<CoverArtController> logger, IConfiguration config)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
_config = config;
|
||||||
|
_connectionString = _config.GetConnectionString("DefaultConnection");
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
#region HTTP Routes
|
#region HTTP Routes
|
||||||
public async Task<IActionResult> Get()
|
public IActionResult Get()
|
||||||
{
|
{
|
||||||
var coverArtRepository = HttpContext
|
var coverArtContext = new CoverArtContext(_connectionString);
|
||||||
.RequestServices
|
|
||||||
.GetService(
|
|
||||||
typeof(CoverArtRepository)) as CoverArtRepository;
|
|
||||||
|
|
||||||
var coverArtRecords = coverArtRepository.GetCoverArtRecords();
|
var coverArtRecords = coverArtContext.CoverArtImages.ToList();
|
||||||
|
|
||||||
if (coverArtRecords == null)
|
if (coverArtRecords == null)
|
||||||
{
|
{
|
||||||
@@ -51,26 +53,22 @@ namespace Icarus.Controllers.V1
|
|||||||
_logger.LogInformation("Found cover art records");
|
_logger.LogInformation("Found cover art records");
|
||||||
return Ok(coverArtRecords);
|
return Ok(coverArtRecords);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("{id}")]
|
[HttpGet("{id}")]
|
||||||
[Authorize("download:cover_art")]
|
[Authorize("download:cover_art")]
|
||||||
public async Task<IActionResult> Get(int id)
|
public async Task<IActionResult> Get(int id)
|
||||||
{
|
{
|
||||||
var coverArt = new CoverArt { CoverArtId = id };
|
var coverArt = new CoverArt { CoverArtID = id };
|
||||||
|
|
||||||
var coverArtRepository = HttpContext
|
var coverArtContext = new CoverArtContext(_connectionString);
|
||||||
.RequestServices
|
|
||||||
.GetService(
|
|
||||||
typeof(CoverArtRepository)) as CoverArtRepository;
|
|
||||||
|
|
||||||
coverArt = coverArtRepository.GetCoverArt(coverArt);
|
coverArt = coverArtContext.RetrieveRecord(coverArt);
|
||||||
|
|
||||||
if (coverArt != null)
|
if (coverArt != null)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Found cover art record");
|
_logger.LogInformation("Found cover art record");
|
||||||
var coverArtBytes = System.IO.File.ReadAllBytes(
|
var coverArtBytes = await System.IO.File.ReadAllBytesAsync(
|
||||||
coverArt.ImagePath);
|
coverArt.ImagePath);
|
||||||
|
|
||||||
return File(coverArtBytes, "application/x-msdownload",
|
return File(coverArtBytes, "application/x-msdownload",
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
@@ -7,7 +8,7 @@ using Microsoft.Extensions.Configuration;
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
using Icarus.Models;
|
using Icarus.Models;
|
||||||
using Icarus.Database.Repositories;
|
using Icarus.Database.Contexts;
|
||||||
|
|
||||||
namespace Icarus.Controllers.V1
|
namespace Icarus.Controllers.V1
|
||||||
{
|
{
|
||||||
@@ -17,6 +18,8 @@ namespace Icarus.Controllers.V1
|
|||||||
{
|
{
|
||||||
#region Fields
|
#region Fields
|
||||||
private readonly ILogger<GenreController> _logger;
|
private readonly ILogger<GenreController> _logger;
|
||||||
|
private string _connectionString;
|
||||||
|
private IConfiguration _config;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
@@ -25,9 +28,11 @@ namespace Icarus.Controllers.V1
|
|||||||
|
|
||||||
|
|
||||||
#region Constructors
|
#region Constructors
|
||||||
public GenreController(ILogger<GenreController> logger)
|
public GenreController(ILogger<GenreController> logger, IConfiguration config)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
_config = config;
|
||||||
|
_connectionString = _config.GetConnectionString("DefaultConnection");
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -39,10 +44,9 @@ namespace Icarus.Controllers.V1
|
|||||||
{
|
{
|
||||||
var genres = new List<Genre>();
|
var genres = new List<Genre>();
|
||||||
|
|
||||||
var genreStore = HttpContext.RequestServices
|
var genreStore = new GenreContext(_connectionString);
|
||||||
.GetService(typeof(GenreRepository)) as GenreRepository;
|
|
||||||
|
|
||||||
genres = genreStore.GetGenres();
|
genres = genreStore.Genres.ToList();
|
||||||
|
|
||||||
if (genres.Count > 0)
|
if (genres.Count > 0)
|
||||||
return Ok(genres);
|
return Ok(genres);
|
||||||
@@ -56,15 +60,14 @@ namespace Icarus.Controllers.V1
|
|||||||
{
|
{
|
||||||
var genre = new Genre
|
var genre = new Genre
|
||||||
{
|
{
|
||||||
GenreId = id
|
GenreID = id
|
||||||
};
|
};
|
||||||
|
|
||||||
var genreStore = HttpContext.RequestServices
|
var genreStore = new GenreContext(_connectionString);
|
||||||
.GetService(typeof(GenreRepository)) as GenreRepository;
|
|
||||||
|
|
||||||
if (genreStore.DoesGenreExist(genre))
|
if (genreStore.DoesRecordExist(genre))
|
||||||
{
|
{
|
||||||
genre = genreStore.GetGenre(genre);
|
genre = genreStore.RetrieveRecord(genre);
|
||||||
|
|
||||||
return Ok(genre);
|
return Ok(genre);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ using Microsoft.Extensions.Logging;
|
|||||||
using Icarus.Controllers.Managers;
|
using Icarus.Controllers.Managers;
|
||||||
using Icarus.Controllers.Utilities;
|
using Icarus.Controllers.Utilities;
|
||||||
using Icarus.Models;
|
using Icarus.Models;
|
||||||
using Icarus.Database.Repositories;
|
using Icarus.Database.Contexts;
|
||||||
|
|
||||||
namespace Icarus.Controllers.V1
|
namespace Icarus.Controllers.V1
|
||||||
{
|
{
|
||||||
@@ -20,6 +20,7 @@ namespace Icarus.Controllers.V1
|
|||||||
public class LoginController : ControllerBase
|
public class LoginController : ControllerBase
|
||||||
{
|
{
|
||||||
#region Fields
|
#region Fields
|
||||||
|
private string _connectionString;
|
||||||
private IConfiguration _config;
|
private IConfiguration _config;
|
||||||
private ILogger<LoginController> _logger;
|
private ILogger<LoginController> _logger;
|
||||||
#endregion
|
#endregion
|
||||||
@@ -32,8 +33,9 @@ namespace Icarus.Controllers.V1
|
|||||||
#region Contructors
|
#region Contructors
|
||||||
public LoginController(IConfiguration config, ILogger<LoginController> logger)
|
public LoginController(IConfiguration config, ILogger<LoginController> logger)
|
||||||
{
|
{
|
||||||
_config = config;
|
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
_config = config;
|
||||||
|
_connectionString = _config.GetConnectionString("DefaultConnection");
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -41,8 +43,7 @@ namespace Icarus.Controllers.V1
|
|||||||
#region HTTP endpoints
|
#region HTTP endpoints
|
||||||
public IActionResult Post([FromBody] User user)
|
public IActionResult Post([FromBody] User user)
|
||||||
{
|
{
|
||||||
UserRepository context = HttpContext.RequestServices
|
var context = new UserContext(_connectionString);
|
||||||
.GetService(typeof(UserRepository)) as UserRepository;
|
|
||||||
|
|
||||||
_logger.LogInformation("Starting process of validating credentials");
|
_logger.LogInformation("Starting process of validating credentials");
|
||||||
|
|
||||||
@@ -54,9 +55,9 @@ namespace Icarus.Controllers.V1
|
|||||||
Username = user.Username
|
Username = user.Username
|
||||||
};
|
};
|
||||||
|
|
||||||
if (context.DoesUserExist(user))
|
if (context.Users.FirstOrDefault(usr => usr.Username.Equals(user.Username)) != null)
|
||||||
{
|
{
|
||||||
user = context.RetrieveUser(user);
|
user = context.Users.FirstOrDefault(usr => usr.Username.Equals(user.Username));
|
||||||
|
|
||||||
var validatePass = new PasswordEncryption();
|
var validatePass = new PasswordEncryption();
|
||||||
var validated = validatePass.VerifyPassword(user, password);
|
var validated = validatePass.VerifyPassword(user, password);
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ namespace Icarus.Controllers.V1
|
|||||||
public class RegisterController : ControllerBase
|
public class RegisterController : ControllerBase
|
||||||
{
|
{
|
||||||
#region Fields
|
#region Fields
|
||||||
|
private string _connectionString;
|
||||||
private IConfiguration _config;
|
private IConfiguration _config;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -31,6 +32,7 @@ namespace Icarus.Controllers.V1
|
|||||||
public RegisterController(IConfiguration config)
|
public RegisterController(IConfiguration config)
|
||||||
{
|
{
|
||||||
_config = config;
|
_config = config;
|
||||||
|
_connectionString = _config.GetConnectionString("DefaultConnection");
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -40,11 +42,14 @@ namespace Icarus.Controllers.V1
|
|||||||
PasswordEncryption pe = new PasswordEncryption();
|
PasswordEncryption pe = new PasswordEncryption();
|
||||||
user.Password = pe.HashPassword(user);
|
user.Password = pe.HashPassword(user);
|
||||||
user.EmailVerified = false;
|
user.EmailVerified = false;
|
||||||
|
user.Status = "Registered";
|
||||||
|
user.DateCreated = DateTime.Now;
|
||||||
|
|
||||||
var context = new UserContext(_config.GetConnectionString("DefaultConnection"));
|
UserContext context = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
context = new UserContext(_config.GetConnectionString("DefaultConnection"));
|
||||||
context.Add(user);
|
context.Add(user);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ using Microsoft.Extensions.Configuration;
|
|||||||
using Icarus.Controllers.Managers;
|
using Icarus.Controllers.Managers;
|
||||||
using Icarus.Controllers.Utilities;
|
using Icarus.Controllers.Utilities;
|
||||||
using Icarus.Models;
|
using Icarus.Models;
|
||||||
using Icarus.Database.Repositories;
|
using Icarus.Database.Contexts;
|
||||||
|
|
||||||
namespace Icarus.Controllers.V1
|
namespace Icarus.Controllers.V1
|
||||||
{
|
{
|
||||||
@@ -22,6 +22,7 @@ namespace Icarus.Controllers.V1
|
|||||||
public class SongCompressedDataController : ControllerBase
|
public class SongCompressedDataController : ControllerBase
|
||||||
{
|
{
|
||||||
#region Fields
|
#region Fields
|
||||||
|
private string _connectionString;
|
||||||
private IConfiguration _config;
|
private IConfiguration _config;
|
||||||
private string _songTempDir;
|
private string _songTempDir;
|
||||||
private string _archiveDir;
|
private string _archiveDir;
|
||||||
@@ -35,9 +36,10 @@ namespace Icarus.Controllers.V1
|
|||||||
#region Constructor
|
#region Constructor
|
||||||
public SongCompressedDataController(IConfiguration config)
|
public SongCompressedDataController(IConfiguration config)
|
||||||
{
|
{
|
||||||
_config = config;
|
|
||||||
_songTempDir = _config.GetValue<string>("TemporaryMusicPath");
|
_songTempDir = _config.GetValue<string>("TemporaryMusicPath");
|
||||||
_archiveDir = _config.GetValue<string>("ArchivePath");
|
_archiveDir = _config.GetValue<string>("ArchivePath");
|
||||||
|
_config = config;
|
||||||
|
_connectionString = _config.GetConnectionString("DefaultConnection");
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -47,15 +49,14 @@ namespace Icarus.Controllers.V1
|
|||||||
[Authorize("download:songs")]
|
[Authorize("download:songs")]
|
||||||
public async Task<IActionResult> Get(int id)
|
public async Task<IActionResult> Get(int id)
|
||||||
{
|
{
|
||||||
SongRepository context = HttpContext.RequestServices
|
var context = new SongContext(_connectionString);
|
||||||
.GetService(typeof(SongRepository)) as SongRepository;
|
|
||||||
|
|
||||||
SongCompression cmp = new SongCompression(_archiveDir);
|
SongCompression cmp = new SongCompression(_archiveDir);
|
||||||
|
|
||||||
Console.WriteLine($"Archive directory root: {_archiveDir}");
|
Console.WriteLine($"Archive directory root: {_archiveDir}");
|
||||||
|
|
||||||
Console.WriteLine("Starting process of retrieving comrpessed song");
|
Console.WriteLine("Starting process of retrieving comrpessed song");
|
||||||
SongData song = await cmp.RetrieveCompressedSong(context.GetSong(id));
|
SongData song = await cmp.RetrieveCompressedSong(context.RetrieveRecord(new Song{ SongID = id }));
|
||||||
|
|
||||||
return File(song.Data, "application/x-msdownload", cmp.CompressedSongFilename);
|
return File(song.Data, "application/x-msdownload", cmp.CompressedSongFilename);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ using Microsoft.Extensions.Logging;
|
|||||||
using Icarus.Controllers.Managers;
|
using Icarus.Controllers.Managers;
|
||||||
using Icarus.Controllers.Utilities;
|
using Icarus.Controllers.Utilities;
|
||||||
using Icarus.Models;
|
using Icarus.Models;
|
||||||
using Icarus.Database.Repositories;
|
using Icarus.Database.Contexts;
|
||||||
|
|
||||||
namespace Icarus.Controllers.V1
|
namespace Icarus.Controllers.V1
|
||||||
{
|
{
|
||||||
@@ -22,6 +22,7 @@ namespace Icarus.Controllers.V1
|
|||||||
{
|
{
|
||||||
#region Fields
|
#region Fields
|
||||||
private readonly ILogger<SongController> _logger;
|
private readonly ILogger<SongController> _logger;
|
||||||
|
private string _connectionString;
|
||||||
private IConfiguration _config;
|
private IConfiguration _config;
|
||||||
private SongManager _songMgr;
|
private SongManager _songMgr;
|
||||||
#endregion
|
#endregion
|
||||||
@@ -35,6 +36,7 @@ namespace Icarus.Controllers.V1
|
|||||||
public SongController(IConfiguration config, ILogger<SongController> logger)
|
public SongController(IConfiguration config, ILogger<SongController> logger)
|
||||||
{
|
{
|
||||||
_config = config;
|
_config = config;
|
||||||
|
_connectionString = _config.GetConnectionString("DefaultConnection");
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_songMgr = new SongManager(config);
|
_songMgr = new SongManager(config);
|
||||||
}
|
}
|
||||||
@@ -49,10 +51,9 @@ namespace Icarus.Controllers.V1
|
|||||||
Console.WriteLine("Attemtping to retrieve songs");
|
Console.WriteLine("Attemtping to retrieve songs");
|
||||||
_logger.LogInformation("Attempting to retrieve songs");
|
_logger.LogInformation("Attempting to retrieve songs");
|
||||||
|
|
||||||
SongRepository context = HttpContext.RequestServices
|
var context = new SongContext(_connectionString);
|
||||||
.GetService(typeof(SongRepository)) as SongRepository;
|
|
||||||
|
|
||||||
songs = context.GetAllSongs();
|
songs = context.Songs.ToList();
|
||||||
|
|
||||||
if (songs.Count > 0)
|
if (songs.Count > 0)
|
||||||
return Ok(songs);
|
return Ok(songs);
|
||||||
@@ -64,15 +65,14 @@ namespace Icarus.Controllers.V1
|
|||||||
[Authorize("read:song_details")]
|
[Authorize("read:song_details")]
|
||||||
public IActionResult Get(int id)
|
public IActionResult Get(int id)
|
||||||
{
|
{
|
||||||
SongRepository context = HttpContext.RequestServices
|
var context = new SongContext(_connectionString);
|
||||||
.GetService(typeof(SongRepository)) as SongRepository;
|
|
||||||
|
|
||||||
Song song = new Song { Id = id };
|
Song song = new Song { SongID = id };
|
||||||
song = context.GetSong(song);
|
song = context.RetrieveRecord(song);
|
||||||
|
|
||||||
Console.WriteLine("Here");
|
Console.WriteLine("Here");
|
||||||
|
|
||||||
if (song.Id != 0)
|
if (song.SongID != 0)
|
||||||
return Ok(song);
|
return Ok(song);
|
||||||
else
|
else
|
||||||
return NotFound();
|
return NotFound();
|
||||||
@@ -82,33 +82,19 @@ namespace Icarus.Controllers.V1
|
|||||||
[HttpPut("{id}")]
|
[HttpPut("{id}")]
|
||||||
public IActionResult Put(int id, [FromBody] Song song)
|
public IActionResult Put(int id, [FromBody] Song song)
|
||||||
{
|
{
|
||||||
SongRepository context = HttpContext.RequestServices
|
var context = new SongContext(_connectionString);
|
||||||
.GetService(typeof(SongRepository)) as SongRepository;
|
|
||||||
|
|
||||||
ArtistRepository artistStore = HttpContext.RequestServices
|
song.SongID = id;
|
||||||
.GetService(typeof(ArtistRepository)) as ArtistRepository;
|
|
||||||
|
|
||||||
AlbumRepository albumStore = HttpContext.RequestServices
|
|
||||||
.GetService(typeof(AlbumRepository)) as AlbumRepository;
|
|
||||||
|
|
||||||
GenreRepository genreStore = HttpContext.RequestServices
|
|
||||||
.GetService(typeof(GenreRepository)) as GenreRepository;
|
|
||||||
|
|
||||||
YearRepository yearStore = HttpContext.RequestServices
|
|
||||||
.GetService(typeof(YearRepository)) as YearRepository;
|
|
||||||
|
|
||||||
song.Id = id;
|
|
||||||
Console.WriteLine("Retrieving filepath of song");
|
Console.WriteLine("Retrieving filepath of song");
|
||||||
_logger.LogInformation("Retrieving filepath of song");
|
_logger.LogInformation("Retrieving filepath of song");
|
||||||
|
|
||||||
if (!context.DoesSongExist(song))
|
if (!context.DoesRecordExist(song))
|
||||||
return NotFound(new SongResult
|
return NotFound(new SongResult
|
||||||
{
|
{
|
||||||
Message = "Song does not exist"
|
Message = "Song does not exist"
|
||||||
});
|
});
|
||||||
|
|
||||||
var songRes = _songMgr.UpdateSong(song, context, albumStore, artistStore, genreStore,
|
var songRes = _songMgr.UpdateSong(song);
|
||||||
yearStore);
|
|
||||||
|
|
||||||
return Ok(songRes);
|
return Ok(songRes);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ namespace Icarus.Controllers.V1
|
|||||||
public class SongDataController : ControllerBase
|
public class SongDataController : ControllerBase
|
||||||
{
|
{
|
||||||
#region Fields
|
#region Fields
|
||||||
|
private string _connectionString;
|
||||||
private IConfiguration _config;
|
private IConfiguration _config;
|
||||||
private ILogger<SongDataController> _logger;
|
private ILogger<SongDataController> _logger;
|
||||||
private SongManager _songMgr;
|
private SongManager _songMgr;
|
||||||
@@ -37,6 +38,7 @@ namespace Icarus.Controllers.V1
|
|||||||
public SongDataController(IConfiguration config, ILogger<SongDataController> logger)
|
public SongDataController(IConfiguration config, ILogger<SongDataController> logger)
|
||||||
{
|
{
|
||||||
_config = config;
|
_config = config;
|
||||||
|
_connectionString = _config.GetConnectionString("DefaultConnection");
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_songTempDir = _config.GetValue<string>("TemporaryMusicPath");
|
_songTempDir = _config.GetValue<string>("TemporaryMusicPath");
|
||||||
_songMgr = new SongManager(config, _songTempDir);
|
_songMgr = new SongManager(config, _songTempDir);
|
||||||
@@ -50,7 +52,8 @@ namespace Icarus.Controllers.V1
|
|||||||
[Authorize("download:songs")]
|
[Authorize("download:songs")]
|
||||||
public async Task<IActionResult> Get(int id)
|
public async Task<IActionResult> Get(int id)
|
||||||
{
|
{
|
||||||
var songMetaData = _songRepository.GetSong(id);
|
var songContext = new SongContext(_connectionString);
|
||||||
|
var songMetaData = songContext.RetrieveRecord(new Song { SongID = id});
|
||||||
|
|
||||||
SongData song = await _songMgr.RetrieveSong(songMetaData);
|
SongData song = await _songMgr.RetrieveSong(songMetaData);
|
||||||
|
|
||||||
@@ -69,14 +72,13 @@ namespace Icarus.Controllers.V1
|
|||||||
var uploads = _songTempDir;
|
var uploads = _songTempDir;
|
||||||
Console.WriteLine($"Song Root Path {uploads}");
|
Console.WriteLine($"Song Root Path {uploads}");
|
||||||
_logger.LogInformation($"Song root path {uploads}");
|
_logger.LogInformation($"Song root path {uploads}");
|
||||||
|
|
||||||
foreach (var sng in songData)
|
foreach (var sng in songData)
|
||||||
if (sng.Length > 0) {
|
if (sng.Length > 0) {
|
||||||
Console.WriteLine($"Song filename {sng.FileName}");
|
Console.WriteLine($"Song filename {sng.FileName}");
|
||||||
_logger.LogInformation($"Song filename {sng.FileName}");
|
_logger.LogInformation($"Song filename {sng.FileName}");
|
||||||
|
|
||||||
await _songMgr.SaveSongToFileSystem(sng, _songRepository,
|
await _songMgr.SaveSongToFileSystem(sng);
|
||||||
_albumRepository, _artistRepository,
|
|
||||||
_genreRepository, _yearRepository, _coverArtRepository);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@@ -90,9 +92,12 @@ namespace Icarus.Controllers.V1
|
|||||||
[Authorize("delete:songs")]
|
[Authorize("delete:songs")]
|
||||||
public IActionResult Delete(int id)
|
public IActionResult Delete(int id)
|
||||||
{
|
{
|
||||||
|
var songContext = new SongContext(_connectionString);
|
||||||
|
|
||||||
var songMetaData = new Song{ SongID = id };
|
var songMetaData = new Song{ SongID = id };
|
||||||
Console.WriteLine($"Id {songMetaData.SongID}");
|
Console.WriteLine($"Id {songMetaData.SongID}");
|
||||||
songMetaData = _songRepository.GetSong(songMetaData);
|
|
||||||
|
songMetaData = songContext.RetrieveRecord(songMetaData);
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(songMetaData.Title))
|
if (string.IsNullOrEmpty(songMetaData.Title))
|
||||||
{
|
{
|
||||||
@@ -103,10 +108,7 @@ namespace Icarus.Controllers.V1
|
|||||||
{
|
{
|
||||||
_logger.LogInformation("Starting process of deleting song from the filesystem and database");
|
_logger.LogInformation("Starting process of deleting song from the filesystem and database");
|
||||||
|
|
||||||
_songMgr.DeleteSong(songMetaData, _songRepository,
|
_songMgr.DeleteSong(songMetaData);
|
||||||
_albumRepository, _artistRepository,
|
|
||||||
_genreRepository, _yearRepository,
|
|
||||||
_coverArtRepository);
|
|
||||||
|
|
||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ namespace Icarus.Controllers.V1
|
|||||||
{
|
{
|
||||||
#region Fields
|
#region Fields
|
||||||
private ILogger<SongStreamController> _logger;
|
private ILogger<SongStreamController> _logger;
|
||||||
|
private string _connectionString;
|
||||||
private IConfiguration _config;
|
private IConfiguration _config;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -36,6 +37,7 @@ namespace Icarus.Controllers.V1
|
|||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_config = config;
|
_config = config;
|
||||||
|
_connectionString = _config.GetConnectionString("DefaultConnection");
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -56,7 +58,11 @@ namespace Icarus.Controllers.V1
|
|||||||
_logger.LogInformation("Starting to stream song...>");
|
_logger.LogInformation("Starting to stream song...>");
|
||||||
Console.WriteLine("Starting to streamsong...");
|
Console.WriteLine("Starting to streamsong...");
|
||||||
|
|
||||||
return File(stream, "application/octet-stream", filename);
|
var file = await Task.Run(() => {
|
||||||
|
return File(stream, "application/octet-stream", filename);
|
||||||
|
});
|
||||||
|
|
||||||
|
return file;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,6 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using MySql.Data;
|
|
||||||
using MySql.Data.EntityFrameworkCore.Extensions;
|
|
||||||
using MySql.Data.MySqlClient;
|
|
||||||
|
|
||||||
using Icarus.Models;
|
using Icarus.Models;
|
||||||
|
|
||||||
@@ -27,9 +24,14 @@ namespace Icarus.Database.Contexts
|
|||||||
.ToTable("Album");
|
.ToTable("Album");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Album RetrieveRecord(Album album)
|
||||||
|
{
|
||||||
|
return Albums.FirstOrDefault(alb => alb.AlbumID == album.AlbumID);
|
||||||
|
}
|
||||||
|
|
||||||
public bool DoesRecordExist(Album album)
|
public bool DoesRecordExist(Album album)
|
||||||
{
|
{
|
||||||
return Albums.FirstOrDefault(alb => alb.AlbumId == album.AlbumId) != null ? true : false;
|
return Albums.FirstOrDefault(alb => alb.AlbumID == album.AlbumID) != null ? true : false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,6 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using MySql.Data;
|
|
||||||
using MySql.Data.EntityFrameworkCore;
|
|
||||||
using MySql.Data.MySqlClient;
|
|
||||||
|
|
||||||
using Icarus.Models;
|
using Icarus.Models;
|
||||||
|
|
||||||
@@ -27,10 +24,16 @@ namespace Icarus.Database.Contexts
|
|||||||
.ToTable("Artist");
|
.ToTable("Artist");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Artist RetrieveRecord(Artist artist)
|
||||||
|
{
|
||||||
|
|
||||||
|
return Artists.FirstOrDefault(arst => arst.ArtistID == artist.ArtistID);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public bool DoesRecordExist(Artist artist)
|
public bool DoesRecordExist(Artist artist)
|
||||||
{
|
{
|
||||||
return Artists.FirstOrDefault(arst => arst.ArtistId == artist.ArtistId) != null ? true : false;
|
return Artists.FirstOrDefault(arst => arst.ArtistID == artist.ArtistID) != null ? true : false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,6 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using MySql.Data;
|
|
||||||
using MySql.Data.EntityFrameworkCore.Extensions;
|
|
||||||
using MySql.Data.MySqlClient;
|
|
||||||
|
|
||||||
using Icarus.Models;
|
using Icarus.Models;
|
||||||
|
|
||||||
@@ -27,10 +24,14 @@ namespace Icarus.Database.Contexts
|
|||||||
.ToTable("CoverArt");
|
.ToTable("CoverArt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CoverArt RetrieveRecord(CoverArt cover)
|
||||||
|
{
|
||||||
|
return CoverArtImages.FirstOrDefault(cov => cov.CoverArtID == cover.CoverArtID);
|
||||||
|
}
|
||||||
|
|
||||||
public bool DoesRecordExist(CoverArt cover)
|
public bool DoesRecordExist(CoverArt cover)
|
||||||
{
|
{
|
||||||
return CoverArtImages.FirstOrDefault(cov => cov.CoverArtId == cover.CoverArtId) != null ? true : false;
|
return CoverArtImages.FirstOrDefault(cov => cov.CoverArtID == cover.CoverArtID) != null ? true : false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,6 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using MySql.Data;
|
|
||||||
using MySql.Data.EntityFrameworkCore.Extensions;
|
|
||||||
using MySql.Data.MySqlClient;
|
|
||||||
|
|
||||||
using Icarus.Models;
|
using Icarus.Models;
|
||||||
|
|
||||||
@@ -27,9 +24,14 @@ namespace Icarus.Database.Contexts
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Genre RetrieveRecord(Genre genre)
|
||||||
|
{
|
||||||
|
return Genres.FirstOrDefault(gnr => gnr.GenreID == genre.GenreID);
|
||||||
|
}
|
||||||
|
|
||||||
public bool DoesRecordExist(Genre genre)
|
public bool DoesRecordExist(Genre genre)
|
||||||
{
|
{
|
||||||
return Genres.FirstOrDefault(gnr => gnr.GenreId == genre.GenreId) != null ? true : false;
|
return Genres.FirstOrDefault(gnr => gnr.GenreID == genre.GenreID) != null ? true : false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,6 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using MySql.Data;
|
|
||||||
using MySql.Data.EntityFrameworkCore.Extensions;
|
|
||||||
using MySql.Data.MySqlClient;
|
|
||||||
|
|
||||||
using Icarus.Models;
|
using Icarus.Models;
|
||||||
|
|
||||||
@@ -28,57 +25,62 @@ namespace Icarus.Database.Contexts
|
|||||||
modelBuilder.Entity<Song>()
|
modelBuilder.Entity<Song>()
|
||||||
.ToTable("Song");
|
.ToTable("Song");
|
||||||
|
|
||||||
|
/**
|
||||||
modelBuilder.Entity<Song>()
|
modelBuilder.Entity<Song>()
|
||||||
.HasOne(s => s.Album)
|
.HasOne(s => s.Album)
|
||||||
.WithMany(al => al.Songs)
|
.WithMany(al => al.Songs)
|
||||||
.HasForeignKey(s => s.AlbumId)
|
.HasForeignKey(s => s.AlbumID)
|
||||||
.OnDelete(DeleteBehavior.SetNull);
|
.OnDelete(DeleteBehavior.SetNull);
|
||||||
|
|
||||||
modelBuilder.Entity<Song>()
|
modelBuilder.Entity<Song>()
|
||||||
.HasOne(sa => sa.SongArtist)
|
.HasOne(sa => sa.SongArtist)
|
||||||
.WithMany(ar => ar.Songs)
|
.WithMany(ar => ar.Songs)
|
||||||
.HasForeignKey(s => s.ArtistId)
|
.HasForeignKey(s => s.ArtistID)
|
||||||
.OnDelete(DeleteBehavior.SetNull);
|
.OnDelete(DeleteBehavior.SetNull);
|
||||||
|
|
||||||
modelBuilder.Entity<Song>()
|
modelBuilder.Entity<Song>()
|
||||||
.HasOne(s => s.SongGenre)
|
.HasOne(s => s.SongGenre)
|
||||||
.WithMany(gnr => gnr.Songs)
|
.WithMany(gnr => gnr.Songs)
|
||||||
.HasForeignKey(s => s.GenreId)
|
.HasForeignKey(s => s.GenreID)
|
||||||
.OnDelete(DeleteBehavior.SetNull);
|
.OnDelete(DeleteBehavior.SetNull);
|
||||||
|
|
||||||
modelBuilder.Entity<Song>()
|
modelBuilder.Entity<Song>()
|
||||||
.HasOne(s => s.SongYear)
|
.HasOne(s => s.SongYear)
|
||||||
.WithMany(yr => yr.Songs)
|
.WithMany(yr => yr.Songs)
|
||||||
.HasForeignKey(s => s.YearId)
|
.HasForeignKey(s => s.YearID)
|
||||||
.OnDelete(DeleteBehavior.SetNull);
|
.OnDelete(DeleteBehavior.SetNull);
|
||||||
|
|
||||||
modelBuilder.Entity<Song>()
|
modelBuilder.Entity<Song>()
|
||||||
.HasOne(s => s.SongCoverArt)
|
.HasOne(s => s.SongCoverArt)
|
||||||
.WithMany(ca => ca.Songs)
|
.WithMany(ca => ca.Songs)
|
||||||
.HasForeignKey(s => s.CoverArtId)
|
.HasForeignKey(s => s.CoverArtID)
|
||||||
.OnDelete(DeleteBehavior.SetNull);
|
.OnDelete(DeleteBehavior.SetNull);
|
||||||
|
*/
|
||||||
|
|
||||||
modelBuilder.Entity<Song>()
|
modelBuilder.Entity<Song>()
|
||||||
.Property(s => s.Year)
|
.Property(s => s.Year)
|
||||||
.IsRequired(false);
|
.IsRequired(false);
|
||||||
modelBuilder.Entity<Song>()
|
modelBuilder.Entity<Song>()
|
||||||
.Property(s => s.YearId)
|
.Property(s => s.GenreID)
|
||||||
.IsRequired(false);
|
.IsRequired(false);
|
||||||
modelBuilder.Entity<Song>()
|
modelBuilder.Entity<Song>()
|
||||||
.Property(s => s.GenreId)
|
.Property(s => s.ArtistID)
|
||||||
.IsRequired(false);
|
.IsRequired(false);
|
||||||
modelBuilder.Entity<Song>()
|
modelBuilder.Entity<Song>()
|
||||||
.Property(s => s.ArtistId)
|
.Property(s => s.AlbumID)
|
||||||
.IsRequired(false);
|
.IsRequired(false);
|
||||||
modelBuilder.Entity<Song>()
|
modelBuilder.Entity<Song>()
|
||||||
.Property(s => s.AlbumId)
|
.Property(s => s.CoverArtID)
|
||||||
.IsRequired(false);
|
|
||||||
modelBuilder.Entity<Song>()
|
|
||||||
.Property(s => s.CoverArtId)
|
|
||||||
.IsRequired(false);
|
.IsRequired(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Song RetrieveRecord(Song song)
|
||||||
|
{
|
||||||
|
return Songs.FirstOrDefault(sng => sng.SongID == song.SongID);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public bool DoesRecordExist(Song song)
|
public bool DoesRecordExist(Song song)
|
||||||
{
|
{
|
||||||
return Songs.FirstOrDefault(sng => sng.SongID == song.SongID) != null ? true : false;
|
return Songs.FirstOrDefault(sng => sng.SongID == song.SongID) != null ? true : false;
|
||||||
|
|||||||
@@ -2,10 +2,12 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
|
// using MySql.Data.EntityFrameworkCore;
|
||||||
|
// using MySql.Data;
|
||||||
|
// using MySql.Data.EntityFrameworkCore.Extensions;
|
||||||
|
// using MySql.Data.Entity;
|
||||||
|
// using MySql.Data.MySqlClient;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using MySql.Data;
|
|
||||||
using MySql.Data.EntityFrameworkCore.Extensions;
|
|
||||||
using MySql.Data.MySqlClient;
|
|
||||||
|
|
||||||
using Icarus.Models;
|
using Icarus.Models;
|
||||||
|
|
||||||
@@ -33,6 +35,11 @@ namespace Icarus.Database.Contexts
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public User RetrieveRecord(User user)
|
||||||
|
{
|
||||||
|
return Users.FirstOrDefault(usr => usr.UserID == user.UserID);
|
||||||
|
}
|
||||||
|
|
||||||
public bool DoesRecordExist(User user)
|
public bool DoesRecordExist(User user)
|
||||||
{
|
{
|
||||||
return Users.FirstOrDefault(usr => usr.UserID == user.UserID) != null ? true : false;
|
return Users.FirstOrDefault(usr => usr.UserID == user.UserID) != null ? true : false;
|
||||||
|
|||||||
+9
-11
@@ -6,26 +6,24 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="BCrypt.Net-Next" Version="3.1.3" />
|
<PackageReference Include="BCrypt.Net-Next" Version="4.0.2" />
|
||||||
<PackageReference Include="DotNetZip" Version="1.15.0" />
|
<PackageReference Include="DotNetZip" Version="1.15.0" />
|
||||||
<PackageReference Include="EntityFramework" Version="6.4.4" />
|
<PackageReference Include="EntityFramework" Version="6.4.4" />
|
||||||
<PackageReference Include="ID3" Version="0.6.0" />
|
<PackageReference Include="ID3" Version="0.6.0" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.App" />
|
<PackageReference Include="Microsoft.AspNetCore.App" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="2.2.0" />
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.1" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
|
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.2.3">
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.8" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.8">
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="mysql.data" Version="8.0.15" />
|
<PackageReference Include="MySql.EntityFrameworkCore" Version="5.0.8" />
|
||||||
<PackageReference Include="MySql.Data.Entity" Version="7.0.7-m61" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||||
<PackageReference Include="MySql.Data.EntityFrameworkCore" Version="8.0.15" />
|
<PackageReference Include="NLog.Web.AspNetCore" Version="4.14.0" />
|
||||||
<PackageReference Include="MySql.Data.EntityFrameworkCore.Design" Version="8.0.15" />
|
<PackageReference Include="RestSharp" Version="106.15.0" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
|
|
||||||
<PackageReference Include="NLog.Web.AspNetCore" Version="4.8.1" />
|
|
||||||
<PackageReference Include="RestSharp" Version="106.12.0" />
|
|
||||||
<PackageReference Include="SevenZip" Version="19.0.0" />
|
<PackageReference Include="SevenZip" Version="19.0.0" />
|
||||||
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="5.4.0" />
|
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.15.0" />
|
||||||
<PackageReference Include="taglib" Version="2.1.0" />
|
<PackageReference Include="taglib" Version="2.1.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
+3
-23
@@ -1,34 +1,14 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio 15
|
# Visual Studio Version 16
|
||||||
VisualStudioVersion = 15.0.26124.0
|
VisualStudioVersion = 16.0.30114.105
|
||||||
MinimumVisualStudioVersion = 15.0.26124.0
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Icarus", "Icarus.csproj", "{3BEBAB33-17BF-4183-9664-3D537A684138}"
|
|
||||||
EndProject
|
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
Debug|x64 = Debug|x64
|
|
||||||
Debug|x86 = Debug|x86
|
|
||||||
Release|Any CPU = Release|Any CPU
|
Release|Any CPU = Release|Any CPU
|
||||||
Release|x64 = Release|x64
|
|
||||||
Release|x86 = Release|x86
|
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
|
||||||
{3BEBAB33-17BF-4183-9664-3D537A684138}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{3BEBAB33-17BF-4183-9664-3D537A684138}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{3BEBAB33-17BF-4183-9664-3D537A684138}.Debug|x64.ActiveCfg = Debug|Any CPU
|
|
||||||
{3BEBAB33-17BF-4183-9664-3D537A684138}.Debug|x64.Build.0 = Debug|Any CPU
|
|
||||||
{3BEBAB33-17BF-4183-9664-3D537A684138}.Debug|x86.ActiveCfg = Debug|Any CPU
|
|
||||||
{3BEBAB33-17BF-4183-9664-3D537A684138}.Debug|x86.Build.0 = Debug|Any CPU
|
|
||||||
{3BEBAB33-17BF-4183-9664-3D537A684138}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{3BEBAB33-17BF-4183-9664-3D537A684138}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{3BEBAB33-17BF-4183-9664-3D537A684138}.Release|x64.ActiveCfg = Release|Any CPU
|
|
||||||
{3BEBAB33-17BF-4183-9664-3D537A684138}.Release|x64.Build.0 = Release|Any CPU
|
|
||||||
{3BEBAB33-17BF-4183-9664-3D537A684138}.Release|x86.ActiveCfg = Release|Any CPU
|
|
||||||
{3BEBAB33-17BF-4183-9664-3D537A684138}.Release|x86.Build.0 = Release|Any CPU
|
|
||||||
EndGlobalSection
|
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
|||||||
+3
-2
@@ -8,8 +8,8 @@ namespace Icarus.Models
|
|||||||
{
|
{
|
||||||
public class Album
|
public class Album
|
||||||
{
|
{
|
||||||
[JsonProperty("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")]
|
||||||
@@ -19,6 +19,7 @@ namespace Icarus.Models
|
|||||||
public int SongCount { get; set; }
|
public int SongCount { get; set; }
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
|
[NotMapped]
|
||||||
public List<Song> Songs { get; set; }
|
public List<Song> Songs { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-2
@@ -8,8 +8,8 @@ namespace Icarus.Models
|
|||||||
{
|
{
|
||||||
public class Artist
|
public class Artist
|
||||||
{
|
{
|
||||||
[JsonProperty("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")]
|
||||||
@@ -17,6 +17,7 @@ namespace Icarus.Models
|
|||||||
public int SongCount { get; set; }
|
public int SongCount { get; set; }
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
|
[NotMapped]
|
||||||
public List<Song> Songs { get; set; }
|
public List<Song> Songs { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-2
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
@@ -8,8 +9,8 @@ namespace Icarus.Models
|
|||||||
{
|
{
|
||||||
public class CoverArt
|
public class CoverArt
|
||||||
{
|
{
|
||||||
[JsonProperty("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]
|
||||||
@@ -17,6 +18,7 @@ namespace Icarus.Models
|
|||||||
[JsonProperty("song_id")]
|
[JsonProperty("song_id")]
|
||||||
public int SongId { get; set; }
|
public int SongId { get; set; }
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
|
[NotMapped]
|
||||||
public List<Song> Songs { get; set; }
|
public List<Song> Songs { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-2
@@ -8,8 +8,8 @@ namespace Icarus.Models
|
|||||||
{
|
{
|
||||||
public class Genre
|
public class Genre
|
||||||
{
|
{
|
||||||
[JsonProperty("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")]
|
||||||
@@ -17,6 +17,7 @@ namespace Icarus.Models
|
|||||||
public int SongCount { get; set; }
|
public int SongCount { get; set; }
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
|
[NotMapped]
|
||||||
public List<Song> Songs { get; set; }
|
public List<Song> Songs { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ namespace Icarus.Models
|
|||||||
{
|
{
|
||||||
public class LoginResult : BaseResult
|
public class LoginResult : BaseResult
|
||||||
{
|
{
|
||||||
[JsonProperty("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")]
|
||||||
|
|||||||
+18
-11
@@ -26,29 +26,36 @@ namespace Icarus.Models
|
|||||||
[JsonProperty("song_path")]
|
[JsonProperty("song_path")]
|
||||||
public string SongPath { get; set; }
|
public string SongPath { get; set; }
|
||||||
|
|
||||||
|
// [JsonIgnore]
|
||||||
|
// public Album Album { get; set; }
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public Album Album { get; set; }
|
public int? AlbumID { get; set; }
|
||||||
[JsonIgnore]
|
|
||||||
public int? AlbumId { get; set; }
|
|
||||||
|
|
||||||
|
/**
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public Artist SongArtist { get; set; }
|
public Artist SongArtist { get; set; }
|
||||||
|
*/
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public int? ArtistId { get; set; }
|
public int? ArtistID { get; set; }
|
||||||
|
/**
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public Genre SongGenre { get; set; }
|
public Genre SongGenre { get; set; }
|
||||||
|
*/
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public int? GenreId { get; set; }
|
public int? GenreID { get; set; }
|
||||||
|
|
||||||
[JsonIgnore]
|
// [JsonIgnore]
|
||||||
public Year SongYear { get; set; }
|
// public Year SongYear { get; set; }
|
||||||
[JsonIgnore]
|
// [JsonIgnore]
|
||||||
public int? YearId { get; set; }
|
// public int? YearId { get; set; }
|
||||||
|
|
||||||
|
/**
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public CoverArt SongCoverArt { get; set; }
|
public CoverArt SongCoverArt { get; set; }
|
||||||
|
*/
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public int? CoverArtId { get; set; }
|
public int? CoverArtID { get; set; }
|
||||||
|
[JsonProperty("date_created")]
|
||||||
|
public DateTime DateCreated { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -5,8 +5,8 @@ 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; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,8 @@ namespace Icarus.Models
|
|||||||
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")]
|
||||||
|
public string Status { get; set; }
|
||||||
[JsonProperty("last_login")]
|
[JsonProperty("last_login")]
|
||||||
public DateTime? LastLogin { get; set; }
|
public DateTime? LastLogin { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-5
@@ -15,9 +15,6 @@ using Microsoft.Extensions.DependencyInjection;
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using MySql.Data;
|
|
||||||
using MySql.Data.EntityFrameworkCore.Extensions;
|
|
||||||
using MySql.Data.MySqlClient;
|
|
||||||
using NLog;
|
using NLog;
|
||||||
using NLog.Web;
|
using NLog.Web;
|
||||||
using NLog.Web.AspNetCore;
|
using NLog.Web.AspNetCore;
|
||||||
@@ -135,12 +132,12 @@ namespace Icarus
|
|||||||
services.AddDbContext<ArtistContext>(options => options.UseMySQL(connString));
|
services.AddDbContext<ArtistContext>(options => options.UseMySQL(connString));
|
||||||
services.AddDbContext<UserContext>(options => options.UseMySQL(connString));
|
services.AddDbContext<UserContext>(options => options.UseMySQL(connString));
|
||||||
services.AddDbContext<GenreContext>(options => options.UseMySQL(connString));
|
services.AddDbContext<GenreContext>(options => options.UseMySQL(connString));
|
||||||
services.AddDbContext<YearContext>(options => options.UseMySQL(connString));
|
// services.AddDbContext<YearContext>(options => options.UseMySQL(connString));
|
||||||
services.AddDbContext<CoverArtContext>(options => options.UseMySQL(connString));
|
services.AddDbContext<CoverArtContext>(options => options.UseMySQL(connString));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called by the runtime. Use this method to configure the HTTP request pipeline.
|
// Called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||||
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||||
{
|
{
|
||||||
// NOTE: Dev-related configuration can be done when env.IsDevelopment() evaluated to true
|
// NOTE: Dev-related configuration can be done when env.IsDevelopment() evaluated to true
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user