diff --git a/Controllers/Managers/AlbumManager.cs b/Controllers/Managers/AlbumManager.cs index 42885e2..039c7ea 100644 --- a/Controllers/Managers/AlbumManager.cs +++ b/Controllers/Managers/AlbumManager.cs @@ -4,7 +4,7 @@ using System.Configuration; using Icarus.Controllers.Utilities; using Icarus.Models; -using Icarus.Models.Context; +using Icarus.Database.Contexts; namespace Icarus.Controllers.Managers { diff --git a/Controllers/Managers/ArtistManager.cs b/Controllers/Managers/ArtistManager.cs index 1cc1805..d370e39 100644 --- a/Controllers/Managers/ArtistManager.cs +++ b/Controllers/Managers/ArtistManager.cs @@ -4,7 +4,7 @@ using System.Configuration; using Icarus.Controllers.Utilities; using Icarus.Models; -using Icarus.Models.Context; +using Icarus.Database.Contexts; namespace Icarus.Controllers.Managers { diff --git a/Controllers/Managers/GenreManager.cs b/Controllers/Managers/GenreManager.cs index 0ac2b22..f73bc6b 100644 --- a/Controllers/Managers/GenreManager.cs +++ b/Controllers/Managers/GenreManager.cs @@ -4,7 +4,7 @@ using System.Configuration; using Icarus.Controllers.Utilities; using Icarus.Models; -using Icarus.Models.Context; +using Icarus.Database.Contexts; namespace Icarus.Controllers.Managers { diff --git a/Controllers/Managers/SongManager.cs b/Controllers/Managers/SongManager.cs index 081bf5c..f5cd3fb 100644 --- a/Controllers/Managers/SongManager.cs +++ b/Controllers/Managers/SongManager.cs @@ -17,7 +17,8 @@ using TagLib; using Icarus.Controllers.Utilities; using Icarus.Models; -using Icarus.Models.Context; +using Icarus.Database.Contexts; +using Icarus.Database.Repositories; namespace Icarus.Controllers.Managers { @@ -94,9 +95,9 @@ namespace Icarus.Controllers.Managers #region Methods - public SongResult UpdateSong(Song song, MusicStoreContext songStore, AlbumStoreContext albumStore, - ArtistStoreContext artistStore, GenreStoreContext genreStore, - YearStoreContext yearStore) + public SongResult UpdateSong(Song song, SongRepository songStore, AlbumRepository albumStore, + ArtistRepository artistStore, GenreRepository genreStore, + YearRepository yearStore) { var result = new SongResult(); @@ -160,9 +161,9 @@ namespace Icarus.Controllers.Managers return successful; } - public void DeleteSong(Song song, MusicStoreContext songStore, - AlbumStoreContext albumStore, ArtistStoreContext artistStore, - GenreStoreContext genreStore, YearStoreContext yearStore) + public void DeleteSong(Song song, SongRepository songStore, + AlbumRepository albumStore, ArtistRepository artistStore, + GenreRepository genreStore, YearRepository yearStore) { try { @@ -303,9 +304,9 @@ namespace Icarus.Controllers.Managers Console.WriteLine($"An error occurred: {exMsg}"); } } - public async Task SaveSongToFileSystem(IFormFile songFile, MusicStoreContext sStoreContext, - AlbumStoreContext alStoreContext, - ArtistStoreContext arStoreContext) + public async Task SaveSongToFileSystem(IFormFile songFile, SongRepository sStoreContext, + AlbumRepository alStoreContext, + ArtistRepository arStoreContext) { try { @@ -339,9 +340,9 @@ namespace Icarus.Controllers.Managers _logger.Error(msg, "An error occurred"); } } - public async Task SaveSongToFileSystem(IFormFile songFile, MusicStoreContext songStore, - AlbumStoreContext albumStore, ArtistStoreContext artistStore, - GenreStoreContext genreStore, YearStoreContext yearStore) + public async Task SaveSongToFileSystem(IFormFile songFile, SongRepository songStore, + AlbumRepository albumStore, ArtistRepository artistStore, + GenreRepository genreStore, YearRepository yearStore) { try { @@ -634,8 +635,8 @@ namespace Icarus.Controllers.Managers _results = new DataTable(); } - private void SaveSongToDatabase(Song song, MusicStoreContext songStore, AlbumStoreContext albumStore, - ArtistStoreContext artistStore) + private void SaveSongToDatabase(Song song, SongRepository songStore, AlbumRepository albumStore, + ArtistRepository artistStore) { _logger.Info("Starting process to save the song to the database"); @@ -649,8 +650,8 @@ namespace Icarus.Controllers.Managers songStore.SaveSong(song); } - private void SaveSongToDatabase(Song song, MusicStoreContext songStore, AlbumStoreContext albumStore, - ArtistStoreContext artistStore, GenreStoreContext genreStore, YearStoreContext yearStore) + private void SaveSongToDatabase(Song song, SongRepository songStore, AlbumRepository albumStore, + ArtistRepository artistStore, GenreRepository genreStore, YearRepository yearStore) { _logger.Info("Starting process to save the song to the database"); @@ -664,7 +665,7 @@ namespace Icarus.Controllers.Managers _logger.Info(info); songStore.SaveSong(song); } - private void SaveAlbumToDatabase(ref Song song, AlbumStoreContext albumStore) + private void SaveAlbumToDatabase(ref Song song, AlbumRepository albumStore) { _logger.Info("Starting process to save the album record of the song to the database"); @@ -691,7 +692,7 @@ namespace Icarus.Controllers.Managers song.AlbumId = album.AlbumId; } - private void SaveArtistToDatabase(ref Song song, ArtistStoreContext artistStore) + private void SaveArtistToDatabase(ref Song song, ArtistRepository artistStore) { _logger.Info("Starting process to save the artist record of the song to the database"); @@ -717,7 +718,7 @@ namespace Icarus.Controllers.Managers song.ArtistId = artist.ArtistId; } - private void SaveGenreToDatabase(ref Song song, GenreStoreContext genreStore) + private void SaveGenreToDatabase(ref Song song, GenreRepository genreStore) { _logger.Info("Starting process to save the genre record of the song to the database"); @@ -748,7 +749,7 @@ namespace Icarus.Controllers.Managers song.GenreId = genre.GenreId; } - private void SaveYearToDatabase(ref Song song, YearStoreContext yearStore) + private void SaveYearToDatabase(ref Song song, YearRepository yearStore) { _logger.Info("Starting process to save the year record of the song to the database"); @@ -812,7 +813,7 @@ namespace Icarus.Controllers.Managers return true; } - private Album UpdateAlbumInDatabase(Song oldSongRecord, Song newSongRecord, AlbumStoreContext albumStore) + private Album UpdateAlbumInDatabase(Song oldSongRecord, Song newSongRecord, AlbumRepository albumStore) { var albumRecord = albumStore.GetAlbum(oldSongRecord, true); var oldAlbumTitle = oldSongRecord.AlbumTitle; @@ -867,7 +868,7 @@ namespace Icarus.Controllers.Managers return existingAlbumRecord; } } - private Artist UpdateArtistInDatabase(Song oldSongRecord, Song newSongRecord, ArtistStoreContext artistStore) + private Artist UpdateArtistInDatabase(Song oldSongRecord, Song newSongRecord, ArtistRepository artistStore) { var oldArtistRecord = artistStore.GetArtist(oldSongRecord, true); var oldArtistName = oldArtistRecord.Name; @@ -912,7 +913,7 @@ namespace Icarus.Controllers.Managers return existingArtistRecord; } } - private Genre UpdateGenreInDatabase(Song oldSongRecord, Song newSongRecord, GenreStoreContext genreStore) + private Genre UpdateGenreInDatabase(Song oldSongRecord, Song newSongRecord, GenreRepository genreStore) { var oldGenreRecord = genreStore.GetGenre(oldSongRecord, true); var oldGenreName = oldGenreRecord.GenreName; @@ -956,7 +957,7 @@ namespace Icarus.Controllers.Managers return genreStore.GetGenre(existingGenreRecord); } } - private Year UpdateYearInDatabase(Song oldSongRecord, Song newSongRecord, YearStoreContext yearStore) + private Year UpdateYearInDatabase(Song oldSongRecord, Song newSongRecord, YearRepository yearStore) { var oldYearRecord = yearStore.GetSongYear(oldSongRecord, true); var oldYearValue = oldYearRecord.YearValue; @@ -1001,7 +1002,7 @@ namespace Icarus.Controllers.Managers return existingYearRecord; } } - private void UpdateSongInDatabase(ref Song oldSongRecord, ref Song newSongRecord, MusicStoreContext songStore, + private void UpdateSongInDatabase(ref Song oldSongRecord, ref Song newSongRecord, SongRepository songStore, ref SongResult result) { var updatedSongRecord = new Song @@ -1111,8 +1112,8 @@ namespace Icarus.Controllers.Managers result.SongTitle = updatedSongRecord.Title; } - private void DeleteSongFromDatabase(Song song, MusicStoreContext songStore, AlbumStoreContext albumStore, - ArtistStoreContext artistStore, GenreStoreContext genreStore, YearStoreContext yearStore) + private void DeleteSongFromDatabase(Song song, SongRepository songStore, AlbumRepository albumStore, + ArtistRepository artistStore, GenreRepository genreStore, YearRepository yearStore) { _logger.Info("Starting process to delete records related to the song from the database"); @@ -1123,7 +1124,7 @@ namespace Icarus.Controllers.Managers songStore.DeleteSong(song); } - private void DeleteAlbumFromDatabase(Song song, AlbumStoreContext albumStore) + private void DeleteAlbumFromDatabase(Song song, AlbumRepository albumStore) { if (!albumStore.DoesAlbumExist(song)) { @@ -1138,7 +1139,7 @@ namespace Icarus.Controllers.Managers albumStore.DeleteAlbum(album); } } - private void DeleteArtistFromDatabase(Song song, ArtistStoreContext artistStore) + private void DeleteArtistFromDatabase(Song song, ArtistRepository artistStore) { if (!artistStore.DoesArtistExist(song)) { @@ -1153,7 +1154,7 @@ namespace Icarus.Controllers.Managers artistStore.DeleteArtist(artist); } } - private void DeleteGenreFromDatabase(Song song, GenreStoreContext genreStore) + private void DeleteGenreFromDatabase(Song song, GenreRepository genreStore) { if (!genreStore.DoesGenreExist(song)) { @@ -1168,7 +1169,7 @@ namespace Icarus.Controllers.Managers genreStore.DeleteGenre(genre); } } - private void DeleteYearFromDatabase(Song song, YearStoreContext yearStore) + private void DeleteYearFromDatabase(Song song, YearRepository yearStore) { if (!yearStore.DoesYearExist(song)) { diff --git a/Controllers/Managers/TokenManager.cs b/Controllers/Managers/TokenManager.cs index 25ff888..46f8b40 100644 --- a/Controllers/Managers/TokenManager.cs +++ b/Controllers/Managers/TokenManager.cs @@ -10,7 +10,7 @@ using Icarus.Models; namespace Icarus.Controllers.Managers { - public class TokenManager + public class TokenManager : BaseManager { #region Fields private IConfiguration _config; @@ -38,20 +38,30 @@ namespace Icarus.Controllers.Managers #region Methods public LoginResult RetrieveLoginResult(User user) { + _logger.Info("Preparing Auth0 API request"); + var client = new RestClient(_url); var request = new RestRequest("oauth/token", Method.POST); var tokenRequest = RetrieveTokenRequest(); + + _logger.Info("Serializing token object into JSON"); var tokenObject = JsonConvert.SerializeObject(tokenRequest); + Console.WriteLine(tokenObject); request.AddParameter("application/json; charset=utf-8", tokenObject, ParameterType.RequestBody); request.RequestFormat = DataFormat.Json; + _logger.Info("Sending request"); IRestResponse response = client.Execute(request); + _logger.Info("Response received"); + _logger.Info("Deserializing response"); var tokenResult = JsonConvert .DeserializeObject(response.Content); + _logger.Info("Response deserialized"); + Console.WriteLine(response.Content); return new LoginResult { @@ -66,6 +76,8 @@ namespace Icarus.Controllers.Managers private TokenRequest RetrieveTokenRequest() { + _logger.Info("Retrieving token object"); + return new TokenRequest { ClientId = _clientId, @@ -77,12 +89,16 @@ namespace Icarus.Controllers.Managers private void InitializeValues() { + _logger.Info("Analyzing Auth0 information"); + _clientId = _config["Auth0:ClientId"]; _clientSecret = _config["Auth0:ClientSecret"]; _audience = _config["Auth0:ApiIdentifier"]; _grantType = "client_credentials"; _url = $"https://{_config["Auth0:Domain"]}"; + PrintCredentials(); + } #region Testing Methods diff --git a/Controllers/Managers/YearManager.cs b/Controllers/Managers/YearManager.cs index 9cf9603..e87ed92 100644 --- a/Controllers/Managers/YearManager.cs +++ b/Controllers/Managers/YearManager.cs @@ -4,7 +4,7 @@ using System.Configuration; using Icarus.Controllers.Utilities; using Icarus.Models; -using Icarus.Models.Context; +using Icarus.Database.Contexts; namespace Icarus.Controllers.Managers { diff --git a/Controllers/AlbumController.cs b/Controllers/v1/AlbumController.cs similarity index 79% rename from Controllers/AlbumController.cs rename to Controllers/v1/AlbumController.cs index 5e57c19..abbecaf 100644 --- a/Controllers/AlbumController.cs +++ b/Controllers/v1/AlbumController.cs @@ -8,11 +8,11 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; using Icarus.Models; -using Icarus.Models.Context; +using Icarus.Database.Repositories; -namespace Icarus.Controllers +namespace Icarus.Controllers.V1 { - [Route("api/album")] + [Route("api/v1/album")] [ApiController] public class AlbumController : ControllerBase { @@ -40,9 +40,9 @@ namespace Icarus.Controllers { List albums = new List(); - AlbumStoreContext albumStoreContext = HttpContext + AlbumRepository albumStoreContext = HttpContext .RequestServices - .GetService(typeof(AlbumStoreContext)) as AlbumStoreContext; + .GetService(typeof(AlbumRepository)) as AlbumRepository; albums = albumStoreContext.GetAlbums(); @@ -65,9 +65,9 @@ namespace Icarus.Controllers AlbumId = id }; - AlbumStoreContext albumStoreContext = HttpContext + AlbumRepository albumStoreContext = HttpContext .RequestServices - .GetService(typeof(AlbumStoreContext)) as AlbumStoreContext; + .GetService(typeof(AlbumRepository)) as AlbumRepository; if (albumStoreContext.DoesAlbumExist(album)) { diff --git a/Controllers/ArtistController.cs b/Controllers/v1/ArtistController.cs similarity index 79% rename from Controllers/ArtistController.cs rename to Controllers/v1/ArtistController.cs index b3fd16e..fc2f52d 100644 --- a/Controllers/ArtistController.cs +++ b/Controllers/v1/ArtistController.cs @@ -9,11 +9,11 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; using Icarus.Models; -using Icarus.Models.Context; +using Icarus.Database.Repositories; -namespace Icarus.Controllers +namespace Icarus.Controllers.V1 { - [Route("api/artist")] + [Route("api/v1/artist")] [ApiController] public class ArtistController : ControllerBase { @@ -39,9 +39,9 @@ namespace Icarus.Controllers [Authorize("read:artists")] public IActionResult Get() { - ArtistStoreContext artistStoreContext = HttpContext + ArtistRepository artistStoreContext = HttpContext .RequestServices - .GetService(typeof(ArtistStoreContext)) as ArtistStoreContext; + .GetService(typeof(ArtistRepository)) as ArtistRepository; var artists = artistStoreContext.GetArtists(); @@ -64,9 +64,9 @@ namespace Icarus.Controllers ArtistId = id }; - ArtistStoreContext artistStoreContext = HttpContext + ArtistRepository artistStoreContext = HttpContext .RequestServices - .GetService(typeof(ArtistStoreContext)) as ArtistStoreContext; + .GetService(typeof(ArtistRepository)) as ArtistRepository; if (artistStoreContext.DoesArtistExist(artist)) { diff --git a/Controllers/GenreController.cs b/Controllers/v1/GenreController.cs similarity index 84% rename from Controllers/GenreController.cs rename to Controllers/v1/GenreController.cs index 731313d..25b604f 100644 --- a/Controllers/GenreController.cs +++ b/Controllers/v1/GenreController.cs @@ -7,11 +7,11 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; using Icarus.Models; -using Icarus.Models.Context; +using Icarus.Database.Repositories; -namespace Icarus.Controllers +namespace Icarus.Controllers.V1 { - [Route("api/genre")] + [Route("api/v1/genre")] [ApiController] public class GenreController : ControllerBase { @@ -40,7 +40,7 @@ namespace Icarus.Controllers var genreStore = HttpContext .RequestServices - .GetService(typeof(GenreStoreContext)) as GenreStoreContext; + .GetService(typeof(GenreRepository)) as GenreRepository; genres = genreStore.GetGenres(); @@ -64,7 +64,7 @@ namespace Icarus.Controllers var genreStore = HttpContext .RequestServices - .GetService(typeof(GenreStoreContext)) as GenreStoreContext; + .GetService(typeof(GenreRepository)) as GenreRepository; if (genreStore.DoesGenreExist(genre)) { diff --git a/Controllers/LoginController.cs b/Controllers/v1/LoginController.cs similarity index 89% rename from Controllers/LoginController.cs rename to Controllers/v1/LoginController.cs index f5e326b..7e31153 100644 --- a/Controllers/LoginController.cs +++ b/Controllers/v1/LoginController.cs @@ -11,11 +11,11 @@ using Microsoft.Extensions.Logging; using Icarus.Controllers.Managers; using Icarus.Controllers.Utilities; using Icarus.Models; -using Icarus.Models.Context; +using Icarus.Database.Repositories; -namespace Icarus.Controllers +namespace Icarus.Controllers.V1 { - [Route("api/login")] + [Route("api/v1/login")] [ApiController] public class LoginController : ControllerBase { @@ -41,9 +41,9 @@ namespace Icarus.Controllers #region HTTP endpoints public IActionResult Post([FromBody] User user) { - UserStoreContext context = HttpContext + UserRepository context = HttpContext .RequestServices - .GetService(typeof(UserStoreContext)) as UserStoreContext; + .GetService(typeof(UserRepository)) as UserRepository; _logger.LogInformation("Starting process of validating credentials"); diff --git a/Controllers/LogoutController.cs b/Controllers/v1/LogoutController.cs similarity index 100% rename from Controllers/LogoutController.cs rename to Controllers/v1/LogoutController.cs diff --git a/Controllers/RegisterController.cs b/Controllers/v1/RegisterController.cs similarity index 86% rename from Controllers/RegisterController.cs rename to Controllers/v1/RegisterController.cs index 0adaebe..fa32738 100644 --- a/Controllers/RegisterController.cs +++ b/Controllers/v1/RegisterController.cs @@ -10,11 +10,11 @@ using Microsoft.Extensions.Configuration; using Icarus.Controllers.Managers; using Icarus.Controllers.Utilities; using Icarus.Models; -using Icarus.Models.Context; +using Icarus.Database.Repositories; -namespace Icarus.Controllers +namespace Icarus.Controllers.V1 { - [Route("api/register")] + [Route("api/v1/register")] [ApiController] public class RegisterController : ControllerBase { @@ -41,9 +41,9 @@ namespace Icarus.Controllers user.Password = pe.HashPassword(user); user.EmailVerified = false; - UserStoreContext context = HttpContext + UserRepository context = HttpContext .RequestServices - .GetService(typeof(UserStoreContext)) as UserStoreContext; + .GetService(typeof(UserRepository)) as UserRepository; context.SaveUser(user); diff --git a/Controllers/SongCompressedDataControllers.cs b/Controllers/v1/SongCompressedDataControllers.cs similarity index 87% rename from Controllers/SongCompressedDataControllers.cs rename to Controllers/v1/SongCompressedDataControllers.cs index a03f4f2..f46b0ac 100644 --- a/Controllers/SongCompressedDataControllers.cs +++ b/Controllers/v1/SongCompressedDataControllers.cs @@ -13,11 +13,11 @@ using Microsoft.Extensions.Configuration; using Icarus.Controllers.Managers; using Icarus.Controllers.Utilities; using Icarus.Models; -using Icarus.Models.Context; +using Icarus.Database.Repositories; -namespace Icarus.Controllers +namespace Icarus.Controllers.V1 { - [Route("api/song/compressed/data")] + [Route("api/v1/song/compressed/data")] [ApiController] public class SongCompressedDataController : ControllerBase { @@ -48,9 +48,9 @@ namespace Icarus.Controllers [Authorize("download:songs")] public async Task Get(int id) { - MusicStoreContext context = HttpContext + SongRepository context = HttpContext .RequestServices - .GetService(typeof(MusicStoreContext)) as MusicStoreContext; + .GetService(typeof(SongRepository)) as SongRepository; SongCompression cmp = new SongCompression(_archiveDir); diff --git a/Controllers/SongController.cs b/Controllers/v1/SongController.cs similarity index 72% rename from Controllers/SongController.cs rename to Controllers/v1/SongController.cs index c544490..e92c154 100644 --- a/Controllers/SongController.cs +++ b/Controllers/v1/SongController.cs @@ -12,11 +12,11 @@ using Microsoft.Extensions.Logging; using Icarus.Controllers.Managers; using Icarus.Controllers.Utilities; using Icarus.Models; -using Icarus.Models.Context; +using Icarus.Database.Repositories; -namespace Icarus.Controllers +namespace Icarus.Controllers.V1 { - [Route("api/song")] + [Route("api/v1/song")] [ApiController] public class SongController : ControllerBase { @@ -49,9 +49,9 @@ namespace Icarus.Controllers Console.WriteLine("Attemtping to retrieve songs"); _logger.LogInformation("Attempting to retrieve songs"); - MusicStoreContext context = HttpContext + SongRepository context = HttpContext .RequestServices - .GetService(typeof(MusicStoreContext)) as MusicStoreContext; + .GetService(typeof(SongRepository)) as SongRepository; songs = context.GetAllSongs(); @@ -69,9 +69,9 @@ namespace Icarus.Controllers [Authorize("read:song_details")] public IActionResult Get(int id) { - MusicStoreContext context = HttpContext + SongRepository context = HttpContext .RequestServices - .GetService(typeof(MusicStoreContext)) as MusicStoreContext; + .GetService(typeof(SongRepository)) as SongRepository; Song song = new Song { Id = id }; song = context.GetSong(song); @@ -92,25 +92,25 @@ namespace Icarus.Controllers [HttpPut("{id}")] public IActionResult Put(int id, [FromBody] Song song) { - MusicStoreContext context = HttpContext + SongRepository context = HttpContext .RequestServices - .GetService(typeof(MusicStoreContext)) as MusicStoreContext; + .GetService(typeof(SongRepository)) as SongRepository; - ArtistStoreContext artistStore = HttpContext + ArtistRepository artistStore = HttpContext .RequestServices - .GetService(typeof(ArtistStoreContext)) as ArtistStoreContext; + .GetService(typeof(ArtistRepository)) as ArtistRepository; - AlbumStoreContext albumStore = HttpContext + AlbumRepository albumStore = HttpContext .RequestServices - .GetService(typeof(AlbumStoreContext)) as AlbumStoreContext; + .GetService(typeof(AlbumRepository)) as AlbumRepository; - GenreStoreContext genreStore = HttpContext + GenreRepository genreStore = HttpContext .RequestServices - .GetService(typeof(GenreStoreContext)) as GenreStoreContext; + .GetService(typeof(GenreRepository)) as GenreRepository; - YearStoreContext yearStore = HttpContext + YearRepository yearStore = HttpContext .RequestServices - .GetService(typeof(YearStoreContext)) as YearStoreContext; + .GetService(typeof(YearRepository)) as YearRepository; song.Id = id; Console.WriteLine("Retrieving filepath of song"); diff --git a/Controllers/SongDataController.cs b/Controllers/v1/SongDataController.cs similarity index 68% rename from Controllers/SongDataController.cs rename to Controllers/v1/SongDataController.cs index 3ab5d7a..cae4129 100644 --- a/Controllers/SongDataController.cs +++ b/Controllers/v1/SongDataController.cs @@ -13,11 +13,11 @@ using Microsoft.Extensions.Logging; using Icarus.Controllers.Managers; using Icarus.Models; -using Icarus.Models.Context; +using Icarus.Database.Repositories; -namespace Icarus.Controllers +namespace Icarus.Controllers.V1 { - [Route("api/song/data")] + [Route("api/v1/song/data")] [ApiController] public class SongDataController : ControllerBase { @@ -49,9 +49,9 @@ namespace Icarus.Controllers [Authorize("download:songs")] public async Task Get(int id) { - MusicStoreContext context = HttpContext + SongRepository context = HttpContext .RequestServices - .GetService(typeof(MusicStoreContext)) as MusicStoreContext; + .GetService(typeof(SongRepository)) as SongRepository; var songMetaData = context.GetSong(id); SongData song = await _songMgr.RetrieveSong(songMetaData); @@ -65,21 +65,21 @@ namespace Icarus.Controllers { try { - MusicStoreContext songStoreContext = HttpContext + SongRepository songRepository = HttpContext .RequestServices - .GetService(typeof(MusicStoreContext)) as MusicStoreContext; - AlbumStoreContext albumStoreContext = HttpContext + .GetService(typeof(SongRepository)) as SongRepository; + AlbumRepository albumStoreContext = HttpContext .RequestServices - .GetService(typeof(AlbumStoreContext)) as AlbumStoreContext; - ArtistStoreContext artistStoreContext = HttpContext + .GetService(typeof(AlbumRepository)) as AlbumRepository; + ArtistRepository artistStoreContext = HttpContext .RequestServices - .GetService(typeof(ArtistStoreContext)) as ArtistStoreContext; - GenreStoreContext genreStore = HttpContext + .GetService(typeof(ArtistRepository)) as ArtistRepository; + GenreRepository genreStore = HttpContext .RequestServices - .GetService(typeof(GenreStoreContext)) as GenreStoreContext; - YearStoreContext yearStore = HttpContext + .GetService(typeof(GenreRepository)) as GenreRepository; + YearRepository yearStore = HttpContext .RequestServices - .GetService(typeof(YearStoreContext)) as YearStoreContext; + .GetService(typeof(YearRepository)) as YearRepository; Console.WriteLine("Uploading song..."); _logger.LogInformation("Uploading song..."); @@ -93,7 +93,7 @@ namespace Icarus.Controllers Console.WriteLine($"Song filename {sng.FileName}"); _logger.LogInformation($"Song filename {sng.FileName}"); - await _songMgr.SaveSongToFileSystem(sng, songStoreContext, + await _songMgr.SaveSongToFileSystem(sng, songRepository, albumStoreContext, artistStoreContext, genreStore, yearStore); } @@ -110,21 +110,21 @@ namespace Icarus.Controllers [Authorize("delete:songs")] public IActionResult Delete(int id) { - MusicStoreContext context = HttpContext + SongRepository context = HttpContext .RequestServices - .GetService(typeof(MusicStoreContext)) as MusicStoreContext; - AlbumStoreContext albumStore = HttpContext + .GetService(typeof(SongRepository)) as SongRepository; + AlbumRepository albumStore = HttpContext .RequestServices - .GetService(typeof(AlbumStoreContext)) as AlbumStoreContext; - ArtistStoreContext artistStore = HttpContext + .GetService(typeof(AlbumRepository)) as AlbumRepository; + ArtistRepository artistStore = HttpContext .RequestServices - .GetService(typeof(ArtistStoreContext)) as ArtistStoreContext; - GenreStoreContext genreStore = HttpContext + .GetService(typeof(ArtistRepository)) as ArtistRepository; + GenreRepository genreStore = HttpContext .RequestServices - .GetService(typeof(GenreStoreContext)) as GenreStoreContext; - YearStoreContext yearStore = HttpContext + .GetService(typeof(GenreRepository)) as GenreRepository; + YearRepository yearStore = HttpContext .RequestServices - .GetService(typeof(YearStoreContext)) as YearStoreContext; + .GetService(typeof(YearRepository)) as YearRepository; var songMetaData = new Song{ Id = id }; Console.WriteLine($"Id {songMetaData.Id}"); diff --git a/Controllers/SongStreamController.cs b/Controllers/v1/SongStreamController.cs similarity index 88% rename from Controllers/SongStreamController.cs rename to Controllers/v1/SongStreamController.cs index a7cfc5d..3c6f0cb 100644 --- a/Controllers/SongStreamController.cs +++ b/Controllers/v1/SongStreamController.cs @@ -12,11 +12,11 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using Icarus.Models; -using Icarus.Models.Context; +using Icarus.Database.Repositories; -namespace Icarus.Controllers +namespace Icarus.Controllers.V1 { - [Route("api/song/stream")] + [Route("api/v1/song/stream")] [ApiController] public class SongStreamController : ControllerBase { @@ -43,7 +43,7 @@ namespace Icarus.Controllers { var songStore= HttpContext .RequestServices - .GetService(typeof(MusicStoreContext)) as MusicStoreContext; + .GetService(typeof(SongRepository)) as SongRepository; var song = songStore.GetSong(new Song { Id = id }); diff --git a/Controllers/YearController.cs b/Controllers/v1/YearController.cs similarity index 85% rename from Controllers/YearController.cs rename to Controllers/v1/YearController.cs index 15bfc84..0592e5f 100644 --- a/Controllers/YearController.cs +++ b/Controllers/v1/YearController.cs @@ -7,11 +7,11 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; using Icarus.Models; -using Icarus.Models.Context; +using Icarus.Database.Repositories; -namespace Icarus.Controller +namespace Icarus.Controller.V1 { - [Route("api/year")] + [Route("api/v1/year")] [ApiController] public class YearController : ControllerBase { @@ -40,7 +40,7 @@ namespace Icarus.Controller var yearStore = HttpContext .RequestServices - .GetService(typeof(YearStoreContext)) as YearStoreContext; + .GetService(typeof(YearRepository)) as YearRepository; yearValues = yearStore.GetSongYears(); @@ -64,7 +64,7 @@ namespace Icarus.Controller var yearStore = HttpContext .RequestServices - .GetService(typeof(YearStoreContext)) as YearStoreContext; + .GetService(typeof(YearRepository)) as YearRepository; if (yearStore.DoesYearExist(year)) { diff --git a/Models/Context/AlbumContext.cs b/Database/Contexts/AlbumContext.cs similarity index 93% rename from Models/Context/AlbumContext.cs rename to Database/Contexts/AlbumContext.cs index 587a114..e367e8b 100644 --- a/Models/Context/AlbumContext.cs +++ b/Database/Contexts/AlbumContext.cs @@ -8,7 +8,7 @@ using MySql.Data.MySqlClient; using Icarus.Models; -namespace Icarus.Models.Context +namespace Icarus.Database.Contexts { public class AlbumContext : DbContext { diff --git a/Models/Context/ArtistContext.cs b/Database/Contexts/ArtistContext.cs similarity index 93% rename from Models/Context/ArtistContext.cs rename to Database/Contexts/ArtistContext.cs index 9664034..0acda95 100644 --- a/Models/Context/ArtistContext.cs +++ b/Database/Contexts/ArtistContext.cs @@ -8,7 +8,7 @@ using MySql.Data.MySqlClient; using Icarus.Models; -namespace Icarus.Models.Context +namespace Icarus.Database.Contexts { public class ArtistContext : DbContext { diff --git a/Models/Context/GenreContext.cs b/Database/Contexts/GenreContext.cs similarity index 93% rename from Models/Context/GenreContext.cs rename to Database/Contexts/GenreContext.cs index 08c8ebe..0393fae 100644 --- a/Models/Context/GenreContext.cs +++ b/Database/Contexts/GenreContext.cs @@ -8,7 +8,7 @@ using MySql.Data.MySqlClient; using Icarus.Models; -namespace Icarus.Models.Context +namespace Icarus.Database.Contexts { public class GenreContext : DbContext { diff --git a/Models/Context/SongContext.cs b/Database/Contexts/SongContext.cs similarity index 97% rename from Models/Context/SongContext.cs rename to Database/Contexts/SongContext.cs index 9572a4e..08c6359 100644 --- a/Models/Context/SongContext.cs +++ b/Database/Contexts/SongContext.cs @@ -8,7 +8,7 @@ using MySql.Data.MySqlClient; using Icarus.Models; -namespace Icarus.Models.Context +namespace Icarus.Database.Contexts { public class SongContext : DbContext { diff --git a/Models/Context/UserContext.cs b/Database/Contexts/UserContext.cs similarity index 95% rename from Models/Context/UserContext.cs rename to Database/Contexts/UserContext.cs index 7f1d821..80e1177 100644 --- a/Models/Context/UserContext.cs +++ b/Database/Contexts/UserContext.cs @@ -8,7 +8,7 @@ using MySql.Data.MySqlClient; using Icarus.Models; -namespace Icarus.Models.Context +namespace Icarus.Database.Contexts { public class UserContext : DbContext { diff --git a/Models/Context/YearContext.cs b/Database/Contexts/YearContext.cs similarity index 93% rename from Models/Context/YearContext.cs rename to Database/Contexts/YearContext.cs index f11114a..134d55e 100644 --- a/Models/Context/YearContext.cs +++ b/Database/Contexts/YearContext.cs @@ -8,7 +8,7 @@ using MySql.Data.MySqlClient; using Icarus.Models; -namespace Icarus.Models.Context +namespace Icarus.Database.Contexts { public class YearContext : DbContext { diff --git a/Models/Context/AlbumStoreContext.cs b/Database/Repositories/AlbumRepository.cs similarity index 98% rename from Models/Context/AlbumStoreContext.cs rename to Database/Repositories/AlbumRepository.cs index 1c482e0..d25c56f 100644 --- a/Models/Context/AlbumStoreContext.cs +++ b/Database/Repositories/AlbumRepository.cs @@ -6,9 +6,9 @@ using MySql.Data.MySqlClient; using Icarus.Models; -namespace Icarus.Models.Context +namespace Icarus.Database.Repositories { - public class AlbumStoreContext : BaseStoreContext + public class AlbumRepository : BaseRepository { #region Fields #endregion @@ -19,7 +19,7 @@ namespace Icarus.Models.Context #region Constructors - public AlbumStoreContext(string connectionString) + public AlbumRepository(string connectionString) { _connectionString = connectionString; } diff --git a/Models/Context/ArtistStoreContext.cs b/Database/Repositories/ArtistRepository.cs similarity index 98% rename from Models/Context/ArtistStoreContext.cs rename to Database/Repositories/ArtistRepository.cs index 844b46e..16f5ecb 100644 --- a/Models/Context/ArtistStoreContext.cs +++ b/Database/Repositories/ArtistRepository.cs @@ -8,9 +8,9 @@ using MySql.Data.MySqlClient; using Icarus.Models; -namespace Icarus.Models.Context +namespace Icarus.Database.Repositories { - public class ArtistStoreContext : BaseStoreContext + public class ArtistRepository : BaseRepository { #region Fields #endregion @@ -21,7 +21,7 @@ namespace Icarus.Models.Context #region Constructors - public ArtistStoreContext(string connectionString) + public ArtistRepository(string connectionString) { _connectionString = connectionString; } diff --git a/Models/Context/BaseStoreContext.cs b/Database/Repositories/BaseRepository.cs similarity index 83% rename from Models/Context/BaseStoreContext.cs rename to Database/Repositories/BaseRepository.cs index 91981ad..aeb6cc5 100644 --- a/Models/Context/BaseStoreContext.cs +++ b/Database/Repositories/BaseRepository.cs @@ -3,9 +3,9 @@ using System; using MySql.Data.MySqlClient; using NLog; -namespace Icarus.Models.Context +namespace Icarus.Database.Repositories { - public class BaseStoreContext + public class BaseRepository { #region Fields protected string _connectionString; diff --git a/Models/Context/GenreStoreContext.cs b/Database/Repositories/GenreRepository.cs similarity index 98% rename from Models/Context/GenreStoreContext.cs rename to Database/Repositories/GenreRepository.cs index ab16097..db47810 100644 --- a/Models/Context/GenreStoreContext.cs +++ b/Database/Repositories/GenreRepository.cs @@ -6,10 +6,9 @@ using MySql.Data.MySqlClient; using Icarus.Models; -namespace Icarus.Models.Context +namespace Icarus.Database.Repositories { - // TODO: Implement Genre store #41 - public class GenreStoreContext : BaseStoreContext + public class GenreRepository : BaseRepository { #region Fields #endregion @@ -20,7 +19,7 @@ namespace Icarus.Models.Context #region Constructors - public GenreStoreContext(string connectionString) + public GenreRepository(string connectionString) { _connectionString = connectionString; } diff --git a/Models/Context/MusicStoreContext.cs b/Database/Repositories/SongRepository.cs similarity index 97% rename from Models/Context/MusicStoreContext.cs rename to Database/Repositories/SongRepository.cs index 58b94ce..74cc0b1 100644 --- a/Models/Context/MusicStoreContext.cs +++ b/Database/Repositories/SongRepository.cs @@ -3,9 +3,11 @@ using System.Collections.Generic; using MySql.Data.MySqlClient; -namespace Icarus.Models.Context +using Icarus.Models; + +namespace Icarus.Database.Repositories { - public class MusicStoreContext : BaseStoreContext + public class SongRepository : BaseRepository { #region Fields #endregion @@ -16,7 +18,7 @@ namespace Icarus.Models.Context #region Constructors - public MusicStoreContext(string connectionString) + public SongRepository(string connectionString) { _connectionString = connectionString; } @@ -101,7 +103,7 @@ namespace Icarus.Models.Context catch (Exception ex) { var msg = ex.Message; - Console.WriteLine("An error occurred in MusicStoreContext:"); + Console.WriteLine("An error occurred in SongRepository:"); Console.WriteLine(msg); _logger.Error(msg, "An error occurred"); } diff --git a/Models/Context/UserStoreContext.cs b/Database/Repositories/UserRepository.cs similarity index 97% rename from Models/Context/UserStoreContext.cs rename to Database/Repositories/UserRepository.cs index eac2a54..937b8f4 100644 --- a/Models/Context/UserStoreContext.cs +++ b/Database/Repositories/UserRepository.cs @@ -6,9 +6,9 @@ using MySql.Data.MySqlClient; using Icarus.Models; -namespace Icarus.Models.Context +namespace Icarus.Database.Repositories { - public class UserStoreContext: BaseStoreContext + public class UserRepository: BaseRepository { #region Fields #endregion @@ -19,7 +19,7 @@ namespace Icarus.Models.Context #region Constructor - public UserStoreContext(string connectionString) + public UserRepository(string connectionString) { _connectionString = connectionString; } diff --git a/Models/Context/YearStoreContext.cs b/Database/Repositories/YearRepository.cs similarity index 97% rename from Models/Context/YearStoreContext.cs rename to Database/Repositories/YearRepository.cs index 000ae32..08f7b60 100644 --- a/Models/Context/YearStoreContext.cs +++ b/Database/Repositories/YearRepository.cs @@ -6,10 +6,9 @@ using MySql.Data.MySqlClient; using Icarus.Models; -namespace Icarus.Models.Context +namespace Icarus.Database.Repositories { - // TODO: Implement Year store #42 - public class YearStoreContext : BaseStoreContext + public class YearRepository : BaseRepository { #region Fields #endregion @@ -20,7 +19,7 @@ namespace Icarus.Models.Context #region Constructors - public YearStoreContext(string connectionString) + public YearRepository(string connectionString) { _connectionString = connectionString; } diff --git a/Models/Song.cs b/Models/Song.cs index 2341d89..69620d5 100644 --- a/Models/Song.cs +++ b/Models/Song.cs @@ -3,8 +3,6 @@ using System.ComponentModel.DataAnnotations.Schema; using Newtonsoft.Json; -using Icarus.Models.Context; - namespace Icarus.Models { public class Song diff --git a/Startup.cs b/Startup.cs index 3f9de84..13a6e57 100644 --- a/Startup.cs +++ b/Startup.cs @@ -24,7 +24,8 @@ using NLog.Web.AspNetCore; using Icarus.Authorization; using Icarus.Authorization.Handlers; -using Icarus.Models.Context; +using Icarus.Database.Contexts; +using Icarus.Database.Repositories; namespace Icarus { @@ -98,28 +99,28 @@ namespace Icarus var connString = Configuration.GetConnectionString("DefaultConnection"); - services.Add(new ServiceDescriptor(typeof(MusicStoreContext), - new MusicStoreContext(Configuration + services.Add(new ServiceDescriptor(typeof(SongRepository), + new SongRepository(Configuration .GetConnectionString("DefaultConnection")))); - services.Add(new ServiceDescriptor(typeof(AlbumStoreContext), - new AlbumStoreContext(Configuration + services.Add(new ServiceDescriptor(typeof(AlbumRepository), + new AlbumRepository(Configuration .GetConnectionString("DefaultConnection")))); - services.Add(new ServiceDescriptor(typeof(ArtistStoreContext), - new ArtistStoreContext(Configuration + services.Add(new ServiceDescriptor(typeof(ArtistRepository), + new ArtistRepository(Configuration .GetConnectionString("DefaultConnection")))); - services.Add(new ServiceDescriptor(typeof(GenreStoreContext), - new GenreStoreContext(Configuration + services.Add(new ServiceDescriptor(typeof(GenreRepository), + new GenreRepository(Configuration .GetConnectionString("DefaultConnection")))); - services.Add(new ServiceDescriptor(typeof(YearStoreContext), - new YearStoreContext(Configuration + services.Add(new ServiceDescriptor(typeof(YearRepository), + new YearRepository(Configuration .GetConnectionString("DefaultConnection")))); - services.Add(new ServiceDescriptor(typeof(UserStoreContext), - new UserStoreContext(Configuration + services.Add(new ServiceDescriptor(typeof(UserRepository), + new UserRepository(Configuration .GetConnectionString("DefaultConnection")))); services.AddDbContext(options => options.UseMySQL(connString));