Finished API functionality for Genre and Year endpoints. #41 and #42. Working on refining the updating song api route that's part of the clean up issue. #37
This commit is contained in:
@@ -11,7 +11,6 @@ using Icarus.Models.Context;
|
|||||||
|
|
||||||
namespace Icarus.Controllers
|
namespace Icarus.Controllers
|
||||||
{
|
{
|
||||||
// TODO: Implement Genre API functionality #41
|
|
||||||
[Route("api/genre")]
|
[Route("api/genre")]
|
||||||
[ApiController]
|
[ApiController]
|
||||||
public class GenreController : ControllerBase
|
public class GenreController : ControllerBase
|
||||||
@@ -39,8 +38,21 @@ namespace Icarus.Controllers
|
|||||||
{
|
{
|
||||||
var genres = new List<Genre>();
|
var genres = new List<Genre>();
|
||||||
|
|
||||||
|
var genreStore = HttpContext
|
||||||
|
.RequestServices
|
||||||
|
.GetService(typeof(GenreStoreContext)) as GenreStoreContext;
|
||||||
|
|
||||||
|
genres = genreStore.GetGenres();
|
||||||
|
|
||||||
|
if (genres.Count > 0)
|
||||||
|
{
|
||||||
return Ok(genres);
|
return Ok(genres);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return NotFound(new List<Genre>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[HttpGet("{id}")]
|
[HttpGet("{id}")]
|
||||||
public IActionResult Get(int id)
|
public IActionResult Get(int id)
|
||||||
@@ -50,8 +62,21 @@ namespace Icarus.Controllers
|
|||||||
GenreId = id
|
GenreId = id
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var genreStore = HttpContext
|
||||||
|
.RequestServices
|
||||||
|
.GetService(typeof(GenreStoreContext)) as GenreStoreContext;
|
||||||
|
|
||||||
|
if (genreStore.DoesGenreExist(genre))
|
||||||
|
{
|
||||||
|
genre = genreStore.GetGenre(genre);
|
||||||
|
|
||||||
return Ok(genre);
|
return Ok(genre);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return NotFound(new Genre());
|
||||||
|
}
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,6 +95,29 @@ namespace Icarus.Controllers.Managers
|
|||||||
|
|
||||||
|
|
||||||
#region Methods
|
#region Methods
|
||||||
|
// TODO: This method should update the Song, Album, and Artist records in the database
|
||||||
|
public SongResult UpdateSong(Song song, MusicStoreContext songStore, AlbumStoreContext albumStore,
|
||||||
|
ArtistStoreContext artistStore, GenreStoreContext genreStore,
|
||||||
|
YearStoreContext yearStore)
|
||||||
|
{
|
||||||
|
var oldSongRecord = songStore.GetSong(song.Id);
|
||||||
|
song.SongPath = oldSongRecord.SongPath;
|
||||||
|
|
||||||
|
MetadataRetriever updateMetadata = new MetadataRetriever();
|
||||||
|
updateMetadata.UpdateMetadata(song, oldSongRecord);
|
||||||
|
|
||||||
|
var updatedSong = updateMetadata.UpdatedSongRecord;
|
||||||
|
|
||||||
|
// TODO: Add the following methods
|
||||||
|
// UpdateAlbumInDatabase(oldSongRecord, newSongRecord, albumStore)
|
||||||
|
// UpdateArtistInDatabase(oldSongRecord, newSongRecord, artistStore
|
||||||
|
// UpdateeGenreInDatabase(oldSongRecord, newSongRecord, genreStore)
|
||||||
|
// UpdateYearInDatabase(oldSongRecord, newSongRecord, yearStore)
|
||||||
|
// UpdateSongInDatabase(oldSongRecord, newSongRecord, songStore)
|
||||||
|
|
||||||
|
return new SongResult();
|
||||||
|
}
|
||||||
|
|
||||||
public bool DeleteSongFromFileSystem(Song songMetaData)
|
public bool DeleteSongFromFileSystem(Song songMetaData)
|
||||||
{
|
{
|
||||||
bool successful = false;
|
bool successful = false;
|
||||||
@@ -191,11 +214,6 @@ namespace Icarus.Controllers.Managers
|
|||||||
Console.WriteLine($"An Error Occurred: {exMsg}");
|
Console.WriteLine($"An Error Occurred: {exMsg}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO: This method should update the Song, Album, and Artist records in the database
|
|
||||||
public void UpdateSong(Song song, MusicStoreContext songStore, AlbumStoreContext albumStore,
|
|
||||||
ArtistStoreContext artistStore)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task SaveSong(SongData songData)
|
public async Task SaveSong(SongData songData)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -42,8 +42,7 @@ namespace Icarus.Controllers
|
|||||||
|
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
// TODO: Remember to uncomment the line below
|
[Authorize("read:song_details")]
|
||||||
//[Authorize("read:song_details")]
|
|
||||||
public IActionResult Get()
|
public IActionResult Get()
|
||||||
{
|
{
|
||||||
List<Song> songs = new List<Song>();
|
List<Song> songs = new List<Song>();
|
||||||
@@ -67,8 +66,7 @@ namespace Icarus.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("{id}")]
|
[HttpGet("{id}")]
|
||||||
// TODO: Remember to uncomment the line below
|
[Authorize("read:song_details")]
|
||||||
//[Authorize("read:song_details")]
|
|
||||||
public IActionResult Get(int id)
|
public IActionResult Get(int id)
|
||||||
{
|
{
|
||||||
MusicStoreContext context = HttpContext
|
MusicStoreContext context = HttpContext
|
||||||
@@ -103,7 +101,14 @@ namespace Icarus.Controllers
|
|||||||
AlbumStoreContext albumStore = HttpContext
|
AlbumStoreContext albumStore = HttpContext
|
||||||
.RequestServices
|
.RequestServices
|
||||||
.GetService(typeof(AlbumStoreContext)) as AlbumStoreContext;
|
.GetService(typeof(AlbumStoreContext)) as AlbumStoreContext;
|
||||||
// TODO: Add the GenreStoreContext and YearStoreContext #41 and #42
|
|
||||||
|
GenreStoreContext genreStore = HttpContext
|
||||||
|
.RequestServices
|
||||||
|
.GetService(typeof(GenreStoreContext)) as GenreStoreContext;
|
||||||
|
|
||||||
|
YearStoreContext yearStore = HttpContext
|
||||||
|
.RequestServices
|
||||||
|
.GetService(typeof(YearStoreContext)) as YearStoreContext;
|
||||||
|
|
||||||
song.Id = id;
|
song.Id = id;
|
||||||
Console.WriteLine("Retrieving filepath of song");
|
Console.WriteLine("Retrieving filepath of song");
|
||||||
@@ -118,6 +123,9 @@ namespace Icarus.Controllers
|
|||||||
}
|
}
|
||||||
// TODO: Provide functionality for the UpdateSong(...) method
|
// TODO: Provide functionality for the UpdateSong(...) method
|
||||||
// before removing the below return statement
|
// before removing the below return statement
|
||||||
|
var songRes = _songMgr.UpdateSong(song, context, albumStore, artistStore, genreStore,
|
||||||
|
yearStore);
|
||||||
|
|
||||||
return Ok("song exists");
|
return Ok("song exists");
|
||||||
|
|
||||||
var oldSongRecord = context.GetSong(id);
|
var oldSongRecord = context.GetSong(id);
|
||||||
|
|||||||
@@ -60,8 +60,7 @@ namespace Icarus.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
// TODO: Remember to uncomment the line below
|
[Authorize("upload:songs")]
|
||||||
//[Authorize("upload:songs")]
|
|
||||||
public async Task Post([FromForm(Name = "file")] List<IFormFile> songData)
|
public async Task Post([FromForm(Name = "file")] List<IFormFile> songData)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ using Icarus.Models.Context;
|
|||||||
|
|
||||||
namespace Icarus.Controller
|
namespace Icarus.Controller
|
||||||
{
|
{
|
||||||
// TODO: Implemnt Year API functionality #42
|
|
||||||
[Route("api/year")]
|
[Route("api/year")]
|
||||||
[ApiController]
|
[ApiController]
|
||||||
public class YearController : ControllerBase
|
public class YearController : ControllerBase
|
||||||
@@ -39,7 +38,20 @@ namespace Icarus.Controller
|
|||||||
{
|
{
|
||||||
var yearValues = new List<Year>();
|
var yearValues = new List<Year>();
|
||||||
|
|
||||||
return Ok();
|
var yearStore = HttpContext
|
||||||
|
.RequestServices
|
||||||
|
.GetService(typeof(YearStoreContext)) as YearStoreContext;
|
||||||
|
|
||||||
|
yearValues = yearStore.GetSongYears();
|
||||||
|
|
||||||
|
if (yearValues.Count > 0)
|
||||||
|
{
|
||||||
|
return Ok(yearValues);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return NotFound(new List<Year>());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("{id}")]
|
[HttpGet("{id}")]
|
||||||
@@ -50,8 +62,21 @@ namespace Icarus.Controller
|
|||||||
YearId = id
|
YearId = id
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var yearStore = HttpContext
|
||||||
|
.RequestServices
|
||||||
|
.GetService(typeof(YearStoreContext)) as YearStoreContext;
|
||||||
|
|
||||||
|
if (yearStore.DoesYearExist(year))
|
||||||
|
{
|
||||||
|
year = yearStore.GetSongYear(year);
|
||||||
|
|
||||||
return Ok(year);
|
return Ok(year);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return NotFound(new Year());
|
||||||
|
}
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user