2018-11-15 15:10:29 +00:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Identity;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using Roadie.Api.Services;
|
|
|
|
|
using Roadie.Library.Caching;
|
2019-06-08 22:32:15 +00:00
|
|
|
|
using Roadie.Library.Configuration;
|
2018-11-15 15:10:29 +00:00
|
|
|
|
using Roadie.Library.Models.Pagination;
|
2019-01-12 00:27:49 +00:00
|
|
|
|
using Roadie.Library.Utility;
|
2018-12-01 03:22:35 +00:00
|
|
|
|
using System;
|
2019-07-03 16:21:29 +00:00
|
|
|
|
using System.Collections.Generic;
|
2019-08-03 15:23:46 +00:00
|
|
|
|
using System.Linq;
|
2018-11-15 15:10:29 +00:00
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace Roadie.Api.Controllers
|
|
|
|
|
{
|
|
|
|
|
[Produces("application/json")]
|
2018-11-18 16:40:52 +00:00
|
|
|
|
[Route("users")]
|
2018-11-15 15:10:29 +00:00
|
|
|
|
[ApiController]
|
2018-12-01 03:22:35 +00:00
|
|
|
|
[Authorize]
|
2018-11-15 15:10:29 +00:00
|
|
|
|
public class UserController : EntityControllerBase
|
|
|
|
|
{
|
2019-01-12 00:27:49 +00:00
|
|
|
|
private IHttpContext RoadieHttpContext { get; }
|
2022-01-18 22:52:02 +00:00
|
|
|
|
|
2019-05-29 22:25:40 +00:00
|
|
|
|
private IUserService UserService { get; }
|
2018-11-15 15:10:29 +00:00
|
|
|
|
|
2020-06-07 22:46:24 +00:00
|
|
|
|
private readonly ITokenService TokenService;
|
|
|
|
|
|
|
|
|
|
public UserController(
|
|
|
|
|
IUserService userService,
|
|
|
|
|
ILogger<UserController> logger,
|
|
|
|
|
ICacheManager cacheManager,
|
|
|
|
|
ITokenService tokenService,
|
|
|
|
|
UserManager<Library.Identity.User> userManager,
|
|
|
|
|
IHttpContext httpContext,
|
|
|
|
|
IRoadieSettings roadieSettings)
|
2019-06-08 22:32:15 +00:00
|
|
|
|
: base(cacheManager, roadieSettings, userManager)
|
2018-11-15 15:10:29 +00:00
|
|
|
|
{
|
2019-10-23 13:45:36 +00:00
|
|
|
|
Logger = logger;
|
2019-07-03 16:21:29 +00:00
|
|
|
|
UserService = userService;
|
|
|
|
|
TokenService = tokenService;
|
|
|
|
|
RoadieHttpContext = httpContext;
|
2018-11-15 15:10:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-06-07 22:46:24 +00:00
|
|
|
|
[HttpPost("deleteAllBookmarks")]
|
|
|
|
|
[ProducesResponseType(200)]
|
|
|
|
|
public async Task<IActionResult> DeleteAllBookmarks()
|
|
|
|
|
{
|
|
|
|
|
var result = await UserService.DeleteAllBookmarksAsync(await CurrentUserModel().ConfigureAwait(false)).ConfigureAwait(false);
|
|
|
|
|
if (!result.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
return StatusCode((int)HttpStatusCode.InternalServerError);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CacheManager.ClearRegion(ControllerCacheRegionUrn);
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet("{id}")]
|
2019-08-02 20:59:24 +00:00
|
|
|
|
[ProducesResponseType(200)]
|
|
|
|
|
[ProducesResponseType(204)]
|
|
|
|
|
[ProducesResponseType(404)]
|
2020-06-07 22:46:24 +00:00
|
|
|
|
public async Task<IActionResult> Get(Guid id, string inc = null)
|
2019-08-02 20:59:24 +00:00
|
|
|
|
{
|
2020-01-28 13:48:59 +00:00
|
|
|
|
var user = await CurrentUserModel().ConfigureAwait(false);
|
2020-06-21 20:39:14 +00:00
|
|
|
|
var result = await CacheManager.GetAsync($"urn:user_model_by_id:{id}", async () =>
|
|
|
|
|
{
|
|
|
|
|
return await UserService.ByIdAsync(user, id, (inc ?? Library.Models.Users.User.DefaultIncludes)
|
|
|
|
|
.ToLower()
|
|
|
|
|
.Split(","))
|
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
},
|
|
|
|
|
ControllerCacheRegionUrn).ConfigureAwait(false);
|
2020-01-28 13:48:59 +00:00
|
|
|
|
if (result?.IsNotFoundResult != false)
|
2019-08-02 20:59:24 +00:00
|
|
|
|
{
|
|
|
|
|
return NotFound();
|
|
|
|
|
}
|
|
|
|
|
if (!result.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
return StatusCode((int)HttpStatusCode.InternalServerError);
|
|
|
|
|
}
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-07 22:46:24 +00:00
|
|
|
|
[HttpGet("accountsettings/{id}")]
|
2018-12-16 23:37:19 +00:00
|
|
|
|
[ProducesResponseType(200)]
|
|
|
|
|
[ProducesResponseType(204)]
|
|
|
|
|
[ProducesResponseType(404)]
|
2020-06-07 22:46:24 +00:00
|
|
|
|
public async Task<IActionResult> GetAccountSettings(Guid id, string inc = null)
|
2018-12-16 23:37:19 +00:00
|
|
|
|
{
|
2020-01-28 13:48:59 +00:00
|
|
|
|
var user = await CurrentUserModel().ConfigureAwait(false);
|
2020-06-07 22:46:24 +00:00
|
|
|
|
var result = await CacheManager.GetAsync($"urn:user_edit_model_by_id:{id}", async () => await UserService.ByIdAsync(user, id, (inc ?? Library.Models.Users.User.DefaultIncludes).ToLower().Split(","), true).ConfigureAwait(false), ControllerCacheRegionUrn).ConfigureAwait(false);
|
2020-01-28 13:48:59 +00:00
|
|
|
|
if (result?.IsNotFoundResult != false)
|
2019-06-08 22:32:15 +00:00
|
|
|
|
{
|
2019-08-02 20:59:24 +00:00
|
|
|
|
return NotFound();
|
|
|
|
|
}
|
|
|
|
|
if (!result.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
return StatusCode((int)HttpStatusCode.InternalServerError);
|
2019-06-08 22:32:15 +00:00
|
|
|
|
}
|
2020-06-07 22:46:24 +00:00
|
|
|
|
result.AdditionalClientData = new Dictionary<string, object>();
|
|
|
|
|
if (RoadieSettings.Integrations.LastFmProviderEnabled)
|
|
|
|
|
{
|
|
|
|
|
var lastFmCallBackUrl = $"{RoadieHttpContext.BaseUrl}/users/integration/grant?userId={user.UserId}&iname=lastfm";
|
|
|
|
|
result.AdditionalClientData.Add("lastFMIntegrationUrl", $"http://www.last.fm/api/auth/?api_key={RoadieSettings.Integrations.LastFMApiKey}&cb={WebUtility.UrlEncode(lastFmCallBackUrl)}");
|
|
|
|
|
}
|
2018-12-16 23:37:19 +00:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
2018-11-15 15:10:29 +00:00
|
|
|
|
|
2019-07-03 16:21:29 +00:00
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
[HttpGet("integration/grant")]
|
|
|
|
|
[ProducesResponseType(200)]
|
|
|
|
|
public async Task<IActionResult> IntegrationGrant(Guid userId, string iname, string token)
|
|
|
|
|
{
|
2020-06-07 22:46:24 +00:00
|
|
|
|
var result = await UserService.UpdateIntegrationGrantAsync(userId, iname, token).ConfigureAwait(false);
|
|
|
|
|
if (!result.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
return Content("Error while attempting to enable integration");
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-03 16:21:29 +00:00
|
|
|
|
return Content("Successfully enabled integration!");
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-05 22:40:33 +00:00
|
|
|
|
[HttpGet]
|
2018-12-16 23:37:19 +00:00
|
|
|
|
[ProducesResponseType(200)]
|
2019-07-03 16:21:29 +00:00
|
|
|
|
public async Task<IActionResult> List([FromQuery] PagedRequest request)
|
2018-12-16 23:37:19 +00:00
|
|
|
|
{
|
2020-06-07 22:46:24 +00:00
|
|
|
|
var result = await UserService.ListAsync(request).ConfigureAwait(false);
|
|
|
|
|
if (!result.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
return StatusCode((int)HttpStatusCode.InternalServerError);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-05 22:40:33 +00:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost("setArtistBookmark/{artistId}/{isBookmarked}")]
|
|
|
|
|
[ProducesResponseType(200)]
|
|
|
|
|
public async Task<IActionResult> SetArtistBookmark(Guid artistId, bool isBookmarked)
|
|
|
|
|
{
|
2020-06-07 22:46:24 +00:00
|
|
|
|
var result = await UserService.SetArtistBookmarkAsync(artistId, await CurrentUserModel().ConfigureAwait(false), isBookmarked).ConfigureAwait(false);
|
|
|
|
|
if (!result.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
return StatusCode((int)HttpStatusCode.InternalServerError);
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-03 16:21:29 +00:00
|
|
|
|
CacheManager.ClearRegion(ControllerCacheRegionUrn);
|
2019-01-05 22:40:33 +00:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost("setArtistDisliked/{artistId}/{isDisliked}")]
|
|
|
|
|
[ProducesResponseType(200)]
|
|
|
|
|
public async Task<IActionResult> SetArtistDisliked(Guid artistId, bool isDisliked)
|
|
|
|
|
{
|
2020-06-07 22:46:24 +00:00
|
|
|
|
var result = await UserService.SetArtistDislikedAsync(artistId, await CurrentUserModel().ConfigureAwait(false), isDisliked).ConfigureAwait(false);
|
|
|
|
|
if (!result.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
return StatusCode((int)HttpStatusCode.InternalServerError);
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-03 16:21:29 +00:00
|
|
|
|
CacheManager.ClearRegion(ControllerCacheRegionUrn);
|
2019-01-05 22:40:33 +00:00
|
|
|
|
return Ok(result);
|
2018-12-16 23:37:19 +00:00
|
|
|
|
}
|
2018-11-15 15:10:29 +00:00
|
|
|
|
|
2019-01-05 22:40:33 +00:00
|
|
|
|
[HttpPost("setArtistFavorite/{artistId}/{isFavorite}")]
|
2018-12-01 03:22:35 +00:00
|
|
|
|
[ProducesResponseType(200)]
|
2019-01-05 22:40:33 +00:00
|
|
|
|
public async Task<IActionResult> SetArtistFavorite(Guid artistId, bool isFavorite)
|
2018-12-01 03:22:35 +00:00
|
|
|
|
{
|
2020-06-07 22:46:24 +00:00
|
|
|
|
var result = await UserService.SetArtistFavoriteAsync(artistId, await CurrentUserModel().ConfigureAwait(false), isFavorite).ConfigureAwait(false);
|
|
|
|
|
if (!result.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
return StatusCode((int)HttpStatusCode.InternalServerError);
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-03 16:21:29 +00:00
|
|
|
|
CacheManager.ClearRegion(ControllerCacheRegionUrn);
|
2018-12-01 03:22:35 +00:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-05 22:40:33 +00:00
|
|
|
|
[HttpPost("setArtistRating/{releaseId}/{rating}")]
|
2018-12-01 03:22:35 +00:00
|
|
|
|
[ProducesResponseType(200)]
|
2019-01-05 22:40:33 +00:00
|
|
|
|
public async Task<IActionResult> SetArtistRating(Guid releaseId, short rating)
|
2018-12-01 03:22:35 +00:00
|
|
|
|
{
|
2020-06-07 22:46:24 +00:00
|
|
|
|
var result = await UserService.SetArtistRatingAsync(releaseId, await CurrentUserModel().ConfigureAwait(false), rating).ConfigureAwait(false);
|
|
|
|
|
if (!result.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
return StatusCode((int)HttpStatusCode.InternalServerError);
|
|
|
|
|
}
|
2018-12-01 03:22:35 +00:00
|
|
|
|
|
2019-11-24 21:58:38 +00:00
|
|
|
|
CacheManager.ClearRegion(ControllerCacheRegionUrn);
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-05 22:40:33 +00:00
|
|
|
|
[HttpPost("setCollectionBookmark/{collectionId}/{isBookmarked}")]
|
2018-12-01 03:22:35 +00:00
|
|
|
|
[ProducesResponseType(200)]
|
2019-01-05 22:40:33 +00:00
|
|
|
|
public async Task<IActionResult> SetCollectionBookmark(Guid collectionId, bool isBookmarked)
|
2018-12-01 03:22:35 +00:00
|
|
|
|
{
|
2020-06-07 22:46:24 +00:00
|
|
|
|
var result = await UserService.SetCollectionBookmarkAsync(collectionId, await CurrentUserModel().ConfigureAwait(false), isBookmarked).ConfigureAwait(false);
|
|
|
|
|
if (!result.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
return StatusCode((int)HttpStatusCode.InternalServerError);
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-03 16:21:29 +00:00
|
|
|
|
CacheManager.ClearRegion(ControllerCacheRegionUrn);
|
2018-12-01 03:22:35 +00:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-05 22:40:33 +00:00
|
|
|
|
[HttpPost("setLabelBookmark/{labelId}/{isBookmarked}")]
|
2018-12-01 18:05:24 +00:00
|
|
|
|
[ProducesResponseType(200)]
|
2019-01-05 22:40:33 +00:00
|
|
|
|
public async Task<IActionResult> SetLabelBookmark(Guid labelId, bool isBookmarked)
|
2018-12-01 18:05:24 +00:00
|
|
|
|
{
|
2020-06-07 22:46:24 +00:00
|
|
|
|
var result = await UserService.SetLabelBookmarkAsync(labelId, await CurrentUserModel().ConfigureAwait(false), isBookmarked).ConfigureAwait(false);
|
|
|
|
|
if (!result.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
return StatusCode((int)HttpStatusCode.InternalServerError);
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-03 16:21:29 +00:00
|
|
|
|
CacheManager.ClearRegion(ControllerCacheRegionUrn);
|
2018-12-01 18:05:24 +00:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-05 22:40:33 +00:00
|
|
|
|
[HttpPost("setPlaylistBookmark/{playlistId}/{isBookmarked}")]
|
2018-12-24 22:35:59 +00:00
|
|
|
|
[ProducesResponseType(200)]
|
2019-01-05 22:40:33 +00:00
|
|
|
|
public async Task<IActionResult> SetPlaylistBookmark(Guid playlistId, bool isBookmarked)
|
2018-12-24 22:35:59 +00:00
|
|
|
|
{
|
2020-06-07 22:46:24 +00:00
|
|
|
|
var result = await UserService.SetPlaylistBookmarkAsync(playlistId, await CurrentUserModel().ConfigureAwait(false), isBookmarked).ConfigureAwait(false);
|
|
|
|
|
if (!result.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
return StatusCode((int)HttpStatusCode.InternalServerError);
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-03 16:21:29 +00:00
|
|
|
|
CacheManager.ClearRegion(ControllerCacheRegionUrn);
|
2018-12-24 22:35:59 +00:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-05 22:40:33 +00:00
|
|
|
|
[HttpPost("setReleaseBookmark/{releaseId}/{isBookmarked}")]
|
2018-12-01 18:05:24 +00:00
|
|
|
|
[ProducesResponseType(200)]
|
2019-01-05 22:40:33 +00:00
|
|
|
|
public async Task<IActionResult> SetReleaseBookmark(Guid releaseId, bool isBookmarked)
|
2018-12-01 18:05:24 +00:00
|
|
|
|
{
|
2020-06-07 22:46:24 +00:00
|
|
|
|
var result = await UserService.SetReleaseBookmarkAsync(releaseId, await CurrentUserModel().ConfigureAwait(false), isBookmarked).ConfigureAwait(false);
|
|
|
|
|
if (!result.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
return StatusCode((int)HttpStatusCode.InternalServerError);
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-03 16:21:29 +00:00
|
|
|
|
CacheManager.ClearRegion(ControllerCacheRegionUrn);
|
2018-12-01 18:05:24 +00:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
2018-12-01 03:22:35 +00:00
|
|
|
|
|
2018-12-24 22:35:59 +00:00
|
|
|
|
[HttpPost("setReleaseDisliked/{releaseId}/{isDisliked}")]
|
|
|
|
|
[ProducesResponseType(200)]
|
|
|
|
|
public async Task<IActionResult> SetReleaseDisliked(Guid releaseId, bool isDisliked)
|
|
|
|
|
{
|
2020-06-07 22:46:24 +00:00
|
|
|
|
var result = await UserService.SetReleaseDislikedAsync(releaseId, await CurrentUserModel().ConfigureAwait(false), isDisliked).ConfigureAwait(false);
|
|
|
|
|
if (!result.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
return StatusCode((int)HttpStatusCode.InternalServerError);
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-03 16:21:29 +00:00
|
|
|
|
CacheManager.ClearRegion(ControllerCacheRegionUrn);
|
2018-12-24 22:35:59 +00:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-05 22:40:33 +00:00
|
|
|
|
[HttpPost("setReleaseFavorite/{releaseId}/{isFavorite}")]
|
2018-12-11 23:09:52 +00:00
|
|
|
|
[ProducesResponseType(200)]
|
2019-01-05 22:40:33 +00:00
|
|
|
|
public async Task<IActionResult> SetReleaseFavorite(Guid releaseId, bool isFavorite)
|
2018-12-11 23:09:52 +00:00
|
|
|
|
{
|
2020-06-07 22:46:24 +00:00
|
|
|
|
var result = await UserService.SetReleaseFavoriteAsync(releaseId, await CurrentUserModel().ConfigureAwait(false), isFavorite).ConfigureAwait(false);
|
|
|
|
|
if (!result.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
return StatusCode((int)HttpStatusCode.InternalServerError);
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-03 16:21:29 +00:00
|
|
|
|
CacheManager.ClearRegion(ControllerCacheRegionUrn);
|
2018-12-11 23:09:52 +00:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-05 22:40:33 +00:00
|
|
|
|
[HttpPost("setReleaseRating/{releaseId}/{rating}")]
|
2018-12-12 14:31:39 +00:00
|
|
|
|
[ProducesResponseType(200)]
|
2019-01-05 22:40:33 +00:00
|
|
|
|
public async Task<IActionResult> SetReleaseRating(Guid releaseId, short rating)
|
2018-12-12 14:31:39 +00:00
|
|
|
|
{
|
2020-06-07 22:46:24 +00:00
|
|
|
|
var result = await UserService.SetReleaseRatingAsync(releaseId, await CurrentUserModel().ConfigureAwait(false), rating).ConfigureAwait(false);
|
|
|
|
|
if (!result.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
return StatusCode((int)HttpStatusCode.InternalServerError);
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-03 16:21:29 +00:00
|
|
|
|
CacheManager.ClearRegion(ControllerCacheRegionUrn);
|
2018-12-12 14:31:39 +00:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost("setTrackBookmark/{trackId}/{isBookmarked}")]
|
|
|
|
|
[ProducesResponseType(200)]
|
|
|
|
|
public async Task<IActionResult> SetTrackBookmark(Guid trackId, bool isBookmarked)
|
|
|
|
|
{
|
2020-06-07 22:46:24 +00:00
|
|
|
|
var result = await UserService.SetTrackBookmarkAsync(trackId, await CurrentUserModel().ConfigureAwait(false), isBookmarked).ConfigureAwait(false);
|
|
|
|
|
if (!result.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
return StatusCode((int)HttpStatusCode.InternalServerError);
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-03 16:21:29 +00:00
|
|
|
|
CacheManager.ClearRegion(ControllerCacheRegionUrn);
|
2018-12-12 14:31:39 +00:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-05 22:40:33 +00:00
|
|
|
|
[HttpPost("setTrackDisliked/{trackId}/{isDisliked}")]
|
2018-12-12 14:31:39 +00:00
|
|
|
|
[ProducesResponseType(200)]
|
2019-01-05 22:40:33 +00:00
|
|
|
|
public async Task<IActionResult> SetTrackDisliked(Guid trackId, bool isDisliked)
|
2018-12-12 14:31:39 +00:00
|
|
|
|
{
|
2020-06-07 22:46:24 +00:00
|
|
|
|
var result = await UserService.SetTrackDislikedAsync(trackId, await CurrentUserModel().ConfigureAwait(false), isDisliked).ConfigureAwait(false);
|
|
|
|
|
if (!result.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
return StatusCode((int)HttpStatusCode.InternalServerError);
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-03 16:21:29 +00:00
|
|
|
|
CacheManager.ClearRegion(ControllerCacheRegionUrn);
|
2018-12-12 14:31:39 +00:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-05 22:40:33 +00:00
|
|
|
|
[HttpPost("setTrackFavorite/{trackId}/{isFavorite}")]
|
2018-12-12 14:31:39 +00:00
|
|
|
|
[ProducesResponseType(200)]
|
2019-01-05 22:40:33 +00:00
|
|
|
|
public async Task<IActionResult> SetTrackFavorite(Guid trackId, bool isFavorite)
|
2018-12-12 14:31:39 +00:00
|
|
|
|
{
|
2020-06-07 22:46:24 +00:00
|
|
|
|
var result = await UserService.SetTrackFavoriteAsync(trackId, await CurrentUserModel().ConfigureAwait(false), isFavorite).ConfigureAwait(false);
|
|
|
|
|
if (!result.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
return StatusCode((int)HttpStatusCode.InternalServerError);
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-03 16:21:29 +00:00
|
|
|
|
CacheManager.ClearRegion(ControllerCacheRegionUrn);
|
2018-12-12 14:31:39 +00:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-05 22:40:33 +00:00
|
|
|
|
[HttpPost("setTrackRating/{trackId}/{rating}")]
|
2018-12-12 14:31:39 +00:00
|
|
|
|
[ProducesResponseType(200)]
|
2019-01-05 22:40:33 +00:00
|
|
|
|
public async Task<IActionResult> SetTrackRating(Guid trackId, short rating)
|
2018-12-12 14:31:39 +00:00
|
|
|
|
{
|
2020-06-07 22:46:24 +00:00
|
|
|
|
var result = await UserService.SetTrackRatingAsync(trackId, await CurrentUserModel().ConfigureAwait(false), rating).ConfigureAwait(false);
|
|
|
|
|
if (!result.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
return StatusCode((int)HttpStatusCode.InternalServerError);
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-03 16:21:29 +00:00
|
|
|
|
CacheManager.ClearRegion(ControllerCacheRegionUrn);
|
2018-12-12 14:31:39 +00:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
2018-12-01 03:22:35 +00:00
|
|
|
|
|
2019-01-05 22:40:33 +00:00
|
|
|
|
[HttpPost("profile/edit")]
|
2018-11-15 15:10:29 +00:00
|
|
|
|
[ProducesResponseType(200)]
|
2019-11-28 17:38:26 +00:00
|
|
|
|
public async Task<IActionResult> UpdateProfile(Library.Models.Users.User model)
|
2018-11-15 15:10:29 +00:00
|
|
|
|
{
|
2019-08-02 20:59:24 +00:00
|
|
|
|
if (!ModelState.IsValid)
|
|
|
|
|
{
|
|
|
|
|
return BadRequest(ModelState);
|
|
|
|
|
}
|
2020-01-28 13:48:59 +00:00
|
|
|
|
var user = await CurrentUserModel().ConfigureAwait(false);
|
2020-06-07 22:46:24 +00:00
|
|
|
|
var result = await UserService.UpdateProfileAsync(user, model).ConfigureAwait(false);
|
|
|
|
|
if (result?.IsNotFoundResult != false)
|
|
|
|
|
{
|
|
|
|
|
return NotFound();
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-03 15:23:46 +00:00
|
|
|
|
if (!result.IsSuccess)
|
|
|
|
|
{
|
2019-11-28 17:38:26 +00:00
|
|
|
|
if (result.IsAccessDeniedResult)
|
2019-08-03 15:23:46 +00:00
|
|
|
|
{
|
|
|
|
|
return StatusCode((int)HttpStatusCode.Forbidden);
|
|
|
|
|
}
|
|
|
|
|
if (result.Messages?.Any() ?? false)
|
|
|
|
|
{
|
|
|
|
|
return StatusCode((int)HttpStatusCode.BadRequest, result.Messages);
|
|
|
|
|
}
|
|
|
|
|
return StatusCode((int)HttpStatusCode.InternalServerError);
|
|
|
|
|
}
|
2019-07-03 16:21:29 +00:00
|
|
|
|
CacheManager.ClearRegion(ControllerCacheRegionUrn);
|
2020-01-28 13:48:59 +00:00
|
|
|
|
var modelUser = await UserManager.FindByNameAsync(model.UserName).ConfigureAwait(false);
|
2020-06-07 22:46:24 +00:00
|
|
|
|
var t = await TokenService.GenerateTokenAsync(modelUser, UserManager).ConfigureAwait(false);
|
2019-07-03 16:21:29 +00:00
|
|
|
|
CacheManager.ClearRegion(ControllerCacheRegionUrn);
|
2019-08-03 15:23:46 +00:00
|
|
|
|
var avatarUrl = $"{RoadieHttpContext.ImageBaseUrl}/user/{modelUser.RoadieId}/{RoadieSettings.ThumbnailImageSize.Width}/{RoadieSettings.ThumbnailImageSize.Height}";
|
2019-01-05 22:40:33 +00:00
|
|
|
|
return Ok(new
|
|
|
|
|
{
|
|
|
|
|
IsSuccess = true,
|
|
|
|
|
Username = modelUser.UserName,
|
2019-01-27 05:05:43 +00:00
|
|
|
|
modelUser.RemoveTrackFromQueAfterPlayed,
|
2019-01-05 22:40:33 +00:00
|
|
|
|
modelUser.Email,
|
|
|
|
|
modelUser.LastLogin,
|
|
|
|
|
avatarUrl,
|
|
|
|
|
Token = t,
|
|
|
|
|
modelUser.Timeformat,
|
2019-08-02 20:59:24 +00:00
|
|
|
|
modelUser.Timezone,
|
|
|
|
|
DefaultRowsPerPage = modelUser.DefaultRowsPerPage ?? RoadieSettings.DefaultRowsPerPage
|
2019-01-05 22:40:33 +00:00
|
|
|
|
});
|
2018-11-15 15:10:29 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-01-18 22:52:02 +00:00
|
|
|
|
}
|