Implemented Artist HTTP endpoint functionality. #21 and #26

This commit is contained in:
amazing-username
2019-05-10 22:21:30 -04:00
parent 0c4a1612b1
commit a3c74b50bc
11 changed files with 224 additions and 102 deletions
+21 -18
View File
@@ -18,6 +18,7 @@ namespace Icarus.Controllers
{
[Route("api/song")]
[ApiController]
// TODO: Secure the HTTP endpoint routes with Auth0 grants. #39
public class SongController : ControllerBase
{
#region Fields
@@ -44,7 +45,7 @@ namespace Icarus.Controllers
[HttpGet]
[Authorize("read:song_details")]
public ActionResult<IEnumerable<Song>> Get()
public IActionResult<IEnumerable<Song>> Get()
{
List<Song> songs = new List<Song>();
Console.WriteLine("Attemtping to retrieve songs");
@@ -56,19 +57,33 @@ namespace Icarus.Controllers
songs = context.GetAllSongs();
return songs;
if (songs.Count > 0)
{
return Ok(songs);
}
else
{
return NotFound();
}
}
[HttpGet("{id}")]
public ActionResult<Song> Get(int id)
public IActionResult<Song> Get(int id)
{
MusicStoreContext context = HttpContext
.RequestServices
.GetService(typeof(MusicStoreContext)) as MusicStoreContext;
Song song = context.GetSong(id);
return song;
if (song.Id != 0)
{
return Ok(song);
}
else
{
return NotFound();
}
}
@@ -99,17 +114,5 @@ namespace Icarus.Controllers
return Ok(songResult);
}
[HttpDelete("{id}")]
public IActionResult Delete(int id)
{
MusicStoreContext context = HttpContext
.RequestServices
.GetService(typeof(MusicStoreContext)) as MusicStoreContext;
context.DeleteSong(id);
return Ok();
}
}
}
}