This commit is contained in:
Steven Hildreth 2018-11-04 18:08:37 -06:00
parent c0d5e5dc24
commit 6becfabd3c
13 changed files with 288 additions and 38 deletions

View file

@ -70,6 +70,8 @@ namespace Roadie.Api.Data.Models
}
}
public List<AssociatedArtist> AssociatedArtists { get; set; }
public Artist()
{
this.BandStatus = "1";

View file

@ -0,0 +1,14 @@
using Mapster;
using System;
using System.Collections.Generic;
using System.Text;
namespace Roadie.Api.Data.Models
{
[Serializable]
public class AssociatedArtist
{
[AdaptMember("AssociatedArtist")]
public AssociatedArtistInfo AssociatedArtistInfo { get; set; }
}
}

View file

@ -0,0 +1,22 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Text;
namespace Roadie.Api.Data.Models
{
[Serializable]
public class AssociatedArtistInfo : EntityInfoModelBase
{
public string Name { get; set; }
public string Tooltip
{
get
{
return this.Name;
}
}
}
}

View file

@ -0,0 +1,21 @@
using Mapster;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text;
namespace Roadie.Api.Data.Models
{
[Serializable]
public abstract class EntityInfoModelBase
{
[Key]
[Required]
[AdaptMember("RoadieId")]
public Guid Id { get; set; }
[MaxLength(250)]
public string SortName { get; set; }
}
}

View file

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text;
namespace Roadie.Api.Data.Models
{
[Serializable]
public class Image : EntityModelBase
{
public int? ArtistId { get; set; }
public byte[] Bytes { get; set; }
[MaxLength(100)]
public string Caption { get; set; }
public int? ReleaseId { get; set; }
[MaxLength(50)]
public string Signature { get; set; }
[MaxLength(500)]
public string Url { get; set; }
}
}

View file

@ -11,6 +11,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using models = Roadie.Api.Data.Models;
using Microsoft.EntityFrameworkCore;
namespace Roadie.Api.Controllers
{
@ -23,7 +24,10 @@ namespace Roadie.Api.Controllers
public ArtistController(IRoadieDbContext RoadieDbContext, ILoggerFactory logger, ICacheManager cacheManager, IConfiguration configuration)
: base(RoadieDbContext, cacheManager, configuration)
{
this._logger = logger.CreateLogger("RoadieApi.Controllers.ArtistController"); ;
this._logger = logger.CreateLogger("RoadieApi.Controllers.ArtistController");
}
[EnableQuery]
@ -40,9 +44,12 @@ namespace Roadie.Api.Controllers
var key = id.ToString();
var result = this._cacheManager.Get<models.Artist>(key, () =>
{
var d = this._RoadieDbContext.Artists.FirstOrDefault(x => x.RoadieId == id);
var d = this._RoadieDbContext.Artists
.Include(x => x.AssociatedArtists).Include("AssociatedArtists.AssociatedArtist")
.FirstOrDefault(x => x.RoadieId == id);
if (d != null)
{
// var info = d.AssociatedArtists.Adapt<models.AssociatedArtistInfo>();
return d.Adapt<models.Artist>();
}
return null;

View file

@ -13,14 +13,28 @@ namespace Roadie.Api.Controllers
protected readonly ICacheManager _cacheManager;
protected readonly IConfiguration _configuration;
protected readonly IRoadieDbContext _RoadieDbContext;
protected readonly IRoadieSettings _roadieSettings;
protected ILogger _logger;
protected IRoadieSettings RoadieSettings
{
get
{
return this._roadieSettings;
}
}
public EntityControllerBase(IRoadieDbContext RoadieDbContext, ICacheManager cacheManager, IConfiguration configuration)
{
this._RoadieDbContext = RoadieDbContext;
this._cacheManager = cacheManager;
this._configuration = configuration;
this._roadieSettings = new RoadieSettings();
this._configuration.GetSection("RoadieSettings").Bind(this._roadieSettings);
}
}
}

View file

@ -0,0 +1,56 @@
using Mapster;
using Microsoft.AspNet.OData;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Roadie.Library.Configuration;
using Roadie.Library.Caching;
using Roadie.Library.Data;
using System;
using System.Linq;
using models = Roadie.Api.Data.Models;
namespace Roadie.Api.Controllers
{
[Produces("application/json")]
[Route("image")]
[ApiController]
[Authorize]
public class ImageController : EntityControllerBase
{
public ImageController(IRoadieDbContext RoadieDbContext, ILoggerFactory logger, ICacheManager cacheManager, IConfiguration configuration)
: base(RoadieDbContext, cacheManager, configuration)
{
this._logger = logger.CreateLogger("RoadieApi.Controllers.ImageController"); ;
}
[EnableQuery]
public IActionResult Get()
{
return Ok(this._RoadieDbContext.Tracks.ProjectToType<models.Image>());
}
[HttpGet("{id}")]
[ProducesResponseType(200)]
[ProducesResponseType(404)]
public IActionResult Get(Guid id)
{
var key = id.ToString();
var result = this._cacheManager.Get<models.Image>(key, () =>
{
var d = this._RoadieDbContext.Images.FirstOrDefault(x => x.RoadieId == id);
if (d != null)
{
return d.Adapt<models.Image>();
}
return null;
}, key);
if (result == null)
{
return NotFound();
}
return Ok(result);
}
}
}

View file

@ -4,7 +4,6 @@ using Microsoft.AspNet.OData.Extensions;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
@ -13,16 +12,15 @@ using Microsoft.Extensions.Logging;
using Microsoft.IdentityModel.Tokens;
using Microsoft.OData.Edm;
using Newtonsoft.Json;
using Roadie.Library.Configuration;
using Roadie.Api.Services;
using Roadie.Library.Caching;
using Roadie.Library.Data;
using Roadie.Library.Encoding;
using Roadie.Library.Identity;
using System;
using System.IO;
using System.Reflection;
using models = Roadie.Api.Data.Models;
using Roadie.Library.Encoding;
namespace Roadie.Api
{
@ -31,6 +29,17 @@ namespace Roadie.Api
private readonly IConfiguration _configuration;
private readonly ILoggerFactory _loggerFactory;
public static string AssemblyDirectory
{
get
{
string codeBase = Assembly.GetExecutingAssembly().CodeBase;
var uri = new UriBuilder(codeBase);
string path = Uri.UnescapeDataString(uri.Path);
return Path.GetDirectoryName(path);
}
}
public Startup(IConfiguration configuration, ILoggerFactory loggerFactory)
{
this._configuration = configuration;
@ -63,17 +72,6 @@ namespace Roadie.Api
});
}
public static string AssemblyDirectory
{
get
{
string codeBase = Assembly.GetExecutingAssembly().CodeBase;
var uri = new UriBuilder(codeBase);
string path = Uri.UnescapeDataString(uri.Path);
return Path.GetDirectoryName(path);
}
}
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
@ -162,9 +160,9 @@ namespace Roadie.Api
.AddJsonOptions(options =>
{
options.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
})
.SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
}
private static IEdmModel GetEdmModel()

