Partially implemented updating song metadata. Need to make it more dynamic, meaning only update attributes that have values sent with the request. #36
This commit is contained in:
@@ -9,15 +9,16 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
using Icarus.Controllers.Managers;
|
||||
using Icarus.Controllers.Utilities;
|
||||
using Icarus.Models;
|
||||
using Icarus.Models.Context;
|
||||
|
||||
namespace Icarus.Controllers
|
||||
{
|
||||
[Route("api/song")]
|
||||
[ApiController]
|
||||
public class SongController : ControllerBase
|
||||
{
|
||||
[Route("api/song")]
|
||||
[ApiController]
|
||||
public class SongController : ControllerBase
|
||||
{
|
||||
#region Fields
|
||||
private IConfiguration _config;
|
||||
private MusicStoreContext _context;
|
||||
@@ -38,10 +39,10 @@ namespace Icarus.Controllers
|
||||
#endregion
|
||||
|
||||
|
||||
[HttpGet]
|
||||
[HttpGet]
|
||||
[Authorize("read:song_details")]
|
||||
public ActionResult<IEnumerable<Song>> Get()
|
||||
{
|
||||
public ActionResult<IEnumerable<Song>> Get()
|
||||
{
|
||||
List<Song> songs = new List<Song>();
|
||||
Console.WriteLine("Attemtping to retrieve songs");
|
||||
|
||||
@@ -53,7 +54,7 @@ namespace Icarus.Controllers
|
||||
songs = context.GetAllSongs();
|
||||
|
||||
return songs;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("{id}")]
|
||||
public ActionResult<Song> Get(int id)
|
||||
@@ -69,14 +70,25 @@ namespace Icarus.Controllers
|
||||
}
|
||||
|
||||
|
||||
[HttpPut("{id}")]
|
||||
public IActionResult Put(int id, [FromBody] Song song)
|
||||
{
|
||||
[HttpPut("{id}")]
|
||||
public IActionResult Put(int id, [FromBody] Song song)
|
||||
{
|
||||
// TODO: Implement updating of song metadata
|
||||
MusicStoreContext context = HttpContext.RequestServices
|
||||
.GetService(typeof(MusicStoreContext)) as MusicStoreContext;
|
||||
Console.WriteLine("Retrieving filepath of song");
|
||||
var songPath = context.GetSong(id).SongPath;
|
||||
song.SongPath = songPath;
|
||||
|
||||
MetadataRetriever updateMetadata = new MetadataRetriever();
|
||||
updateMetadata.UpdateMetadata(song);
|
||||
|
||||
context.UpdateSong(song);
|
||||
|
||||
SongResult songResult = new SongResult();
|
||||
|
||||
return Ok(songResult);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpDelete("{id}")]
|
||||
public void Delete(int id)
|
||||
|
||||
Reference in New Issue
Block a user