mirror of
https://github.com/sphildreth/roadie
synced 2024-11-10 06:44:12 +00:00
v20190228.1
This commit is contained in:
parent
ed4030dcda
commit
bdcc8993c3
9 changed files with 188 additions and 3 deletions
15
Inspector/Properties/PublishProfiles/FolderProfile.pubxml
Normal file
15
Inspector/Properties/PublishProfiles/FolderProfile.pubxml
Normal file
|
@ -0,0 +1,15 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
https://go.microsoft.com/fwlink/?LinkID=208121.
|
||||
-->
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<PublishProtocol>FileSystem</PublishProtocol>
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
<TargetFramework>netcoreapp2.2</TargetFramework>
|
||||
<PublishDir>bin\Release\netcoreapp2.2\publish\</PublishDir>
|
||||
<SelfContained>false</SelfContained>
|
||||
<_IsPortable>true</_IsPortable>
|
||||
</PropertyGroup>
|
||||
</Project>
|
|
@ -37,6 +37,7 @@ namespace Roadie.Library.Data
|
|||
public RoadieDbContext(DbContextOptions<RoadieDbContext> options)
|
||||
: base(options)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder builder)
|
||||
|
|
|
@ -30,6 +30,9 @@ namespace Roadie.Library.Models.Playlists
|
|||
public short? TrackCount { get; set; }
|
||||
public short? ReleaseCount { get; set; }
|
||||
public decimal? Duration { get; set; }
|
||||
|
||||
// When populated a "data:image" base64 byte array of an image to use as new Thumbnail
|
||||
public string NewThumbnailData { get; set; }
|
||||
public string DurationTime
|
||||
{
|
||||
get
|
||||
|
|
|
@ -9,5 +9,6 @@ namespace Roadie.Library.Models.Playlists
|
|||
{
|
||||
public TrackList Track { get; set; }
|
||||
public int ListNumber { get; set; }
|
||||
public int? OldListNumber { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Roadie.Library.Models.Playlists
|
||||
{
|
||||
[Serializable]
|
||||
public class PlaylistTrackModifyRequest
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public List<PlaylistTrack> Tracks { get; set; }
|
||||
}
|
||||
}
|
|
@ -22,5 +22,9 @@ namespace Roadie.Api.Services
|
|||
Task<PagedResult<PlaylistList>> List(PagedRequest request, User roadieUser = null);
|
||||
|
||||
Task<OperationResult<bool>> ReorderPlaylist(data.Playlist playlist);
|
||||
|
||||
Task<OperationResult<bool>> UpdatePlaylist(User user, Playlist label);
|
||||
|
||||
Task<OperationResult<bool>> UpdatePlaylistTracks(User user, PlaylistTrackModifyRequest request);
|
||||
}
|
||||
}
|
|
@ -7,6 +7,7 @@ using Roadie.Library.Configuration;
|
|||
using Roadie.Library.Encoding;
|
||||
using Roadie.Library.Enums;
|
||||
using Roadie.Library.Extensions;
|
||||
using Roadie.Library.Imaging;
|
||||
using Roadie.Library.Models;
|
||||
using Roadie.Library.Models.Pagination;
|
||||
using Roadie.Library.Models.Playlists;
|
||||
|
@ -62,6 +63,113 @@ namespace Roadie.Api.Services
|
|||
};
|
||||
}
|
||||
|
||||
public async Task<OperationResult<bool>> UpdatePlaylistTracks(User user, PlaylistTrackModifyRequest request)
|
||||
{
|
||||
var sw = new Stopwatch();
|
||||
sw.Start();
|
||||
var errors = new List<Exception>();
|
||||
var playlist = this.DbContext.Playlists.Include(x => x.Tracks).FirstOrDefault(x => x.RoadieId == request.Id);
|
||||
if (playlist == null)
|
||||
{
|
||||
return new OperationResult<bool>(true, string.Format("Label Not Found [{0}]", request.Id));
|
||||
}
|
||||
try
|
||||
{
|
||||
var now = DateTime.UtcNow;
|
||||
|
||||
playlist.Tracks.Clear();
|
||||
|
||||
var tracks = (from t in this.DbContext.Tracks
|
||||
join plt in request.Tracks on t.RoadieId equals plt.Track.Id
|
||||
select t).ToArray();
|
||||
foreach(var newPlaylistTrack in request.Tracks.OrderBy(x => x.ListNumber))
|
||||
{
|
||||
var track = tracks.FirstOrDefault(x => x.RoadieId == newPlaylistTrack.Track.Id);
|
||||
playlist.Tracks.Add(new data.PlaylistTrack
|
||||
{
|
||||
ListNumber = newPlaylistTrack.ListNumber,
|
||||
PlayListId = playlist.Id,
|
||||
CreatedDate = now,
|
||||
TrackId = track.Id
|
||||
});
|
||||
}
|
||||
playlist.LastUpdated = now;
|
||||
await this.DbContext.SaveChangesAsync();
|
||||
|
||||
// await base.UpdatePlaylistCounts(playlist.Id, now);
|
||||
|
||||
this.Logger.LogInformation($"UpdatePlaylistTracks `{ playlist }` By User `{ user }`");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.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<bool>> UpdatePlaylist(User user, Playlist model)
|
||||
{
|
||||
var sw = new Stopwatch();
|
||||
sw.Start();
|
||||
var errors = new List<Exception>();
|
||||
var playlist = this.DbContext.Playlists.FirstOrDefault(x => x.RoadieId == model.Id);
|
||||
if (playlist == null)
|
||||
{
|
||||
return new OperationResult<bool>(true, string.Format("Label Not Found [{0}]", model.Id));
|
||||
}
|
||||
try
|
||||
{
|
||||
var now = DateTime.UtcNow;
|
||||
playlist.AlternateNames = model.AlternateNamesList.ToDelimitedList();
|
||||
playlist.Description = model.Description;
|
||||
playlist.IsLocked = model.IsLocked;
|
||||
playlist.IsPublic = model.IsPublic;
|
||||
playlist.Name = model.Name;
|
||||
playlist.Status = SafeParser.ToEnum<Statuses>(model.Status);
|
||||
playlist.Tags = model.TagsList.ToDelimitedList();
|
||||
playlist.URLs = model.URLsList.ToDelimitedList();
|
||||
|
||||
var playlistImage = ImageHelper.ImageDataFromUrl(model.NewThumbnailData);
|
||||
if (playlistImage != null)
|
||||
{
|
||||
// Ensure is jpeg first
|
||||
playlist.Thumbnail = ImageHelper.ConvertToJpegFormat(playlistImage);
|
||||
|
||||
// Resize to store in database as thumbnail
|
||||
playlist.Thumbnail = ImageHelper.ResizeImage(playlist.Thumbnail, this.Configuration.MediumImageSize.Width, this.Configuration.MediumImageSize.Height);
|
||||
}
|
||||
playlist.LastUpdated = now;
|
||||
await this.DbContext.SaveChangesAsync();
|
||||
|
||||
this.CacheManager.ClearRegion(playlist.CacheRegion);
|
||||
this.Logger.LogInformation($"UpdatePlaylist `{ playlist }` By User `{ user }`");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.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<bool>> AddTracksToPlaylist(data.Playlist playlist, IEnumerable<Guid> trackIds)
|
||||
{
|
||||
var sw = new Stopwatch();
|
||||
|
@ -152,7 +260,7 @@ namespace Roadie.Api.Services
|
|||
{
|
||||
return new OperationResult<bool>(true, string.Format("Playlist Not Found [{0}]", id));
|
||||
}
|
||||
if (!user.IsAdmin || user.Id != playlist.UserId)
|
||||
if (!user.IsAdmin && user.Id != playlist.UserId)
|
||||
{
|
||||
this.Logger.LogWarning("User `{0}` attempted to delete Playlist `{1}`", user, playlist);
|
||||
return new OperationResult<bool>("Access Denied")
|
||||
|
@ -280,7 +388,7 @@ namespace Roadie.Api.Services
|
|||
join pltr in this.DbContext.PlaylistTracks on pl.Id equals pltr.PlayListId
|
||||
join t in this.DbContext.Tracks on pltr.TrackId equals t.Id
|
||||
where pl.Id == playlist.Id
|
||||
select new { t, pltr });
|
||||
select new { t, pltr }).ToArray();
|
||||
|
||||
if (includes.Contains("stats"))
|
||||
{
|
||||
|
|
|
@ -96,5 +96,45 @@ namespace Roadie.Api.Controllers
|
|||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpPost("edit")]
|
||||
[ProducesResponseType(200)]
|
||||
[ProducesResponseType(404)]
|
||||
public async Task<IActionResult> Update(models.Playlists.Playlist playlist)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState);
|
||||
}
|
||||
var result = await this.PlaylistService.UpdatePlaylist(await this.CurrentUserModel(), playlist);
|
||||
if (result == null || result.IsNotFoundResult)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
if (!result.IsSuccess)
|
||||
{
|
||||
return StatusCode((int)HttpStatusCode.InternalServerError);
|
||||
}
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpPost("edittracks")]
|
||||
[ProducesResponseType(200)]
|
||||
[ProducesResponseType(404)]
|
||||
public async Task<IActionResult> UpdateTracks(models.Playlists.PlaylistTrackModifyRequest request)
|
||||
{
|
||||
var result = await this.PlaylistService.UpdatePlaylistTracks(await this.CurrentUserModel(), request);
|
||||
if (result == null || result.IsNotFoundResult)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
if (!result.IsSuccess)
|
||||
{
|
||||
return StatusCode((int)HttpStatusCode.InternalServerError);
|
||||
}
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -3,7 +3,7 @@
|
|||
"Roadie.Api": {
|
||||
"commandName": "Project",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Production"
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"applicationUrl": "http://localhost:5123/"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue