roadie-vuejs client changes

This commit is contained in:
Steven Hildreth 2018-12-04 17:26:27 -06:00
parent d0ce983150
commit a2b549f283
12 changed files with 145 additions and 110 deletions

View file

@ -17,7 +17,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">

View file

@ -19,7 +19,7 @@
<PackageReference Include="Microsoft.AspNet.SignalR" Version="2.4.0" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.1.6" />
<PackageReference Include="Microsoft.AspNetCore.OData" Version="7.1.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.6" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.0" />
<PackageReference Include="Serilog.AspNetCore" Version="2.1.1" />
<PackageReference Include="Serilog.Exceptions" Version="4.1.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="3.0.1" />

View file

@ -63,7 +63,8 @@ namespace Roadie.Api.Services
var userBookmarkResult = await this.BookmarkService.List(roadieUser, new PagedRequest(), false, BookmarkType.Artist);
if(userBookmarkResult.IsSuccess)
{
result.Data.UserBookmark = userBookmarkResult?.Rows?.FirstOrDefault(x => x.Bookmark.Text == artist.RoadieId.ToString());
result.Data.UserBookmarked = userBookmarkResult?.Rows?.FirstOrDefault(x => x.Bookmark.Value == artist.RoadieId.ToString()) != null;
}
var userArtist = this.DbContext.UserArtists.FirstOrDefault(x => x.ArtistId == artist.Id && x.UserId == roadieUser.Id);
if (userArtist != null)
@ -180,31 +181,57 @@ namespace Roadie.Api.Services
}
if (includes.Contains("images"))
{
result.Images = this.DbContext.Images.Where(x => x.ArtistId == artist.Id).Select(x => MakeImage(x.RoadieId, this.Configuration.LargeImageSize.Width, this.Configuration.LargeImageSize.Height)).ToArray();
result.Images = this.DbContext.Images.Where(x => x.ArtistId == artist.Id).Select(x => MakeFullsizeImage(x.RoadieId, x.Caption)).ToArray();
}
if (includes.Contains("associatedartists"))
{
var associatedWithArtists = (from aa in this.DbContext.ArtistAssociations
join a in this.DbContext.Artists on aa.AssociatedArtistId equals a.Id
where aa.ArtistId == artist.Id
select new DataToken
{
Text = a.Name,
Value = a.RoadieId.ToString(),
Data = this.MakeArtistThumbnailImage(a.RoadieId).Url
}).ToArray();
select new ArtistList
{
DatabaseId = a.Id,
Id = a.RoadieId,
Artist = new DataToken
{
Text = a.Name,
Value = a.RoadieId.ToString()
},
Thumbnail = this.MakeArtistThumbnailImage(a.RoadieId),
Rating = a.Rating,
CreatedDate = a.CreatedDate,
LastUpdated = a.LastUpdated,
LastPlayed = a.LastPlayed,
PlayedCount = a.PlayedCount,
ReleaseCount = a.ReleaseCount,
TrackCount = a.TrackCount,
SortName = a.SortName
}).ToArray();
var associatedArtists = (from aa in this.DbContext.ArtistAssociations
join a in this.DbContext.Artists on aa.ArtistId equals a.Id
where aa.AssociatedArtistId == artist.Id
select new DataToken
select new ArtistList
{
Text = a.Name,
Value = a.RoadieId.ToString(),
Data = this.MakeArtistThumbnailImage(a.RoadieId).Url
DatabaseId = a.Id,
Id = a.RoadieId,
Artist = new DataToken
{
Text = a.Name,
Value = a.RoadieId.ToString()
},
Thumbnail = this.MakeArtistThumbnailImage(a.RoadieId),
Rating = a.Rating,
CreatedDate = a.CreatedDate,
LastUpdated = a.LastUpdated,
LastPlayed = a.LastPlayed,
PlayedCount = a.PlayedCount,
ReleaseCount = a.ReleaseCount,
TrackCount = a.TrackCount,
SortName = a.SortName
}).ToArray();
result.AssociatedArtists = associatedArtists.Union(associatedWithArtists).OrderBy(x => x.Text);
result.AssociatedArtists = associatedArtists.Union(associatedWithArtists).OrderBy(x => x.SortName);
}
if (includes.Contains("collections"))
@ -268,20 +295,6 @@ namespace Roadie.Api.Services
if (includes.Contains("labels"))
{
result.ArtistLabels = (from l in this.DbContext.Labels
let releaseCount = (from lbb in this.DbContext.Labels
join rlll in this.DbContext.ReleaseLabels on lbb.Id equals rlll.LabelId into rlddd
from rlll in rlddd.DefaultIfEmpty()
join rrr in this.DbContext.Releases on rlll.ReleaseId equals rrr.Id
where lbb.Id == l.Id
select rrr.Id).Count()
let trackCount = (from lbtc in this.DbContext.Labels
join rlltc in this.DbContext.ReleaseLabels on lbtc.Id equals rlltc.LabelId into rlddtc
from rlltc in rlddtc.DefaultIfEmpty()
join rrtc in this.DbContext.Releases on rlltc.ReleaseId equals rrtc.Id
join rmtc in this.DbContext.ReleaseMedias on rrtc.Id equals rmtc.ReleaseId
join tttc in this.DbContext.Tracks on rmtc.Id equals tttc.ReleaseMediaId
where lbtc.Id == l.Id
select tttc.Id).Count()
join rl in this.DbContext.ReleaseLabels on l.Id equals rl.LabelId
join r in this.DbContext.Releases on rl.ReleaseId equals r.Id
where r.ArtistId == artist.Id
@ -297,8 +310,9 @@ namespace Roadie.Api.Services
SortName = l.SortName,
CreatedDate = l.CreatedDate,
LastUpdated = l.LastUpdated,
ReleaseCount = releaseCount,
TrackCount = trackCount,
ArtistCount = l.ArtistCount,
ReleaseCount = l.ReleaseCount,
TrackCount = l.TrackCount,
Thumbnail = MakeLabelThumbnailImage(l.RoadieId)
}).ToArray().GroupBy(x => x.Label.Value).Select(x => x.First()).OrderBy(x => x.SortName).ThenBy(x => x.Label.Text).ToArray();
result.ArtistLabels = result.ArtistLabels.Any() ? result.ArtistLabels : null;

