Untitled
unknown
plain_text
10 months ago
4.3 kB
21
Indexable
using Geico.ProductMgmt.Application.Authorization;
using Geico.ProductMgmt.Application.Services.Abstractions;
using Geico.ProductMgmt.Domain.ActionServiceCatalog;
using Geico.ProductMgmt.Domain.ActionServiceCatalog.Permissions;
using Geico.ProductMgmt.Domain.Constants;
using Geico.ProductMgmt.Infrastructure.Api.Contracts;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace Geico.ProductMgmt.Infrastructure.Api.Controllers;
/// <summary>
/// The ActionServiceCatalogController.
/// </summary>
[Authorize]
[ApiController]
[ApiExplorerSettings(GroupName = "v2")]
public class ActionServiceCatalogController : BaseController
{
private readonly IActionServiceCatalogService _actionServiceCatalogService;
/// <summary>
/// Initializes a new instance of the <see cref="ActionServiceCatalogController" /> class.
/// </summary>
/// <param name="appAuthService">The authorization service.</param>
/// <param name="cacheService">The cache service.</param>
/// <param name="logger">The logger.</param>
/// <param name="actionServiceCatalogService">The action service catalog service</param>
public ActionServiceCatalogController(
IAppAuthorizationService? appAuthService,
ILogger<ActionServiceCatalogController> logger,
IActionServiceCatalogService actionServiceCatalogService,
ICacheService? cacheService = null)
: base(appAuthService, logger, cacheService)
{
this._actionServiceCatalogService = actionServiceCatalogService;
}
/// <summary>
/// Gets an Action Service Catalog.
/// </summary>
/// <param name="serviceName">Catalog ServiceName.</param>
/// <param name="serviceProviderName">Catalog ServiceProviderName.</param>
/// <returns>An Action Service Catalog.</returns>
[HttpGet("api/ActionServiceCatalog")]
public async Task<ActionResult<ApiResponse<ActionServiceCatalog?>>> GetCatalog([FromQuery] string serviceName, [FromQuery] string serviceProviderName)
{
this.logger.ControllerRouteExecuting(DateTimeOffset.UtcNow, this.Request.Path.Value!);
var isAuthorized = await this.AuthorizeUser().ConfigureAwait(false);
if (!isAuthorized)
{
return this.UnauthorizedResponse<ActionServiceCatalog?>(MessageConstants.UnAuthorized);
}
var isValidMessage = this.ReturnBadRequestResponseIfInValid(serviceName, serviceProviderName);
if (!string.IsNullOrEmpty(isValidMessage))
{
return this.BadRequestResponse<ActionServiceCatalog?>(null, isValidMessage);
}
var actionServiceCatalog = await this._actionServiceCatalogService.GetActionServiceCatalog(serviceName, serviceProviderName).ConfigureAwait(false);
if (actionServiceCatalog == null)
return this.ExceptionResponse<ActionServiceCatalog?>($"Failed to get Action Service Contract");
return this.OkResponse(actionServiceCatalog);
}
/// <summary>
/// Gets an Action Service Contract.
/// </summary>
/// <param name="request">Target Action Service Contract details.</param>
/// <returns>An Action Service Contract.</returns>
[HttpGet("api/ActionServiceCatalog/Contract")]
public async Task<ActionResult<ApiResponse<ActionServiceContract?>>> GetContract([FromQuery] GetActionServiceContractRequest request)
{
this.logger.ControllerRouteExecuting(DateTimeOffset.UtcNow, this.Request.Path.Value!);
var isAuthorized = await this.AuthorizeUser().ConfigureAwait(false);
if (!isAuthorized)
{
return this.UnauthorizedResponse<ActionServiceContract?>(MessageConstants.UnAuthorized);
}
var actionServiceContract = await this._actionServiceCatalogService.GetActionServiceContract(request.ServiceName, request.ServiceProviderName, request.MajorVersion, request.MinorVersion, request.Patch).ConfigureAwait(false);
if (actionServiceContract == null)
return this.ExceptionResponse<ActionServiceContract?>($"Failed to get Action Service Contract");
return this.OkResponse(actionServiceContract);
}Editor is loading...
Leave a Comment