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:
amazing-username
2019-05-18 02:09:59 -04:00
parent 30abf31877
commit 41398461be
5 changed files with 93 additions and 18 deletions
+26 -1
View File
@@ -11,7 +11,6 @@ using Icarus.Models.Context;
namespace Icarus.Controllers
{
// TODO: Implement Genre API functionality #41
[Route("api/genre")]
[ApiController]
public class GenreController : ControllerBase
@@ -39,8 +38,21 @@ namespace Icarus.Controllers
{
var genres = new List<Genre>();
var genreStore = HttpContext
.RequestServices
.GetService(typeof(GenreStoreContext)) as GenreStoreContext;
genres = genreStore.GetGenres();
if (genres.Count > 0)
{
return Ok(genres);
}
else
{
return NotFound(new List<Genre>());
}
}
[HttpGet("{id}")]
public IActionResult Get(int id)
@@ -50,8 +62,21 @@ namespace Icarus.Controllers
GenreId = id
};
var genreStore = HttpContext
.RequestServices
.GetService(typeof(GenreStoreContext)) as GenreStoreContext;
if (genreStore.DoesGenreExist(genre))
{
genre = genreStore.GetGenre(genre);
return Ok(genre);
}
else
{
return NotFound(new Genre());
}
}
#endregion
}
}
+23 -5
View File
@@ -95,6 +95,29 @@ namespace Icarus.Controllers.Managers
#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)
{
bool successful = false;
@@ -191,11 +214,6 @@ namespace Icarus.Controllers.Managers
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)
{
+13 -5
View File
@@ -42,8 +42,7 @@ namespace Icarus.Controllers
[HttpGet]
// TODO: Remember to uncomment the line below
//[Authorize("read:song_details")]
[Authorize("read:song_details")]
public IActionResult Get()
{
List<Song> songs = new List<Song>();
@@ -67,8 +66,7 @@ namespace Icarus.Controllers
}
[HttpGet("{id}")]
// TODO: Remember to uncomment the line below
//[Authorize("read:song_details")]
[Authorize("read:song_details")]
public IActionResult Get(int id)
{
MusicStoreContext context = HttpContext
@@ -103,7 +101,14 @@ namespace Icarus.Controllers
AlbumStoreContext albumStore = HttpContext
.RequestServices
.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;
Console.WriteLine("Retrieving filepath of song");
@@ -118,6 +123,9 @@ namespace Icarus.Controllers
}
// TODO: Provide functionality for the UpdateSong(...) method
// before removing the below return statement
var songRes = _songMgr.UpdateSong(song, context, albumStore, artistStore, genreStore,
yearStore);
return Ok("song exists");
var oldSongRecord = context.GetSong(id);
+1 -2
View File
@@ -60,8 +60,7 @@ namespace Icarus.Controllers
}
[HttpPost]
// TODO: Remember to uncomment the line below
//[Authorize("upload:songs")]
[Authorize("upload:songs")]
public async Task Post([FromForm(Name = "file")] List<IFormFile> songData)
{
try
+27 -2
View File
@@ -11,7 +11,6 @@ using Icarus.Models.Context;
namespace Icarus.Controller
{
// TODO: Implemnt Year API functionality #42
[Route("api/year")]
[ApiController]
public class YearController : ControllerBase
@@ -39,7 +38,20 @@ namespace Icarus.Controller
{
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}")]
@@ -50,8 +62,21 @@ namespace Icarus.Controller
YearId = id
};
var yearStore = HttpContext
.RequestServices
.GetService(typeof(YearStoreContext)) as YearStoreContext;
if (yearStore.DoesYearExist(year))
{
year = yearStore.GetSongYear(year);
return Ok(year);
}
else
{
return NotFound(new Year());
}
}
#endregion
}
}