Added functionality to stream a song. I just need to test it. #7
This commit is contained in:
@@ -112,10 +112,15 @@ namespace Icarus.Controllers.Managers
|
|||||||
|
|
||||||
var updatedAlbum = UpdateAlbumInDatabase(oldSongRecord, updatedSong, albumStore);
|
var updatedAlbum = UpdateAlbumInDatabase(oldSongRecord, updatedSong, albumStore);
|
||||||
oldSongRecord.AlbumId = updatedAlbum.AlbumId;
|
oldSongRecord.AlbumId = updatedAlbum.AlbumId;
|
||||||
|
|
||||||
var updatedArtist = UpdateArtistInDatabase(oldSongRecord, updatedSong, artistStore);
|
var updatedArtist = UpdateArtistInDatabase(oldSongRecord, updatedSong, artistStore);
|
||||||
oldSongRecord.ArtistId = updatedArtist.ArtistId;
|
oldSongRecord.ArtistId = updatedArtist.ArtistId;
|
||||||
|
|
||||||
var updatedGenre = UpdateGenreInDatabase(oldSongRecord, updatedSong, genreStore);
|
var updatedGenre = UpdateGenreInDatabase(oldSongRecord, updatedSong, genreStore);
|
||||||
|
Console.WriteLine($"Old Genre Id {oldSongRecord.GenreId}");
|
||||||
oldSongRecord.GenreId = updatedGenre.GenreId;
|
oldSongRecord.GenreId = updatedGenre.GenreId;
|
||||||
|
Console.WriteLine($"Updated Genre Id {updatedGenre.GenreId}");
|
||||||
|
|
||||||
var updatedYear = UpdateYearInDatabase(oldSongRecord, updatedSong, yearStore);
|
var updatedYear = UpdateYearInDatabase(oldSongRecord, updatedSong, yearStore);
|
||||||
oldSongRecord.YearId = updatedYear.YearId;
|
oldSongRecord.YearId = updatedYear.YearId;
|
||||||
|
|
||||||
@@ -836,13 +841,6 @@ 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 (albumRecord.SongCount <= 1)
|
|
||||||
{
|
|
||||||
_logger.Info("Deleting existing album record that no longer has any songs");
|
|
||||||
|
|
||||||
albumStore.DeleteAlbum(albumRecord);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!albumStore.DoesAlbumExist(newSongRecord))
|
if (!albumStore.DoesAlbumExist(newSongRecord))
|
||||||
{
|
{
|
||||||
_logger.Info("Creating new album record");
|
_logger.Info("Creating new album record");
|
||||||
@@ -854,6 +852,8 @@ namespace Icarus.Controllers.Managers
|
|||||||
};
|
};
|
||||||
|
|
||||||
albumStore.SaveAlbum(newAlbumRecord);
|
albumStore.SaveAlbum(newAlbumRecord);
|
||||||
|
|
||||||
|
return albumStore.GetAlbum(newSongRecord, true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -863,9 +863,9 @@ namespace Icarus.Controllers.Managers
|
|||||||
existingAlbumRecord.AlbumArtist = newAlbumArtist;
|
existingAlbumRecord.AlbumArtist = newAlbumArtist;
|
||||||
|
|
||||||
albumStore.UpdateAlbum(existingAlbumRecord);
|
albumStore.UpdateAlbum(existingAlbumRecord);
|
||||||
}
|
|
||||||
|
|
||||||
return albumStore.GetAlbum(newSongRecord, true);
|
return existingAlbumRecord;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
private Artist UpdateArtistInDatabase(Song oldSongRecord, Song newSongRecord, ArtistStoreContext artistStore)
|
private Artist UpdateArtistInDatabase(Song oldSongRecord, Song newSongRecord, ArtistStoreContext artistStore)
|
||||||
{
|
{
|
||||||
@@ -898,6 +898,8 @@ namespace Icarus.Controllers.Managers
|
|||||||
};
|
};
|
||||||
|
|
||||||
artistStore.SaveArtist(newArtistRecord);
|
artistStore.SaveArtist(newArtistRecord);
|
||||||
|
|
||||||
|
return artistStore.GetArtist(newSongRecord, true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -906,9 +908,9 @@ namespace Icarus.Controllers.Managers
|
|||||||
var existingArtistRecord = artistStore.GetArtist(newSongRecord);
|
var existingArtistRecord = artistStore.GetArtist(newSongRecord);
|
||||||
|
|
||||||
artistStore.UpdateArtist(existingArtistRecord);
|
artistStore.UpdateArtist(existingArtistRecord);
|
||||||
}
|
|
||||||
|
|
||||||
return artistStore.GetArtist(newSongRecord, true);
|
return existingArtistRecord;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
private Genre UpdateGenreInDatabase(Song oldSongRecord, Song newSongRecord, GenreStoreContext genreStore)
|
private Genre UpdateGenreInDatabase(Song oldSongRecord, Song newSongRecord, GenreStoreContext genreStore)
|
||||||
{
|
{
|
||||||
@@ -941,6 +943,8 @@ namespace Icarus.Controllers.Managers
|
|||||||
};
|
};
|
||||||
|
|
||||||
genreStore.SaveGenre(newGenreRecord);
|
genreStore.SaveGenre(newGenreRecord);
|
||||||
|
|
||||||
|
return genreStore.GetGenre(newSongRecord, true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -949,10 +953,8 @@ namespace Icarus.Controllers.Managers
|
|||||||
var existingGenreRecord = genreStore.GetGenre(newSongRecord);
|
var existingGenreRecord = genreStore.GetGenre(newSongRecord);
|
||||||
|
|
||||||
genreStore.UpdateGenre(existingGenreRecord);
|
genreStore.UpdateGenre(existingGenreRecord);
|
||||||
|
return genreStore.GetGenre(existingGenreRecord);
|
||||||
}
|
}
|
||||||
|
|
||||||
return genreStore.GetGenre(newSongRecord, true);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
private Year UpdateYearInDatabase(Song oldSongRecord, Song newSongRecord, YearStoreContext yearStore)
|
private Year UpdateYearInDatabase(Song oldSongRecord, Song newSongRecord, YearStoreContext yearStore)
|
||||||
{
|
{
|
||||||
@@ -985,6 +987,8 @@ namespace Icarus.Controllers.Managers
|
|||||||
};
|
};
|
||||||
|
|
||||||
yearStore.SaveYear(newYearRecord);
|
yearStore.SaveYear(newYearRecord);
|
||||||
|
|
||||||
|
return yearStore.GetSongYear(newSongRecord, true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -993,9 +997,9 @@ namespace Icarus.Controllers.Managers
|
|||||||
var existingYearRecord = yearStore.GetSongYear(newSongRecord);
|
var existingYearRecord = yearStore.GetSongYear(newSongRecord);
|
||||||
|
|
||||||
yearStore.UpdateYear(existingYearRecord);
|
yearStore.UpdateYear(existingYearRecord);
|
||||||
}
|
|
||||||
|
|
||||||
return yearStore.GetSongYear(newSongRecord, true);
|
return existingYearRecord;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
private void UpdateSongInDatabase(ref Song oldSongRecord, ref Song newSongRecord, MusicStoreContext songStore,
|
private void UpdateSongInDatabase(ref Song oldSongRecord, ref Song newSongRecord, MusicStoreContext songStore,
|
||||||
ref SongResult result)
|
ref SongResult result)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@@ -32,5 +33,36 @@ namespace Icarus.Controllers
|
|||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region HTTP endpoints
|
||||||
|
[HttpGet("{id}")]
|
||||||
|
public IActionResult Get(int id)
|
||||||
|
{
|
||||||
|
var songStore= HttpContext
|
||||||
|
.RequestServices
|
||||||
|
.GetService(typeof(MusicStoreContext)) as MusicStoreContext;
|
||||||
|
|
||||||
|
var song = songStore.GetSong(new Song
|
||||||
|
{
|
||||||
|
Id = id
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
var mem = new MemoryStream();
|
||||||
|
|
||||||
|
using (var stream = new FileStream(song.SongPath, FileMode.Open, FileAccess.Read))
|
||||||
|
{
|
||||||
|
stream.CopyToAsync(mem);
|
||||||
|
}
|
||||||
|
|
||||||
|
mem.Position = 0;
|
||||||
|
|
||||||
|
_logger.LogInformation("Starting to stream song...>");
|
||||||
|
Console.WriteLine("Starting to streamsong...");
|
||||||
|
|
||||||
|
return File(mem, "application/octet-stream", Path.GetFileName(song.SongPath));
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -193,7 +193,7 @@ namespace Icarus.Models.Context
|
|||||||
|
|
||||||
if (retrieveCount)
|
if (retrieveCount)
|
||||||
{
|
{
|
||||||
query = "SELECT gnr.*, 0 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";
|
||||||
|
|||||||
Reference in New Issue
Block a user