View file

@ -22,33 +22,111 @@
"Audience": "http://localhost:5500"
},
"ConnectionStrings": {
"RoadieDatabaseConnection": "server=voyager;userid=Roadie;password=MenAtW0rk668;persistsecurityinfo=True;database=Roadie;ConvertZeroDateTime=true"
"RoadieDatabaseConnection": "server=voyager;userid=roadie;password=MenAtW0rk668;persistsecurityinfo=True;database=roadie;ConvertZeroDateTime=true"
},
"Settings": {
"SecretKey": "a9kf^!y@rd-ci0&7l#da6ko$(l@_$9(y^r^a@2j+8!7zpk!zw88wi069",
"RoadieSettings": {
"SiteName": "Roadie",
"DefaultTimeZone": "US/Central",
"DiagnosticsPassword": "RoadieDiagPassword",
"InboundFolder": "Z:/incoming/",
"LibraryFolder": "Z:/library/",
"Thumbnails": {
"Height": 80,
"Width": 80
},
"MediumThumbnails": {
"Height": 160,
"Width": 160
},
"LargeThumbnails": {
"Height": 320,
"Width": 320
},
"DontDoMetaDataProvidersSearchArtists": [ "Various Artists", "Sound Tracks" ],
"FileExtenionsToDelete": [ ".cue", ".db", ".gif", ".html", ".ini", ".jpg", ".jpeg", ".log", ".mpg", ".m3u", ".png", ".nfo", ".nzb", ".sfv", ".srr", ".txt", ".url" ],
"RecordNoResultSearches": true,
"SingleArtistHoldingFolder": "Z:/single_holding/",
"ArtistNameReplace": {
"AC/DC": [ "AC; DC", "AC;DC", "AC/ DC", "AC DC" ],
"Love/Hate": [ "Love; Hate", "Love;Hate", "Love/ Hate", "Love Hate" ]
},
"ApiKeys": [
{
"ApiName": "BingImageSearch",
"Key": "<KEY HERE>"
},
{
"ApiName": "LastFMApiKey",
"Key": "<KEY HERE>",
"KeySecret": "<SECRET HERE>"
},
{
"ApiName": "DiscogsConsumerKey",
"Key": "<KEY HERE>",
"KeySecret": "<SECRET HERE>"
}
]
"Converting": {
"DoDeleteAfter": true,
"M4AConvertCommand": "ffmpeg -i \"{0}\" -acodec libmp3lame -q:a 0 \"{1}\"",
"OGGConvertCommand": "ffmpeg -i \"{0}\" -acodec libmp3lame -q:a 0 \"{1}\"\"",
"APEConvertCommand": "ffmpeg -i \"{0}\" \"{1}\""
},
"Integrations": {
"ITunesProviderEnabled": true,
"MusicBrainzProviderEnabled": true,
"SpotifyProviderEnabled": true,
"ApiKeys": [
{
"ApiName": "BingImageSearch",
"Key": "<KEY HERE>"
},
{
"ApiName": "LastFMApiKey",
"Key": "<KEY HERE>",
"KeySecret": "<SECRET HERE>"
},
{
"ApiName": "DiscogsConsumerKey",
"Key": "<KEY HERE>",
"KeySecret": "<SECRET HERE>"
}
]
},
"Processing": {
"DoAudioCleanup": true,
"DoSaveEditsToTags": true,
"DoClearComments": true,
"DoParseFromFileName": true,
"DoParseFromDiscogsDBFindingTrackForArtist": true,
"DoParseFromDiscogsDB": true,
"DoParseFromMusicBrainz": true,
"DoParseFromLastFM": true,
"MaximumArtistImagesToAdd": 12,
"MaximumReleaseImagesToAdd": 12,
"MaxImageWidth": 800,
"RemoveStringsRegex": "\\b[0-9]+\\s#\\s\\b",
"ReplaceStrings": [
{
"order": 1,
"key": "-OBSERVER",
"replaceWith": ""
},
{
"order": 2,
"key": "[Torrent Tatty]",
"replaceWith": ""
},
{
"order": 3,
"key": "_",
"replaceWith": ""
},
{
"order": 4,
"key": "-",
"replaceWith": ""
},
{
"order": 5,
"key": "~",
"replaceWith": ""
},
{
"order": 6,
"key": "^",
"replaceWith": ""
},
{
"order": 7,
"key": "#",
"replaceWith": ""
}
]
}
}
}