View file

@ -56,7 +56,7 @@ namespace Roadie.Api.Services
var userBookmarkResult = await this.BookmarkService.List(roadieUser, new PagedRequest(), false, BookmarkType.Release);
if (userBookmarkResult.IsSuccess)
{
result.Data.UserBookmark = userBookmarkResult?.Rows?.FirstOrDefault(x => x.Bookmark.Text == release.RoadieId.ToString());
result.Data.UserBookmarked = userBookmarkResult?.Rows?.FirstOrDefault(x => x.Bookmark.Text == release.RoadieId.ToString()) != null;
}
if (result.Data.Medias != null)
{
@ -494,7 +494,7 @@ namespace Roadie.Api.Services
}
if (includes.Contains("images"))
{
var releaseImages = this.DbContext.Images.Where(x => x.ReleaseId == release.Id).Select(x => MakeImage(x.RoadieId, this.Configuration.LargeImageSize.Width, this.Configuration.LargeImageSize.Height)).ToArray();
var releaseImages = this.DbContext.Images.Where(x => x.ReleaseId == release.Id).Select(x => MakeFullsizeImage(x.RoadieId, x.Caption)).ToArray();
if (releaseImages != null && releaseImages.Any())
{
result.Images = releaseImages;

View file

@ -1,5 +1,4 @@
using Mapster;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Roadie.Library;
using Roadie.Library.Caching;
@ -7,10 +6,8 @@ using Roadie.Library.Configuration;
using Roadie.Library.Encoding;
using Roadie.Library.Identity;
using Roadie.Library.Models;
using Roadie.Library.Models.Users;
using Roadie.Library.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using data = Roadie.Library.Data;
@ -85,6 +82,11 @@ namespace Roadie.Api.Services
this._httpContext = httpContext;
}
public Image MakeThumbnailImage(Guid id, string type, int? width = null, int? height = null)
{
return this.MakeImage(id, type, width ?? this.Configuration.ThumbnailImageSize.Width, height ?? this.Configuration.ThumbnailImageSize.Height);
}
protected data.Artist GetArtist(string artistName)
{
if (string.IsNullOrEmpty(artistName))
@ -219,6 +221,60 @@ namespace Roadie.Api.Services
}, ApplicationUser.CacheRegionUrn(id.Value));
}
protected Image MakeArtistThumbnailImage(Guid id)
{
return MakeThumbnailImage(id, "artist");
}
protected Image MakeCollectionThumbnailImage(Guid id)
{
return MakeThumbnailImage(id, "collection");
}
protected Image MakeImage(Guid id, int width = 200, int height = 200, string caption = null)
{
return new Image($"{this.HttpContext.ImageBaseUrl }/{id}/{ width }/{ height }", caption, $"{this.HttpContext.ImageBaseUrl }/{id}/{ this.Configuration.SmallImageSize.Width }/{ this.Configuration.SmallImageSize.Height }");
}
protected Image MakeFullsizeImage(Guid id, string caption = null)
{
return new Image($"{this.HttpContext.ImageBaseUrl }/{id}", caption, $"{this.HttpContext.ImageBaseUrl }/{id}/{ this.Configuration.SmallImageSize.Width }/{ this.Configuration.SmallImageSize.Height }");
}
protected Image MakeImage(Guid id, string type, ImageSize imageSize)
{
return this.MakeImage(id, type, imageSize.Width, imageSize.Height);
}
protected Image MakeLabelThumbnailImage(Guid id)
{
return MakeThumbnailImage(id, "label");
}
protected string MakeLastFmUrl(string artistName, string releaseTitle)
{
return "http://www.last.fm/music/" + this.HttpEncoder.UrlEncode($"{ artistName }/{ releaseTitle }");
}
protected Image MakePlaylistThumbnailImage(Guid id)
{
return MakeThumbnailImage(id, "playlist");
}
protected Image MakeReleaseThumbnailImage(Guid id)
{
return MakeThumbnailImage(id, "release");
}
protected Image MakeTrackThumbnailImage(Guid id)
{
return MakeThumbnailImage(id, "track");
}
protected Image MakeUserThumbnailImage(Guid id)
{
return MakeThumbnailImage(id, "user");
}
protected async Task<OperationResult<short>> SetArtistRating(Guid artistId, ApplicationUser user, short rating)
{
@ -461,71 +517,13 @@ namespace Roadie.Api.Services
};
}
protected Image MakeArtistThumbnailImage(Guid id)
private Image MakeImage(Guid id, string type, int? width, int? height, string caption = null)
{
return MakeThumbnailImage(id, "artist");
}
protected Image MakeCollectionThumbnailImage(Guid id)
{
return MakeThumbnailImage(id, "collection");
}
protected Image MakeImage(Guid id, int width = 200, int height = 200)
{
return new Image($"{this.HttpContext.ImageBaseUrl }/{id}/{ width }/{ height }");
}
protected Image MakeImage(Guid id, string type, ImageSize imageSize)
{
return this.MakeImage(id, type, imageSize.Width, imageSize.Height);
}
protected Image MakeLabelThumbnailImage(Guid id)
{
return MakeThumbnailImage(id, "label");
}
protected string MakeLastFmUrl(string artistName, string releaseTitle)
{
return "http://www.last.fm/music/" + this.HttpEncoder.UrlEncode($"{ artistName }/{ releaseTitle }");
}
protected Image MakePlaylistThumbnailImage(Guid id)
{
return MakeThumbnailImage(id, "playlist");
}
protected Image MakeReleaseThumbnailImage(Guid id)
{
return MakeThumbnailImage(id, "release");
}
protected Image MakeTrackThumbnailImage(Guid id)
{
return MakeThumbnailImage(id, "track");
}
protected Image MakeUserThumbnailImage(Guid id)
{
return MakeThumbnailImage(id, "user");
}
private Image MakeImage(Guid id, string type, int? width, int? height)
{
if (width.HasValue && height.HasValue)
if (width.HasValue && height.HasValue && (width.Value != this.Configuration.ThumbnailImageSize.Width || height.Value != this.Configuration.ThumbnailImageSize.Height))
{
return new Image($"{this.HttpContext.ImageBaseUrl }/{type}/{id}/{width}/{height}");
return new Image($"{this.HttpContext.ImageBaseUrl }/{type}/{id}/{width}/{height}", caption, $"{this.HttpContext.ImageBaseUrl }/{type}/{id}/{ this.Configuration.ThumbnailImageSize.Width }/{ this.Configuration.ThumbnailImageSize.Height }");
}
return new Image($"{this.HttpContext.ImageBaseUrl }/{type}/{id}");
}
public Image MakeThumbnailImage(Guid id, string type, int? width = null, int? height = null)
{
return this.MakeImage(id, type, width ?? this.Configuration.ThumbnailImageSize.Width, height ?? this.Configuration.ThumbnailImageSize.Height);
return new Image($"{this.HttpContext.ImageBaseUrl }/{type}/{id}", caption, null);
}
}
}

