fix BaseItemProvider Controller Stuffs ...
This commit is contained in:
@@ -0,0 +1,398 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using xCommons.Configurations;
|
||||
using xCommons.Extensions;
|
||||
using xCommons.Providers;
|
||||
using xExceptions.Constants;
|
||||
using xIdentityService.Controllers;
|
||||
using xIdentityService.Interfaces;
|
||||
using xModels.Dtos;
|
||||
using xStringService.Interfaces;
|
||||
using xStringService.Models.Dtos;
|
||||
|
||||
namespace xStringService.Controllers
|
||||
{
|
||||
public abstract class XBaseItemResourceProviderControllerBase : XBaseIdentityApiV1Controller, IXBaseItemResourceProviderController
|
||||
{
|
||||
private readonly IXItemResourceProvider provider;
|
||||
|
||||
protected XBaseItemResourceProviderControllerBase(
|
||||
ILogger<XBaseItemResourceProviderControllerBase> logger,
|
||||
XAppConfiguration appConfiguration,
|
||||
IXIdentityProvider identityProvider,
|
||||
XValidationProvider validationProvider,
|
||||
IXItemResourceProvider provider
|
||||
) : base(
|
||||
logger,
|
||||
appConfiguration,
|
||||
identityProvider,
|
||||
validationProvider
|
||||
)
|
||||
{
|
||||
this.provider = provider;
|
||||
}
|
||||
|
||||
//
|
||||
#region Actions ...
|
||||
/// <summary>
|
||||
/// Retrieve a List of Exists Languages ...
|
||||
/// </summary>
|
||||
/// <param name="identifier">if null or empty, check all languages in Item Side</param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("Languages")]
|
||||
public virtual async Task<ActionResult<IEnumerable<string>>> GetLanguages(
|
||||
[FromQuery] object identifier,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
try
|
||||
{
|
||||
//
|
||||
var result = Enumerable.Empty<string>();
|
||||
if (!identifier.IsNull())
|
||||
{
|
||||
//
|
||||
result = await provider.GetLanguages(
|
||||
identifier: identifier,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
result = await provider.GetLanguages(
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return Ok(result.ToDynamicObject());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//
|
||||
var result = GetExceptionActionResult(ex);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve all Exists Items ...
|
||||
/// </summary>
|
||||
/// <param name="resource">Specified Resource Title</param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("ResourceLocales")]
|
||||
public virtual async Task<ActionResult<IEnumerable<XStringDto>>> GetResourceLocales(
|
||||
[FromQuery] object identifier,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
try
|
||||
{
|
||||
//
|
||||
var result = Enumerable.Empty<XStringDto>();
|
||||
if (!identifier.IsNull())
|
||||
{
|
||||
//
|
||||
result = await provider.GetResourceLocales(
|
||||
identifier: identifier,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
result = await provider.GetResourceLocales(
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return Ok(result.ToDynamicObject());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//
|
||||
var result = GetExceptionActionResult(ex);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get all Exists Items for Specified identitifer ...
|
||||
/// </summary>
|
||||
/// <param name="identifier"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("Locales/{identifier}")]
|
||||
public virtual async Task<ActionResult<IEnumerable<XLocaleResourceDto>>> GetLocales(
|
||||
[FromRoute] object identifier,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
try
|
||||
{
|
||||
//
|
||||
|
||||
//
|
||||
return Ok();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var result = GetExceptionActionResult(ex);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove Specified Language Locale of Specified Identifier ...
|
||||
/// </summary>
|
||||
/// <param name="identifier"></param>
|
||||
/// <param name="language">if null or empty Remove all Locales</param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[HttpDelete("Locales/{identifier}")]
|
||||
public virtual async Task<ActionResult<XResourceDto>> RemoveLocale(
|
||||
[FromRoute] object identifier,
|
||||
[FromQuery] string language,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
try
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
var isValid = !identifier.IsNull();
|
||||
if (!isValid)
|
||||
{
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Connection ID ...
|
||||
var connectionId = GetConnectionId();
|
||||
|
||||
//
|
||||
XResourceDto result = null;
|
||||
if (!language.IsNullOrEmpty())
|
||||
{
|
||||
//
|
||||
result = await provider.RemoveLocale(
|
||||
language: language,
|
||||
identifier: identifier,
|
||||
connectionId: connectionId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
await provider.RemoveLocales(
|
||||
identifier: identifier,
|
||||
connectionId: connectionId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return Ok(result.ToDynamicObject());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//
|
||||
var result = GetExceptionActionResult(ex);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check Specified ocale Exists for Specified Identifier ...
|
||||
/// </summary>
|
||||
/// <param name="identifier"></param>
|
||||
/// <param name="language"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("Locales/{identifier}/{language}/Has")]
|
||||
public virtual async Task<ActionResult<bool>> HasLocale(
|
||||
[FromRoute] object identifier,
|
||||
[FromRoute] string language,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
try
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
await ValidationProvider
|
||||
.GroupValidationBuilder()
|
||||
.AddNotEmpty(language)
|
||||
.AddNotNull(identifier)
|
||||
.ValidateGroupAsync();
|
||||
|
||||
//
|
||||
// Calculate Result ...
|
||||
var result = await provider.HasLocale(
|
||||
language: language,
|
||||
identifier: identifier,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//
|
||||
var result = GetExceptionActionResult(ex);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get all Exists Locales Representaion based on Specified Identitifer
|
||||
/// as XResourceDto ...
|
||||
/// </summary>
|
||||
/// <param name="identifier"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("Resource/{identifier}")]
|
||||
public virtual async Task<ActionResult<XResourceDto>> GetResource(
|
||||
[FromRoute] object identifier,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
try
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
ValidationProvider.NotNull(identifier);
|
||||
|
||||
//
|
||||
var result = await provider.GetResource(
|
||||
identifier: identifier,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
return Ok(result.ToDynamicObject());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//
|
||||
var result = GetExceptionActionResult(ex);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add Or Update Locale for Specified Identitifer ...
|
||||
/// </summary>
|
||||
/// <param name="identifier"></param>
|
||||
/// <param name="locale"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("Locales/{identifier}")]
|
||||
public virtual async Task<ActionResult<XResourceDto>> AddOrUpdateLocale(
|
||||
[FromRoute] object identifier,
|
||||
[FromBody] XLocaleResourceDto locale,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
try
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
await ValidationProvider
|
||||
.GroupValidationBuilder()
|
||||
.AddNotNull(identifier)
|
||||
.AddNotNull(locale)
|
||||
.AddNotEmpty(locale.Value)
|
||||
.AddNotEmpty(locale.Language)
|
||||
.ValidateGroupAsync();
|
||||
|
||||
//
|
||||
// Retrieve Connection ID ...
|
||||
var connectionId = GetConnectionId();
|
||||
|
||||
//
|
||||
var result = await provider.AddOrUpdateLocale(
|
||||
locale: locale,
|
||||
identifier: identifier,
|
||||
connectionId: connectionId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
return Ok(result.ToDynamicObject());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var result = GetExceptionActionResult(ex);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update a Resource State ...
|
||||
/// </summary>
|
||||
/// <param name="identifier"></param>
|
||||
/// <param name="resource"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("Resource/{identifier}")]
|
||||
public virtual async Task<ActionResult<XResourceDto>> AddOrUpdateResource(
|
||||
[FromRoute] object identifier,
|
||||
[FromBody] XResourceDto resource,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
try
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
await ValidationProvider
|
||||
.GroupValidationBuilder()
|
||||
.AddNotNull(identifier)
|
||||
.AddNotNull(resource)
|
||||
.ValidateGroupAsync();
|
||||
|
||||
//
|
||||
// Retrieve Connection ID ...
|
||||
var connectionId = GetConnectionId();
|
||||
|
||||
//
|
||||
var result = await provider.AddOrUpdateResource(
|
||||
resource: resource,
|
||||
identifier: identifier,
|
||||
connectionId: connectionId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
return Ok(result.ToDynamicObject());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//
|
||||
var result = GetExceptionActionResult(ex);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user