Added functionality to retrieve cover art records in json format
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
@@ -31,9 +32,31 @@ namespace Icarus.Controllers.V1
|
|||||||
|
|
||||||
|
|
||||||
#region HTTP Routes
|
#region HTTP Routes
|
||||||
|
public async Task<IActionResult> Get()
|
||||||
|
{
|
||||||
|
var coverArtRepository = HttpContext
|
||||||
|
.RequestServices
|
||||||
|
.GetService(
|
||||||
|
typeof(CoverArtRepository)) as CoverArtRepository;
|
||||||
|
|
||||||
|
var coverArtRecords = coverArtRepository.GetCoverArtRecords();
|
||||||
|
|
||||||
|
if (coverArtRecords == null)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("No cover art records");
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Found cover art records");
|
||||||
|
return Ok(coverArtRecords);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
[HttpGet("{id}")]
|
[HttpGet("{id}")]
|
||||||
[Authorize("download:cover_art")]
|
[Authorize("download:cover_art")]
|
||||||
public IActionResult Get(int id)
|
public async Task<IActionResult> Get(int id)
|
||||||
{
|
{
|
||||||
var coverArt = new CoverArt { CoverArtId = id };
|
var coverArt = new CoverArt { CoverArtId = id };
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,32 @@ namespace Icarus.Database.Repositories
|
|||||||
|
|
||||||
|
|
||||||
#region Methods
|
#region Methods
|
||||||
|
public List<CoverArt> GetCoverArtRecords()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var conn = GetConnection())
|
||||||
|
{
|
||||||
|
conn.Open();
|
||||||
|
|
||||||
|
_logger.Info("Querying cover art records");
|
||||||
|
|
||||||
|
var query = "SELECT cv.*, sng.Id AS SongId FROM CoverArt " +
|
||||||
|
"cv LEFT JOIN Song sng ON cv.CoverArtId=sng.CoverArtId";
|
||||||
|
|
||||||
|
using (var cmd = new MySqlCommand(query, conn))
|
||||||
|
using (var reader = cmd.ExecuteReader())
|
||||||
|
return ParseData(reader);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
var msg = ex.Message;
|
||||||
|
_logger.Error(msg, "An error occurred");
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
public CoverArt GetCoverArt(CoverArt cover)
|
public CoverArt GetCoverArt(CoverArt cover)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -194,7 +220,8 @@ namespace Icarus.Database.Repositories
|
|||||||
{
|
{
|
||||||
CoverArtId = Convert.ToInt32(reader["CoverArtId"]),
|
CoverArtId = Convert.ToInt32(reader["CoverArtId"]),
|
||||||
SongTitle = reader["SongTitle"].ToString(),
|
SongTitle = reader["SongTitle"].ToString(),
|
||||||
ImagePath = reader["ImagePath"].ToString()
|
ImagePath = reader["ImagePath"].ToString(),
|
||||||
|
SongId = Convert.ToInt32(reader["SongId"].ToString())
|
||||||
});
|
});
|
||||||
|
|
||||||
return coverArtList;
|
return coverArtList;
|
||||||
|
|||||||
+2
-1
@@ -14,7 +14,8 @@ namespace Icarus.Models
|
|||||||
public string SongTitle { get; set; }
|
public string SongTitle { get; set; }
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public string ImagePath { get; set; }
|
public string ImagePath { get; set; }
|
||||||
|
[JsonProperty("song_id")]
|
||||||
|
public int SongId { get; set; }
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public List<Song> Songs { get; set; }
|
public List<Song> Songs { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user