Added functionality to retrieve cover art records in json format

This commit is contained in:
amazing-username
2019-07-29 01:07:16 +00:00
parent 3948e25fc3
commit 2c3152a9a5
3 changed files with 58 additions and 7 deletions
+24 -1
View File
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
@@ -31,9 +32,31 @@ namespace Icarus.Controllers.V1
#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}")]
[Authorize("download:cover_art")]
public IActionResult Get(int id)
public async Task<IActionResult> Get(int id)
{
var coverArt = new CoverArt { CoverArtId = id };
+28 -1
View File
@@ -19,6 +19,32 @@ namespace Icarus.Database.Repositories
#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)
{
try
@@ -194,7 +220,8 @@ namespace Icarus.Database.Repositories
{
CoverArtId = Convert.ToInt32(reader["CoverArtId"]),
SongTitle = reader["SongTitle"].ToString(),
ImagePath = reader["ImagePath"].ToString()
ImagePath = reader["ImagePath"].ToString(),
SongId = Convert.ToInt32(reader["SongId"].ToString())
});
return coverArtList;
+6 -5
View File
@@ -11,11 +11,12 @@ namespace Icarus.Models
[JsonProperty("id")]
public int CoverArtId { get; set; }
[JsonProperty("title")]
public string SongTitle { get; set; }
public string SongTitle { get; set; }
[JsonIgnore]
public string ImagePath { get; set; }
[JsonIgnore]
public List<Song> Songs { get; set; }
public string ImagePath { get; set; }
[JsonProperty("song_id")]
public int SongId { get; set; }
[JsonIgnore]
public List<Song> Songs { get; set; }
}
}