This commit is contained in:
Steven Hildreth 2019-11-17 08:10:17 -06:00
parent 97300534a4
commit df47a9c918
47 changed files with 239 additions and 83 deletions

View file

@ -2,6 +2,7 @@
using Microsoft.Extensions.Configuration;
using Roadie.Library.Configuration;
using Roadie.Library.Data;
using Roadie.Library.Data.Context;
using Roadie.Library.FilePlugins;
using Roadie.Library.Imaging;
using System;

View file

@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Roadie.Library.Configuration
{
public enum DbContexts : short
{
MySQL = 1
}
}

View file

@ -4,6 +4,7 @@ namespace Roadie.Library.Configuration
{
public interface IRoadieSettings
{
DbContexts DbContextToUse { get; set; }
Dictionary<string, IEnumerable<string>> ArtistNameReplace { get; set; }
string BehindProxyHost { get; set; }
string CollectionImageFolder { get; }

View file

@ -7,6 +7,8 @@ namespace Roadie.Library.Configuration
[Serializable]
public sealed class RoadieSettings : IRoadieSettings
{
public DbContexts DbContextToUse { get; set; }
/// <summary>
/// If the artist name is found in the values then use the key.
/// <remark>This was desgined to handle 'AC/DC' type names as they contain the ID3 v2.3 spec artist seperator</remark>
@ -145,6 +147,7 @@ namespace Roadie.Library.Configuration
public RoadieSettings()
{
DbContextToUse = DbContexts.MySQL;
ArtistNameReplace = new Dictionary<string, IEnumerable<string>>
{
{ "AC/DC", new List<string>{ "AC; DC", "AC;DC", "AC/ DC", "AC DC" }},

View file

@ -0,0 +1,29 @@
using Microsoft.EntityFrameworkCore;
using Pomelo.EntityFrameworkCore.MySql.Infrastructure;
using Roadie.Library.Configuration;
using Roadie.Library.Data.Context.Implementation;
using System;
namespace Roadie.Library.Data.Context
{
public static class DbContextFactory
{
public static IRoadieDbContext Create(IRoadieSettings configuration)
{
switch (configuration.DbContextToUse)
{
default:
var mysqlOptionsBuilder = new DbContextOptionsBuilder<MySQLRoadieDbContext>();
mysqlOptionsBuilder.UseMySql(configuration.ConnectionString, mySqlOptions =>
{
mySqlOptions.ServerVersion(new Version(5, 5), ServerType.MariaDb);
mySqlOptions.EnableRetryOnFailure(
10,
TimeSpan.FromSeconds(30),
null);
});
return new MySQLRoadieDbContext(mysqlOptionsBuilder.Options);
}
}
}
}

View file

@ -8,7 +8,7 @@ using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace Roadie.Library.Data
namespace Roadie.Library.Data.Context
{
public interface IRoadieDbContext : IRoadieDbRandomizer, IRoadieDbUserStats, IDisposable, IInfrastructure<IServiceProvider>, IDbContextDependencies, IDbSetCache, IDbContextPoolable
{

View file

@ -1,6 +1,6 @@
using System.Collections.Generic;
namespace Roadie.Library.Data
namespace Roadie.Library.Data.Context
{
public interface IRoadieDbRandomizer
{

View file

@ -1,6 +1,6 @@
using System.Threading.Tasks;
namespace Roadie.Library.Data
namespace Roadie.Library.Data.Context
{
public interface IRoadieDbUserStats
{

View file

@ -4,7 +4,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Roadie.Library.Data
namespace Roadie.Library.Data.Context.Implementation
{
/// <summary>
/// MySQL/MariaDB implementation of DbContext

View file

@ -7,7 +7,7 @@ using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace Roadie.Library.Data
namespace Roadie.Library.Data.Context
{
public abstract partial class RoadieDbContext : DbContext, IRoadieDbContext
{

View file

@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Roadie.Library.Data
namespace Roadie.Library.Data.Context
{
public abstract partial class RoadieDbContext : DbContext, IRoadieDbContext
{

View file

@ -1,26 +0,0 @@
using Microsoft.EntityFrameworkCore;
using Pomelo.EntityFrameworkCore.MySql.Infrastructure;
using Roadie.Library.Configuration;
using System;
using System.Collections.Generic;
using System.Text;
namespace Roadie.Library.Data
{
public static class DbContextFactory
{
public static IRoadieDbContext Create(IRoadieSettings configuration)
{
var optionsBuilder = new DbContextOptionsBuilder<MySQLRoadieDbContext>();
optionsBuilder.UseMySql(configuration.ConnectionString, mySqlOptions =>
{
mySqlOptions.ServerVersion(new Version(5, 5), ServerType.MariaDb);
mySqlOptions.EnableRetryOnFailure(
10,
TimeSpan.FromSeconds(30),
null);
});
return new MySQLRoadieDbContext(optionsBuilder.Options);
}
}
}

View file

@ -3,6 +3,7 @@ using Newtonsoft.Json;
using Roadie.Library.Caching;
using Roadie.Library.Configuration;
using Roadie.Library.Data;
using Roadie.Library.Data.Context;
using Roadie.Library.Encoding;
using Roadie.Library.Enums;
using Roadie.Library.Extensions;

View file

@ -2,6 +2,7 @@
using Roadie.Library.Caching;
using Roadie.Library.Configuration;
using Roadie.Library.Data;
using Roadie.Library.Data.Context;
using Roadie.Library.Encoding;
using Roadie.Library.Extensions;
using Roadie.Library.SearchEngines.MetaData;

View file

@ -2,6 +2,7 @@
using Roadie.Library.Caching;
using Roadie.Library.Configuration;
using Roadie.Library.Data;
using Roadie.Library.Data.Context;
using Roadie.Library.Encoding;
namespace Roadie.Library.Engines

View file

@ -2,6 +2,7 @@
using Roadie.Library.Caching;
using Roadie.Library.Configuration;
using Roadie.Library.Data;
using Roadie.Library.Data.Context;
using Roadie.Library.Encoding;
using Roadie.Library.Enums;
using Roadie.Library.Extensions;

View file

@ -29,5 +29,8 @@ namespace Roadie.Library.Models
return $"urn:genre_by_id:{Id}";
}
public Image MediumThumbnail { get; set; }
// When populated a "data:image" base64 byte array of an image to use as new Thumbnail
public string NewThumbnailData { get; set; }
}
}

View file

@ -3,6 +3,7 @@ using MimeMapping;
using Roadie.Library.Caching;
using Roadie.Library.Configuration;
using Roadie.Library.Data;
using Roadie.Library.Data.Context;
using Roadie.Library.Encoding;
using Roadie.Library.Engines;
using Roadie.Library.Extensions;

View file

@ -1,6 +1,7 @@
using Microsoft.Extensions.Logging;
using Roadie.Library.Caching;
using Roadie.Library.Configuration;
using Roadie.Library.Data.Context;
using Roadie.Library.MetaData.LastFm;
using Roadie.Library.Models.Users;
using Roadie.Library.Utility;
@ -17,7 +18,7 @@ namespace Roadie.Library.Scrobble
{
private ILastFmHelper LastFmHelper { get; }
public LastFMScrobbler(IRoadieSettings configuration, ILogger<LastFMScrobbler> logger, data.IRoadieDbContext dbContext,
public LastFMScrobbler(IRoadieSettings configuration, ILogger<LastFMScrobbler> logger, IRoadieDbContext dbContext,
ICacheManager cacheManager, ILastFmHelper lastFmHelper, IHttpContext httpContext)
: base(configuration, logger, dbContext, cacheManager, httpContext)
{

View file

@ -2,6 +2,7 @@
using Microsoft.Extensions.Logging;
using Roadie.Library.Caching;
using Roadie.Library.Configuration;
using Roadie.Library.Data.Context;
using Roadie.Library.Models.Users;
using Roadie.Library.Utility;
using System;
@ -15,12 +16,12 @@ namespace Roadie.Library.Scrobble
public class RoadieScrobbler : ScrobblerIntegrationBase, IRoadieScrobbler
{
public RoadieScrobbler(IRoadieSettings configuration, ILogger logger, data.IRoadieDbContext dbContext, ICacheManager cacheManager)
public RoadieScrobbler(IRoadieSettings configuration, ILogger logger, IRoadieDbContext dbContext, ICacheManager cacheManager)
: base(configuration, logger, dbContext, cacheManager, null)
{
}
public RoadieScrobbler(IRoadieSettings configuration, ILogger<RoadieScrobbler> logger, data.IRoadieDbContext dbContext,
public RoadieScrobbler(IRoadieSettings configuration, ILogger<RoadieScrobbler> logger, IRoadieDbContext dbContext,
ICacheManager cacheManager, IHttpContext httpContext)
: base(configuration, logger, dbContext, cacheManager, httpContext)
{

View file

@ -1,6 +1,7 @@
using Microsoft.Extensions.Logging;
using Roadie.Library.Caching;
using Roadie.Library.Configuration;
using Roadie.Library.Data.Context;
using Roadie.Library.Encoding;
using Roadie.Library.MetaData.LastFm;
using Roadie.Library.Models.Users;
@ -20,7 +21,7 @@ namespace Roadie.Library.Scrobble
{
private IRoadieSettings Configuration { get; }
private data.IRoadieDbContext DbContext { get; }
private IRoadieDbContext DbContext { get; }
private IHttpContext HttpContext { get; }
@ -30,7 +31,7 @@ namespace Roadie.Library.Scrobble
private IEnumerable<IScrobblerIntegration> Scrobblers { get; }
public ScrobbleHandler(IRoadieSettings configuration, ILogger<ScrobbleHandler> logger, data.IRoadieDbContext dbContext,
public ScrobbleHandler(IRoadieSettings configuration, ILogger<ScrobbleHandler> logger, IRoadieDbContext dbContext,
ICacheManager cacheManager, IHttpEncoder httpEncoder, IHttpContext httpContext,
ILastFmHelper lastFmHelper, IRoadieScrobbler roadieScrobbler, ILastFMScrobbler lastFMScrobbler)
{
@ -50,7 +51,7 @@ namespace Roadie.Library.Scrobble
Scrobblers = scrobblers;
}
public ScrobbleHandler(IRoadieSettings configuration, ILogger logger, data.IRoadieDbContext dbContext, ICacheManager cacheManager, RoadieScrobbler roadieScrobbler)
public ScrobbleHandler(IRoadieSettings configuration, ILogger logger, IRoadieDbContext dbContext, ICacheManager cacheManager, RoadieScrobbler roadieScrobbler)
{
Logger = logger;
Configuration = configuration;

View file

@ -1,6 +1,7 @@
using Microsoft.Extensions.Logging;
using Roadie.Library.Caching;
using Roadie.Library.Configuration;
using Roadie.Library.Data.Context;
using Roadie.Library.Models.Users;
using Roadie.Library.Utility;
using System.Threading.Tasks;
@ -14,13 +15,13 @@ namespace Roadie.Library.Scrobble
protected IRoadieSettings Configuration { get; }
protected data.IRoadieDbContext DbContext { get; }
protected IRoadieDbContext DbContext { get; }
protected IHttpContext HttpContext { get; }
protected ILogger Logger { get; }
public ScrobblerIntegrationBase(IRoadieSettings configuration, ILogger logger, data.IRoadieDbContext dbContext,
public ScrobblerIntegrationBase(IRoadieSettings configuration, ILogger logger, IRoadieDbContext dbContext,
ICacheManager cacheManager, IHttpContext httpContext)
{
Logger = logger;

View file

@ -2,6 +2,7 @@
using Roadie.Library.Caching;
using Roadie.Library.Configuration;
using Roadie.Library.Data;
using Roadie.Library.Data.Context;
using Roadie.Library.Encoding;
using Roadie.Library.Engines;
using Roadie.Library.Extensions;

View file

@ -4,6 +4,7 @@ using Microsoft.Extensions.Logging;
using RestSharp;
using Roadie.Library.Caching;
using Roadie.Library.Configuration;
using Roadie.Library.Data.Context;
using Roadie.Library.Encoding;
using Roadie.Library.Extensions;
using Roadie.Library.MetaData.Audio;
@ -37,12 +38,12 @@ namespace Roadie.Library.MetaData.LastFm
!string.IsNullOrEmpty(Configuration.Integrations.LastFMApiKey) &&
!string.IsNullOrEmpty(Configuration.Integrations.LastFmApiSecret);
private data.IRoadieDbContext DbContext { get; }
private IRoadieDbContext DbContext { get; }
private IHttpEncoder HttpEncoder { get; }
public LastFmHelper(IRoadieSettings configuration, ICacheManager cacheManager, ILogger<LastFmHelper> logger,
data.IRoadieDbContext dbContext, IHttpEncoder httpEncoder)
IRoadieDbContext dbContext, IHttpEncoder httpEncoder)
: base(configuration, cacheManager, logger)
{
_apiKey = configuration.Integrations.ApiKeys.FirstOrDefault(x => x.ApiName == "LastFMApiKey") ??

View file

@ -6,6 +6,7 @@ using Roadie.Api.Hubs;
using Roadie.Library;
using Roadie.Library.Caching;
using Roadie.Library.Configuration;
using Roadie.Library.Data.Context;
using Roadie.Library.Encoding;
using Roadie.Library.Engines;
using Roadie.Library.Enums;
@ -43,7 +44,7 @@ namespace Roadie.Api.Services
private IReleaseService ReleaseService { get; }
public AdminService(IRoadieSettings configuration, IHttpEncoder httpEncoder, IHttpContext httpContext,
data.IRoadieDbContext context, ICacheManager cacheManager, ILogger<ArtistService> logger,
IRoadieDbContext context, ICacheManager cacheManager, ILogger<ArtistService> logger,
IHubContext<ScanActivityHub> scanActivityHub, IFileDirectoryProcessorService fileDirectoryProcessorService, IArtistService artistService,
IReleaseService releaseService, IArtistLookupEngine artistLookupEngine, IReleaseLookupEngine releaseLookupEngine,
ILabelService labelService, IGenreService genreService

View file

@ -5,6 +5,7 @@ using Microsoft.Extensions.Logging;
using Roadie.Library;
using Roadie.Library.Caching;
using Roadie.Library.Configuration;
using Roadie.Library.Data.Context;
using Roadie.Library.Encoding;
using Roadie.Library.Engines;
using Roadie.Library.Enums;
@ -48,7 +49,7 @@ namespace Roadie.Api.Services
public ArtistService(IRoadieSettings configuration,
IHttpEncoder httpEncoder,
IHttpContext httpContext,
data.IRoadieDbContext dbContext,
IRoadieDbContext dbContext,
ICacheManager cacheManager,
ILogger<ArtistService> logger,
ICollectionService collectionService,

View file

@ -2,6 +2,7 @@
using Microsoft.Extensions.Logging;
using Roadie.Library.Caching;
using Roadie.Library.Configuration;
using Roadie.Library.Data.Context;
using Roadie.Library.Encoding;
using Roadie.Library.Enums;
using Roadie.Library.Models.Collections;
@ -26,7 +27,7 @@ namespace Roadie.Api.Services
public BookmarkService(IRoadieSettings configuration,
IHttpEncoder httpEncoder,
IHttpContext httpContext,
data.IRoadieDbContext context,
IRoadieDbContext context,
ICacheManager cacheManager,
ILogger<BookmarkService> logger)
: base(configuration, httpEncoder, context, cacheManager, logger, httpContext)

View file

@ -4,6 +4,7 @@ using Microsoft.Extensions.Logging;
using Roadie.Library;
using Roadie.Library.Caching;
using Roadie.Library.Configuration;
using Roadie.Library.Data.Context;
using Roadie.Library.Encoding;
using Roadie.Library.Enums;
using Roadie.Library.Extensions;
@ -33,7 +34,7 @@ namespace Roadie.Api.Services
public CollectionService(IRoadieSettings configuration,
IHttpEncoder httpEncoder,
IHttpContext httpContext,
data.IRoadieDbContext dbContext,
IRoadieDbContext dbContext,
ICacheManager cacheManager,
ILogger<CollectionService> logger,
IBookmarkService bookmarkService)

View file

@ -2,6 +2,7 @@
using Roadie.Library;
using Roadie.Library.Caching;
using Roadie.Library.Configuration;
using Roadie.Library.Data.Context;
using Roadie.Library.Encoding;
using Roadie.Library.Enums;
using Roadie.Library.Models.Users;
@ -20,7 +21,7 @@ namespace Roadie.Api.Services
public CommentService(IRoadieSettings configuration,
IHttpEncoder httpEncoder,
IHttpContext httpContext,
data.IRoadieDbContext context,
IRoadieDbContext context,
ICacheManager cacheManager,
ILogger<CommentService> logger)
: base(configuration, httpEncoder, context, cacheManager, logger, httpContext)

View file

@ -2,6 +2,7 @@
using Roadie.Library;
using Roadie.Library.Caching;
using Roadie.Library.Configuration;
using Roadie.Library.Data.Context;
using Roadie.Library.Encoding;
using Roadie.Library.Engines;
using Roadie.Library.Extensions;
@ -44,7 +45,7 @@ namespace Roadie.Api.Services
public FileDirectoryProcessorService(IRoadieSettings configuration,
IHttpEncoder httpEncoder,
IHttpContext httpContext,
data.IRoadieDbContext context,
IRoadieDbContext context,
ICacheManager cacheManager,
ILogger<FileDirectoryProcessorService> logger,
IArtistLookupEngine artistLookupEngine,

View file

@ -5,7 +5,9 @@ using Microsoft.Extensions.Logging;
using Roadie.Library;
using Roadie.Library.Caching;
using Roadie.Library.Configuration;
using Roadie.Library.Data.Context;
using Roadie.Library.Encoding;
using Roadie.Library.Enums;
using Roadie.Library.Extensions;
using Roadie.Library.Identity;
using Roadie.Library.Imaging;
@ -29,7 +31,7 @@ namespace Roadie.Api.Services
public GenreService(IRoadieSettings configuration,
IHttpEncoder httpEncoder,
IHttpContext httpContext,
data.IRoadieDbContext dbContext,
IRoadieDbContext dbContext,
ICacheManager cacheManager,
ILogger<GenreService> logger)
: base(configuration, httpEncoder, dbContext, cacheManager, logger, httpContext)
@ -165,6 +167,79 @@ namespace Roadie.Api.Services
return await SaveImageBytes(user, id, WebHelper.BytesForImageUrl(imageUrl));
}
public async Task<OperationResult<bool>> UpdateGenre(User user, Genre model)
{
var sw = new Stopwatch();
sw.Start();
var errors = new List<Exception>();
var genre = DbContext.Genres.FirstOrDefault(x => x.RoadieId == model.Id);
if (genre == null)
{
return new OperationResult<bool>(true, string.Format("Genre Not Found [{0}]", model.Id));
}
// If genre is being renamed, see if genre already exists with new model supplied name
if (genre.Name.ToAlphanumericName() != model.Name.ToAlphanumericName())
{
var existingGenre = DbContext.Genres.FirstOrDefault(x => x.Name == model.Name);
if (existingGenre != null)
{
return new OperationResult<bool>($"Genre already exists with name [{ model.Name }].");
}
}
try
{
var now = DateTime.UtcNow;
var specialGenreName = model.Name.ToAlphanumericName();
var alt = new List<string>(model.AlternateNamesList);
if (!model.AlternateNamesList.Contains(specialGenreName, StringComparer.OrdinalIgnoreCase))
{
alt.Add(specialGenreName);
}
genre.AlternateNames = alt.ToDelimitedList();
genre.IsLocked = model.IsLocked;
var oldPathToImage = genre.PathToImage(Configuration);
var didChangeName = genre.Name != model.Name;
genre.Name = model.Name;
genre.SortName = model.SortName;
genre.Status = SafeParser.ToEnum<Statuses>(model.Status);
genre.Tags = model.TagsList.ToDelimitedList();
if (didChangeName)
{
if (File.Exists(oldPathToImage))
{
File.Move(oldPathToImage, genre.PathToImage(Configuration));
}
}
var genreImage = ImageHelper.ImageDataFromUrl(model.NewThumbnailData);
if (genreImage != null)
{
// Save unaltered genre image
File.WriteAllBytes(genre.PathToImage(Configuration), ImageHelper.ConvertToJpegFormat(genreImage));
}
genre.LastUpdated = now;
await DbContext.SaveChangesAsync();
CacheManager.ClearRegion(genre.CacheRegion);
Logger.LogInformation($"UpdateGenre `{genre}` By User `{user}`");
}
catch (Exception ex)
{
Logger.LogError(ex);
errors.Add(ex);
}
sw.Stop();
return new OperationResult<bool>
{
IsSuccess = !errors.Any(),
Data = !errors.Any(),
OperationTime = sw.ElapsedMilliseconds,
Errors = errors
};
}
public async Task<OperationResult<Library.Models.Image>> UploadGenreImage(User user, Guid id, IFormFile file)
{
var bytes = new byte[0];
@ -197,7 +272,7 @@ namespace Roadie.Api.Services
var result = genre.Adapt<Genre>();
result.AlternateNames = genre.AlternateNames;
result.Tags = genre.Tags;
result.Thumbnail = MakeLabelThumbnailImage(Configuration, HttpContext, genre.RoadieId);
result.Thumbnail = MakeGenreThumbnailImage(Configuration, HttpContext, genre.RoadieId);
result.MediumThumbnail = MakeThumbnailImage(Configuration, HttpContext, id, "genre", Configuration.MediumImageSize.Width, Configuration.MediumImageSize.Height);
tsw.Stop();
timings.Add("adapt", tsw.ElapsedMilliseconds);

View file

@ -20,6 +20,8 @@ namespace Roadie.Api.Services
Task<OperationResult<Image>> SetGenreImageByUrl(User user, Guid id, string imageUrl);
Task<OperationResult<bool>> UpdateGenre(User user, Genre model);
Task<OperationResult<Image>> UploadGenreImage(User user, Guid id, IFormFile file);
}
}

View file

@ -4,6 +4,7 @@ using Microsoft.Net.Http.Headers;
using Roadie.Library;
using Roadie.Library.Caching;
using Roadie.Library.Configuration;
using Roadie.Library.Data.Context;
using Roadie.Library.Encoding;
using Roadie.Library.Enums;
using Roadie.Library.Identity;
@ -32,7 +33,7 @@ namespace Roadie.Api.Services
public ImageService(IRoadieSettings configuration,
IHttpEncoder httpEncoder,
IHttpContext httpContext,
data.IRoadieDbContext context,
IRoadieDbContext context,
ICacheManager cacheManager,
ILogger<ImageService> logger,
IDefaultNotFoundImages defaultNotFoundImages,
@ -43,7 +44,7 @@ namespace Roadie.Api.Services
ImageSearchManager = imageSearchManager;
}
public ImageService(IRoadieSettings configuration, data.IRoadieDbContext dbContext, ICacheManager cacheManager,
public ImageService(IRoadieSettings configuration, IRoadieDbContext dbContext, ICacheManager cacheManager,
ILogger logger, DefaultNotFoundImages defaultNotFoundImages)
: base(configuration, null, dbContext, cacheManager, logger, null)
{

View file

@ -5,6 +5,7 @@ using Microsoft.Extensions.Logging;
using Roadie.Library;
using Roadie.Library.Caching;
using Roadie.Library.Configuration;
using Roadie.Library.Data.Context;
using Roadie.Library.Encoding;
using Roadie.Library.Enums;
using Roadie.Library.Extensions;
@ -33,11 +34,9 @@ namespace Roadie.Api.Services
public LabelService(IRoadieSettings configuration,
IHttpEncoder httpEncoder,
IHttpContext httpContext,
data.IRoadieDbContext context,
IRoadieDbContext context,
ICacheManager cacheManager,
ILogger<LabelService> logger,
ICollectionService collectionService,
IPlaylistService playlistService,
IBookmarkService bookmarkService)
: base(configuration, httpEncoder, context, cacheManager, logger, httpContext)
{
@ -286,10 +285,12 @@ namespace Roadie.Api.Services
try
{
var now = DateTime.UtcNow;
var specialArtistName = model.Name.ToAlphanumericName();
var specialLabelName = model.Name.ToAlphanumericName();
var alt = new List<string>(model.AlternateNamesList);
if (!model.AlternateNamesList.Contains(specialArtistName, StringComparer.OrdinalIgnoreCase))
alt.Add(specialArtistName);
if (!model.AlternateNamesList.Contains(specialLabelName, StringComparer.OrdinalIgnoreCase))
{
alt.Add(specialLabelName);
}
label.AlternateNames = alt.ToDelimitedList();
label.BeginDate = model.BeginDate;
label.DiscogsId = model.DiscogsId;

View file

@ -2,6 +2,7 @@
using Roadie.Library;
using Roadie.Library.Caching;
using Roadie.Library.Configuration;
using Roadie.Library.Data.Context;
using Roadie.Library.Encoding;
using Roadie.Library.Enums;
using Roadie.Library.Models;
@ -23,7 +24,7 @@ namespace Roadie.Api.Services
public LookupService(IRoadieSettings configuration,
IHttpEncoder httpEncoder,
IHttpContext httpContext,
data.IRoadieDbContext dbContext,
IRoadieDbContext dbContext,
ICacheManager cacheManager,
ILogger<PlaylistService> logger)
: base(configuration, httpEncoder, dbContext, cacheManager, logger, httpContext)

View file

@ -5,6 +5,7 @@ using Roadie.Api.Hubs;
using Roadie.Library;
using Roadie.Library.Caching;
using Roadie.Library.Configuration;
using Roadie.Library.Data.Context;
using Roadie.Library.Encoding;
using Roadie.Library.Models;
using Roadie.Library.Models.Pagination;
@ -28,7 +29,7 @@ namespace Roadie.Api.Services
protected IScrobbleHandler ScrobblerHandler { get; }
public PlayActivityService(IRoadieSettings configuration, IHttpEncoder httpEncoder,IHttpContext httpContext,
data.IRoadieDbContext dbContext, ICacheManager cacheManager,ILogger<PlayActivityService> logger,
IRoadieDbContext dbContext, ICacheManager cacheManager,ILogger<PlayActivityService> logger,
IScrobbleHandler scrobbleHandler, IHubContext<PlayActivityHub> playActivityHub)
: base(configuration, httpEncoder, dbContext, cacheManager, logger, httpContext)
{
@ -36,7 +37,7 @@ namespace Roadie.Api.Services
ScrobblerHandler = scrobbleHandler;
}
public PlayActivityService(IRoadieSettings configuration, data.IRoadieDbContext dbContext, ICacheManager cacheManager,
public PlayActivityService(IRoadieSettings configuration, IRoadieDbContext dbContext, ICacheManager cacheManager,
ILogger logger, ScrobbleHandler scrobbleHandler)
: base(configuration, null, dbContext, cacheManager, logger, null)
{

View file

@ -4,6 +4,7 @@ using Microsoft.Extensions.Logging;
using Roadie.Library;
using Roadie.Library.Caching;
using Roadie.Library.Configuration;
using Roadie.Library.Data.Context;
using Roadie.Library.Encoding;
using Roadie.Library.Enums;
using Roadie.Library.Extensions;
@ -32,7 +33,7 @@ namespace Roadie.Api.Services
public PlaylistService(IRoadieSettings configuration,
IHttpEncoder httpEncoder,
IHttpContext httpContext,
data.IRoadieDbContext dbContext,
IRoadieDbContext dbContext,
ICacheManager cacheManager,
ILogger<PlaylistService> logger,
IBookmarkService bookmarkService)

View file

@ -5,6 +5,7 @@ using Microsoft.Extensions.Logging;
using Roadie.Library;
using Roadie.Library.Caching;
using Roadie.Library.Configuration;
using Roadie.Library.Data.Context;
using Roadie.Library.Encoding;
using Roadie.Library.Engines;
using Roadie.Library.Enums;
@ -49,7 +50,7 @@ namespace Roadie.Api.Services
public ReleaseService(IRoadieSettings configuration,
IHttpEncoder httpEncoder,
IHttpContext httpContext,
data.IRoadieDbContext dbContext,
IRoadieDbContext dbContext,
ICacheManager cacheManager,
IPlaylistService playlistService,
ILogger<ReleaseService> logger,

View file

@ -4,6 +4,7 @@ using Microsoft.Extensions.Logging;
using Roadie.Library;
using Roadie.Library.Caching;
using Roadie.Library.Configuration;
using Roadie.Library.Data.Context;
using Roadie.Library.Encoding;
using Roadie.Library.Enums;
using Roadie.Library.Identity;
@ -26,7 +27,7 @@ namespace Roadie.Api.Services
protected readonly IRoadieSettings _configuration;
protected readonly data.IRoadieDbContext _dbContext;
protected readonly IRoadieDbContext _dbContext;
protected readonly IHttpContext _httpContext;
@ -43,7 +44,7 @@ namespace Roadie.Api.Services
protected IRoadieSettings Configuration => _configuration;
protected data.IRoadieDbContext DbContext => _dbContext;
protected IRoadieDbContext DbContext => _dbContext;
protected IHttpContext HttpContext => _httpContext;
@ -51,8 +52,8 @@ namespace Roadie.Api.Services
protected ILogger Logger => _logger;
public ServiceBase(IRoadieSettings configuration, IHttpEncoder httpEncoder, data.IRoadieDbContext context,
ICacheManager cacheManager, ILogger logger, IHttpContext httpContext)
public ServiceBase(IRoadieSettings configuration, IHttpEncoder httpEncoder, IRoadieDbContext context,
ICacheManager cacheManager, ILogger logger, IHttpContext httpContext)
{
_configuration = configuration;
_httpEncoder = httpEncoder;

View file

@ -2,6 +2,7 @@
using Roadie.Library;
using Roadie.Library.Caching;
using Roadie.Library.Configuration;
using Roadie.Library.Data.Context;
using Roadie.Library.Encoding;
using Roadie.Library.Models.Statistics;
using Roadie.Library.Utility;
@ -19,7 +20,7 @@ namespace Roadie.Api.Services
public StatisticsService(IRoadieSettings configuration,
IHttpEncoder httpEncoder,
IHttpContext httpContext,
data.IRoadieDbContext context,
IRoadieDbContext context,
ICacheManager cacheManager,
ILogger<StatisticsService> logger)
: base(configuration, httpEncoder, context, cacheManager, logger, httpContext)

View file

@ -5,6 +5,7 @@ using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Roadie.Library.Caching;
using Roadie.Library.Configuration;
using Roadie.Library.Data.Context;
using Roadie.Library.Encoding;
using Roadie.Library.Enums;
using Roadie.Library.Extensions;
@ -55,9 +56,9 @@ namespace Roadie.Api.Services
private UserManager<ApplicationUser> UserManger { get; }
public SubsonicService(IRoadieSettings configuration,
IHttpEncoder httpEncoder,
IHttpEncoder httpEncoder,
IHttpContext httpContext,
data.IRoadieDbContext context,
IRoadieDbContext context,
ICacheManager cacheManager,
ILogger<SubsonicService> logger,
IArtistService artistService,

View file

@ -6,6 +6,7 @@ using Newtonsoft.Json;
using Roadie.Library;
using Roadie.Library.Caching;
using Roadie.Library.Configuration;
using Roadie.Library.Data.Context;
using Roadie.Library.Encoding;
using Roadie.Library.Enums;
using Roadie.Library.Extensions;
@ -38,7 +39,7 @@ namespace Roadie.Api.Services
private IBookmarkService BookmarkService { get; }
public TrackService(IRoadieSettings configuration, IHttpEncoder httpEncoder, IHttpContext httpContext,
data.IRoadieDbContext dbContext, ICacheManager cacheManager, ILogger<TrackService> logger,
IRoadieDbContext dbContext, ICacheManager cacheManager, ILogger<TrackService> logger,
IBookmarkService bookmarkService, IAdminService adminService, IAudioMetaDataHelper audioMetaDataHelper)
: base(configuration, httpEncoder, dbContext, cacheManager, logger, httpContext)
{
@ -47,7 +48,7 @@ namespace Roadie.Api.Services
AdminService = adminService;
}
public TrackService(IRoadieSettings configuration, data.IRoadieDbContext dbContext, ICacheManager cacheManager, ILogger logger)
public TrackService(IRoadieSettings configuration, IRoadieDbContext dbContext, ICacheManager cacheManager, ILogger logger)
: base(configuration, null, dbContext, cacheManager, logger, null)
{
}
@ -287,7 +288,7 @@ namespace Roadie.Api.Services
SortedDictionary<int, int> randomTrackData = null;
if (doRandomize ?? false)
{
var randomLimit = request.Limit ?? roadieUser?.RandomReleaseLimit ?? request.LimitValue;
var randomLimit = roadieUser?.RandomReleaseLimit ?? request.LimitValue;
randomTrackData = DbContext.RandomTrackIds(roadieUser?.Id ?? -1, randomLimit, request.FilterFavoriteOnly, request.FilterRatedOnly);
randomTrackIds = randomTrackData.Select(x => x.Value).ToArray();
rowCount = DbContext.Releases.Count();

View file

@ -6,6 +6,7 @@ using Newtonsoft.Json;
using Roadie.Library;
using Roadie.Library.Caching;
using Roadie.Library.Configuration;
using Roadie.Library.Data.Context;
using Roadie.Library.Encoding;
using Roadie.Library.Enums;
using Roadie.Library.Extensions;
@ -38,7 +39,7 @@ namespace Roadie.Api.Services
public UserService(IRoadieSettings configuration,
IHttpEncoder httpEncoder,
IHttpContext httpContext,
data.IRoadieDbContext context,
IRoadieDbContext context,
ICacheManager cacheManager,
ILogger<ArtistService> logger,
UserManager<ApplicationUser> userManager,

View file

@ -116,5 +116,32 @@ namespace Roadie.Api.Controllers
}
return Ok(result);
}
[HttpPost("edit")]
[ProducesResponseType(200)]
[ProducesResponseType(404)]
[Authorize(Policy = "Editor")]
public async Task<IActionResult> Update(models.Genre genre)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
var result = await GenreService.UpdateGenre(await CurrentUserModel(), genre);
if (result == null || result.IsNotFoundResult)
{
return NotFound();
}
if (!result.IsSuccess)
{
if (result.Messages?.Any() ?? false)
{
return StatusCode((int)HttpStatusCode.BadRequest, result.Messages);
}
return StatusCode((int)HttpStatusCode.InternalServerError);
}
return Ok(result);
}
}
}

View file

@ -6,13 +6,13 @@ using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.UI.Services;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.AspNetCore.Mvc.Routing;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.IdentityModel.Tokens;
using Newtonsoft.Json;
using Pomelo.EntityFrameworkCore.MySql.Infrastructure;
@ -22,7 +22,8 @@ using Roadie.Api.Services;
using Roadie.Dlna.Services;
using Roadie.Library.Caching;
using Roadie.Library.Configuration;
using Roadie.Library.Data;
using Roadie.Library.Data.Context;
using Roadie.Library.Data.Context.Implementation;
using Roadie.Library.Encoding;
using Roadie.Library.Engines;
using Roadie.Library.Identity;
@ -39,12 +40,11 @@ using Roadie.Library.SearchEngines.MetaData.Discogs;
using Roadie.Library.SearchEngines.MetaData.Spotify;
using Roadie.Library.SearchEngines.MetaData.Wikipedia;
using Roadie.Library.Utility;
using Serilog;
using System;
using System.Collections.Generic;
using System.Text;
using Serilog;
using Microsoft.Extensions.Logging;
using System.Diagnostics;
using System.Text;
#endregion Usings

View file

@ -5,6 +5,7 @@ using Roadie.Api.Services;
using Roadie.Dlna.Server;
using Roadie.Library.Caching;
using Roadie.Library.Configuration;
using Roadie.Library.Data.Context;
using Roadie.Library.Imaging;
using Roadie.Library.Scrobble;
using System;
@ -24,7 +25,7 @@ namespace Roadie.Dlna.Services
private ICacheManager CacheManager { get; }
private IRoadieSettings Configuration { get; }
private data.IRoadieDbContext DbContext { get; set; }
private IRoadieDbContext DbContext { get; set; }
private ILogger Logger { get; }
private ILoggerFactory LoggerFactory { get; }
private IServiceScopeFactory ServiceScopeFactory { get; }
@ -56,7 +57,7 @@ namespace Roadie.Dlna.Services
{
_authorizer.AddMethod(new UserAgentAuthorizer(Configuration.Dlna.AllowedUserAgents));
}
DbContext = data.DbContextFactory.Create(Configuration);
DbContext = DbContextFactory.Create(Configuration);
var defaultNotFoundImages = new DefaultNotFoundImages(LoggerFactory.CreateLogger("DefaultNotFoundImages"), Configuration);
var imageService = new ImageService(Configuration, DbContext, CacheManager, LoggerFactory.CreateLogger("ImageService"), defaultNotFoundImages);

View file

@ -4,6 +4,7 @@ using Roadie.Api.Services;
using Roadie.Dlna.Server;
using Roadie.Library.Caching;
using Roadie.Library.Configuration;
using Roadie.Library.Data.Context;
using Roadie.Library.Extensions;
using Roadie.Library.Models;
using Roadie.Library.Models.Releases;
@ -26,14 +27,14 @@ namespace Roadie.Dlna.Services
public Guid UUID { get; } = Guid.NewGuid();
private ICacheManager CacheManager { get; }
private IRoadieSettings Configuration { get; }
private data.IRoadieDbContext DbContext { get; }
private IRoadieDbContext DbContext { get; }
private IImageService ImageService { get; }
private ILogger Logger { get; }
private IPlayActivityService PlayActivityService { get; }
private int RandomTrackLimit { get; }
private ITrackService TrackService { get; }
public DlnaService(IRoadieSettings configuration, data.IRoadieDbContext dbContext, ICacheManager cacheManager,
public DlnaService(IRoadieSettings configuration, IRoadieDbContext dbContext, ICacheManager cacheManager,
ILogger logger, IImageService imageService, ITrackService trackService, IPlayActivityService playActivityService)
{
Configuration = configuration;