From 287719db426584ec5982dbae9ae3741f2a5db4cb Mon Sep 17 00:00:00 2001 From: amazing-username Date: Thu, 9 May 2019 20:40:58 -0400 Subject: [PATCH] Completed Album API functionality #22, #25 --- Controllers/AlbumController.cs | 27 +++++++++++++++++++++------ Models/Context/AlbumStoreContext.cs | 2 +- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/Controllers/AlbumController.cs b/Controllers/AlbumController.cs index 9481c9b..c887945 100644 --- a/Controllers/AlbumController.cs +++ b/Controllers/AlbumController.cs @@ -44,23 +44,38 @@ namespace Icarus.Controllers albums = albumStoreContext.GetAlbums(); - - return Ok(albums); + if (albums.Count > 0) + { + return Ok(albums); + } + else + { + return NotFound(); + } } [HttpGet("{id}")] public IActionResult Get(int id) { - Album album = new Album(); - album.AlbumId = id; + Album album = new Album + { + AlbumId = id + }; AlbumStoreContext albumStoreContext = HttpContext .RequestServices .GetService(typeof(AlbumStoreContext)) as AlbumStoreContext; - album = albumStoreContext.GetAlbum(album); + if (albumStoreContext.DoesAlbumExist(album)) + { + album = albumStoreContext.GetAlbum(album); - return Ok(album); + return Ok(album); + } + else + { + return NotFound(); + } } #endregion } diff --git a/Models/Context/AlbumStoreContext.cs b/Models/Context/AlbumStoreContext.cs index c34a1b8..9a8a47c 100644 --- a/Models/Context/AlbumStoreContext.cs +++ b/Models/Context/AlbumStoreContext.cs @@ -172,7 +172,7 @@ namespace Icarus.Models.Context { album = ParseSingleData(reader); - if (album != null) + if (album.Title != null) { _logger.Info($"Album {album.Title} exists"); return true;