Code cleanup and conforming to a coding covention
This commit is contained in:
@@ -12,74 +12,66 @@ using Icarus.Database.Repositories;
|
||||
|
||||
namespace Icarus.Controllers.V1
|
||||
{
|
||||
[Route("api/v1/album")]
|
||||
[ApiController]
|
||||
public class AlbumController : ControllerBase
|
||||
{
|
||||
#region Fields
|
||||
private readonly ILogger<AlbumController> _logger;
|
||||
#endregion
|
||||
[Route("api/v1/album")]
|
||||
[ApiController]
|
||||
public class AlbumController : ControllerBase
|
||||
{
|
||||
#region Fields
|
||||
private readonly ILogger<AlbumController> _logger;
|
||||
#endregion
|
||||
|
||||
|
||||
#region Properties
|
||||
#endregion
|
||||
#region Properties
|
||||
#endregion
|
||||
|
||||
|
||||
#region Constructors
|
||||
public AlbumController(ILogger<AlbumController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
#endregion
|
||||
#region Constructors
|
||||
public AlbumController(ILogger<AlbumController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region HTTP Routes
|
||||
[HttpGet]
|
||||
[Authorize("read:albums")]
|
||||
public IActionResult Get()
|
||||
{
|
||||
List<Album> albums = new List<Album>();
|
||||
#region HTTP Routes
|
||||
[HttpGet]
|
||||
[Authorize("read:albums")]
|
||||
public IActionResult Get()
|
||||
{
|
||||
List<Album> albums = new List<Album>();
|
||||
|
||||
AlbumRepository albumStoreContext = HttpContext
|
||||
.RequestServices
|
||||
.GetService(typeof(AlbumRepository)) as AlbumRepository;
|
||||
AlbumRepository albumStoreContext = HttpContext.RequestServices
|
||||
.GetService(typeof(AlbumRepository)) as AlbumRepository;
|
||||
|
||||
albums = albumStoreContext.GetAlbums();
|
||||
albums = albumStoreContext.GetAlbums();
|
||||
|
||||
if (albums.Count > 0)
|
||||
{
|
||||
return Ok(albums);
|
||||
}
|
||||
else
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
}
|
||||
if (albums.Count > 0)
|
||||
return Ok(albums);
|
||||
else
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
[HttpGet("{id}")]
|
||||
[Authorize("read:albums")]
|
||||
public IActionResult Get(int id)
|
||||
{
|
||||
Album album = new Album
|
||||
{
|
||||
AlbumId = id
|
||||
};
|
||||
[HttpGet("{id}")]
|
||||
[Authorize("read:albums")]
|
||||
public IActionResult Get(int id)
|
||||
{
|
||||
Album album = new Album
|
||||
{
|
||||
AlbumId = id
|
||||
};
|
||||
|
||||
AlbumRepository albumStoreContext = HttpContext
|
||||
.RequestServices
|
||||
.GetService(typeof(AlbumRepository)) as AlbumRepository;
|
||||
AlbumRepository albumStoreContext = HttpContext.RequestServices
|
||||
.GetService(typeof(AlbumRepository)) as AlbumRepository;
|
||||
|
||||
if (albumStoreContext.DoesAlbumExist(album))
|
||||
{
|
||||
album = albumStoreContext.GetAlbum(album);
|
||||
if (albumStoreContext.DoesAlbumExist(album))
|
||||
{
|
||||
album = albumStoreContext.GetAlbum(album);
|
||||
|
||||
return Ok(album);
|
||||
}
|
||||
else
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
return Ok(album);
|
||||
}
|
||||
else
|
||||
return NotFound();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,73 +13,64 @@ using Icarus.Database.Repositories;
|
||||
|
||||
namespace Icarus.Controllers.V1
|
||||
{
|
||||
[Route("api/v1/artist")]
|
||||
[ApiController]
|
||||
public class ArtistController : ControllerBase
|
||||
{
|
||||
#region Fields
|
||||
private readonly ILogger<ArtistController> _logger;
|
||||
#endregion
|
||||
[Route("api/v1/artist")]
|
||||
[ApiController]
|
||||
public class ArtistController : ControllerBase
|
||||
{
|
||||
#region Fields
|
||||
private readonly ILogger<ArtistController> _logger;
|
||||
#endregion
|
||||
|
||||
|
||||
#region Properties
|
||||
#endregion
|
||||
#region Properties
|
||||
#endregion
|
||||
|
||||
|
||||
#region Constructors
|
||||
public ArtistController(ILogger<ArtistController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
#endregion
|
||||
#region Constructors
|
||||
public ArtistController(ILogger<ArtistController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region HTTP Routes
|
||||
[HttpGet]
|
||||
[Authorize("read:artists")]
|
||||
public IActionResult Get()
|
||||
{
|
||||
ArtistRepository artistStoreContext = HttpContext
|
||||
.RequestServices
|
||||
.GetService(typeof(ArtistRepository)) as ArtistRepository;
|
||||
#region HTTP Routes
|
||||
[HttpGet]
|
||||
[Authorize("read:artists")]
|
||||
public IActionResult Get()
|
||||
{
|
||||
ArtistRepository artistStoreContext = HttpContext.RequestServices
|
||||
.GetService(typeof(ArtistRepository)) as ArtistRepository;
|
||||
|
||||
var artists = artistStoreContext.GetArtists();
|
||||
var artists = artistStoreContext.GetArtists();
|
||||
|
||||
if (artists.Count > 0)
|
||||
{
|
||||
return Ok(artists);
|
||||
}
|
||||
else
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
}
|
||||
if (artists.Count > 0)
|
||||
return Ok(artists);
|
||||
else
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
[HttpGet("{id}")]
|
||||
[Authorize("read:artists")]
|
||||
public IActionResult Get(int id)
|
||||
{
|
||||
Artist artist = new Artist
|
||||
{
|
||||
ArtistId = id
|
||||
};
|
||||
|
||||
ArtistRepository artistStoreContext = HttpContext
|
||||
.RequestServices
|
||||
.GetService(typeof(ArtistRepository)) as ArtistRepository;
|
||||
[HttpGet("{id}")]
|
||||
[Authorize("read:artists")]
|
||||
public IActionResult Get(int id)
|
||||
{
|
||||
Artist artist = new Artist
|
||||
{
|
||||
ArtistId = id
|
||||
};
|
||||
|
||||
ArtistRepository artistStoreContext = HttpContext.RequestServices
|
||||
.GetService(typeof(ArtistRepository)) as ArtistRepository;
|
||||
|
||||
if (artistStoreContext.DoesArtistExist(artist))
|
||||
{
|
||||
artist = artistStoreContext.GetArtist(artist);
|
||||
if (artistStoreContext.DoesArtistExist(artist))
|
||||
{
|
||||
artist = artistStoreContext.GetArtist(artist);
|
||||
|
||||
|
||||
return Ok(artist);
|
||||
}
|
||||
else
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
return Ok(artist);
|
||||
}
|
||||
else
|
||||
return NotFound();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,74 +11,66 @@ using Icarus.Database.Repositories;
|
||||
|
||||
namespace Icarus.Controllers.V1
|
||||
{
|
||||
[Route("api/v1/genre")]
|
||||
[ApiController]
|
||||
public class GenreController : ControllerBase
|
||||
{
|
||||
#region Fields
|
||||
private readonly ILogger<GenreController> _logger;
|
||||
#endregion
|
||||
[Route("api/v1/genre")]
|
||||
[ApiController]
|
||||
public class GenreController : ControllerBase
|
||||
{
|
||||
#region Fields
|
||||
private readonly ILogger<GenreController> _logger;
|
||||
#endregion
|
||||
|
||||
|
||||
#region Properties
|
||||
#endregion
|
||||
#region Properties
|
||||
#endregion
|
||||
|
||||
|
||||
#region Constructors
|
||||
public GenreController(ILogger<GenreController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
#endregion
|
||||
#region Constructors
|
||||
public GenreController(ILogger<GenreController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region HTTP Routes
|
||||
[HttpGet]
|
||||
[Authorize("read:genre")]
|
||||
public IActionResult Get()
|
||||
{
|
||||
var genres = new List<Genre>();
|
||||
#region HTTP Routes
|
||||
[HttpGet]
|
||||
[Authorize("read:genre")]
|
||||
public IActionResult Get()
|
||||
{
|
||||
var genres = new List<Genre>();
|
||||
|
||||
var genreStore = HttpContext
|
||||
.RequestServices
|
||||
.GetService(typeof(GenreRepository)) as GenreRepository;
|
||||
var genreStore = HttpContext.RequestServices
|
||||
.GetService(typeof(GenreRepository)) as GenreRepository;
|
||||
|
||||
genres = genreStore.GetGenres();
|
||||
genres = genreStore.GetGenres();
|
||||
|
||||
if (genres.Count > 0)
|
||||
{
|
||||
return Ok(genres);
|
||||
}
|
||||
else
|
||||
{
|
||||
return NotFound(new List<Genre>());
|
||||
}
|
||||
}
|
||||
if (genres.Count > 0)
|
||||
return Ok(genres);
|
||||
else
|
||||
return NotFound(new List<Genre>());
|
||||
}
|
||||
|
||||
[HttpGet("{id}")]
|
||||
[Authorize("read:genre")]
|
||||
public IActionResult Get(int id)
|
||||
{
|
||||
var genre = new Genre
|
||||
{
|
||||
GenreId = id
|
||||
};
|
||||
[HttpGet("{id}")]
|
||||
[Authorize("read:genre")]
|
||||
public IActionResult Get(int id)
|
||||
{
|
||||
var genre = new Genre
|
||||
{
|
||||
GenreId = id
|
||||
};
|
||||
|
||||
var genreStore = HttpContext
|
||||
.RequestServices
|
||||
.GetService(typeof(GenreRepository)) as GenreRepository;
|
||||
var genreStore = HttpContext.RequestServices
|
||||
.GetService(typeof(GenreRepository)) as GenreRepository;
|
||||
|
||||
if (genreStore.DoesGenreExist(genre))
|
||||
{
|
||||
genre = genreStore.GetGenre(genre);
|
||||
if (genreStore.DoesGenreExist(genre))
|
||||
{
|
||||
genre = genreStore.GetGenre(genre);
|
||||
|
||||
return Ok(genre);
|
||||
}
|
||||
else
|
||||
{
|
||||
return NotFound(new Genre());
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
return Ok(genre);
|
||||
}
|
||||
else
|
||||
return NotFound(new Genre());
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,75 +15,74 @@ using Icarus.Database.Repositories;
|
||||
|
||||
namespace Icarus.Controllers.V1
|
||||
{
|
||||
[Route("api/v1/login")]
|
||||
[ApiController]
|
||||
public class LoginController : ControllerBase
|
||||
{
|
||||
#region Fields
|
||||
private IConfiguration _config;
|
||||
private ILogger<LoginController> _logger;
|
||||
#endregion
|
||||
[Route("api/v1/login")]
|
||||
[ApiController]
|
||||
public class LoginController : ControllerBase
|
||||
{
|
||||
#region Fields
|
||||
private IConfiguration _config;
|
||||
private ILogger<LoginController> _logger;
|
||||
#endregion
|
||||
|
||||
|
||||
#region Properties
|
||||
#endregion
|
||||
#region Properties
|
||||
#endregion
|
||||
|
||||
|
||||
#region Contructors
|
||||
public LoginController(IConfiguration config, ILogger<LoginController> logger)
|
||||
{
|
||||
_config = config;
|
||||
_logger = logger;
|
||||
}
|
||||
#endregion
|
||||
#region Contructors
|
||||
public LoginController(IConfiguration config, ILogger<LoginController> logger)
|
||||
{
|
||||
_config = config;
|
||||
_logger = logger;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region HTTP endpoints
|
||||
public IActionResult Post([FromBody] User user)
|
||||
{
|
||||
UserRepository context = HttpContext
|
||||
.RequestServices
|
||||
.GetService(typeof(UserRepository)) as UserRepository;
|
||||
#region HTTP endpoints
|
||||
public IActionResult Post([FromBody] User user)
|
||||
{
|
||||
UserRepository context = HttpContext.RequestServices
|
||||
.GetService(typeof(UserRepository)) as UserRepository;
|
||||
|
||||
_logger.LogInformation("Starting process of validating credentials");
|
||||
|
||||
var message = "Invalid credentials";
|
||||
var password = user.Password;
|
||||
_logger.LogInformation("Starting process of validating credentials");
|
||||
|
||||
var message = "Invalid credentials";
|
||||
var password = user.Password;
|
||||
|
||||
var loginRes = new LoginResult
|
||||
{
|
||||
Username = user.Username
|
||||
};
|
||||
var loginRes = new LoginResult
|
||||
{
|
||||
Username = user.Username
|
||||
};
|
||||
|
||||
if (context.DoesUserExist(user))
|
||||
{
|
||||
user = context.RetrieveUser(user);
|
||||
if (context.DoesUserExist(user))
|
||||
{
|
||||
user = context.RetrieveUser(user);
|
||||
|
||||
var validatePass = new PasswordEncryption();
|
||||
var validated = validatePass.VerifyPassword(user, password);
|
||||
if (!validated)
|
||||
{
|
||||
loginRes.Message = message;
|
||||
_logger.LogInformation(message);
|
||||
var validatePass = new PasswordEncryption();
|
||||
var validated = validatePass.VerifyPassword(user, password);
|
||||
if (!validated)
|
||||
{
|
||||
loginRes.Message = message;
|
||||
_logger.LogInformation(message);
|
||||
|
||||
return Ok(loginRes);
|
||||
}
|
||||
return Ok(loginRes);
|
||||
}
|
||||
|
||||
_logger.LogInformation("Successfully validated user credentials");
|
||||
_logger.LogInformation("Successfully validated user credentials");
|
||||
|
||||
TokenManager tk = new TokenManager(_config);
|
||||
TokenManager tk = new TokenManager(_config);
|
||||
|
||||
loginRes = tk.RetrieveLoginResult(user);
|
||||
loginRes = tk.RetrieveLoginResult(user);
|
||||
|
||||
return Ok(loginRes);
|
||||
}
|
||||
else
|
||||
{
|
||||
loginRes.Message = message;
|
||||
return Ok(loginRes);
|
||||
}
|
||||
else
|
||||
{
|
||||
loginRes.Message = message;
|
||||
|
||||
return NotFound(loginRes);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
return NotFound(loginRes);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,58 +14,57 @@ using Icarus.Database.Repositories;
|
||||
|
||||
namespace Icarus.Controllers.V1
|
||||
{
|
||||
[Route("api/v1/register")]
|
||||
[ApiController]
|
||||
public class RegisterController : ControllerBase
|
||||
{
|
||||
#region Fields
|
||||
private IConfiguration _config;
|
||||
#endregion
|
||||
[Route("api/v1/register")]
|
||||
[ApiController]
|
||||
public class RegisterController : ControllerBase
|
||||
{
|
||||
#region Fields
|
||||
private IConfiguration _config;
|
||||
#endregion
|
||||
|
||||
|
||||
#region Properties
|
||||
#endregion
|
||||
#region Properties
|
||||
#endregion
|
||||
|
||||
|
||||
#region Constructor
|
||||
public RegisterController(IConfiguration config)
|
||||
{
|
||||
_config = config;
|
||||
}
|
||||
#endregion
|
||||
#region Constructor
|
||||
public RegisterController(IConfiguration config)
|
||||
{
|
||||
_config = config;
|
||||
}
|
||||
#endregion
|
||||
|
||||
[HttpPost]
|
||||
public IActionResult Post([FromBody] User user)
|
||||
{
|
||||
PasswordEncryption pe = new PasswordEncryption();
|
||||
user.Password = pe.HashPassword(user);
|
||||
user.EmailVerified = false;
|
||||
[HttpPost]
|
||||
public IActionResult Post([FromBody] User user)
|
||||
{
|
||||
PasswordEncryption pe = new PasswordEncryption();
|
||||
user.Password = pe.HashPassword(user);
|
||||
user.EmailVerified = false;
|
||||
|
||||
UserRepository context = HttpContext
|
||||
.RequestServices
|
||||
.GetService(typeof(UserRepository)) as UserRepository;
|
||||
UserRepository context = HttpContext.RequestServices
|
||||
.GetService(typeof(UserRepository)) as UserRepository;
|
||||
|
||||
context.SaveUser(user);
|
||||
context.SaveUser(user);
|
||||
|
||||
var registerResult = new RegisterResult
|
||||
{
|
||||
Username = user.Username
|
||||
};
|
||||
var registerResult = new RegisterResult
|
||||
{
|
||||
Username = user.Username
|
||||
};
|
||||
|
||||
if (context.DoesUserExist(user))
|
||||
{
|
||||
registerResult.Message = "Successful registration";
|
||||
registerResult.SuccessfullyRegistered = true;
|
||||
if (context.DoesUserExist(user))
|
||||
{
|
||||
registerResult.Message = "Successful registration";
|
||||
registerResult.SuccessfullyRegistered = true;
|
||||
|
||||
return Ok(registerResult);
|
||||
}
|
||||
else
|
||||
{
|
||||
registerResult.Message = "Registration failed";
|
||||
registerResult.SuccessfullyRegistered = false;
|
||||
return Ok(registerResult);
|
||||
}
|
||||
else
|
||||
{
|
||||
registerResult.Message = "Registration failed";
|
||||
registerResult.SuccessfullyRegistered = false;
|
||||
|
||||
return Ok(registerResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Ok(registerResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,49 +17,48 @@ using Icarus.Database.Repositories;
|
||||
|
||||
namespace Icarus.Controllers.V1
|
||||
{
|
||||
[Route("api/v1/song/compressed/data")]
|
||||
[ApiController]
|
||||
public class SongCompressedDataController : ControllerBase
|
||||
{
|
||||
#region Fields
|
||||
private IConfiguration _config;
|
||||
private string _songTempDir;
|
||||
private string _archiveDir;
|
||||
#endregion
|
||||
[Route("api/v1/song/compressed/data")]
|
||||
[ApiController]
|
||||
public class SongCompressedDataController : ControllerBase
|
||||
{
|
||||
#region Fields
|
||||
private IConfiguration _config;
|
||||
private string _songTempDir;
|
||||
private string _archiveDir;
|
||||
#endregion
|
||||
|
||||
|
||||
#region Properties
|
||||
#endregion
|
||||
#region Properties
|
||||
#endregion
|
||||
|
||||
|
||||
#region Constructor
|
||||
public SongCompressedDataController(IConfiguration config)
|
||||
{
|
||||
_config = config;
|
||||
_songTempDir = _config.GetValue<string>("TemporaryMusicPath");
|
||||
_archiveDir = _config.GetValue<string>("ArchivePath");
|
||||
}
|
||||
#endregion
|
||||
#region Constructor
|
||||
public SongCompressedDataController(IConfiguration config)
|
||||
{
|
||||
_config = config;
|
||||
_songTempDir = _config.GetValue<string>("TemporaryMusicPath");
|
||||
_archiveDir = _config.GetValue<string>("ArchivePath");
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region API Routes
|
||||
[HttpGet("{id}")]
|
||||
[Authorize("download:songs")]
|
||||
public async Task<IActionResult> Get(int id)
|
||||
{
|
||||
SongRepository context = HttpContext
|
||||
.RequestServices
|
||||
.GetService(typeof(SongRepository)) as SongRepository;
|
||||
#region API Routes
|
||||
[HttpGet("{id}")]
|
||||
[Authorize("download:songs")]
|
||||
public async Task<IActionResult> Get(int id)
|
||||
{
|
||||
SongRepository context = HttpContext.RequestServices
|
||||
.GetService(typeof(SongRepository)) as SongRepository;
|
||||
|
||||
SongCompression cmp = new SongCompression(_archiveDir);
|
||||
|
||||
Console.WriteLine($"Archive directory root: {_archiveDir}");
|
||||
SongCompression cmp = new SongCompression(_archiveDir);
|
||||
|
||||
Console.WriteLine($"Archive directory root: {_archiveDir}");
|
||||
|
||||
Console.WriteLine("Starting process of retrieving comrpessed song");
|
||||
SongData song = await cmp.RetrieveCompressedSong(context.GetSong(id));
|
||||
Console.WriteLine("Starting process of retrieving comrpessed song");
|
||||
SongData song = await cmp.RetrieveCompressedSong(context.GetSong(id));
|
||||
|
||||
return File(song.Data, "application/x-msdownload", cmp.CompressedSongFilename);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
return File(song.Data, "application/x-msdownload", cmp.CompressedSongFilename);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,118 +16,101 @@ using Icarus.Database.Repositories;
|
||||
|
||||
namespace Icarus.Controllers.V1
|
||||
{
|
||||
[Route("api/v1/song")]
|
||||
[ApiController]
|
||||
public class SongController : ControllerBase
|
||||
{
|
||||
#region Fields
|
||||
private readonly ILogger<SongController> _logger;
|
||||
private IConfiguration _config;
|
||||
private SongManager _songMgr;
|
||||
#endregion
|
||||
[Route("api/v1/song")]
|
||||
[ApiController]
|
||||
public class SongController : ControllerBase
|
||||
{
|
||||
#region Fields
|
||||
private readonly ILogger<SongController> _logger;
|
||||
private IConfiguration _config;
|
||||
private SongManager _songMgr;
|
||||
#endregion
|
||||
|
||||
|
||||
#region Properties
|
||||
#endregion
|
||||
#region Properties
|
||||
#endregion
|
||||
|
||||
|
||||
#region Constructor
|
||||
public SongController(IConfiguration config, ILogger<SongController> logger)
|
||||
{
|
||||
_config = config;
|
||||
_logger = logger;
|
||||
_songMgr = new SongManager(config);
|
||||
}
|
||||
#endregion
|
||||
#region Constructor
|
||||
public SongController(IConfiguration config, ILogger<SongController> logger)
|
||||
{
|
||||
_config = config;
|
||||
_logger = logger;
|
||||
_songMgr = new SongManager(config);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
[HttpGet]
|
||||
[Authorize("read:song_details")]
|
||||
public IActionResult Get()
|
||||
{
|
||||
List<Song> songs = new List<Song>();
|
||||
Console.WriteLine("Attemtping to retrieve songs");
|
||||
_logger.LogInformation("Attempting to retrieve songs");
|
||||
|
||||
SongRepository context = HttpContext
|
||||
.RequestServices
|
||||
.GetService(typeof(SongRepository)) as SongRepository;
|
||||
[HttpGet]
|
||||
[Authorize("read:song_details")]
|
||||
public IActionResult Get()
|
||||
{
|
||||
List<Song> songs = new List<Song>();
|
||||
Console.WriteLine("Attemtping to retrieve songs");
|
||||
_logger.LogInformation("Attempting to retrieve songs");
|
||||
|
||||
SongRepository context = HttpContext.RequestServices
|
||||
.GetService(typeof(SongRepository)) as SongRepository;
|
||||
|
||||
songs = context.GetAllSongs();
|
||||
songs = context.GetAllSongs();
|
||||
|
||||
if (songs.Count > 0)
|
||||
{
|
||||
return Ok(songs);
|
||||
}
|
||||
else
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
}
|
||||
if (songs.Count > 0)
|
||||
return Ok(songs);
|
||||
else
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
[HttpGet("{id}")]
|
||||
[Authorize("read:song_details")]
|
||||
public IActionResult Get(int id)
|
||||
{
|
||||
SongRepository context = HttpContext
|
||||
.RequestServices
|
||||
.GetService(typeof(SongRepository)) as SongRepository;
|
||||
|
||||
Song song = new Song { Id = id };
|
||||
song = context.GetSong(song);
|
||||
[HttpGet("{id}")]
|
||||
[Authorize("read:song_details")]
|
||||
public IActionResult Get(int id)
|
||||
{
|
||||
SongRepository context = HttpContext.RequestServices
|
||||
.GetService(typeof(SongRepository)) as SongRepository;
|
||||
|
||||
Song song = new Song { Id = id };
|
||||
song = context.GetSong(song);
|
||||
|
||||
Console.WriteLine("Here");
|
||||
Console.WriteLine("Here");
|
||||
|
||||
if (song.Id != 0)
|
||||
{
|
||||
return Ok(song);
|
||||
}
|
||||
else
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
}
|
||||
if (song.Id != 0)
|
||||
return Ok(song);
|
||||
else
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
[Authorize("update:songs")]
|
||||
[HttpPut("{id}")]
|
||||
public IActionResult Put(int id, [FromBody] Song song)
|
||||
{
|
||||
SongRepository context = HttpContext
|
||||
.RequestServices
|
||||
.GetService(typeof(SongRepository)) as SongRepository;
|
||||
[Authorize("update:songs")]
|
||||
[HttpPut("{id}")]
|
||||
public IActionResult Put(int id, [FromBody] Song song)
|
||||
{
|
||||
SongRepository context = HttpContext.RequestServices
|
||||
.GetService(typeof(SongRepository)) as SongRepository;
|
||||
|
||||
ArtistRepository artistStore = HttpContext
|
||||
.RequestServices
|
||||
.GetService(typeof(ArtistRepository)) as ArtistRepository;
|
||||
ArtistRepository artistStore = HttpContext.RequestServices
|
||||
.GetService(typeof(ArtistRepository)) as ArtistRepository;
|
||||
|
||||
AlbumRepository albumStore = HttpContext
|
||||
.RequestServices
|
||||
.GetService(typeof(AlbumRepository)) as AlbumRepository;
|
||||
|
||||
GenreRepository genreStore = HttpContext
|
||||
.RequestServices
|
||||
.GetService(typeof(GenreRepository)) as GenreRepository;
|
||||
AlbumRepository albumStore = HttpContext.RequestServices
|
||||
.GetService(typeof(AlbumRepository)) as AlbumRepository;
|
||||
|
||||
GenreRepository genreStore = HttpContext.RequestServices
|
||||
.GetService(typeof(GenreRepository)) as GenreRepository;
|
||||
|
||||
YearRepository yearStore = HttpContext
|
||||
.RequestServices
|
||||
.GetService(typeof(YearRepository)) as YearRepository;
|
||||
YearRepository yearStore = HttpContext.RequestServices
|
||||
.GetService(typeof(YearRepository)) as YearRepository;
|
||||
|
||||
song.Id = id;
|
||||
Console.WriteLine("Retrieving filepath of song");
|
||||
_logger.LogInformation("Retrieving filepath of song");
|
||||
song.Id = id;
|
||||
Console.WriteLine("Retrieving filepath of song");
|
||||
_logger.LogInformation("Retrieving filepath of song");
|
||||
|
||||
if (!context.DoesSongExist(song))
|
||||
{
|
||||
return NotFound(new SongResult
|
||||
{
|
||||
Message = "Song does not exist"
|
||||
});
|
||||
}
|
||||
if (!context.DoesSongExist(song))
|
||||
return NotFound(new SongResult
|
||||
{
|
||||
Message = "Song does not exist"
|
||||
});
|
||||
|
||||
var songRes = _songMgr.UpdateSong(song, context, albumStore, artistStore, genreStore,
|
||||
yearStore);
|
||||
var songRes = _songMgr.UpdateSong(song, context, albumStore, artistStore, genreStore,
|
||||
yearStore);
|
||||
|
||||
return Ok(songRes);
|
||||
}
|
||||
}
|
||||
return Ok(songRes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,133 +17,128 @@ using Icarus.Database.Repositories;
|
||||
|
||||
namespace Icarus.Controllers.V1
|
||||
{
|
||||
[Route("api/v1/song/data")]
|
||||
[ApiController]
|
||||
public class SongDataController : ControllerBase
|
||||
{
|
||||
#region Fields
|
||||
private IConfiguration _config;
|
||||
private ILogger<SongDataController> _logger;
|
||||
private SongManager _songMgr;
|
||||
private string _songTempDir;
|
||||
#endregion
|
||||
[Route("api/v1/song/data")]
|
||||
[ApiController]
|
||||
public class SongDataController : ControllerBase
|
||||
{
|
||||
#region Fields
|
||||
private IConfiguration _config;
|
||||
private ILogger<SongDataController> _logger;
|
||||
private SongManager _songMgr;
|
||||
private string _songTempDir;
|
||||
#endregion
|
||||
|
||||
|
||||
#region Properties
|
||||
#endregion
|
||||
#region Properties
|
||||
#endregion
|
||||
|
||||
|
||||
#region Constructor
|
||||
public SongDataController(IConfiguration config, ILogger<SongDataController> logger)
|
||||
{
|
||||
_config = config;
|
||||
_logger = logger;
|
||||
_songTempDir = _config.GetValue<string>("TemporaryMusicPath");
|
||||
_songMgr = new SongManager(config, _songTempDir);
|
||||
}
|
||||
#endregion
|
||||
#region Constructor
|
||||
public SongDataController(IConfiguration config, ILogger<SongDataController> logger)
|
||||
{
|
||||
_config = config;
|
||||
_logger = logger;
|
||||
_songTempDir = _config.GetValue<string>("TemporaryMusicPath");
|
||||
_songMgr = new SongManager(config, _songTempDir);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
[HttpGet("{id}")]
|
||||
[Route("private-scoped")]
|
||||
[Authorize("download:songs")]
|
||||
public async Task<IActionResult> Get(int id)
|
||||
{
|
||||
SongRepository context = HttpContext
|
||||
.RequestServices
|
||||
.GetService(typeof(SongRepository)) as SongRepository;
|
||||
var songMetaData = context.GetSong(id);
|
||||
|
||||
SongData song = await _songMgr.RetrieveSong(songMetaData);
|
||||
|
||||
return File(song.Data, "application/x-msdownload", songMetaData.Filename);
|
||||
}
|
||||
[HttpGet("{id}")]
|
||||
[Route("private-scoped")]
|
||||
[Authorize("download:songs")]
|
||||
public async Task<IActionResult> Get(int id)
|
||||
{
|
||||
SongRepository context = HttpContext.RequestServices
|
||||
.GetService(typeof(SongRepository)) as SongRepository;
|
||||
var songMetaData = context.GetSong(id);
|
||||
|
||||
SongData song = await _songMgr.RetrieveSong(songMetaData);
|
||||
|
||||
return File(song.Data, "application/x-msdownload", songMetaData.Filename);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize("upload:songs")]
|
||||
public async Task Post([FromForm(Name = "file")] List<IFormFile> songData)
|
||||
{
|
||||
try
|
||||
{
|
||||
SongRepository songRepository = HttpContext
|
||||
.RequestServices
|
||||
.GetService(typeof(SongRepository)) as SongRepository;
|
||||
AlbumRepository albumStoreContext = HttpContext
|
||||
.RequestServices
|
||||
.GetService(typeof(AlbumRepository)) as AlbumRepository;
|
||||
ArtistRepository artistStoreContext = HttpContext
|
||||
.RequestServices
|
||||
.GetService(typeof(ArtistRepository)) as ArtistRepository;
|
||||
GenreRepository genreStore = HttpContext
|
||||
.RequestServices
|
||||
.GetService(typeof(GenreRepository)) as GenreRepository;
|
||||
YearRepository yearStore = HttpContext
|
||||
.RequestServices
|
||||
.GetService(typeof(YearRepository)) as YearRepository;
|
||||
[HttpPost]
|
||||
[Authorize("upload:songs")]
|
||||
public async Task Post([FromForm(Name = "file")] List<IFormFile> songData)
|
||||
{
|
||||
try
|
||||
{
|
||||
SongRepository songRepository = HttpContext.RequestServices
|
||||
.GetService(typeof(SongRepository)) as SongRepository;
|
||||
|
||||
Console.WriteLine("Uploading song...");
|
||||
_logger.LogInformation("Uploading song...");
|
||||
AlbumRepository albumStoreContext = HttpContext.RequestServices
|
||||
.GetService(typeof(AlbumRepository)) as AlbumRepository;
|
||||
|
||||
var uploads = _songTempDir;
|
||||
Console.WriteLine($"Song Root Path {uploads}");
|
||||
_logger.LogInformation($"Song root path {uploads}");
|
||||
foreach (var sng in songData)
|
||||
{
|
||||
if (sng.Length > 0) {
|
||||
Console.WriteLine($"Song filename {sng.FileName}");
|
||||
_logger.LogInformation($"Song filename {sng.FileName}");
|
||||
ArtistRepository artistStoreContext = HttpContext.RequestServices
|
||||
.GetService(typeof(ArtistRepository)) as ArtistRepository;
|
||||
|
||||
await _songMgr.SaveSongToFileSystem(sng, songRepository,
|
||||
albumStoreContext, artistStoreContext,
|
||||
genreStore, yearStore);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var msg = ex.Message;
|
||||
_logger.LogError(msg, "An error occurred");
|
||||
}
|
||||
}
|
||||
GenreRepository genreStore = HttpContext.RequestServices
|
||||
.GetService(typeof(GenreRepository)) as GenreRepository;
|
||||
|
||||
[HttpDelete("{id}")]
|
||||
[Authorize("delete:songs")]
|
||||
public IActionResult Delete(int id)
|
||||
{
|
||||
SongRepository context = HttpContext
|
||||
.RequestServices
|
||||
.GetService(typeof(SongRepository)) as SongRepository;
|
||||
AlbumRepository albumStore = HttpContext
|
||||
.RequestServices
|
||||
.GetService(typeof(AlbumRepository)) as AlbumRepository;
|
||||
ArtistRepository artistStore = HttpContext
|
||||
.RequestServices
|
||||
.GetService(typeof(ArtistRepository)) as ArtistRepository;
|
||||
GenreRepository genreStore = HttpContext
|
||||
.RequestServices
|
||||
.GetService(typeof(GenreRepository)) as GenreRepository;
|
||||
YearRepository yearStore = HttpContext
|
||||
.RequestServices
|
||||
.GetService(typeof(YearRepository)) as YearRepository;
|
||||
|
||||
var songMetaData = new Song{ Id = id };
|
||||
Console.WriteLine($"Id {songMetaData.Id}");
|
||||
songMetaData = context.GetSong(songMetaData);
|
||||
YearRepository yearStore = HttpContext.RequestServices
|
||||
.GetService(typeof(YearRepository)) as YearRepository;
|
||||
|
||||
if (string.IsNullOrEmpty(songMetaData.Title))
|
||||
{
|
||||
_logger.LogInformation("Song does not exist");
|
||||
return NotFound("Song does not exist");
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogInformation("Starting process of deleting song from the filesystem and database");
|
||||
Console.WriteLine("Uploading song...");
|
||||
_logger.LogInformation("Uploading song...");
|
||||
|
||||
_songMgr.DeleteSong(songMetaData, context, albumStore,
|
||||
artistStore, genreStore, yearStore);
|
||||
var uploads = _songTempDir;
|
||||
Console.WriteLine($"Song Root Path {uploads}");
|
||||
_logger.LogInformation($"Song root path {uploads}");
|
||||
foreach (var sng in songData)
|
||||
if (sng.Length > 0) {
|
||||
Console.WriteLine($"Song filename {sng.FileName}");
|
||||
_logger.LogInformation($"Song filename {sng.FileName}");
|
||||
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
await _songMgr.SaveSongToFileSystem(sng, songRepository,
|
||||
albumStoreContext, artistStoreContext,
|
||||
genreStore, yearStore);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var msg = ex.Message;
|
||||
_logger.LogError(msg, "An error occurred");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpDelete("{id}")]
|
||||
[Authorize("delete:songs")]
|
||||
public IActionResult Delete(int id)
|
||||
{
|
||||
SongRepository context = HttpContext.RequestServices
|
||||
.GetService(typeof(SongRepository)) as SongRepository;
|
||||
|
||||
AlbumRepository albumStore = HttpContext.RequestServices
|
||||
.GetService(typeof(AlbumRepository)) as AlbumRepository;
|
||||
|
||||
ArtistRepository artistStore = HttpContext.RequestServices
|
||||
.GetService(typeof(ArtistRepository)) as ArtistRepository;
|
||||
|
||||
GenreRepository genreStore = HttpContext.RequestServices
|
||||
.GetService(typeof(GenreRepository)) as GenreRepository;
|
||||
|
||||
YearRepository yearStore = HttpContext.RequestServices
|
||||
.GetService(typeof(YearRepository)) as YearRepository;
|
||||
|
||||
var songMetaData = new Song{ Id = id };
|
||||
Console.WriteLine($"Id {songMetaData.Id}");
|
||||
songMetaData = context.GetSong(songMetaData);
|
||||
|
||||
if (string.IsNullOrEmpty(songMetaData.Title))
|
||||
{
|
||||
_logger.LogInformation("Song does not exist");
|
||||
return NotFound("Song does not exist");
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogInformation("Starting process of deleting song from the filesystem and database");
|
||||
|
||||
_songMgr.DeleteSong(songMetaData, context, albumStore,
|
||||
artistStore, genreStore, yearStore);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,52 +16,49 @@ using Icarus.Database.Repositories;
|
||||
|
||||
namespace Icarus.Controllers.V1
|
||||
{
|
||||
[Route("api/v1/song/stream")]
|
||||
[ApiController]
|
||||
public class SongStreamController : ControllerBase
|
||||
{
|
||||
#region Fields
|
||||
private ILogger<SongStreamController> _logger;
|
||||
#endregion
|
||||
[Route("api/v1/song/stream")]
|
||||
[ApiController]
|
||||
public class SongStreamController : ControllerBase
|
||||
{
|
||||
#region Fields
|
||||
private ILogger<SongStreamController> _logger;
|
||||
#endregion
|
||||
|
||||
|
||||
#region Properties
|
||||
#endregion
|
||||
#region Properties
|
||||
#endregion
|
||||
|
||||
|
||||
#region Constructor
|
||||
public SongStreamController(ILogger<SongStreamController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
#endregion
|
||||
#region Constructor
|
||||
public SongStreamController(ILogger<SongStreamController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region HTTP endpoints
|
||||
[HttpGet("{id}")]
|
||||
[Authorize("stream:songs")]
|
||||
public async Task<IActionResult> Get(int id)
|
||||
{
|
||||
var songStore= HttpContext
|
||||
.RequestServices
|
||||
.GetService(typeof(SongRepository)) as SongRepository;
|
||||
#region HTTP endpoints
|
||||
[HttpGet("{id}")]
|
||||
[Authorize("stream:songs")]
|
||||
public async Task<IActionResult> Get(int id)
|
||||
{
|
||||
var songStore= HttpContext.RequestServices
|
||||
.GetService(typeof(SongRepository)) as SongRepository;
|
||||
|
||||
var song = songStore.GetSong(new Song { Id = id });
|
||||
var song = songStore.GetSong(new Song { Id = id });
|
||||
|
||||
var mem = new MemoryStream();
|
||||
var mem = new MemoryStream();
|
||||
|
||||
using (var stream = new FileStream(song.SongPath, FileMode.Open, FileAccess.Read))
|
||||
{
|
||||
await stream.CopyToAsync(mem);
|
||||
}
|
||||
using (var stream = new FileStream(song.SongPath, FileMode.Open, FileAccess.Read))
|
||||
await stream.CopyToAsync(mem);
|
||||
|
||||
mem.Position = 0;
|
||||
mem.Position = 0;
|
||||
|
||||
_logger.LogInformation("Starting to stream song...>");
|
||||
Console.WriteLine("Starting to streamsong...");
|
||||
_logger.LogInformation("Starting to stream song...>");
|
||||
Console.WriteLine("Starting to streamsong...");
|
||||
|
||||
return File(mem, "application/octet-stream", Path.GetFileName(song.SongPath));
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
return File(mem, "application/octet-stream", Path.GetFileName(song.SongPath));
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,74 +11,66 @@ using Icarus.Database.Repositories;
|
||||
|
||||
namespace Icarus.Controller.V1
|
||||
{
|
||||
[Route("api/v1/year")]
|
||||
[ApiController]
|
||||
public class YearController : ControllerBase
|
||||
{
|
||||
#region Fields
|
||||
private readonly ILogger<YearController> _logger;
|
||||
#endregion
|
||||
[Route("api/v1/year")]
|
||||
[ApiController]
|
||||
public class YearController : ControllerBase
|
||||
{
|
||||
#region Fields
|
||||
private readonly ILogger<YearController> _logger;
|
||||
#endregion
|
||||
|
||||
|
||||
#region Properties
|
||||
#endregion
|
||||
#region Properties
|
||||
#endregion
|
||||
|
||||
|
||||
#region Constructors
|
||||
public YearController(ILogger<YearController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
#endregion
|
||||
#region Constructors
|
||||
public YearController(ILogger<YearController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region HTTP Routes
|
||||
[HttpGet]
|
||||
[Authorize("read:year")]
|
||||
public IActionResult Get()
|
||||
{
|
||||
var yearValues = new List<Year>();
|
||||
#region HTTP Routes
|
||||
[HttpGet]
|
||||
[Authorize("read:year")]
|
||||
public IActionResult Get()
|
||||
{
|
||||
var yearValues = new List<Year>();
|
||||
|
||||
var yearStore = HttpContext
|
||||
.RequestServices
|
||||
.GetService(typeof(YearRepository)) as YearRepository;
|
||||
var yearStore = HttpContext.RequestServices
|
||||
.GetService(typeof(YearRepository)) as YearRepository;
|
||||
|
||||
yearValues = yearStore.GetSongYears();
|
||||
yearValues = yearStore.GetSongYears();
|
||||
|
||||
if (yearValues.Count > 0)
|
||||
{
|
||||
return Ok(yearValues);
|
||||
}
|
||||
else
|
||||
{
|
||||
return NotFound(new List<Year>());
|
||||
}
|
||||
}
|
||||
if (yearValues.Count > 0)
|
||||
return Ok(yearValues);
|
||||
else
|
||||
return NotFound(new List<Year>());
|
||||
}
|
||||
|
||||
[HttpGet("{id}")]
|
||||
[Authorize("read:year")]
|
||||
public IActionResult Get(int id)
|
||||
{
|
||||
var year = new Year
|
||||
{
|
||||
YearId = id
|
||||
};
|
||||
[HttpGet("{id}")]
|
||||
[Authorize("read:year")]
|
||||
public IActionResult Get(int id)
|
||||
{
|
||||
var year = new Year
|
||||
{
|
||||
YearId = id
|
||||
};
|
||||
|
||||
var yearStore = HttpContext
|
||||
.RequestServices
|
||||
.GetService(typeof(YearRepository)) as YearRepository;
|
||||
var yearStore = HttpContext.RequestServices
|
||||
.GetService(typeof(YearRepository)) as YearRepository;
|
||||
|
||||
if (yearStore.DoesYearExist(year))
|
||||
{
|
||||
year = yearStore.GetSongYear(year);
|
||||
if (yearStore.DoesYearExist(year))
|
||||
{
|
||||
year = yearStore.GetSongYear(year);
|
||||
|
||||
return Ok(year);
|
||||
}
|
||||
else
|
||||
{
|
||||
return NotFound(new Year());
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
return Ok(year);
|
||||
}
|
||||
else
|
||||
return NotFound(new Year());
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user