View file

@ -16,7 +16,9 @@ namespace Roadie.Library.Data
[Column("artistType", TypeName = "enum")]
public string ArtistType { get; set; }
public ICollection<ArtistAssociation> AssociatedArtists { get; set; }
public virtual ICollection<ArtistAssociation> AssociatedArtists { get; set; }
public virtual ICollection<ArtistAssociation> AssociatedArtists1 { get; set; }
[Column("bandStatus", TypeName = "enum")]
public BandStatus? BandStatus { get; set; }

View file

@ -15,7 +15,6 @@ namespace Roadie.Library.Data
public Artist AssociatedArtist { get; set; }
[Column("associatedArtistId")]
[Required]
public int AssociatedArtistId { get; set; }
[Key]

View file

@ -121,6 +121,17 @@ namespace Roadie.Library.Data
.HasOne(b => b.User)
.WithMany(u => u.Bookmarks)
.HasForeignKey(b => b.UserId);
// I dont understand why the "1" but without this self join generates "1" based columns on the selectd and blows up ef.
builder.Entity<Artist>()
.HasMany(e => e.AssociatedArtists)
.WithOne(e => e.Artist)
.HasForeignKey(e => e.ArtistId);
builder.Entity<Artist>()
.HasMany(e => e.AssociatedArtists1)
.WithOne(e => e.AssociatedArtist)
.HasForeignKey(e => e.AssociatedArtistId);
}
}
}