mirror of
https://github.com/sphildreth/roadie
synced 2024-11-10 06:44:12 +00:00
Release edit work
This commit is contained in:
parent
bbf85c0cf0
commit
d64fbe00a2
6 changed files with 369 additions and 0 deletions
|
@ -26,6 +26,17 @@ namespace Roadie.Api.Controllers
|
|||
this.AdminService = adminService;
|
||||
}
|
||||
|
||||
[HttpGet("clearcache")]
|
||||
[ProducesResponseType(200)]
|
||||
[Authorize("Admin")]
|
||||
public IActionResult ClearCache()
|
||||
{
|
||||
this.CacheManager.Clear();
|
||||
this.Logger.LogInformation("Cache Cleared");
|
||||
return Ok();
|
||||
}
|
||||
|
||||
|
||||
[HttpGet("scan/inbound")]
|
||||
[ProducesResponseType(200)]
|
||||
[Authorize("Admin")]
|
||||
|
|
149
RoadieApi/Controllers/LookupController.cs
Normal file
149
RoadieApi/Controllers/LookupController.cs
Normal file
|
@ -0,0 +1,149 @@
|
|||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Roadie.Api.Services;
|
||||
using Roadie.Library.Caching;
|
||||
using Roadie.Library.Identity;
|
||||
using Roadie.Library.Utility;
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Roadie.Api.Controllers
|
||||
{
|
||||
[Produces("application/json")]
|
||||
[Route("lookups")]
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
public class LookupController : EntityControllerBase
|
||||
{
|
||||
private ILookupService LookupService { get; }
|
||||
|
||||
public LookupController(ILabelService labelService, ILoggerFactory logger, ICacheManager cacheManager, IConfiguration configuration, UserManager<ApplicationUser> userManager, ILookupService lookupService)
|
||||
: base(cacheManager, configuration, userManager)
|
||||
{
|
||||
this.Logger = logger.CreateLogger("RoadieApi.Controllers.LookupController");
|
||||
this.LookupService = lookupService;
|
||||
}
|
||||
|
||||
[HttpGet("artistTypes")]
|
||||
[ProducesResponseType(200)]
|
||||
[ProducesResponseType(404)]
|
||||
public async Task<IActionResult> ArtistTypes(Guid id, string inc = null)
|
||||
{
|
||||
var result = await this.LookupService.ArtistTypes();
|
||||
if (!result.IsSuccess)
|
||||
{
|
||||
return StatusCode((int)HttpStatusCode.InternalServerError);
|
||||
}
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpGet("bandStatus")]
|
||||
[ProducesResponseType(200)]
|
||||
[ProducesResponseType(404)]
|
||||
public async Task<IActionResult> BandStatus(Guid id, string inc = null)
|
||||
{
|
||||
var result = await this.LookupService.BandStatus();
|
||||
if (!result.IsSuccess)
|
||||
{
|
||||
return StatusCode((int)HttpStatusCode.InternalServerError);
|
||||
}
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpGet("bookmarkTypes")]
|
||||
[ProducesResponseType(200)]
|
||||
[ProducesResponseType(404)]
|
||||
public async Task<IActionResult> BookmarkTypes(Guid id, string inc = null)
|
||||
{
|
||||
var result = await this.LookupService.BookmarkTypes();
|
||||
if (!result.IsSuccess)
|
||||
{
|
||||
return StatusCode((int)HttpStatusCode.InternalServerError);
|
||||
}
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpGet("collectionTypes")]
|
||||
[ProducesResponseType(200)]
|
||||
[ProducesResponseType(404)]
|
||||
public async Task<IActionResult> CollectionTypes(Guid id, string inc = null)
|
||||
{
|
||||
var result = await this.LookupService.CollectionTypes();
|
||||
if (!result.IsSuccess)
|
||||
{
|
||||
return StatusCode((int)HttpStatusCode.InternalServerError);
|
||||
}
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpGet("libraryStatus")]
|
||||
[ProducesResponseType(200)]
|
||||
[ProducesResponseType(404)]
|
||||
public async Task<IActionResult> LibraryStatus(Guid id, string inc = null)
|
||||
{
|
||||
var result = await this.LookupService.LibraryStatus();
|
||||
if (!result.IsSuccess)
|
||||
{
|
||||
return StatusCode((int)HttpStatusCode.InternalServerError);
|
||||
}
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpGet("queMessageTypes")]
|
||||
[ProducesResponseType(200)]
|
||||
[ProducesResponseType(404)]
|
||||
public async Task<IActionResult> QueMessageTypes(Guid id, string inc = null)
|
||||
{
|
||||
var result = await this.LookupService.QueMessageTypes();
|
||||
if (!result.IsSuccess)
|
||||
{
|
||||
return StatusCode((int)HttpStatusCode.InternalServerError);
|
||||
}
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpGet("releaseTypes")]
|
||||
[ProducesResponseType(200)]
|
||||
[ProducesResponseType(404)]
|
||||
public async Task<IActionResult> ReleaseTypes(Guid id, string inc = null)
|
||||
{
|
||||
var result = await this.LookupService.ReleaseTypes();
|
||||
if (!result.IsSuccess)
|
||||
{
|
||||
return StatusCode((int)HttpStatusCode.InternalServerError);
|
||||
}
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpGet("requestStatus")]
|
||||
[ProducesResponseType(200)]
|
||||
[ProducesResponseType(404)]
|
||||
public async Task<IActionResult> RequestStatus(Guid id, string inc = null)
|
||||
{
|
||||
var result = await this.LookupService.RequestStatus();
|
||||
if (!result.IsSuccess)
|
||||
{
|
||||
return StatusCode((int)HttpStatusCode.InternalServerError);
|
||||
}
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpGet("status")]
|
||||
[ProducesResponseType(200)]
|
||||
[ProducesResponseType(404)]
|
||||
public async Task<IActionResult> Status(Guid id, string inc = null)
|
||||
{
|
||||
var result = await this.LookupService.Status();
|
||||
if (!result.IsSuccess)
|
||||
{
|
||||
return StatusCode((int)HttpStatusCode.InternalServerError);
|
||||
}
|
||||
return Ok(result);
|
||||
}
|
||||
}
|
||||
}
|
21
RoadieApi/Services/ILookupService.cs
Normal file
21
RoadieApi/Services/ILookupService.cs
Normal file
|
@ -0,0 +1,21 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Roadie.Library;
|
||||
using Roadie.Library.Models;
|
||||
|
||||
namespace Roadie.Api.Services
|
||||
{
|
||||
public interface ILookupService
|
||||
{
|
||||
Task<OperationResult<IEnumerable<DataToken>>> ArtistTypes();
|
||||
Task<OperationResult<IEnumerable<DataToken>>> BandStatus();
|
||||
Task<OperationResult<IEnumerable<DataToken>>> BookmarkTypes();
|
||||
Task<OperationResult<IEnumerable<DataToken>>> CollectionTypes();
|
||||
Task<OperationResult<IEnumerable<DataToken>>> LibraryStatus();
|
||||
Task<OperationResult<IEnumerable<DataToken>>> QueMessageTypes();
|
||||
Task<OperationResult<IEnumerable<DataToken>>> ReleaseTypes();
|
||||
Task<OperationResult<IEnumerable<DataToken>>> RequestStatus();
|
||||
Task<OperationResult<IEnumerable<DataToken>>> Status();
|
||||
}
|
||||
}
|
145
RoadieApi/Services/LookupService.cs
Normal file
145
RoadieApi/Services/LookupService.cs
Normal file
|
@ -0,0 +1,145 @@
|
|||
using Microsoft.Extensions.Logging;
|
||||
using Roadie.Library;
|
||||
using Roadie.Library.Caching;
|
||||
using Roadie.Library.Configuration;
|
||||
using Roadie.Library.Encoding;
|
||||
using Roadie.Library.Models;
|
||||
using Roadie.Library.Utility;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using data = Roadie.Library.Data;
|
||||
|
||||
namespace Roadie.Api.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns lookups (or dictionaries) of various allowable values for a given Type
|
||||
/// </summary>
|
||||
public class LookupService : ServiceBase, ILookupService
|
||||
{
|
||||
public LookupService(IRoadieSettings configuration,
|
||||
IHttpEncoder httpEncoder,
|
||||
IHttpContext httpContext,
|
||||
data.IRoadieDbContext dbContext,
|
||||
ICacheManager cacheManager,
|
||||
ILogger<PlaylistService> logger)
|
||||
: base(configuration, httpEncoder, dbContext, cacheManager, logger, httpContext)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<OperationResult<IEnumerable<DataToken>>> ArtistTypes()
|
||||
{
|
||||
var sw = Stopwatch.StartNew();
|
||||
return new OperationResult<IEnumerable<DataToken>>
|
||||
{
|
||||
Data = this.EnumToDataTokens(typeof(Roadie.Library.Enums.ArtistType)),
|
||||
IsSuccess = true,
|
||||
OperationTime = sw.ElapsedMilliseconds
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<OperationResult<IEnumerable<DataToken>>> BandStatus()
|
||||
{
|
||||
var sw = Stopwatch.StartNew();
|
||||
return new OperationResult<IEnumerable<DataToken>>
|
||||
{
|
||||
Data = this.EnumToDataTokens(typeof(Roadie.Library.Enums.BandStatus)),
|
||||
IsSuccess = true,
|
||||
OperationTime = sw.ElapsedMilliseconds
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<OperationResult<IEnumerable<DataToken>>> BookmarkTypes()
|
||||
{
|
||||
var sw = Stopwatch.StartNew();
|
||||
return new OperationResult<IEnumerable<DataToken>>
|
||||
{
|
||||
Data = this.EnumToDataTokens(typeof(Roadie.Library.Enums.BookmarkType)),
|
||||
IsSuccess = true,
|
||||
OperationTime = sw.ElapsedMilliseconds
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<OperationResult<IEnumerable<DataToken>>> CollectionTypes()
|
||||
{
|
||||
var sw = Stopwatch.StartNew();
|
||||
return new OperationResult<IEnumerable<DataToken>>
|
||||
{
|
||||
Data = this.EnumToDataTokens(typeof(Roadie.Library.Enums.CollectionType)),
|
||||
IsSuccess = true,
|
||||
OperationTime = sw.ElapsedMilliseconds
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<OperationResult<IEnumerable<DataToken>>> LibraryStatus()
|
||||
{
|
||||
var sw = Stopwatch.StartNew();
|
||||
return new OperationResult<IEnumerable<DataToken>>
|
||||
{
|
||||
Data = this.EnumToDataTokens(typeof(Roadie.Library.Enums.LibraryStatus)),
|
||||
IsSuccess = true,
|
||||
OperationTime = sw.ElapsedMilliseconds
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<OperationResult<IEnumerable<DataToken>>> ReleaseTypes()
|
||||
{
|
||||
var sw = Stopwatch.StartNew();
|
||||
return new OperationResult<IEnumerable<DataToken>>
|
||||
{
|
||||
Data = this.EnumToDataTokens(typeof(Roadie.Library.Enums.ReleaseType)),
|
||||
IsSuccess = true,
|
||||
OperationTime = sw.ElapsedMilliseconds
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<OperationResult<IEnumerable<DataToken>>> RequestStatus()
|
||||
{
|
||||
var sw = Stopwatch.StartNew();
|
||||
return new OperationResult<IEnumerable<DataToken>>
|
||||
{
|
||||
Data = this.EnumToDataTokens(typeof(Roadie.Library.Enums.RequestStatus)),
|
||||
IsSuccess = true,
|
||||
OperationTime = sw.ElapsedMilliseconds
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<OperationResult<IEnumerable<DataToken>>> Status()
|
||||
{
|
||||
var sw = Stopwatch.StartNew();
|
||||
return new OperationResult<IEnumerable<DataToken>>
|
||||
{
|
||||
Data = this.EnumToDataTokens(typeof(Roadie.Library.Enums.Statuses)),
|
||||
IsSuccess = true,
|
||||
OperationTime = sw.ElapsedMilliseconds
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<OperationResult<IEnumerable<DataToken>>> QueMessageTypes()
|
||||
{
|
||||
var sw = Stopwatch.StartNew();
|
||||
return new OperationResult<IEnumerable<DataToken>>
|
||||
{
|
||||
Data = this.EnumToDataTokens(typeof(Roadie.Library.Enums.QueMessageType)),
|
||||
IsSuccess = true,
|
||||
OperationTime = sw.ElapsedMilliseconds
|
||||
};
|
||||
}
|
||||
|
||||
private IEnumerable<DataToken> EnumToDataTokens(Type ee)
|
||||
{
|
||||
var result = new List<DataToken>();
|
||||
foreach (var ls in Enum.GetValues(ee))
|
||||
{
|
||||
result.Add(new DataToken
|
||||
{
|
||||
Text = ls.ToString(),
|
||||
Value = ((short)ls).ToString()
|
||||
});
|
||||
}
|
||||
return result.OrderBy(x => x.Text);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -183,6 +183,7 @@ namespace Roadie.Api
|
|||
services.AddScoped<ISubsonicService, SubsonicService>();
|
||||
services.AddScoped<IUserService, UserService>();
|
||||
services.AddScoped<IAdminService, AdminService>();
|
||||
services.AddScoped<ILookupService, LookupService>();
|
||||
|
||||
var securityKey = new SymmetricSecurityKey(System.Text.Encoding.Default.GetBytes(this._configuration["Tokens:PrivateKey"]));
|
||||
|
||||
|
|
42
RoadieLibrary/Utility/LookupSerializer.cs
Normal file
42
RoadieLibrary/Utility/LookupSerializer.cs
Normal file
|
@ -0,0 +1,42 @@
|
|||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Roadie.Library.Utility
|
||||
{
|
||||
public class LookupSerializer : JsonConverter
|
||||
{
|
||||
public override bool CanConvert(Type objectType)
|
||||
{
|
||||
var result = objectType.GetInterfaces().Any(a => a.IsGenericType
|
||||
&& a.GetGenericTypeDefinition() == typeof(ILookup<,>));
|
||||
return result;
|
||||
}
|
||||
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||
{
|
||||
var obj = new JObject();
|
||||
var enumerable = (IEnumerable)value;
|
||||
|
||||
foreach (object kvp in enumerable)
|
||||
{
|
||||
// TODO: caching
|
||||
var keyProp = kvp.GetType().GetProperty("Key");
|
||||
var keyValue = keyProp.GetValue(kvp, null);
|
||||
|
||||
obj.Add(keyValue.ToString(), JArray.FromObject((IEnumerable)kvp));
|
||||
}
|
||||
|
||||
obj.WriteTo(writer);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue