Updates
This commit is contained in:
@@ -8,7 +8,8 @@ using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
using Icarus.Models;
|
||||
using Icarus.Database.Repositories;
|
||||
using Icarus.Database.Contexts;
|
||||
// using Icarus.Database.Repositories;
|
||||
|
||||
namespace Icarus.Controllers.V1
|
||||
{
|
||||
|
||||
@@ -10,7 +10,7 @@ using Microsoft.Extensions.Configuration;
|
||||
using Icarus.Controllers.Managers;
|
||||
using Icarus.Controllers.Utilities;
|
||||
using Icarus.Models;
|
||||
using Icarus.Database.Repositories;
|
||||
using Icarus.Database.Contexts;
|
||||
|
||||
namespace Icarus.Controllers.V1
|
||||
{
|
||||
@@ -41,12 +41,12 @@ namespace Icarus.Controllers.V1
|
||||
user.Password = pe.HashPassword(user);
|
||||
user.EmailVerified = false;
|
||||
|
||||
UserRepository context = HttpContext.RequestServices
|
||||
.GetService(typeof(UserRepository)) as UserRepository;
|
||||
var context = new UserContext(_config.GetConnectionString("DefaultConnection"));
|
||||
|
||||
try
|
||||
{
|
||||
context.SaveUser(user);
|
||||
context.Add(user);
|
||||
context.SaveChanges();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -61,7 +61,7 @@ namespace Icarus.Controllers.V1
|
||||
Username = user.Username
|
||||
};
|
||||
|
||||
if (context.DoesUserExist(user))
|
||||
if (context.Users.FirstOrDefault(sng => sng.Username.Equals(user.Username)) != null)
|
||||
{
|
||||
registerResult.Message = "Successful registration";
|
||||
registerResult.SuccessfullyRegistered = true;
|
||||
|
||||
@@ -14,7 +14,6 @@ using Microsoft.Extensions.Logging;
|
||||
using Icarus.Controllers.Managers;
|
||||
using Icarus.Models;
|
||||
using Icarus.Database.Contexts;
|
||||
using Icarus.Database.Repositories;
|
||||
|
||||
namespace Icarus.Controllers.V1
|
||||
{
|
||||
@@ -23,12 +22,6 @@ namespace Icarus.Controllers.V1
|
||||
public class SongDataController : ControllerBase
|
||||
{
|
||||
#region Fields
|
||||
private SongRepository _songRepository;
|
||||
private AlbumRepository _albumRepository;
|
||||
private ArtistRepository _artistRepository;
|
||||
private GenreRepository _genreRepository;
|
||||
private YearRepository _yearRepository;
|
||||
private CoverArtRepository _coverArtRepository;
|
||||
private IConfiguration _config;
|
||||
private ILogger<SongDataController> _logger;
|
||||
private SongManager _songMgr;
|
||||
@@ -50,33 +43,6 @@ namespace Icarus.Controllers.V1
|
||||
}
|
||||
#endregion
|
||||
|
||||
private void Initialize()
|
||||
{
|
||||
_songRepository = HttpContext
|
||||
.RequestServices
|
||||
.GetService
|
||||
(typeof(SongRepository)) as SongRepository;
|
||||
|
||||
_albumRepository = HttpContext
|
||||
.RequestServices
|
||||
.GetService(typeof(AlbumRepository)) as AlbumRepository;
|
||||
|
||||
_artistRepository = HttpContext
|
||||
.RequestServices
|
||||
.GetService(typeof(ArtistRepository)) as ArtistRepository;
|
||||
|
||||
_genreRepository = HttpContext
|
||||
.RequestServices
|
||||
.GetService(typeof(GenreRepository)) as GenreRepository;
|
||||
|
||||
_yearRepository = HttpContext
|
||||
.RequestServices
|
||||
.GetService(typeof(YearRepository)) as YearRepository;
|
||||
|
||||
_coverArtRepository = HttpContext
|
||||
.RequestServices
|
||||
.GetService(typeof(CoverArtRepository)) as CoverArtRepository;
|
||||
}
|
||||
|
||||
|
||||
[HttpGet("{id}")]
|
||||
@@ -84,7 +50,6 @@ namespace Icarus.Controllers.V1
|
||||
[Authorize("download:songs")]
|
||||
public async Task<IActionResult> Get(int id)
|
||||
{
|
||||
Initialize();
|
||||
var songMetaData = _songRepository.GetSong(id);
|
||||
|
||||
SongData song = await _songMgr.RetrieveSong(songMetaData);
|
||||
@@ -98,8 +63,6 @@ namespace Icarus.Controllers.V1
|
||||
{
|
||||
try
|
||||
{
|
||||
Initialize();
|
||||
|
||||
Console.WriteLine("Uploading song...");
|
||||
_logger.LogInformation("Uploading song...");
|
||||
|
||||
@@ -127,10 +90,8 @@ namespace Icarus.Controllers.V1
|
||||
[Authorize("delete:songs")]
|
||||
public IActionResult Delete(int id)
|
||||
{
|
||||
Initialize();
|
||||
|
||||
var songMetaData = new Song{ Id = id };
|
||||
Console.WriteLine($"Id {songMetaData.Id}");
|
||||
var songMetaData = new Song{ SongID = id };
|
||||
Console.WriteLine($"Id {songMetaData.SongID}");
|
||||
songMetaData = _songRepository.GetSong(songMetaData);
|
||||
|
||||
if (string.IsNullOrEmpty(songMetaData.Title))
|
||||
|
||||
@@ -9,10 +9,11 @@ using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
using Icarus.Models;
|
||||
using Icarus.Database.Repositories;
|
||||
using Icarus.Database.Contexts;
|
||||
|
||||
namespace Icarus.Controllers.V1
|
||||
{
|
||||
@@ -22,6 +23,7 @@ namespace Icarus.Controllers.V1
|
||||
{
|
||||
#region Fields
|
||||
private ILogger<SongStreamController> _logger;
|
||||
private IConfiguration _config;
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -30,9 +32,10 @@ namespace Icarus.Controllers.V1
|
||||
|
||||
|
||||
#region Constructor
|
||||
public SongStreamController(ILogger<SongStreamController> logger)
|
||||
public SongStreamController(ILogger<SongStreamController> logger, IConfiguration config)
|
||||
{
|
||||
_logger = logger;
|
||||
_config = config;
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -42,10 +45,9 @@ namespace Icarus.Controllers.V1
|
||||
[Authorize("stream:songs")]
|
||||
public async Task<IActionResult> Get(int id)
|
||||
{
|
||||
var songStore= HttpContext.RequestServices
|
||||
.GetService(typeof(SongRepository)) as SongRepository;
|
||||
var context = new SongContext(_config.GetConnectionString("DefaultConnection"));
|
||||
|
||||
var song = songStore.GetSong(new Song { Id = id });
|
||||
var song = context.Songs.FirstOrDefault(sng => sng.SongID == id);
|
||||
|
||||
var stream = new FileStream(song.SongPath, FileMode.Open, FileAccess.Read);
|
||||
stream.Position = 0;
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
using Icarus.Models;
|
||||
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
|
||||
|
||||
|
||||
#region Properties
|
||||
#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>();
|
||||
|
||||
var yearStore = HttpContext.RequestServices
|
||||
.GetService(typeof(YearRepository)) as YearRepository;
|
||||
|
||||
yearValues = yearStore.GetSongYears();
|
||||
|
||||
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
|
||||
};
|
||||
|
||||
var yearStore = HttpContext.RequestServices
|
||||
.GetService(typeof(YearRepository)) as YearRepository;
|
||||
|
||||
if (yearStore.DoesYearExist(year))
|
||||
{
|
||||
year = yearStore.GetSongYear(year);
|
||||
|
||||
return Ok(year);
|
||||
}
|
||||
else
|
||||
return NotFound(new Year());
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user