View file

@ -197,7 +197,7 @@ namespace Roadie.Api
options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
})
.AddXmlSerializerFormatters()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
.SetCompatibilityVersion(CompatibilityVersion.Latest);
services.AddHttpContextAccessor();
services.AddScoped<IHttpContext>(factory =>

View file

@ -12,6 +12,9 @@ namespace Roadie.Library.Data
public int BookmarkTargetId { get; set; }
[Column("bookmarkType")]
public short? Type { get; set; }
// [Column("bookmarkType")]
public BookmarkType? BookmarkType { get; set; }
public ApplicationUser User { get; set; }

View file

@ -23,6 +23,17 @@ namespace Roadie.Library.Data
[MaxLength(65535)]
public string Profile { get; set; }
[Column("artistCount")]
public int? ArtistCount { get; set; } // TODO update this on artist folder scane
[Column("releaseCount")]
public int? ReleaseCount { get; set; } // TODO update this on artist folder scan
[Column("trackCount")]
public int? TrackCount { get; set; } // TODO update this on artist folder scan
public List<ReleaseLabel> ReleaseLabels { get; set; }
}
}

View file

@ -74,13 +74,13 @@ namespace Roadie.Library.Data
v => string.IsNullOrEmpty(v) ? CollectionType.Unknown : (CollectionType)Enum.Parse(typeof(CollectionType), v))
.HasDefaultValue(CollectionType.Unknown);
builder
.Entity<Bookmark>()
.Property(e => e.BookmarkType)
.HasConversion(
v => v.ToString(),
v => string.IsNullOrEmpty(v) ? BookmarkType.Unknown : (BookmarkType)Enum.Parse(typeof(BookmarkType), v))
.HasDefaultValue(BookmarkType.Unknown);
//builder
// .Entity<Bookmark>()
// .Property(e => e.BookmarkType)
// .HasConversion(
// v => v.ToString(),
// v => string.IsNullOrEmpty(v) ? BookmarkType.Unknown : (BookmarkType)Enum.Parse(typeof(BookmarkType), v))
// .HasDefaultValue(BookmarkType.Unknown);
builder.Entity<ReleaseLabel>()
.HasOne(rl => rl.Release)

View file

@ -24,7 +24,7 @@ namespace Roadie.Library.Models
public string ArtistType { get; set; }
public IEnumerable<DataToken> AssociatedArtists { get; set; }
public IEnumerable<ArtistList> AssociatedArtists { get; set; }
public string BandStatus { get; set; }

View file

@ -80,7 +80,7 @@ namespace Roadie.Library.Models
}
}
public BookmarkList UserBookmark { get; set; }
public bool UserBookmarked { get; set; }
public EntityModelBase()
{

View file

@ -22,6 +22,9 @@ namespace Roadie.Library.Models
[MaxLength(500)]
public string Url { get; set; }
[MaxLength(500)]
public string ThumbnailUrl { get; set; }
public Image()
{
}
@ -29,12 +32,18 @@ namespace Roadie.Library.Models
/// <summary>
/// Set image Url to given value and nullify other entity values, intended to be used in List collection (like images for an artist)
/// </summary>
public Image(string url)
public Image(string url) : this(url, null, null)
{
}
public Image(string url, string caption, string thumbnailUrl)
{
this.Url = url;
this.ThumbnailUrl = thumbnailUrl;
this.CreatedDate = null;
this.Id = null;
this.Status = null;
this.Caption = caption;
}
public Image(byte[] bytes)