Added but did not complete the repository for cover art, updated migration script to create migration for CoverArt, and prepping for the cover art api
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using MySql.Data;
|
||||
using MySql.Data.EntityFrameworkCore.Extensions;
|
||||
using MySql.Data.MySqlClient;
|
||||
|
||||
using Icarus.Models;
|
||||
|
||||
namespace Icarus.Database.Contexts
|
||||
{
|
||||
public class CoverArtContext : DbContext
|
||||
{
|
||||
public DbSet<CoverArt> CoverArtImages { get; set; }
|
||||
|
||||
public CoverArtContext(DbContextOptions<CoverArtContext> options) : base(options) { }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<CoverArt>()
|
||||
.ToTable("CoverArt");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,6 +46,12 @@ namespace Icarus.Database.Contexts
|
||||
.HasForeignKey(s => s.YearId)
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
|
||||
modelBuilder.Entity<Song>()
|
||||
.HasOne(s => s.SongCoverArt)
|
||||
.WithMany(ca => ca.Songs)
|
||||
.HasForeignKey(s => s.CoverArtId)
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
|
||||
modelBuilder.Entity<Song>()
|
||||
.Property(s => s.Year)
|
||||
.IsRequired(false);
|
||||
@@ -61,6 +67,9 @@ namespace Icarus.Database.Contexts
|
||||
modelBuilder.Entity<Song>()
|
||||
.Property(s => s.AlbumId)
|
||||
.IsRequired(false);
|
||||
modelBuilder.Entity<Song>()
|
||||
.Property(s => s.CoverArtId)
|
||||
.IsRequired(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using MySql.Data.MySqlClient;
|
||||
|
||||
using Icarus.Models;
|
||||
|
||||
namespace Icarus.Database.Repositories
|
||||
{
|
||||
public class CoverArtRepository : BaseRepository
|
||||
{
|
||||
#region Constructors
|
||||
public CoverArtRepository(string connectionString)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region Methods
|
||||
public CoverArt GetCoverArt(Song song)
|
||||
{
|
||||
// TODO: Implement sql record retrieval
|
||||
return null;
|
||||
}
|
||||
|
||||
public void DeleteCoverArt(CoverArt coverArt)
|
||||
{
|
||||
try
|
||||
{
|
||||
// TODO: Implement sql record deletion
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var msg = ex.Message;
|
||||
_logger.Error(msg, "An error occurred");
|
||||
}
|
||||
}
|
||||
|
||||
private List<CoverArt> ParseData(MySqlDataReader reader)
|
||||
{
|
||||
if (reader.HasRows)
|
||||
{
|
||||
var coverArtList = new List<CoverArt>();
|
||||
while (reader.Read())
|
||||
coverArtList.Add(new CoverArt
|
||||
{
|
||||
CoverArtId = Convert.ToInt32(reader["CoverArtId"]),
|
||||
SongTitle = reader["SongTitle"].ToString(),
|
||||
ImagePath = reader["ImagePath"].ToString()
|
||||
});
|
||||
|
||||
return coverArtList;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private CoverArt ParseSingleData(MySqlDataReader reader)
|
||||
{
|
||||
if (reader.HasRows)
|
||||
{
|
||||
reader.Read();
|
||||
|
||||
return new CoverArt
|
||||
{
|
||||
CoverArtId = Convert.ToInt32(reader["CoverArtId"]),
|
||||
SongTitle = reader["SongTitle"].ToString(),
|
||||
ImagePath = reader["ImagePath}"].ToString()
|
||||
};
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private bool? AnyCoverArt()
|
||||
{
|
||||
using (var conn = GetConnection())
|
||||
{
|
||||
conn.Open();
|
||||
|
||||
var query = "SELECT * FROM CoverArt";
|
||||
|
||||
using (var cmd = new MySqlCommand(query, conn))
|
||||
using (var reader = cmd.ExecuteReader())
|
||||
return reader.HasRows;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+5
-1
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
using Newtonsoft.Json;
|
||||
@@ -8,10 +9,13 @@ namespace Icarus.Models
|
||||
public class CoverArt
|
||||
{
|
||||
[JsonProperty("id")]
|
||||
public int Id { get; set; }
|
||||
public int CoverArtId { get; set; }
|
||||
[JsonProperty("title")]
|
||||
public string SongTitle { get; set; }
|
||||
[JsonIgnore]
|
||||
public string ImagePath { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public List<Song> Songs { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,5 +45,10 @@ namespace Icarus.Models
|
||||
public Year SongYear { get; set; }
|
||||
[JsonIgnore]
|
||||
public int? YearId { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public CoverArt SongCoverArt { get; set; }
|
||||
[JsonIgnore]
|
||||
public int? CoverArtId { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@ echo "Adding Genre migration"
|
||||
dotnet ef migrations add Genre --context GenreContext
|
||||
echo "Adding Year migration"
|
||||
dotnet ef migrations add Year --context YearContext
|
||||
echo "Adding Cover art migration"
|
||||
dotnet ef migrations add CoverArt --context CoverArtContext
|
||||
|
||||
echo "Updating migrations.."
|
||||
echo "Updating User migration"
|
||||
@@ -20,4 +22,5 @@ echo "Updating Album migration"
|
||||
echo "Updating Artist migration"
|
||||
echo "Updating Genre migration"
|
||||
echo "Updating Year migration"
|
||||
echo "Updating Cover art migration"
|
||||
dotnet ef database update --context SongContext
|
||||
|
||||
@@ -119,6 +119,9 @@ namespace Icarus
|
||||
services.Add(new ServiceDescriptor(typeof(YearRepository),
|
||||
new YearRepository(Configuration.GetConnectionString("DefaultConnection"))));
|
||||
|
||||
services.Add(new ServiceDescriptor(typeof(CoverArtRepository),
|
||||
new CoverArtRepository(Configuration.GetConnectionString("DefaultConnection"))));
|
||||
|
||||
services.Add(new ServiceDescriptor(typeof(UserRepository),
|
||||
new UserRepository(Configuration.GetConnectionString("DefaultConnection"))));
|
||||
|
||||
@@ -128,6 +131,7 @@ namespace Icarus
|
||||
services.AddDbContext<UserContext>(options => options.UseMySQL(connString));
|
||||
services.AddDbContext<GenreContext>(options => options.UseMySQL(connString));
|
||||
services.AddDbContext<YearContext>(options => options.UseMySQL(connString));
|
||||
services.AddDbContext<CoverArtContext>(options => options.UseMySQL(connString));
|
||||
}
|
||||
|
||||
// Called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
|
||||
Reference in New Issue
Block a user