Created functionality to upload song data. #6
This commit is contained in:
@@ -0,0 +1,75 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Configuration;
|
||||||
|
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
|
||||||
|
using MySql.Data;
|
||||||
|
using MySql.Data.MySqlClient;
|
||||||
|
|
||||||
|
using Icarus.Models;
|
||||||
|
|
||||||
|
namespace Icarus.Controllers.Managers
|
||||||
|
{
|
||||||
|
public class SongManager
|
||||||
|
{
|
||||||
|
#region Fields
|
||||||
|
private List<Song> _songs;
|
||||||
|
private Song _song;
|
||||||
|
private IConfiguration _config;
|
||||||
|
private string _connectionString;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region Properties
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region Constructors
|
||||||
|
public SongManager()
|
||||||
|
{
|
||||||
|
Initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
public SongManager(Song song)
|
||||||
|
{
|
||||||
|
Initialize();
|
||||||
|
_song = song;
|
||||||
|
}
|
||||||
|
public SongManager(IConfiguration config)
|
||||||
|
{
|
||||||
|
Initialize();
|
||||||
|
_config = config;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region Methods
|
||||||
|
public void SaveSong(Song song)
|
||||||
|
{
|
||||||
|
_song = song;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Song RetrieveSong(int id)
|
||||||
|
{
|
||||||
|
return new Song();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Initialize()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_connectionString = _config.GetConnectionString("IcarusDev");
|
||||||
|
Console.WriteLine(_connectionString);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Error Occurred: {ex.Message}");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
|
||||||
|
using Icarus.Controllers.Managers;
|
||||||
|
using Icarus.Models;
|
||||||
|
|
||||||
|
namespace Icarus.Controllers
|
||||||
|
{
|
||||||
|
[Route("api/Song")]
|
||||||
|
[ApiController]
|
||||||
|
public class SongController : ControllerBase
|
||||||
|
{
|
||||||
|
#region Fields
|
||||||
|
private SongManager _songMgr;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region Properties
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region Constructor
|
||||||
|
public SongController(IConfiguration config)
|
||||||
|
{
|
||||||
|
_songMgr = new SongManager(config);
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
// GET api/song
|
||||||
|
[HttpGet]
|
||||||
|
public ActionResult<IEnumerable<Song>> Get()
|
||||||
|
{
|
||||||
|
List<Song> songs = new List<Song>();
|
||||||
|
|
||||||
|
|
||||||
|
return songs;
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET api/song/5
|
||||||
|
[HttpGet("{id}")]
|
||||||
|
public ActionResult<Song> Get(int id)
|
||||||
|
{
|
||||||
|
Song song = _songMgr.RetrieveSong(id);
|
||||||
|
|
||||||
|
return song;
|
||||||
|
}
|
||||||
|
|
||||||
|
// POST api/song
|
||||||
|
[HttpPost]
|
||||||
|
public void Post([FromBody] Song song)
|
||||||
|
{
|
||||||
|
Console.WriteLine("The song's title is: ");
|
||||||
|
Console.WriteLine(song.Title);
|
||||||
|
_songMgr.SaveSong(song);
|
||||||
|
}
|
||||||
|
|
||||||
|
// PUT api/song/5
|
||||||
|
[HttpPut("{id}")]
|
||||||
|
public void Put(int id, [FromBody] Song song)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// DELETE api/song/5
|
||||||
|
[HttpDelete("{id}")]
|
||||||
|
public void Delete(int id)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,6 +8,8 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.AspNetCore.App" />
|
<PackageReference Include="Microsoft.AspNetCore.App" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
|
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
|
||||||
|
<PackageReference Include="mysql.data" Version="8.0.15" />
|
||||||
|
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -1,15 +1,26 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace Icarus.Models
|
namespace Icarus.Models
|
||||||
{
|
{
|
||||||
public class Song
|
public class Song
|
||||||
{
|
{
|
||||||
|
[JsonProperty("id")]
|
||||||
|
public int Id { get; set; }
|
||||||
|
[JsonProperty("title")]
|
||||||
public string Title { get; set; }
|
public string Title { get; set; }
|
||||||
|
[JsonProperty("album")]
|
||||||
public string Album { get; set; }
|
public string Album { get; set; }
|
||||||
|
[JsonProperty("artist")]
|
||||||
public string Artist { get; set; }
|
public string Artist { get; set; }
|
||||||
|
[JsonProperty("year")]
|
||||||
public int Year { get; set; }
|
public int Year { get; set; }
|
||||||
|
[JsonProperty("genre")]
|
||||||
public string Genre { get; set; }
|
public string Genre { get; set; }
|
||||||
|
[JsonProperty("duration")]
|
||||||
public int Duration { get; set; }
|
public int Duration { get; set; }
|
||||||
|
[JsonProperty("song_data")]
|
||||||
public byte[] SongFile { get; set; }
|
public byte[] SongFile { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user