Code cleanup and conforming to a coding covention
This commit is contained in:
@@ -96,8 +96,7 @@ namespace Icarus.Controllers.Managers
|
|||||||
|
|
||||||
#region Methods
|
#region Methods
|
||||||
public SongResult UpdateSong(Song song, SongRepository songStore, AlbumRepository albumStore,
|
public SongResult UpdateSong(Song song, SongRepository songStore, AlbumRepository albumStore,
|
||||||
ArtistRepository artistStore, GenreRepository genreStore,
|
ArtistRepository artistStore, GenreRepository genreStore, YearRepository yearStore)
|
||||||
YearRepository yearStore)
|
|
||||||
{
|
{
|
||||||
var result = new SongResult();
|
var result = new SongResult();
|
||||||
|
|
||||||
@@ -161,9 +160,8 @@ namespace Icarus.Controllers.Managers
|
|||||||
return successful;
|
return successful;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteSong(Song song, SongRepository songStore,
|
public void DeleteSong(Song song, SongRepository songStore, AlbumRepository albumStore,
|
||||||
AlbumRepository albumStore, ArtistRepository artistStore,
|
ArtistRepository artistStore, GenreRepository genreStore, YearRepository yearStore)
|
||||||
GenreRepository genreStore, YearRepository yearStore)
|
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -283,6 +281,7 @@ namespace Icarus.Controllers.Managers
|
|||||||
DirectoryManager dirMgr = new DirectoryManager(_config, _song);
|
DirectoryManager dirMgr = new DirectoryManager(_config, _song);
|
||||||
dirMgr.CreateDirectory();
|
dirMgr.CreateDirectory();
|
||||||
filePath = dirMgr.SongDirectory;
|
filePath = dirMgr.SongDirectory;
|
||||||
|
|
||||||
if (!song.FileName.EndsWith(".mp3"))
|
if (!song.FileName.EndsWith(".mp3"))
|
||||||
filePath += $"{song.FileName}.mp3";
|
filePath += $"{song.FileName}.mp3";
|
||||||
else
|
else
|
||||||
@@ -305,8 +304,7 @@ namespace Icarus.Controllers.Managers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
public async Task SaveSongToFileSystem(IFormFile songFile, SongRepository sStoreContext,
|
public async Task SaveSongToFileSystem(IFormFile songFile, SongRepository sStoreContext,
|
||||||
AlbumRepository alStoreContext,
|
AlbumRepository alStoreContext, ArtistRepository arStoreContext)
|
||||||
ArtistRepository arStoreContext)
|
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -318,6 +316,7 @@ namespace Icarus.Controllers.Managers
|
|||||||
DirectoryManager dirMgr = new DirectoryManager(_config, song);
|
DirectoryManager dirMgr = new DirectoryManager(_config, song);
|
||||||
dirMgr.CreateDirectory();
|
dirMgr.CreateDirectory();
|
||||||
var filePath = dirMgr.SongDirectory;
|
var filePath = dirMgr.SongDirectory;
|
||||||
|
|
||||||
if (!songFile.FileName.EndsWith(".mp3"))
|
if (!songFile.FileName.EndsWith(".mp3"))
|
||||||
filePath += $"{songFile.FileName}.mp3";
|
filePath += $"{songFile.FileName}.mp3";
|
||||||
else
|
else
|
||||||
@@ -599,9 +598,7 @@ namespace Icarus.Controllers.Managers
|
|||||||
if (!currentTitle.Equals(songUpdates.Title) || !currentArtist.Equals(songUpdates.Artist) ||
|
if (!currentTitle.Equals(songUpdates.Title) || !currentArtist.Equals(songUpdates.Artist) ||
|
||||||
!currentAlbum.Equals(songUpdates.AlbumTitle) ||
|
!currentAlbum.Equals(songUpdates.AlbumTitle) ||
|
||||||
!currentGenre.Equals(songUpdates.Genre) || currentYear != songUpdates.Year)
|
!currentGenre.Equals(songUpdates.Genre) || currentYear != songUpdates.Year)
|
||||||
{
|
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -824,13 +821,9 @@ namespace Icarus.Controllers.Managers
|
|||||||
var info = string.Empty;
|
var info = string.Empty;
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(newAlbumArtist))
|
if (string.IsNullOrEmpty(newAlbumArtist))
|
||||||
{
|
|
||||||
newAlbumArtist = oldAlbumArtist;
|
newAlbumArtist = oldAlbumArtist;
|
||||||
}
|
|
||||||
if (string.IsNullOrEmpty(newAlbumTitle))
|
if (string.IsNullOrEmpty(newAlbumTitle))
|
||||||
{
|
|
||||||
newAlbumTitle = oldAlbumTitle;
|
newAlbumTitle = oldAlbumTitle;
|
||||||
}
|
|
||||||
|
|
||||||
if ((string.IsNullOrEmpty(newAlbumTitle) && string.IsNullOrEmpty(newAlbumArtist) ||
|
if ((string.IsNullOrEmpty(newAlbumTitle) && string.IsNullOrEmpty(newAlbumArtist) ||
|
||||||
oldAlbumTitle.Equals(newAlbumTitle) && oldAlbumArtist.Equals(newAlbumArtist)))
|
oldAlbumTitle.Equals(newAlbumTitle) && oldAlbumArtist.Equals(newAlbumArtist)))
|
||||||
@@ -1032,9 +1025,7 @@ namespace Icarus.Controllers.Managers
|
|||||||
_logger.Info("Changes to song record found");
|
_logger.Info("Changes to song record found");
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(newSongRecord.Title))
|
if (!string.IsNullOrEmpty(newSongRecord.Title))
|
||||||
{
|
|
||||||
updatedSongRecord.Title = newSongRecord.Title;
|
updatedSongRecord.Title = newSongRecord.Title;
|
||||||
}
|
|
||||||
if (!string.IsNullOrEmpty(newSongRecord.AlbumTitle))
|
if (!string.IsNullOrEmpty(newSongRecord.AlbumTitle))
|
||||||
{
|
{
|
||||||
updatedSongRecord.AlbumTitle = newSongRecord.AlbumTitle;
|
updatedSongRecord.AlbumTitle = newSongRecord.AlbumTitle;
|
||||||
@@ -1052,9 +1043,7 @@ namespace Icarus.Controllers.Managers
|
|||||||
Console.WriteLine($"{updatedSongRecord.Genre} {newSongRecord.Genre}");
|
Console.WriteLine($"{updatedSongRecord.Genre} {newSongRecord.Genre}");
|
||||||
}
|
}
|
||||||
if (newSongRecord.Year != null || newSongRecord.Year > 0)
|
if (newSongRecord.Year != null || newSongRecord.Year > 0)
|
||||||
{
|
|
||||||
updatedSongRecord.Year = newSongRecord.Year;
|
updatedSongRecord.Year = newSongRecord.Year;
|
||||||
}
|
|
||||||
|
|
||||||
_logger.Info("Applied changes to song record");
|
_logger.Info("Applied changes to song record");
|
||||||
|
|
||||||
@@ -1090,21 +1079,15 @@ namespace Icarus.Controllers.Managers
|
|||||||
System.IO.File.Delete(oldSongPath);
|
System.IO.File.Delete(oldSongPath);
|
||||||
|
|
||||||
if (System.IO.File.Exists(oldSongPath))
|
if (System.IO.File.Exists(oldSongPath))
|
||||||
{
|
|
||||||
Console.WriteLine("Old path exists when it should not");
|
Console.WriteLine("Old path exists when it should not");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
_logger.Info("Saving song metadata to the database");
|
_logger.Info("Saving song metadata to the database");
|
||||||
|
|
||||||
if (songStore.DoesSongExist(newSongRecord))
|
if (songStore.DoesSongExist(newSongRecord))
|
||||||
{
|
|
||||||
songStore.UpdateSong(updatedSongRecord);
|
songStore.UpdateSong(updatedSongRecord);
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
songStore.SaveSong(updatedSongRecord);
|
songStore.SaveSong(updatedSongRecord);
|
||||||
}
|
|
||||||
|
|
||||||
newSongRecord = updatedSongRecord;
|
newSongRecord = updatedSongRecord;
|
||||||
|
|
||||||
@@ -1135,10 +1118,8 @@ namespace Icarus.Controllers.Managers
|
|||||||
var album = albumStore.GetAlbum(song, true);
|
var album = albumStore.GetAlbum(song, true);
|
||||||
|
|
||||||
if (album.SongCount <= 1)
|
if (album.SongCount <= 1)
|
||||||
{
|
|
||||||
albumStore.DeleteAlbum(album);
|
albumStore.DeleteAlbum(album);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
private void DeleteArtistFromDatabase(Song song, ArtistRepository artistStore)
|
private void DeleteArtistFromDatabase(Song song, ArtistRepository artistStore)
|
||||||
{
|
{
|
||||||
if (!artistStore.DoesArtistExist(song))
|
if (!artistStore.DoesArtistExist(song))
|
||||||
@@ -1150,10 +1131,8 @@ namespace Icarus.Controllers.Managers
|
|||||||
var artist = artistStore.GetArtist(song, true);
|
var artist = artistStore.GetArtist(song, true);
|
||||||
|
|
||||||
if (artist.SongCount <= 1)
|
if (artist.SongCount <= 1)
|
||||||
{
|
|
||||||
artistStore.DeleteArtist(artist);
|
artistStore.DeleteArtist(artist);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
private void DeleteGenreFromDatabase(Song song, GenreRepository genreStore)
|
private void DeleteGenreFromDatabase(Song song, GenreRepository genreStore)
|
||||||
{
|
{
|
||||||
if (!genreStore.DoesGenreExist(song))
|
if (!genreStore.DoesGenreExist(song))
|
||||||
@@ -1165,10 +1144,8 @@ namespace Icarus.Controllers.Managers
|
|||||||
var genre = genreStore.GetGenre(song, true);
|
var genre = genreStore.GetGenre(song, true);
|
||||||
|
|
||||||
if (genre.SongCount <= 1)
|
if (genre.SongCount <= 1)
|
||||||
{
|
|
||||||
genreStore.DeleteGenre(genre);
|
genreStore.DeleteGenre(genre);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
private void DeleteYearFromDatabase(Song song, YearRepository yearStore)
|
private void DeleteYearFromDatabase(Song song, YearRepository yearStore)
|
||||||
{
|
{
|
||||||
if (!yearStore.DoesYearExist(song))
|
if (!yearStore.DoesYearExist(song))
|
||||||
@@ -1180,10 +1157,8 @@ namespace Icarus.Controllers.Managers
|
|||||||
var year = yearStore.GetSongYear(song, true);
|
var year = yearStore.GetSongYear(song, true);
|
||||||
|
|
||||||
if (year.SongCount <= 1)
|
if (year.SongCount <= 1)
|
||||||
{
|
|
||||||
yearStore.DeleteYear(year);
|
yearStore.DeleteYear(year);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private async Task PopulateSongDetails()
|
private async Task PopulateSongDetails()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ namespace Icarus.Controllers.Managers
|
|||||||
|
|
||||||
_logger.Info("Serializing token object into JSON");
|
_logger.Info("Serializing token object into JSON");
|
||||||
var tokenObject = JsonConvert.SerializeObject(tokenRequest);
|
var tokenObject = JsonConvert.SerializeObject(tokenRequest);
|
||||||
Console.WriteLine(tokenObject);
|
|
||||||
request.AddParameter("application/json; charset=utf-8",
|
request.AddParameter("application/json; charset=utf-8",
|
||||||
tokenObject, ParameterType.RequestBody);
|
tokenObject, ParameterType.RequestBody);
|
||||||
|
|
||||||
@@ -61,15 +61,11 @@ namespace Icarus.Controllers.Managers
|
|||||||
var tokenResult = JsonConvert
|
var tokenResult = JsonConvert
|
||||||
.DeserializeObject<Token>(response.Content);
|
.DeserializeObject<Token>(response.Content);
|
||||||
_logger.Info("Response deserialized");
|
_logger.Info("Response deserialized");
|
||||||
Console.WriteLine(response.Content);
|
|
||||||
|
|
||||||
return new LoginResult
|
return new LoginResult
|
||||||
{
|
{
|
||||||
UserId = user.Id,
|
UserId = user.Id, Username = user.Username, Token = tokenResult.AccessToken,
|
||||||
Username = user.Username,
|
TokenType = tokenResult.TokenType, Expiration = tokenResult.Expiration,
|
||||||
Token = tokenResult.AccessToken,
|
|
||||||
TokenType = tokenResult.TokenType,
|
|
||||||
Expiration = tokenResult.Expiration,
|
|
||||||
Message = "Successfully retrieved token"
|
Message = "Successfully retrieved token"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -80,10 +76,8 @@ namespace Icarus.Controllers.Managers
|
|||||||
|
|
||||||
return new TokenRequest
|
return new TokenRequest
|
||||||
{
|
{
|
||||||
ClientId = _clientId,
|
ClientId = _clientId, ClientSecret = _clientSecret,
|
||||||
ClientSecret = _clientSecret,
|
Audience = _audience, GrantType = _grantType
|
||||||
Audience = _audience,
|
|
||||||
GrantType = _grantType
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,7 +92,6 @@ namespace Icarus.Controllers.Managers
|
|||||||
_url = $"https://{_config["Auth0:Domain"]}";
|
_url = $"https://{_config["Auth0:Domain"]}";
|
||||||
|
|
||||||
PrintCredentials();
|
PrintCredentials();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Testing Methods
|
#region Testing Methods
|
||||||
|
|||||||
@@ -161,7 +161,6 @@ namespace Icarus.Controllers.Utilities
|
|||||||
|
|
||||||
|
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
|
||||||
switch (key.ToLower())
|
switch (key.ToLower())
|
||||||
{
|
{
|
||||||
case "title":
|
case "title":
|
||||||
@@ -186,7 +185,6 @@ namespace Icarus.Controllers.Utilities
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fileTag.Save();
|
fileTag.Save();
|
||||||
|
|
||||||
@@ -263,18 +261,14 @@ namespace Icarus.Controllers.Utilities
|
|||||||
songValues["Artists"] = String.IsNullOrEmpty(song.Artist);
|
songValues["Artists"] = String.IsNullOrEmpty(song.Artist);
|
||||||
songValues["Album"] = String.IsNullOrEmpty(song.AlbumTitle);
|
songValues["Album"] = String.IsNullOrEmpty(song.AlbumTitle);
|
||||||
songValues["Genre"] = String.IsNullOrEmpty(song.Genre);
|
songValues["Genre"] = String.IsNullOrEmpty(song.Genre);
|
||||||
|
|
||||||
if (song.Year == null)
|
if (song.Year == null)
|
||||||
{
|
|
||||||
songValues["Year"] = true;
|
songValues["Year"] = true;
|
||||||
}
|
|
||||||
else if (song.Year==0)
|
else if (song.Year==0)
|
||||||
{
|
|
||||||
songValues["Year"] = true;
|
songValues["Year"] = true;
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
songValues["Year"] = false;
|
songValues["Year"] = false;
|
||||||
}
|
|
||||||
Console.WriteLine("Checking for null data completed");
|
Console.WriteLine("Checking for null data completed");
|
||||||
_logger.Info("Checking for null data completed");
|
_logger.Info("Checking for null data completed");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,8 +67,7 @@ namespace Icarus.Controllers.Utilities
|
|||||||
{
|
{
|
||||||
|
|
||||||
string hashed = Convert.ToBase64String(KeyDerivation.Pbkdf2(
|
string hashed = Convert.ToBase64String(KeyDerivation.Pbkdf2(
|
||||||
password: password,
|
password: password, salt: salt,
|
||||||
salt: salt,
|
|
||||||
prf: KeyDerivationPrf.HMACSHA1,
|
prf: KeyDerivationPrf.HMACSHA1,
|
||||||
iterationCount: 10000,
|
iterationCount: 10000,
|
||||||
numBytesRequested: 256/8));
|
numBytesRequested: 256/8));
|
||||||
@@ -81,9 +80,7 @@ namespace Icarus.Controllers.Utilities
|
|||||||
byte[] salt = new byte[128/8];
|
byte[] salt = new byte[128/8];
|
||||||
|
|
||||||
using (var rng = RandomNumberGenerator.Create())
|
using (var rng = RandomNumberGenerator.Create())
|
||||||
{
|
|
||||||
rng.GetBytes(salt);
|
rng.GetBytes(salt);
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return salt;
|
return salt;
|
||||||
|
|||||||
@@ -40,21 +40,16 @@ namespace Icarus.Controllers.V1
|
|||||||
{
|
{
|
||||||
List<Album> albums = new List<Album>();
|
List<Album> albums = new List<Album>();
|
||||||
|
|
||||||
AlbumRepository albumStoreContext = HttpContext
|
AlbumRepository albumStoreContext = HttpContext.RequestServices
|
||||||
.RequestServices
|
|
||||||
.GetService(typeof(AlbumRepository)) as AlbumRepository;
|
.GetService(typeof(AlbumRepository)) as AlbumRepository;
|
||||||
|
|
||||||
albums = albumStoreContext.GetAlbums();
|
albums = albumStoreContext.GetAlbums();
|
||||||
|
|
||||||
if (albums.Count > 0)
|
if (albums.Count > 0)
|
||||||
{
|
|
||||||
return Ok(albums);
|
return Ok(albums);
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
[HttpGet("{id}")]
|
[HttpGet("{id}")]
|
||||||
[Authorize("read:albums")]
|
[Authorize("read:albums")]
|
||||||
@@ -65,8 +60,7 @@ namespace Icarus.Controllers.V1
|
|||||||
AlbumId = id
|
AlbumId = id
|
||||||
};
|
};
|
||||||
|
|
||||||
AlbumRepository albumStoreContext = HttpContext
|
AlbumRepository albumStoreContext = HttpContext.RequestServices
|
||||||
.RequestServices
|
|
||||||
.GetService(typeof(AlbumRepository)) as AlbumRepository;
|
.GetService(typeof(AlbumRepository)) as AlbumRepository;
|
||||||
|
|
||||||
if (albumStoreContext.DoesAlbumExist(album))
|
if (albumStoreContext.DoesAlbumExist(album))
|
||||||
@@ -76,10 +70,8 @@ namespace Icarus.Controllers.V1
|
|||||||
return Ok(album);
|
return Ok(album);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,21 +39,16 @@ namespace Icarus.Controllers.V1
|
|||||||
[Authorize("read:artists")]
|
[Authorize("read:artists")]
|
||||||
public IActionResult Get()
|
public IActionResult Get()
|
||||||
{
|
{
|
||||||
ArtistRepository artistStoreContext = HttpContext
|
ArtistRepository artistStoreContext = HttpContext.RequestServices
|
||||||
.RequestServices
|
|
||||||
.GetService(typeof(ArtistRepository)) as ArtistRepository;
|
.GetService(typeof(ArtistRepository)) as ArtistRepository;
|
||||||
|
|
||||||
var artists = artistStoreContext.GetArtists();
|
var artists = artistStoreContext.GetArtists();
|
||||||
|
|
||||||
if (artists.Count > 0)
|
if (artists.Count > 0)
|
||||||
{
|
|
||||||
return Ok(artists);
|
return Ok(artists);
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
[HttpGet("{id}")]
|
[HttpGet("{id}")]
|
||||||
[Authorize("read:artists")]
|
[Authorize("read:artists")]
|
||||||
@@ -64,22 +59,18 @@ namespace Icarus.Controllers.V1
|
|||||||
ArtistId = id
|
ArtistId = id
|
||||||
};
|
};
|
||||||
|
|
||||||
ArtistRepository artistStoreContext = HttpContext
|
ArtistRepository artistStoreContext = HttpContext.RequestServices
|
||||||
.RequestServices
|
|
||||||
.GetService(typeof(ArtistRepository)) as ArtistRepository;
|
.GetService(typeof(ArtistRepository)) as ArtistRepository;
|
||||||
|
|
||||||
if (artistStoreContext.DoesArtistExist(artist))
|
if (artistStoreContext.DoesArtistExist(artist))
|
||||||
{
|
{
|
||||||
artist = artistStoreContext.GetArtist(artist);
|
artist = artistStoreContext.GetArtist(artist);
|
||||||
|
|
||||||
|
|
||||||
return Ok(artist);
|
return Ok(artist);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,21 +39,16 @@ namespace Icarus.Controllers.V1
|
|||||||
{
|
{
|
||||||
var genres = new List<Genre>();
|
var genres = new List<Genre>();
|
||||||
|
|
||||||
var genreStore = HttpContext
|
var genreStore = HttpContext.RequestServices
|
||||||
.RequestServices
|
|
||||||
.GetService(typeof(GenreRepository)) as GenreRepository;
|
.GetService(typeof(GenreRepository)) as GenreRepository;
|
||||||
|
|
||||||
genres = genreStore.GetGenres();
|
genres = genreStore.GetGenres();
|
||||||
|
|
||||||
if (genres.Count > 0)
|
if (genres.Count > 0)
|
||||||
{
|
|
||||||
return Ok(genres);
|
return Ok(genres);
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
return NotFound(new List<Genre>());
|
return NotFound(new List<Genre>());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
[HttpGet("{id}")]
|
[HttpGet("{id}")]
|
||||||
[Authorize("read:genre")]
|
[Authorize("read:genre")]
|
||||||
@@ -64,8 +59,7 @@ namespace Icarus.Controllers.V1
|
|||||||
GenreId = id
|
GenreId = id
|
||||||
};
|
};
|
||||||
|
|
||||||
var genreStore = HttpContext
|
var genreStore = HttpContext.RequestServices
|
||||||
.RequestServices
|
|
||||||
.GetService(typeof(GenreRepository)) as GenreRepository;
|
.GetService(typeof(GenreRepository)) as GenreRepository;
|
||||||
|
|
||||||
if (genreStore.DoesGenreExist(genre))
|
if (genreStore.DoesGenreExist(genre))
|
||||||
@@ -75,10 +69,8 @@ namespace Icarus.Controllers.V1
|
|||||||
return Ok(genre);
|
return Ok(genre);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
return NotFound(new Genre());
|
return NotFound(new Genre());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,8 +41,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
|
UserRepository context = HttpContext.RequestServices
|
||||||
.RequestServices
|
|
||||||
.GetService(typeof(UserRepository)) as UserRepository;
|
.GetService(typeof(UserRepository)) as UserRepository;
|
||||||
|
|
||||||
_logger.LogInformation("Starting process of validating credentials");
|
_logger.LogInformation("Starting process of validating credentials");
|
||||||
|
|||||||
@@ -41,8 +41,7 @@ namespace Icarus.Controllers.V1
|
|||||||
user.Password = pe.HashPassword(user);
|
user.Password = pe.HashPassword(user);
|
||||||
user.EmailVerified = false;
|
user.EmailVerified = false;
|
||||||
|
|
||||||
UserRepository context = HttpContext
|
UserRepository context = HttpContext.RequestServices
|
||||||
.RequestServices
|
|
||||||
.GetService(typeof(UserRepository)) as UserRepository;
|
.GetService(typeof(UserRepository)) as UserRepository;
|
||||||
|
|
||||||
context.SaveUser(user);
|
context.SaveUser(user);
|
||||||
|
|||||||
@@ -47,8 +47,7 @@ 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
|
SongRepository context = HttpContext.RequestServices
|
||||||
.RequestServices
|
|
||||||
.GetService(typeof(SongRepository)) as SongRepository;
|
.GetService(typeof(SongRepository)) as SongRepository;
|
||||||
|
|
||||||
SongCompression cmp = new SongCompression(_archiveDir);
|
SongCompression cmp = new SongCompression(_archiveDir);
|
||||||
|
|||||||
@@ -49,28 +49,22 @@ 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
|
SongRepository context = HttpContext.RequestServices
|
||||||
.RequestServices
|
|
||||||
.GetService(typeof(SongRepository)) as SongRepository;
|
.GetService(typeof(SongRepository)) as SongRepository;
|
||||||
|
|
||||||
songs = context.GetAllSongs();
|
songs = context.GetAllSongs();
|
||||||
|
|
||||||
if (songs.Count > 0)
|
if (songs.Count > 0)
|
||||||
{
|
|
||||||
return Ok(songs);
|
return Ok(songs);
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
[HttpGet("{id}")]
|
[HttpGet("{id}")]
|
||||||
[Authorize("read:song_details")]
|
[Authorize("read:song_details")]
|
||||||
public IActionResult Get(int id)
|
public IActionResult Get(int id)
|
||||||
{
|
{
|
||||||
SongRepository context = HttpContext
|
SongRepository context = HttpContext.RequestServices
|
||||||
.RequestServices
|
|
||||||
.GetService(typeof(SongRepository)) as SongRepository;
|
.GetService(typeof(SongRepository)) as SongRepository;
|
||||||
|
|
||||||
Song song = new Song { Id = id };
|
Song song = new Song { Id = id };
|
||||||
@@ -79,37 +73,28 @@ namespace Icarus.Controllers.V1
|
|||||||
Console.WriteLine("Here");
|
Console.WriteLine("Here");
|
||||||
|
|
||||||
if (song.Id != 0)
|
if (song.Id != 0)
|
||||||
{
|
|
||||||
return Ok(song);
|
return Ok(song);
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
[Authorize("update:songs")]
|
[Authorize("update:songs")]
|
||||||
[HttpPut("{id}")]
|
[HttpPut("{id}")]
|
||||||
public IActionResult Put(int id, [FromBody] Song song)
|
public IActionResult Put(int id, [FromBody] Song song)
|
||||||
{
|
{
|
||||||
SongRepository context = HttpContext
|
SongRepository context = HttpContext.RequestServices
|
||||||
.RequestServices
|
|
||||||
.GetService(typeof(SongRepository)) as SongRepository;
|
.GetService(typeof(SongRepository)) as SongRepository;
|
||||||
|
|
||||||
ArtistRepository artistStore = HttpContext
|
ArtistRepository artistStore = HttpContext.RequestServices
|
||||||
.RequestServices
|
|
||||||
.GetService(typeof(ArtistRepository)) as ArtistRepository;
|
.GetService(typeof(ArtistRepository)) as ArtistRepository;
|
||||||
|
|
||||||
AlbumRepository albumStore = HttpContext
|
AlbumRepository albumStore = HttpContext.RequestServices
|
||||||
.RequestServices
|
|
||||||
.GetService(typeof(AlbumRepository)) as AlbumRepository;
|
.GetService(typeof(AlbumRepository)) as AlbumRepository;
|
||||||
|
|
||||||
GenreRepository genreStore = HttpContext
|
GenreRepository genreStore = HttpContext.RequestServices
|
||||||
.RequestServices
|
|
||||||
.GetService(typeof(GenreRepository)) as GenreRepository;
|
.GetService(typeof(GenreRepository)) as GenreRepository;
|
||||||
|
|
||||||
YearRepository yearStore = HttpContext
|
YearRepository yearStore = HttpContext.RequestServices
|
||||||
.RequestServices
|
|
||||||
.GetService(typeof(YearRepository)) as YearRepository;
|
.GetService(typeof(YearRepository)) as YearRepository;
|
||||||
|
|
||||||
song.Id = id;
|
song.Id = id;
|
||||||
@@ -117,12 +102,10 @@ namespace Icarus.Controllers.V1
|
|||||||
_logger.LogInformation("Retrieving filepath of song");
|
_logger.LogInformation("Retrieving filepath of song");
|
||||||
|
|
||||||
if (!context.DoesSongExist(song))
|
if (!context.DoesSongExist(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, context, albumStore, artistStore, genreStore,
|
||||||
yearStore);
|
yearStore);
|
||||||
|
|||||||
@@ -49,8 +49,7 @@ 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
|
SongRepository context = HttpContext.RequestServices
|
||||||
.RequestServices
|
|
||||||
.GetService(typeof(SongRepository)) as SongRepository;
|
.GetService(typeof(SongRepository)) as SongRepository;
|
||||||
var songMetaData = context.GetSong(id);
|
var songMetaData = context.GetSong(id);
|
||||||
|
|
||||||
@@ -65,20 +64,19 @@ namespace Icarus.Controllers.V1
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
SongRepository songRepository = HttpContext
|
SongRepository songRepository = HttpContext.RequestServices
|
||||||
.RequestServices
|
|
||||||
.GetService(typeof(SongRepository)) as SongRepository;
|
.GetService(typeof(SongRepository)) as SongRepository;
|
||||||
AlbumRepository albumStoreContext = HttpContext
|
|
||||||
.RequestServices
|
AlbumRepository albumStoreContext = HttpContext.RequestServices
|
||||||
.GetService(typeof(AlbumRepository)) as AlbumRepository;
|
.GetService(typeof(AlbumRepository)) as AlbumRepository;
|
||||||
ArtistRepository artistStoreContext = HttpContext
|
|
||||||
.RequestServices
|
ArtistRepository artistStoreContext = HttpContext.RequestServices
|
||||||
.GetService(typeof(ArtistRepository)) as ArtistRepository;
|
.GetService(typeof(ArtistRepository)) as ArtistRepository;
|
||||||
GenreRepository genreStore = HttpContext
|
|
||||||
.RequestServices
|
GenreRepository genreStore = HttpContext.RequestServices
|
||||||
.GetService(typeof(GenreRepository)) as GenreRepository;
|
.GetService(typeof(GenreRepository)) as GenreRepository;
|
||||||
YearRepository yearStore = HttpContext
|
|
||||||
.RequestServices
|
YearRepository yearStore = HttpContext.RequestServices
|
||||||
.GetService(typeof(YearRepository)) as YearRepository;
|
.GetService(typeof(YearRepository)) as YearRepository;
|
||||||
|
|
||||||
Console.WriteLine("Uploading song...");
|
Console.WriteLine("Uploading song...");
|
||||||
@@ -88,7 +86,6 @@ namespace Icarus.Controllers.V1
|
|||||||
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}");
|
||||||
@@ -98,7 +95,6 @@ namespace Icarus.Controllers.V1
|
|||||||
genreStore, yearStore);
|
genreStore, yearStore);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var msg = ex.Message;
|
var msg = ex.Message;
|
||||||
@@ -110,20 +106,19 @@ namespace Icarus.Controllers.V1
|
|||||||
[Authorize("delete:songs")]
|
[Authorize("delete:songs")]
|
||||||
public IActionResult Delete(int id)
|
public IActionResult Delete(int id)
|
||||||
{
|
{
|
||||||
SongRepository context = HttpContext
|
SongRepository context = HttpContext.RequestServices
|
||||||
.RequestServices
|
|
||||||
.GetService(typeof(SongRepository)) as SongRepository;
|
.GetService(typeof(SongRepository)) as SongRepository;
|
||||||
AlbumRepository albumStore = HttpContext
|
|
||||||
.RequestServices
|
AlbumRepository albumStore = HttpContext.RequestServices
|
||||||
.GetService(typeof(AlbumRepository)) as AlbumRepository;
|
.GetService(typeof(AlbumRepository)) as AlbumRepository;
|
||||||
ArtistRepository artistStore = HttpContext
|
|
||||||
.RequestServices
|
ArtistRepository artistStore = HttpContext.RequestServices
|
||||||
.GetService(typeof(ArtistRepository)) as ArtistRepository;
|
.GetService(typeof(ArtistRepository)) as ArtistRepository;
|
||||||
GenreRepository genreStore = HttpContext
|
|
||||||
.RequestServices
|
GenreRepository genreStore = HttpContext.RequestServices
|
||||||
.GetService(typeof(GenreRepository)) as GenreRepository;
|
.GetService(typeof(GenreRepository)) as GenreRepository;
|
||||||
YearRepository yearStore = HttpContext
|
|
||||||
.RequestServices
|
YearRepository yearStore = HttpContext.RequestServices
|
||||||
.GetService(typeof(YearRepository)) as YearRepository;
|
.GetService(typeof(YearRepository)) as YearRepository;
|
||||||
|
|
||||||
var songMetaData = new Song{ Id = id };
|
var songMetaData = new Song{ Id = id };
|
||||||
|
|||||||
@@ -42,8 +42,7 @@ namespace Icarus.Controllers.V1
|
|||||||
[Authorize("stream:songs")]
|
[Authorize("stream:songs")]
|
||||||
public async Task<IActionResult> Get(int id)
|
public async Task<IActionResult> Get(int id)
|
||||||
{
|
{
|
||||||
var songStore= HttpContext
|
var songStore= HttpContext.RequestServices
|
||||||
.RequestServices
|
|
||||||
.GetService(typeof(SongRepository)) as SongRepository;
|
.GetService(typeof(SongRepository)) as SongRepository;
|
||||||
|
|
||||||
var song = songStore.GetSong(new Song { Id = id });
|
var song = songStore.GetSong(new Song { Id = id });
|
||||||
@@ -51,9 +50,7 @@ namespace Icarus.Controllers.V1
|
|||||||
var mem = new MemoryStream();
|
var mem = new MemoryStream();
|
||||||
|
|
||||||
using (var stream = new FileStream(song.SongPath, FileMode.Open, FileAccess.Read))
|
using (var stream = new FileStream(song.SongPath, FileMode.Open, FileAccess.Read))
|
||||||
{
|
|
||||||
await stream.CopyToAsync(mem);
|
await stream.CopyToAsync(mem);
|
||||||
}
|
|
||||||
|
|
||||||
mem.Position = 0;
|
mem.Position = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -39,21 +39,16 @@ namespace Icarus.Controller.V1
|
|||||||
{
|
{
|
||||||
var yearValues = new List<Year>();
|
var yearValues = new List<Year>();
|
||||||
|
|
||||||
var yearStore = HttpContext
|
var yearStore = HttpContext.RequestServices
|
||||||
.RequestServices
|
|
||||||
.GetService(typeof(YearRepository)) as YearRepository;
|
.GetService(typeof(YearRepository)) as YearRepository;
|
||||||
|
|
||||||
yearValues = yearStore.GetSongYears();
|
yearValues = yearStore.GetSongYears();
|
||||||
|
|
||||||
if (yearValues.Count > 0)
|
if (yearValues.Count > 0)
|
||||||
{
|
|
||||||
return Ok(yearValues);
|
return Ok(yearValues);
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
return NotFound(new List<Year>());
|
return NotFound(new List<Year>());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
[HttpGet("{id}")]
|
[HttpGet("{id}")]
|
||||||
[Authorize("read:year")]
|
[Authorize("read:year")]
|
||||||
@@ -64,8 +59,7 @@ namespace Icarus.Controller.V1
|
|||||||
YearId = id
|
YearId = id
|
||||||
};
|
};
|
||||||
|
|
||||||
var yearStore = HttpContext
|
var yearStore = HttpContext.RequestServices
|
||||||
.RequestServices
|
|
||||||
.GetService(typeof(YearRepository)) as YearRepository;
|
.GetService(typeof(YearRepository)) as YearRepository;
|
||||||
|
|
||||||
if (yearStore.DoesYearExist(year))
|
if (yearStore.DoesYearExist(year))
|
||||||
@@ -75,10 +69,8 @@ namespace Icarus.Controller.V1
|
|||||||
return Ok(year);
|
return Ok(year);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
return NotFound(new Year());
|
return NotFound(new Year());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ namespace Icarus.Database.Repositories
|
|||||||
var albums = new List<Album>();
|
var albums = new List<Album>();
|
||||||
|
|
||||||
if (AnyAlbums())
|
if (AnyAlbums())
|
||||||
{
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (MySqlConnection conn = GetConnection())
|
using (MySqlConnection conn = GetConnection())
|
||||||
@@ -40,20 +39,15 @@ namespace Icarus.Database.Repositories
|
|||||||
conn.Open();
|
conn.Open();
|
||||||
var query = "SELECT * FROM Album";
|
var query = "SELECT * FROM Album";
|
||||||
using (MySqlCommand cmd = new MySqlCommand(query, conn))
|
using (MySqlCommand cmd = new MySqlCommand(query, conn))
|
||||||
{
|
|
||||||
using (var reader = cmd.ExecuteReader())
|
using (var reader = cmd.ExecuteReader())
|
||||||
{
|
|
||||||
albums = ParseData(reader);
|
albums = ParseData(reader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var msg = ex.Message;
|
var msg = ex.Message;
|
||||||
_logger.Error(msg, "An error occurred");
|
_logger.Error(msg, "An error occurred");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return albums;
|
return albums;
|
||||||
}
|
}
|
||||||
@@ -70,14 +64,10 @@ namespace Icarus.Database.Repositories
|
|||||||
"LEFT JOIN Song sng ON alb.AlbumId=sng.AlbumId WHERE " +
|
"LEFT JOIN Song sng ON alb.AlbumId=sng.AlbumId WHERE " +
|
||||||
"alb.AlbumId=sng.AlbumId GROUP BY alb.AlbumId";
|
"alb.AlbumId=sng.AlbumId GROUP BY alb.AlbumId";
|
||||||
using (MySqlCommand cmd = new MySqlCommand(query, conn))
|
using (MySqlCommand cmd = new MySqlCommand(query, conn))
|
||||||
{
|
|
||||||
using (var reader = cmd.ExecuteReader())
|
using (var reader = cmd.ExecuteReader())
|
||||||
{
|
|
||||||
albums = ParseData(reader);
|
albums = ParseData(reader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var msg = ex.Message;
|
var msg = ex.Message;
|
||||||
@@ -103,12 +93,10 @@ namespace Icarus.Database.Repositories
|
|||||||
cmd.Parameters.AddWithValue("@AlbumId", album.AlbumId);
|
cmd.Parameters.AddWithValue("@AlbumId", album.AlbumId);
|
||||||
|
|
||||||
using (var reader = cmd.ExecuteReader())
|
using (var reader = cmd.ExecuteReader())
|
||||||
{
|
|
||||||
album = ParseSingleData(reader);
|
album = ParseSingleData(reader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var msg = ex.Message;
|
var msg = ex.Message;
|
||||||
@@ -135,12 +123,10 @@ namespace Icarus.Database.Repositories
|
|||||||
cmd.Parameters.AddWithValue("@Title", song.AlbumTitle);
|
cmd.Parameters.AddWithValue("@Title", song.AlbumTitle);
|
||||||
|
|
||||||
using (var reader = cmd.ExecuteReader())
|
using (var reader = cmd.ExecuteReader())
|
||||||
{
|
|
||||||
album = ParseSingleData(reader);
|
album = ParseSingleData(reader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var msg = ex.Message;
|
var msg = ex.Message;
|
||||||
@@ -160,28 +146,22 @@ namespace Icarus.Database.Repositories
|
|||||||
conn.Open();
|
conn.Open();
|
||||||
var query = string.Empty;
|
var query = string.Empty;
|
||||||
if (retrieveCount)
|
if (retrieveCount)
|
||||||
{
|
|
||||||
query = "SELECT alb.*, COUNT(*) AS SongCount FROM Album alb " +
|
query = "SELECT alb.*, COUNT(*) AS SongCount FROM Album alb " +
|
||||||
"LEFT JOIN Song sng ON alb.AlbumId=sng.AlbumId WHERE " +
|
"LEFT JOIN Song sng ON alb.AlbumId=sng.AlbumId WHERE " +
|
||||||
"alb.Title=@Title GROUP BY alb.AlbumId LIMIT 1";
|
"alb.Title=@Title GROUP BY alb.AlbumId LIMIT 1";
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
query = "SELECT alb.*, 0 AS SongCount FROM Album alb WHERE " +
|
query = "SELECT alb.*, 0 AS SongCount FROM Album alb WHERE " +
|
||||||
"alb.Title=@Title LIMIT 1";
|
"alb.Title=@Title LIMIT 1";
|
||||||
}
|
|
||||||
|
|
||||||
using (MySqlCommand cmd = new MySqlCommand(query, conn))
|
using (MySqlCommand cmd = new MySqlCommand(query, conn))
|
||||||
{
|
{
|
||||||
cmd.Parameters.AddWithValue("@Title", song.AlbumTitle);
|
cmd.Parameters.AddWithValue("@Title", song.AlbumTitle);
|
||||||
|
|
||||||
using (var reader = cmd.ExecuteReader())
|
using (var reader = cmd.ExecuteReader())
|
||||||
{
|
|
||||||
album = ParseSingleData(reader);
|
album = ParseSingleData(reader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var msg = ex.Message;
|
var msg = ex.Message;
|
||||||
@@ -391,18 +371,12 @@ namespace Icarus.Database.Repositories
|
|||||||
var query = "SELECT * FROM Album";
|
var query = "SELECT * FROM Album";
|
||||||
|
|
||||||
using (var cmd = new MySqlCommand(query, conn))
|
using (var cmd = new MySqlCommand(query, conn))
|
||||||
{
|
|
||||||
using (var reader = cmd.ExecuteReader())
|
using (var reader = cmd.ExecuteReader())
|
||||||
{
|
|
||||||
albums = ParseData(reader);
|
albums = ParseData(reader);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (albums.Count > 0)
|
if (albums.Count > 0)
|
||||||
{
|
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,15 +42,10 @@ namespace Icarus.Database.Repositories
|
|||||||
"GROUP BY art.ArtistId";
|
"GROUP BY art.ArtistId";
|
||||||
|
|
||||||
using (MySqlCommand cmd = new MySqlCommand(query, conn))
|
using (MySqlCommand cmd = new MySqlCommand(query, conn))
|
||||||
{
|
|
||||||
using (var reader = cmd.ExecuteReader())
|
using (var reader = cmd.ExecuteReader())
|
||||||
{
|
|
||||||
|
|
||||||
artists = ParseData(reader);
|
artists = ParseData(reader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var msg = ex.Message;
|
var msg = ex.Message;
|
||||||
@@ -78,12 +73,10 @@ namespace Icarus.Database.Repositories
|
|||||||
cmd.Parameters.AddWithValue("@ArtistId", artist.ArtistId);
|
cmd.Parameters.AddWithValue("@ArtistId", artist.ArtistId);
|
||||||
|
|
||||||
using (var reader = cmd.ExecuteReader())
|
using (var reader = cmd.ExecuteReader())
|
||||||
{
|
|
||||||
artist = ParseSingleData(reader);
|
artist = ParseSingleData(reader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var msg = ex.Message;
|
var msg = ex.Message;
|
||||||
@@ -109,12 +102,10 @@ namespace Icarus.Database.Repositories
|
|||||||
cmd.Parameters.AddWithValue("@Name", song.Artist);
|
cmd.Parameters.AddWithValue("@Name", song.Artist);
|
||||||
|
|
||||||
using (var reader = cmd.ExecuteReader())
|
using (var reader = cmd.ExecuteReader())
|
||||||
{
|
|
||||||
artist = ParseSingleData(reader);
|
artist = ParseSingleData(reader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var msg = ex.Message;
|
var msg = ex.Message;
|
||||||
@@ -137,28 +128,22 @@ namespace Icarus.Database.Repositories
|
|||||||
var query = string.Empty;
|
var query = string.Empty;
|
||||||
|
|
||||||
if (retrieveCount)
|
if (retrieveCount)
|
||||||
{
|
|
||||||
query = "SELECT art.*, COUNT(*) AS SongCount FROM Artist " +
|
query = "SELECT art.*, COUNT(*) AS SongCount FROM Artist " +
|
||||||
"art LEFT JOIN Song sng ON art.ArtistId=sng.ArtistId " +
|
"art LEFT JOIN Song sng ON art.ArtistId=sng.ArtistId " +
|
||||||
"WHERE art.Name=@Name GROUP BY art.ArtistId LIMIT 1";
|
"WHERE art.Name=@Name GROUP BY art.ArtistId LIMIT 1";
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
query = "SELECT art.*, 0 AS SongCount FROM Artist art " +
|
query = "SELECT art.*, 0 AS SongCount FROM Artist art " +
|
||||||
"WHERE art.Name=@Name LIMIT 1";
|
"WHERE art.Name=@Name LIMIT 1";
|
||||||
}
|
|
||||||
|
|
||||||
using (MySqlCommand cmd = new MySqlCommand(query, conn))
|
using (MySqlCommand cmd = new MySqlCommand(query, conn))
|
||||||
{
|
{
|
||||||
cmd.Parameters.AddWithValue("@Name", song.Artist);
|
cmd.Parameters.AddWithValue("@Name", song.Artist);
|
||||||
|
|
||||||
using (var reader = cmd.ExecuteReader())
|
using (var reader = cmd.ExecuteReader())
|
||||||
{
|
|
||||||
artist = ParseSingleData(reader);
|
artist = ParseSingleData(reader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var msg = ex.Message;
|
var msg = ex.Message;
|
||||||
|
|||||||
@@ -45,14 +45,10 @@ namespace Icarus.Database.Repositories
|
|||||||
var query = "SELECT * FROM Genre";
|
var query = "SELECT * FROM Genre";
|
||||||
|
|
||||||
using (var cmd = new MySqlCommand(query, conn))
|
using (var cmd = new MySqlCommand(query, conn))
|
||||||
{
|
|
||||||
using (var reader = cmd.ExecuteReader())
|
using (var reader = cmd.ExecuteReader())
|
||||||
{
|
|
||||||
genres = ParseData(reader);
|
genres = ParseData(reader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var msg = ex.Message;
|
var msg = ex.Message;
|
||||||
@@ -82,14 +78,10 @@ namespace Icarus.Database.Repositories
|
|||||||
"GROUP BY gnr.GenreId";
|
"GROUP BY gnr.GenreId";
|
||||||
|
|
||||||
using (var cmd = new MySqlCommand(query, conn))
|
using (var cmd = new MySqlCommand(query, conn))
|
||||||
{
|
|
||||||
using (var reader = cmd.ExecuteReader())
|
using (var reader = cmd.ExecuteReader())
|
||||||
{
|
|
||||||
genres = ParseData(reader);
|
genres = ParseData(reader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var msg = ex.Message;
|
var msg = ex.Message;
|
||||||
@@ -121,12 +113,10 @@ namespace Icarus.Database.Repositories
|
|||||||
cmd.Parameters.AddWithValue("@GenreId", genre.GenreId);
|
cmd.Parameters.AddWithValue("@GenreId", genre.GenreId);
|
||||||
|
|
||||||
using (var reader = cmd.ExecuteReader())
|
using (var reader = cmd.ExecuteReader())
|
||||||
{
|
|
||||||
genre = ParseSingleData(reader);
|
genre = ParseSingleData(reader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var msg = ex.Message;
|
var msg = ex.Message;
|
||||||
@@ -159,12 +149,10 @@ namespace Icarus.Database.Repositories
|
|||||||
_logger.Info($"Song genre:\n\n\n {song.Genre}");
|
_logger.Info($"Song genre:\n\n\n {song.Genre}");
|
||||||
|
|
||||||
using (var reader = cmd.ExecuteReader())
|
using (var reader = cmd.ExecuteReader())
|
||||||
{
|
|
||||||
genre = ParseSingleData(reader);
|
genre = ParseSingleData(reader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var msg = ex.Message;
|
var msg = ex.Message;
|
||||||
@@ -191,17 +179,13 @@ namespace Icarus.Database.Repositories
|
|||||||
var query = string.Empty;
|
var query = string.Empty;
|
||||||
|
|
||||||
if (retrieveCount)
|
if (retrieveCount)
|
||||||
{
|
|
||||||
query = "SELECT gnr.*, COUNT(*) AS SongCount FROM Genre gnr " +
|
query = "SELECT gnr.*, COUNT(*) AS SongCount FROM Genre gnr " +
|
||||||
"LEFT JOIN Song sng ON gnr.GenreId=sng.GenreId " +
|
"LEFT JOIN Song sng ON gnr.GenreId=sng.GenreId " +
|
||||||
"WHERE gnr.GenreName=@GenreName GROUP BY gnr.GenreId " +
|
"WHERE gnr.GenreName=@GenreName GROUP BY gnr.GenreId " +
|
||||||
"LIMIT 1";
|
"LIMIT 1";
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
query = "SELECT gnr.*, 0 AS SongCount FROM Genre gnr " +
|
query = "SELECT gnr.*, 0 AS SongCount FROM Genre gnr " +
|
||||||
"WHERE gnr.GenreName=@GenreName LIMIT 1";
|
"WHERE gnr.GenreName=@GenreName LIMIT 1";
|
||||||
}
|
|
||||||
|
|
||||||
using (var cmd = new MySqlCommand(query, conn))
|
using (var cmd = new MySqlCommand(query, conn))
|
||||||
{
|
{
|
||||||
@@ -209,12 +193,10 @@ namespace Icarus.Database.Repositories
|
|||||||
_logger.Info($"Song genre:\n\n\n {song.Genre}");
|
_logger.Info($"Song genre:\n\n\n {song.Genre}");
|
||||||
|
|
||||||
using (var reader = cmd.ExecuteReader())
|
using (var reader = cmd.ExecuteReader())
|
||||||
{
|
|
||||||
genre = ParseSingleData(reader);
|
genre = ParseSingleData(reader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var msg = ex.Message;
|
var msg = ex.Message;
|
||||||
@@ -446,14 +428,10 @@ namespace Icarus.Database.Repositories
|
|||||||
var query = "SELECT * FROM Genre";
|
var query = "SELECT * FROM Genre";
|
||||||
|
|
||||||
using (var cmd = new MySqlCommand(query, conn))
|
using (var cmd = new MySqlCommand(query, conn))
|
||||||
{
|
|
||||||
using (var reader = cmd.ExecuteReader())
|
using (var reader = cmd.ExecuteReader())
|
||||||
{
|
|
||||||
return reader.HasRows;
|
return reader.HasRows;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var msg = ex.Message;
|
var msg = ex.Message;
|
||||||
|
|||||||
@@ -175,11 +175,9 @@ namespace Icarus.Database.Repositories
|
|||||||
Console.WriteLine("ffff");
|
Console.WriteLine("ffff");
|
||||||
MySqlCommand cmd = new MySqlCommand(query, conn);
|
MySqlCommand cmd = new MySqlCommand(query, conn);
|
||||||
using (var reader = cmd.ExecuteReader())
|
using (var reader = cmd.ExecuteReader())
|
||||||
{
|
|
||||||
songs = ParseData(reader);
|
songs = ParseData(reader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var exMsg = ex.Message;
|
var exMsg = ex.Message;
|
||||||
@@ -207,12 +205,10 @@ namespace Icarus.Database.Repositories
|
|||||||
cmd.Parameters.AddWithValue("@Id", song.Id);
|
cmd.Parameters.AddWithValue("@Id", song.Id);
|
||||||
|
|
||||||
using (var reader = cmd.ExecuteReader())
|
using (var reader = cmd.ExecuteReader())
|
||||||
{
|
|
||||||
song = ParseSingleData(reader);
|
song = ParseSingleData(reader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var msg = ex.Message;
|
var msg = ex.Message;
|
||||||
@@ -237,10 +233,8 @@ namespace Icarus.Database.Repositories
|
|||||||
cmd.Parameters.AddWithValue("@Id", id);
|
cmd.Parameters.AddWithValue("@Id", id);
|
||||||
|
|
||||||
using (var reader = cmd.ExecuteReader())
|
using (var reader = cmd.ExecuteReader())
|
||||||
{
|
|
||||||
song = ParseSingleData(reader);
|
song = ParseSingleData(reader);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
_logger.Info("Song found");
|
_logger.Info("Song found");
|
||||||
}
|
}
|
||||||
catch(Exception ex)
|
catch(Exception ex)
|
||||||
|
|||||||
@@ -83,11 +83,9 @@ namespace Icarus.Database.Repositories
|
|||||||
cmd.Parameters.AddWithValue("@Username", user.Username);
|
cmd.Parameters.AddWithValue("@Username", user.Username);
|
||||||
|
|
||||||
using (var reader = cmd.ExecuteReader())
|
using (var reader = cmd.ExecuteReader())
|
||||||
{
|
|
||||||
user = ParseSingleData(reader);
|
user = ParseSingleData(reader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
_logger.Info("Successfully retrieved user");
|
_logger.Info("Successfully retrieved user");
|
||||||
|
|
||||||
|
|||||||
@@ -44,14 +44,10 @@ namespace Icarus.Database.Repositories
|
|||||||
"GROUP BY yr.YearId";
|
"GROUP BY yr.YearId";
|
||||||
|
|
||||||
using (var cmd = new MySqlCommand(query, conn))
|
using (var cmd = new MySqlCommand(query, conn))
|
||||||
{
|
|
||||||
using (var reader = cmd.ExecuteReader())
|
using (var reader = cmd.ExecuteReader())
|
||||||
{
|
|
||||||
yearValues = ParseData(reader);
|
yearValues = ParseData(reader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var msg = ex.Message;
|
var msg = ex.Message;
|
||||||
@@ -80,12 +76,10 @@ namespace Icarus.Database.Repositories
|
|||||||
cmd.Parameters.AddWithValue("@YearId", year.YearId);
|
cmd.Parameters.AddWithValue("@YearId", year.YearId);
|
||||||
|
|
||||||
using (var reader = cmd.ExecuteReader())
|
using (var reader = cmd.ExecuteReader())
|
||||||
{
|
|
||||||
year = ParseSingleData(reader);
|
year = ParseSingleData(reader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var msg = ex.Message;
|
var msg = ex.Message;
|
||||||
@@ -114,12 +108,10 @@ namespace Icarus.Database.Repositories
|
|||||||
cmd.Parameters.AddWithValue("@YearValue", song.Year);
|
cmd.Parameters.AddWithValue("@YearValue", song.Year);
|
||||||
|
|
||||||
using (var reader = cmd.ExecuteReader())
|
using (var reader = cmd.ExecuteReader())
|
||||||
{
|
|
||||||
year = ParseSingleData(reader);
|
year = ParseSingleData(reader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var msg = ex.Message;
|
var msg = ex.Message;
|
||||||
@@ -143,28 +135,22 @@ namespace Icarus.Database.Repositories
|
|||||||
var query = string.Empty;
|
var query = string.Empty;
|
||||||
|
|
||||||
if (retrieveCount)
|
if (retrieveCount)
|
||||||
{
|
|
||||||
query = "SELECT yr.*, COUNT(*) AS SongCount FROM Year yr " +
|
query = "SELECT yr.*, COUNT(*) AS SongCount FROM Year yr " +
|
||||||
"LEFT JOIN Song sng ON yr.YearValue=sng.Year WHERE " +
|
"LEFT JOIN Song sng ON yr.YearValue=sng.Year WHERE " +
|
||||||
"yr.YearValue=@YearValue GROUP BY yr.YearId LIMIT 1";
|
"yr.YearValue=@YearValue GROUP BY yr.YearId LIMIT 1";
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
query = "SELECT yr.*, 0 AS SongCount FROM Year yr " +
|
query = "SELECT yr.*, 0 AS SongCount FROM Year yr " +
|
||||||
"WHERE yr.YearValue=@YearValue LIMIT 1";
|
"WHERE yr.YearValue=@YearValue LIMIT 1";
|
||||||
}
|
|
||||||
|
|
||||||
using(var cmd = new MySqlCommand(query, conn))
|
using(var cmd = new MySqlCommand(query, conn))
|
||||||
{
|
{
|
||||||
cmd.Parameters.AddWithValue("@YearValue", song.Year);
|
cmd.Parameters.AddWithValue("@YearValue", song.Year);
|
||||||
|
|
||||||
using (var reader = cmd.ExecuteReader())
|
using (var reader = cmd.ExecuteReader())
|
||||||
{
|
|
||||||
year = ParseSingleData(reader);
|
year = ParseSingleData(reader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var msg = ex.Message;
|
var msg = ex.Message;
|
||||||
|
|||||||
@@ -134,15 +134,11 @@ namespace Icarus
|
|||||||
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
|
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
|
||||||
{
|
{
|
||||||
if (env.IsDevelopment())
|
if (env.IsDevelopment())
|
||||||
{
|
|
||||||
app.UseDeveloperExceptionPage();
|
app.UseDeveloperExceptionPage();
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
// The default HSTS value is 30 days.
|
// The default HSTS value is 30 days.
|
||||||
// You may want to change this for production scenarios
|
// You may want to change this for production scenarios
|
||||||
app.UseHsts();
|
app.UseHsts();
|
||||||
}
|
|
||||||
|
|
||||||
app.UseAuthentication();
|
app.UseAuthentication();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user