Added versioning to the API, created namespace for the Reposiorites, Changed the StoreContexts to Repositories, moved the Contexts class to another namespace. #37

This commit is contained in:
amazing-username
2019-05-28 23:36:56 +00:00
parent 9ad620db06
commit 42facee883
32 changed files with 183 additions and 167 deletions
+1 -1
View File
@@ -4,7 +4,7 @@ using System.Configuration;
using Icarus.Controllers.Utilities; using Icarus.Controllers.Utilities;
using Icarus.Models; using Icarus.Models;
using Icarus.Models.Context; using Icarus.Database.Contexts;
namespace Icarus.Controllers.Managers namespace Icarus.Controllers.Managers
{ {
+1 -1
View File
@@ -4,7 +4,7 @@ using System.Configuration;
using Icarus.Controllers.Utilities; using Icarus.Controllers.Utilities;
using Icarus.Models; using Icarus.Models;
using Icarus.Models.Context; using Icarus.Database.Contexts;
namespace Icarus.Controllers.Managers namespace Icarus.Controllers.Managers
{ {
+1 -1
View File
@@ -4,7 +4,7 @@ using System.Configuration;
using Icarus.Controllers.Utilities; using Icarus.Controllers.Utilities;
using Icarus.Models; using Icarus.Models;
using Icarus.Models.Context; using Icarus.Database.Contexts;
namespace Icarus.Controllers.Managers namespace Icarus.Controllers.Managers
{ {
+33 -32
View File
@@ -17,7 +17,8 @@ using TagLib;
using Icarus.Controllers.Utilities; using Icarus.Controllers.Utilities;
using Icarus.Models; using Icarus.Models;
using Icarus.Models.Context; using Icarus.Database.Contexts;
using Icarus.Database.Repositories;
namespace Icarus.Controllers.Managers namespace Icarus.Controllers.Managers
{ {
@@ -94,9 +95,9 @@ namespace Icarus.Controllers.Managers
#region Methods #region Methods
public SongResult UpdateSong(Song song, MusicStoreContext songStore, AlbumStoreContext albumStore, public SongResult UpdateSong(Song song, SongRepository songStore, AlbumRepository albumStore,
ArtistStoreContext artistStore, GenreStoreContext genreStore, ArtistRepository artistStore, GenreRepository genreStore,
YearStoreContext yearStore) YearRepository yearStore)
{ {
var result = new SongResult(); var result = new SongResult();
@@ -160,9 +161,9 @@ namespace Icarus.Controllers.Managers
return successful; return successful;
} }
public void DeleteSong(Song song, MusicStoreContext songStore, public void DeleteSong(Song song, SongRepository songStore,
AlbumStoreContext albumStore, ArtistStoreContext artistStore, AlbumRepository albumStore, ArtistRepository artistStore,
GenreStoreContext genreStore, YearStoreContext yearStore) GenreRepository genreStore, YearRepository yearStore)
{ {
try try
{ {
@@ -303,9 +304,9 @@ namespace Icarus.Controllers.Managers
Console.WriteLine($"An error occurred: {exMsg}"); Console.WriteLine($"An error occurred: {exMsg}");
} }
} }
public async Task SaveSongToFileSystem(IFormFile songFile, MusicStoreContext sStoreContext, public async Task SaveSongToFileSystem(IFormFile songFile, SongRepository sStoreContext,
AlbumStoreContext alStoreContext, AlbumRepository alStoreContext,
ArtistStoreContext arStoreContext) ArtistRepository arStoreContext)
{ {
try try
{ {
@@ -339,9 +340,9 @@ namespace Icarus.Controllers.Managers
_logger.Error(msg, "An error occurred"); _logger.Error(msg, "An error occurred");
} }
} }
public async Task SaveSongToFileSystem(IFormFile songFile, MusicStoreContext songStore, public async Task SaveSongToFileSystem(IFormFile songFile, SongRepository songStore,
AlbumStoreContext albumStore, ArtistStoreContext artistStore, AlbumRepository albumStore, ArtistRepository artistStore,
GenreStoreContext genreStore, YearStoreContext yearStore) GenreRepository genreStore, YearRepository yearStore)
{ {
try try
{ {
@@ -634,8 +635,8 @@ namespace Icarus.Controllers.Managers
_results = new DataTable(); _results = new DataTable();
} }
private void SaveSongToDatabase(Song song, MusicStoreContext songStore, AlbumStoreContext albumStore, private void SaveSongToDatabase(Song song, SongRepository songStore, AlbumRepository albumStore,
ArtistStoreContext artistStore) ArtistRepository artistStore)
{ {
_logger.Info("Starting process to save the song to the database"); _logger.Info("Starting process to save the song to the database");
@@ -649,8 +650,8 @@ namespace Icarus.Controllers.Managers
songStore.SaveSong(song); songStore.SaveSong(song);
} }
private void SaveSongToDatabase(Song song, MusicStoreContext songStore, AlbumStoreContext albumStore, private void SaveSongToDatabase(Song song, SongRepository songStore, AlbumRepository albumStore,
ArtistStoreContext artistStore, GenreStoreContext genreStore, YearStoreContext yearStore) ArtistRepository artistStore, GenreRepository genreStore, YearRepository yearStore)
{ {
_logger.Info("Starting process to save the song to the database"); _logger.Info("Starting process to save the song to the database");
@@ -664,7 +665,7 @@ namespace Icarus.Controllers.Managers
_logger.Info(info); _logger.Info(info);
songStore.SaveSong(song); 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"); _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; 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"); _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; 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"); _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; 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"); _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; 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 albumRecord = albumStore.GetAlbum(oldSongRecord, true);
var oldAlbumTitle = oldSongRecord.AlbumTitle; var oldAlbumTitle = oldSongRecord.AlbumTitle;
@@ -867,7 +868,7 @@ namespace Icarus.Controllers.Managers
return existingAlbumRecord; 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 oldArtistRecord = artistStore.GetArtist(oldSongRecord, true);
var oldArtistName = oldArtistRecord.Name; var oldArtistName = oldArtistRecord.Name;
@@ -912,7 +913,7 @@ namespace Icarus.Controllers.Managers
return existingArtistRecord; 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 oldGenreRecord = genreStore.GetGenre(oldSongRecord, true);
var oldGenreName = oldGenreRecord.GenreName; var oldGenreName = oldGenreRecord.GenreName;
@@ -956,7 +957,7 @@ namespace Icarus.Controllers.Managers
return genreStore.GetGenre(existingGenreRecord); 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 oldYearRecord = yearStore.GetSongYear(oldSongRecord, true);
var oldYearValue = oldYearRecord.YearValue; var oldYearValue = oldYearRecord.YearValue;
@@ -1001,7 +1002,7 @@ namespace Icarus.Controllers.Managers
return existingYearRecord; 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) ref SongResult result)
{ {
var updatedSongRecord = new Song var updatedSongRecord = new Song
@@ -1111,8 +1112,8 @@ namespace Icarus.Controllers.Managers
result.SongTitle = updatedSongRecord.Title; result.SongTitle = updatedSongRecord.Title;
} }
private void DeleteSongFromDatabase(Song song, MusicStoreContext songStore, AlbumStoreContext albumStore, private void DeleteSongFromDatabase(Song song, SongRepository songStore, AlbumRepository albumStore,
ArtistStoreContext artistStore, GenreStoreContext genreStore, YearStoreContext yearStore) ArtistRepository artistStore, GenreRepository genreStore, YearRepository yearStore)
{ {
_logger.Info("Starting process to delete records related to the song from the database"); _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); songStore.DeleteSong(song);
} }
private void DeleteAlbumFromDatabase(Song song, AlbumStoreContext albumStore) private void DeleteAlbumFromDatabase(Song song, AlbumRepository albumStore)
{ {
if (!albumStore.DoesAlbumExist(song)) if (!albumStore.DoesAlbumExist(song))
{ {
@@ -1138,7 +1139,7 @@ namespace Icarus.Controllers.Managers
albumStore.DeleteAlbum(album); albumStore.DeleteAlbum(album);
} }
} }
private void DeleteArtistFromDatabase(Song song, ArtistStoreContext artistStore) private void DeleteArtistFromDatabase(Song song, ArtistRepository artistStore)
{ {
if (!artistStore.DoesArtistExist(song)) if (!artistStore.DoesArtistExist(song))
{ {
@@ -1153,7 +1154,7 @@ namespace Icarus.Controllers.Managers
artistStore.DeleteArtist(artist); artistStore.DeleteArtist(artist);
} }
} }
private void DeleteGenreFromDatabase(Song song, GenreStoreContext genreStore) private void DeleteGenreFromDatabase(Song song, GenreRepository genreStore)
{ {
if (!genreStore.DoesGenreExist(song)) if (!genreStore.DoesGenreExist(song))
{ {
@@ -1168,7 +1169,7 @@ namespace Icarus.Controllers.Managers
genreStore.DeleteGenre(genre); genreStore.DeleteGenre(genre);
} }
} }
private void DeleteYearFromDatabase(Song song, YearStoreContext yearStore) private void DeleteYearFromDatabase(Song song, YearRepository yearStore)
{ {
if (!yearStore.DoesYearExist(song)) if (!yearStore.DoesYearExist(song))
{ {
+17 -1
View File
@@ -10,7 +10,7 @@ using Icarus.Models;
namespace Icarus.Controllers.Managers namespace Icarus.Controllers.Managers
{ {
public class TokenManager public class TokenManager : BaseManager
{ {
#region Fields #region Fields
private IConfiguration _config; private IConfiguration _config;
@@ -38,20 +38,30 @@ namespace Icarus.Controllers.Managers
#region Methods #region Methods
public LoginResult RetrieveLoginResult(User user) public LoginResult RetrieveLoginResult(User user)
{ {
_logger.Info("Preparing Auth0 API request");
var client = new RestClient(_url); var client = new RestClient(_url);
var request = new RestRequest("oauth/token", Method.POST); var request = new RestRequest("oauth/token", Method.POST);
var tokenRequest = RetrieveTokenRequest(); var tokenRequest = RetrieveTokenRequest();
_logger.Info("Serializing token object into JSON");
var tokenObject = JsonConvert.SerializeObject(tokenRequest); var tokenObject = JsonConvert.SerializeObject(tokenRequest);
Console.WriteLine(tokenObject);
request.AddParameter("application/json; charset=utf-8", request.AddParameter("application/json; charset=utf-8",
tokenObject, ParameterType.RequestBody); tokenObject, ParameterType.RequestBody);
request.RequestFormat = DataFormat.Json; request.RequestFormat = DataFormat.Json;
_logger.Info("Sending request");
IRestResponse response = client.Execute(request); IRestResponse response = client.Execute(request);
_logger.Info("Response received");
_logger.Info("Deserializing response");
var tokenResult = JsonConvert var tokenResult = JsonConvert
.DeserializeObject<Token>(response.Content); .DeserializeObject<Token>(response.Content);
_logger.Info("Response deserialized");
Console.WriteLine(response.Content);
return new LoginResult return new LoginResult
{ {
@@ -66,6 +76,8 @@ namespace Icarus.Controllers.Managers
private TokenRequest RetrieveTokenRequest() private TokenRequest RetrieveTokenRequest()
{ {
_logger.Info("Retrieving token object");
return new TokenRequest return new TokenRequest
{ {
ClientId = _clientId, ClientId = _clientId,
@@ -77,12 +89,16 @@ namespace Icarus.Controllers.Managers
private void InitializeValues() private void InitializeValues()
{ {
_logger.Info("Analyzing Auth0 information");
_clientId = _config["Auth0:ClientId"]; _clientId = _config["Auth0:ClientId"];
_clientSecret = _config["Auth0:ClientSecret"]; _clientSecret = _config["Auth0:ClientSecret"];
_audience = _config["Auth0:ApiIdentifier"]; _audience = _config["Auth0:ApiIdentifier"];
_grantType = "client_credentials"; _grantType = "client_credentials";
_url = $"https://{_config["Auth0:Domain"]}"; _url = $"https://{_config["Auth0:Domain"]}";
PrintCredentials();
} }
#region Testing Methods #region Testing Methods
+1 -1
View File
@@ -4,7 +4,7 @@ using System.Configuration;
using Icarus.Controllers.Utilities; using Icarus.Controllers.Utilities;
using Icarus.Models; using Icarus.Models;
using Icarus.Models.Context; using Icarus.Database.Contexts;
namespace Icarus.Controllers.Managers namespace Icarus.Controllers.Managers
{ {
@@ -8,11 +8,11 @@ using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Icarus.Models; 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] [ApiController]
public class AlbumController : ControllerBase public class AlbumController : ControllerBase
{ {
@@ -40,9 +40,9 @@ namespace Icarus.Controllers
{ {
List<Album> albums = new List<Album>(); List<Album> albums = new List<Album>();
AlbumStoreContext albumStoreContext = HttpContext AlbumRepository albumStoreContext = HttpContext
.RequestServices .RequestServices
.GetService(typeof(AlbumStoreContext)) as AlbumStoreContext; .GetService(typeof(AlbumRepository)) as AlbumRepository;
albums = albumStoreContext.GetAlbums(); albums = albumStoreContext.GetAlbums();
@@ -65,9 +65,9 @@ namespace Icarus.Controllers
AlbumId = id AlbumId = id
}; };
AlbumStoreContext albumStoreContext = HttpContext AlbumRepository albumStoreContext = HttpContext
.RequestServices .RequestServices
.GetService(typeof(AlbumStoreContext)) as AlbumStoreContext; .GetService(typeof(AlbumRepository)) as AlbumRepository;
if (albumStoreContext.DoesAlbumExist(album)) if (albumStoreContext.DoesAlbumExist(album))
{ {
@@ -9,11 +9,11 @@ using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Icarus.Models; 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] [ApiController]
public class ArtistController : ControllerBase public class ArtistController : ControllerBase
{ {
@@ -39,9 +39,9 @@ namespace Icarus.Controllers
[Authorize("read:artists")] [Authorize("read:artists")]
public IActionResult Get() public IActionResult Get()
{ {
ArtistStoreContext artistStoreContext = HttpContext ArtistRepository artistStoreContext = HttpContext
.RequestServices .RequestServices
.GetService(typeof(ArtistStoreContext)) as ArtistStoreContext; .GetService(typeof(ArtistRepository)) as ArtistRepository;
var artists = artistStoreContext.GetArtists(); var artists = artistStoreContext.GetArtists();
@@ -64,9 +64,9 @@ namespace Icarus.Controllers
ArtistId = id ArtistId = id
}; };
ArtistStoreContext artistStoreContext = HttpContext ArtistRepository artistStoreContext = HttpContext
.RequestServices .RequestServices
.GetService(typeof(ArtistStoreContext)) as ArtistStoreContext; .GetService(typeof(ArtistRepository)) as ArtistRepository;
if (artistStoreContext.DoesArtistExist(artist)) if (artistStoreContext.DoesArtistExist(artist))
{ {
@@ -7,11 +7,11 @@ using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Icarus.Models; 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] [ApiController]
public class GenreController : ControllerBase public class GenreController : ControllerBase
{ {
@@ -40,7 +40,7 @@ namespace Icarus.Controllers
var genreStore = HttpContext var genreStore = HttpContext
.RequestServices .RequestServices
.GetService(typeof(GenreStoreContext)) as GenreStoreContext; .GetService(typeof(GenreRepository)) as GenreRepository;
genres = genreStore.GetGenres(); genres = genreStore.GetGenres();
@@ -64,7 +64,7 @@ namespace Icarus.Controllers
var genreStore = HttpContext var genreStore = HttpContext
.RequestServices .RequestServices
.GetService(typeof(GenreStoreContext)) as GenreStoreContext; .GetService(typeof(GenreRepository)) as GenreRepository;
if (genreStore.DoesGenreExist(genre)) if (genreStore.DoesGenreExist(genre))
{ {
@@ -11,11 +11,11 @@ using Microsoft.Extensions.Logging;
using Icarus.Controllers.Managers; using Icarus.Controllers.Managers;
using Icarus.Controllers.Utilities; using Icarus.Controllers.Utilities;
using Icarus.Models; 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] [ApiController]
public class LoginController : ControllerBase public class LoginController : ControllerBase
{ {
@@ -41,9 +41,9 @@ namespace Icarus.Controllers
#region HTTP endpoints #region HTTP endpoints
public IActionResult Post([FromBody] User user) public IActionResult Post([FromBody] User user)
{ {
UserStoreContext context = HttpContext UserRepository context = HttpContext
.RequestServices .RequestServices
.GetService(typeof(UserStoreContext)) as UserStoreContext; .GetService(typeof(UserRepository)) as UserRepository;
_logger.LogInformation("Starting process of validating credentials"); _logger.LogInformation("Starting process of validating credentials");
@@ -10,11 +10,11 @@ using Microsoft.Extensions.Configuration;
using Icarus.Controllers.Managers; using Icarus.Controllers.Managers;
using Icarus.Controllers.Utilities; using Icarus.Controllers.Utilities;
using Icarus.Models; 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] [ApiController]
public class RegisterController : ControllerBase public class RegisterController : ControllerBase
{ {
@@ -41,9 +41,9 @@ namespace Icarus.Controllers
user.Password = pe.HashPassword(user); user.Password = pe.HashPassword(user);
user.EmailVerified = false; user.EmailVerified = false;
UserStoreContext context = HttpContext UserRepository context = HttpContext
.RequestServices .RequestServices
.GetService(typeof(UserStoreContext)) as UserStoreContext; .GetService(typeof(UserRepository)) as UserRepository;
context.SaveUser(user); context.SaveUser(user);
@@ -13,11 +13,11 @@ using Microsoft.Extensions.Configuration;
using Icarus.Controllers.Managers; using Icarus.Controllers.Managers;
using Icarus.Controllers.Utilities; using Icarus.Controllers.Utilities;
using Icarus.Models; 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] [ApiController]
public class SongCompressedDataController : ControllerBase public class SongCompressedDataController : ControllerBase
{ {
@@ -48,9 +48,9 @@ namespace Icarus.Controllers
[Authorize("download:songs")] [Authorize("download:songs")]
public async Task<IActionResult> Get(int id) public async Task<IActionResult> Get(int id)
{ {
MusicStoreContext context = HttpContext SongRepository context = HttpContext
.RequestServices .RequestServices
.GetService(typeof(MusicStoreContext)) as MusicStoreContext; .GetService(typeof(SongRepository)) as SongRepository;
SongCompression cmp = new SongCompression(_archiveDir); SongCompression cmp = new SongCompression(_archiveDir);
@@ -12,11 +12,11 @@ using Microsoft.Extensions.Logging;
using Icarus.Controllers.Managers; using Icarus.Controllers.Managers;
using Icarus.Controllers.Utilities; using Icarus.Controllers.Utilities;
using Icarus.Models; 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] [ApiController]
public class SongController : ControllerBase public class SongController : ControllerBase
{ {
@@ -49,9 +49,9 @@ namespace Icarus.Controllers
Console.WriteLine("Attemtping to retrieve songs"); Console.WriteLine("Attemtping to retrieve songs");
_logger.LogInformation("Attempting to retrieve songs"); _logger.LogInformation("Attempting to retrieve songs");
MusicStoreContext context = HttpContext SongRepository context = HttpContext
.RequestServices .RequestServices
.GetService(typeof(MusicStoreContext)) as MusicStoreContext; .GetService(typeof(SongRepository)) as SongRepository;
songs = context.GetAllSongs(); songs = context.GetAllSongs();
@@ -69,9 +69,9 @@ namespace Icarus.Controllers
[Authorize("read:song_details")] [Authorize("read:song_details")]
public IActionResult Get(int id) public IActionResult Get(int id)
{ {
MusicStoreContext context = HttpContext SongRepository context = HttpContext
.RequestServices .RequestServices
.GetService(typeof(MusicStoreContext)) as MusicStoreContext; .GetService(typeof(SongRepository)) as SongRepository;
Song song = new Song { Id = id }; Song song = new Song { Id = id };
song = context.GetSong(song); song = context.GetSong(song);
@@ -92,25 +92,25 @@ namespace Icarus.Controllers
[HttpPut("{id}")] [HttpPut("{id}")]
public IActionResult Put(int id, [FromBody] Song song) public IActionResult Put(int id, [FromBody] Song song)
{ {
MusicStoreContext context = HttpContext SongRepository context = HttpContext
.RequestServices .RequestServices
.GetService(typeof(MusicStoreContext)) as MusicStoreContext; .GetService(typeof(SongRepository)) as SongRepository;
ArtistStoreContext artistStore = HttpContext ArtistRepository artistStore = HttpContext
.RequestServices .RequestServices
.GetService(typeof(ArtistStoreContext)) as ArtistStoreContext; .GetService(typeof(ArtistRepository)) as ArtistRepository;
AlbumStoreContext albumStore = HttpContext AlbumRepository albumStore = HttpContext
.RequestServices .RequestServices
.GetService(typeof(AlbumStoreContext)) as AlbumStoreContext; .GetService(typeof(AlbumRepository)) as AlbumRepository;
GenreStoreContext genreStore = HttpContext GenreRepository genreStore = HttpContext
.RequestServices .RequestServices
.GetService(typeof(GenreStoreContext)) as GenreStoreContext; .GetService(typeof(GenreRepository)) as GenreRepository;
YearStoreContext yearStore = HttpContext YearRepository yearStore = HttpContext
.RequestServices .RequestServices
.GetService(typeof(YearStoreContext)) as YearStoreContext; .GetService(typeof(YearRepository)) as YearRepository;
song.Id = id; song.Id = id;
Console.WriteLine("Retrieving filepath of song"); Console.WriteLine("Retrieving filepath of song");
@@ -13,11 +13,11 @@ using Microsoft.Extensions.Logging;
using Icarus.Controllers.Managers; using Icarus.Controllers.Managers;
using Icarus.Models; 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] [ApiController]
public class SongDataController : ControllerBase public class SongDataController : ControllerBase
{ {
@@ -49,9 +49,9 @@ namespace Icarus.Controllers
[Authorize("download:songs")] [Authorize("download:songs")]
public async Task<IActionResult> Get(int id) public async Task<IActionResult> Get(int id)
{ {
MusicStoreContext context = HttpContext SongRepository context = HttpContext
.RequestServices .RequestServices
.GetService(typeof(MusicStoreContext)) as MusicStoreContext; .GetService(typeof(SongRepository)) as SongRepository;
var songMetaData = context.GetSong(id); var songMetaData = context.GetSong(id);
SongData song = await _songMgr.RetrieveSong(songMetaData); SongData song = await _songMgr.RetrieveSong(songMetaData);
@@ -65,21 +65,21 @@ namespace Icarus.Controllers
{ {
try try
{ {
MusicStoreContext songStoreContext = HttpContext SongRepository songRepository = HttpContext
.RequestServices .RequestServices
.GetService(typeof(MusicStoreContext)) as MusicStoreContext; .GetService(typeof(SongRepository)) as SongRepository;
AlbumStoreContext albumStoreContext = HttpContext AlbumRepository albumStoreContext = HttpContext
.RequestServices .RequestServices
.GetService(typeof(AlbumStoreContext)) as AlbumStoreContext; .GetService(typeof(AlbumRepository)) as AlbumRepository;
ArtistStoreContext artistStoreContext = HttpContext ArtistRepository artistStoreContext = HttpContext
.RequestServices .RequestServices
.GetService(typeof(ArtistStoreContext)) as ArtistStoreContext; .GetService(typeof(ArtistRepository)) as ArtistRepository;
GenreStoreContext genreStore = HttpContext GenreRepository genreStore = HttpContext
.RequestServices .RequestServices
.GetService(typeof(GenreStoreContext)) as GenreStoreContext; .GetService(typeof(GenreRepository)) as GenreRepository;
YearStoreContext yearStore = HttpContext YearRepository yearStore = HttpContext
.RequestServices .RequestServices
.GetService(typeof(YearStoreContext)) as YearStoreContext; .GetService(typeof(YearRepository)) as YearRepository;
Console.WriteLine("Uploading song..."); Console.WriteLine("Uploading song...");
_logger.LogInformation("Uploading song..."); _logger.LogInformation("Uploading song...");
@@ -93,7 +93,7 @@ namespace Icarus.Controllers
Console.WriteLine($"Song filename {sng.FileName}"); Console.WriteLine($"Song filename {sng.FileName}");
_logger.LogInformation($"Song filename {sng.FileName}"); _logger.LogInformation($"Song filename {sng.FileName}");
await _songMgr.SaveSongToFileSystem(sng, songStoreContext, await _songMgr.SaveSongToFileSystem(sng, songRepository,
albumStoreContext, artistStoreContext, albumStoreContext, artistStoreContext,
genreStore, yearStore); genreStore, yearStore);
} }
@@ -110,21 +110,21 @@ namespace Icarus.Controllers
[Authorize("delete:songs")] [Authorize("delete:songs")]
public IActionResult Delete(int id) public IActionResult Delete(int id)
{ {
MusicStoreContext context = HttpContext SongRepository context = HttpContext
.RequestServices .RequestServices
.GetService(typeof(MusicStoreContext)) as MusicStoreContext; .GetService(typeof(SongRepository)) as SongRepository;
AlbumStoreContext albumStore = HttpContext AlbumRepository albumStore = HttpContext
.RequestServices .RequestServices
.GetService(typeof(AlbumStoreContext)) as AlbumStoreContext; .GetService(typeof(AlbumRepository)) as AlbumRepository;
ArtistStoreContext artistStore = HttpContext ArtistRepository artistStore = HttpContext
.RequestServices .RequestServices
.GetService(typeof(ArtistStoreContext)) as ArtistStoreContext; .GetService(typeof(ArtistRepository)) as ArtistRepository;
GenreStoreContext genreStore = HttpContext GenreRepository genreStore = HttpContext
.RequestServices .RequestServices
.GetService(typeof(GenreStoreContext)) as GenreStoreContext; .GetService(typeof(GenreRepository)) as GenreRepository;
YearStoreContext yearStore = HttpContext YearRepository yearStore = HttpContext
.RequestServices .RequestServices
.GetService(typeof(YearStoreContext)) as YearStoreContext; .GetService(typeof(YearRepository)) as YearRepository;
var songMetaData = new Song{ Id = id }; var songMetaData = new Song{ Id = id };
Console.WriteLine($"Id {songMetaData.Id}"); Console.WriteLine($"Id {songMetaData.Id}");
@@ -12,11 +12,11 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Icarus.Models; 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] [ApiController]
public class SongStreamController : ControllerBase public class SongStreamController : ControllerBase
{ {
@@ -43,7 +43,7 @@ namespace Icarus.Controllers
{ {
var songStore= HttpContext var songStore= HttpContext
.RequestServices .RequestServices
.GetService(typeof(MusicStoreContext)) as MusicStoreContext; .GetService(typeof(SongRepository)) as SongRepository;
var song = songStore.GetSong(new Song { Id = id }); var song = songStore.GetSong(new Song { Id = id });
@@ -7,11 +7,11 @@ using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Icarus.Models; 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] [ApiController]
public class YearController : ControllerBase public class YearController : ControllerBase
{ {
@@ -40,7 +40,7 @@ namespace Icarus.Controller
var yearStore = HttpContext var yearStore = HttpContext
.RequestServices .RequestServices
.GetService(typeof(YearStoreContext)) as YearStoreContext; .GetService(typeof(YearRepository)) as YearRepository;
yearValues = yearStore.GetSongYears(); yearValues = yearStore.GetSongYears();
@@ -64,7 +64,7 @@ namespace Icarus.Controller
var yearStore = HttpContext var yearStore = HttpContext
.RequestServices .RequestServices
.GetService(typeof(YearStoreContext)) as YearStoreContext; .GetService(typeof(YearRepository)) as YearRepository;
if (yearStore.DoesYearExist(year)) if (yearStore.DoesYearExist(year))
{ {
@@ -8,7 +8,7 @@ using MySql.Data.MySqlClient;
using Icarus.Models; using Icarus.Models;
namespace Icarus.Models.Context namespace Icarus.Database.Contexts
{ {
public class AlbumContext : DbContext public class AlbumContext : DbContext
{ {
@@ -8,7 +8,7 @@ using MySql.Data.MySqlClient;
using Icarus.Models; using Icarus.Models;
namespace Icarus.Models.Context namespace Icarus.Database.Contexts
{ {
public class ArtistContext : DbContext public class ArtistContext : DbContext
{ {
@@ -8,7 +8,7 @@ using MySql.Data.MySqlClient;
using Icarus.Models; using Icarus.Models;
namespace Icarus.Models.Context namespace Icarus.Database.Contexts
{ {
public class GenreContext : DbContext public class GenreContext : DbContext
{ {
@@ -8,7 +8,7 @@ using MySql.Data.MySqlClient;
using Icarus.Models; using Icarus.Models;
namespace Icarus.Models.Context namespace Icarus.Database.Contexts
{ {
public class SongContext : DbContext public class SongContext : DbContext
{ {
@@ -8,7 +8,7 @@ using MySql.Data.MySqlClient;
using Icarus.Models; using Icarus.Models;
namespace Icarus.Models.Context namespace Icarus.Database.Contexts
{ {
public class UserContext : DbContext public class UserContext : DbContext
{ {
@@ -8,7 +8,7 @@ using MySql.Data.MySqlClient;
using Icarus.Models; using Icarus.Models;
namespace Icarus.Models.Context namespace Icarus.Database.Contexts
{ {
public class YearContext : DbContext public class YearContext : DbContext
{ {
@@ -6,9 +6,9 @@ using MySql.Data.MySqlClient;
using Icarus.Models; using Icarus.Models;
namespace Icarus.Models.Context namespace Icarus.Database.Repositories
{ {
public class AlbumStoreContext : BaseStoreContext public class AlbumRepository : BaseRepository
{ {
#region Fields #region Fields
#endregion #endregion
@@ -19,7 +19,7 @@ namespace Icarus.Models.Context
#region Constructors #region Constructors
public AlbumStoreContext(string connectionString) public AlbumRepository(string connectionString)
{ {
_connectionString = connectionString; _connectionString = connectionString;
} }
@@ -8,9 +8,9 @@ using MySql.Data.MySqlClient;
using Icarus.Models; using Icarus.Models;
namespace Icarus.Models.Context namespace Icarus.Database.Repositories
{ {
public class ArtistStoreContext : BaseStoreContext public class ArtistRepository : BaseRepository
{ {
#region Fields #region Fields
#endregion #endregion
@@ -21,7 +21,7 @@ namespace Icarus.Models.Context
#region Constructors #region Constructors
public ArtistStoreContext(string connectionString) public ArtistRepository(string connectionString)
{ {
_connectionString = connectionString; _connectionString = connectionString;
} }
@@ -3,9 +3,9 @@ using System;
using MySql.Data.MySqlClient; using MySql.Data.MySqlClient;
using NLog; using NLog;
namespace Icarus.Models.Context namespace Icarus.Database.Repositories
{ {
public class BaseStoreContext public class BaseRepository
{ {
#region Fields #region Fields
protected string _connectionString; protected string _connectionString;
@@ -6,10 +6,9 @@ using MySql.Data.MySqlClient;
using Icarus.Models; using Icarus.Models;
namespace Icarus.Models.Context namespace Icarus.Database.Repositories
{ {
// TODO: Implement Genre store #41 public class GenreRepository : BaseRepository
public class GenreStoreContext : BaseStoreContext
{ {
#region Fields #region Fields
#endregion #endregion
@@ -20,7 +19,7 @@ namespace Icarus.Models.Context
#region Constructors #region Constructors
public GenreStoreContext(string connectionString) public GenreRepository(string connectionString)
{ {
_connectionString = connectionString; _connectionString = connectionString;
} }
@@ -3,9 +3,11 @@ using System.Collections.Generic;
using MySql.Data.MySqlClient; 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 #region Fields
#endregion #endregion
@@ -16,7 +18,7 @@ namespace Icarus.Models.Context
#region Constructors #region Constructors
public MusicStoreContext(string connectionString) public SongRepository(string connectionString)
{ {
_connectionString = connectionString; _connectionString = connectionString;
} }
@@ -101,7 +103,7 @@ namespace Icarus.Models.Context
catch (Exception ex) catch (Exception ex)
{ {
var msg = ex.Message; var msg = ex.Message;
Console.WriteLine("An error occurred in MusicStoreContext:"); Console.WriteLine("An error occurred in SongRepository:");
Console.WriteLine(msg); Console.WriteLine(msg);
_logger.Error(msg, "An error occurred"); _logger.Error(msg, "An error occurred");
} }
@@ -6,9 +6,9 @@ using MySql.Data.MySqlClient;
using Icarus.Models; using Icarus.Models;
namespace Icarus.Models.Context namespace Icarus.Database.Repositories
{ {
public class UserStoreContext: BaseStoreContext public class UserRepository: BaseRepository
{ {
#region Fields #region Fields
#endregion #endregion
@@ -19,7 +19,7 @@ namespace Icarus.Models.Context
#region Constructor #region Constructor
public UserStoreContext(string connectionString) public UserRepository(string connectionString)
{ {
_connectionString = connectionString; _connectionString = connectionString;
} }
@@ -6,10 +6,9 @@ using MySql.Data.MySqlClient;
using Icarus.Models; using Icarus.Models;
namespace Icarus.Models.Context namespace Icarus.Database.Repositories
{ {
// TODO: Implement Year store #42 public class YearRepository : BaseRepository
public class YearStoreContext : BaseStoreContext
{ {
#region Fields #region Fields
#endregion #endregion
@@ -20,7 +19,7 @@ namespace Icarus.Models.Context
#region Constructors #region Constructors
public YearStoreContext(string connectionString) public YearRepository(string connectionString)
{ {
_connectionString = connectionString; _connectionString = connectionString;
} }
-2
View File
@@ -3,8 +3,6 @@ using System.ComponentModel.DataAnnotations.Schema;
using Newtonsoft.Json; using Newtonsoft.Json;
using Icarus.Models.Context;
namespace Icarus.Models namespace Icarus.Models
{ {
public class Song public class Song
+14 -13
View File
@@ -24,7 +24,8 @@ using NLog.Web.AspNetCore;
using Icarus.Authorization; using Icarus.Authorization;
using Icarus.Authorization.Handlers; using Icarus.Authorization.Handlers;
using Icarus.Models.Context; using Icarus.Database.Contexts;
using Icarus.Database.Repositories;
namespace Icarus namespace Icarus
{ {
@@ -98,28 +99,28 @@ namespace Icarus
var connString = Configuration.GetConnectionString("DefaultConnection"); var connString = Configuration.GetConnectionString("DefaultConnection");
services.Add(new ServiceDescriptor(typeof(MusicStoreContext), services.Add(new ServiceDescriptor(typeof(SongRepository),
new MusicStoreContext(Configuration new SongRepository(Configuration
.GetConnectionString("DefaultConnection")))); .GetConnectionString("DefaultConnection"))));
services.Add(new ServiceDescriptor(typeof(AlbumStoreContext), services.Add(new ServiceDescriptor(typeof(AlbumRepository),
new AlbumStoreContext(Configuration new AlbumRepository(Configuration
.GetConnectionString("DefaultConnection")))); .GetConnectionString("DefaultConnection"))));
services.Add(new ServiceDescriptor(typeof(ArtistStoreContext), services.Add(new ServiceDescriptor(typeof(ArtistRepository),
new ArtistStoreContext(Configuration new ArtistRepository(Configuration
.GetConnectionString("DefaultConnection")))); .GetConnectionString("DefaultConnection"))));
services.Add(new ServiceDescriptor(typeof(GenreStoreContext), services.Add(new ServiceDescriptor(typeof(GenreRepository),
new GenreStoreContext(Configuration new GenreRepository(Configuration
.GetConnectionString("DefaultConnection")))); .GetConnectionString("DefaultConnection"))));
services.Add(new ServiceDescriptor(typeof(YearStoreContext), services.Add(new ServiceDescriptor(typeof(YearRepository),
new YearStoreContext(Configuration new YearRepository(Configuration
.GetConnectionString("DefaultConnection")))); .GetConnectionString("DefaultConnection"))));
services.Add(new ServiceDescriptor(typeof(UserStoreContext), services.Add(new ServiceDescriptor(typeof(UserRepository),
new UserStoreContext(Configuration new UserRepository(Configuration
.GetConnectionString("DefaultConnection")))); .GetConnectionString("DefaultConnection"))));
services.AddDbContext<SongContext>(options => options.UseMySQL(connString)); services.AddDbContext<SongContext>(options => options.UseMySQL(connString));