refactoring the code.
This commit is contained in:
@ -17,7 +17,7 @@ using System;
|
||||
namespace Oqtane.Modules.HtmlText.Manager
|
||||
{
|
||||
[PrivateApi("Mark HtmlText classes as private, since it's not very useful in the public docs")]
|
||||
public class HtmlTextManager : MigratableModuleBase, IInstallable, IPortable, IModuleSearch
|
||||
public class HtmlTextManager : MigratableModuleBase, IInstallable, IPortable, ISearchable
|
||||
{
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
private readonly IHtmlTextRepository _htmlText;
|
||||
@ -48,25 +48,25 @@ namespace Oqtane.Modules.HtmlText.Manager
|
||||
return content;
|
||||
}
|
||||
|
||||
public IList<SearchDocument> GetSearchDocuments(Module module, DateTime startDate)
|
||||
public IList<SearchContent> GetSearchContentList(Module module, DateTime startDate)
|
||||
{
|
||||
var searchDocuments = new List<SearchDocument>();
|
||||
var searchContentList = new List<SearchContent>();
|
||||
|
||||
var htmltexts = _htmlText.GetHtmlTexts(module.ModuleId);
|
||||
if (htmltexts != null && htmltexts.Any(i => i.CreatedOn >= startDate))
|
||||
{
|
||||
var htmltext = htmltexts.OrderByDescending(item => item.CreatedOn).First();
|
||||
|
||||
searchDocuments.Add(new SearchDocument
|
||||
searchContentList.Add(new SearchContent
|
||||
{
|
||||
Title = module.Title,
|
||||
Description = string.Empty,
|
||||
Body = SearchUtils.Clean(htmltext.Content, true),
|
||||
Body = htmltext.Content,
|
||||
ModifiedTime = htmltext.ModifiedOn
|
||||
});
|
||||
}
|
||||
|
||||
return searchDocuments;
|
||||
return searchContentList;
|
||||
}
|
||||
|
||||
public void ImportModule(Module module, string content, string version)
|
||||
|
@ -1,43 +0,0 @@
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Oqtane.Controllers;
|
||||
using Oqtane.Documentation;
|
||||
using Oqtane.Enums;
|
||||
using Oqtane.Infrastructure;
|
||||
using Oqtane.Modules.SearchResults.Services;
|
||||
using Oqtane.Shared;
|
||||
|
||||
namespace Oqtane.Modules.SearchResults.Controllers
|
||||
{
|
||||
[Route(ControllerRoutes.ApiRoute)]
|
||||
[PrivateApi("Mark SearchResults classes as private, since it's not very useful in the public docs")]
|
||||
public class SearchResultsController : ModuleControllerBase
|
||||
{
|
||||
private readonly ISearchResultsService _searchResultsService;
|
||||
|
||||
public SearchResultsController(ISearchResultsService searchResultsService, ILogManager logger, IHttpContextAccessor accessor) : base(logger, accessor)
|
||||
{
|
||||
_searchResultsService = searchResultsService;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Policy = PolicyNames.ViewModule)]
|
||||
public async Task<Models.SearchResults> Post([FromBody] Models.SearchQuery searchQuery)
|
||||
{
|
||||
try
|
||||
{
|
||||
return await _searchResultsService.SearchAsync(AuthEntityId(EntityNames.Module), searchQuery);
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
_logger.Log(LogLevel.Error, this, LogFunction.Other, ex, "Fetch search results failed.", searchQuery);
|
||||
HttpContext.Response.StatusCode = (int)HttpStatusCode.BadRequest;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Oqtane.Documentation;
|
||||
using Oqtane.Infrastructure;
|
||||
using Oqtane.Models;
|
||||
using Oqtane.Services;
|
||||
|
||||
namespace Oqtane.Modules.SearchResults.Services
|
||||
{
|
||||
[PrivateApi("Mark SearchResults classes as private, since it's not very useful in the public docs")]
|
||||
public class ServerSearchResultsService : ISearchResultsService, ITransientService
|
||||
{
|
||||
private readonly ILogManager _logger;
|
||||
private readonly IHttpContextAccessor _accessor;
|
||||
private readonly Alias _alias;
|
||||
private readonly ISearchService _searchService;
|
||||
|
||||
public ServerSearchResultsService(
|
||||
ITenantManager tenantManager,
|
||||
ILogManager logger,
|
||||
IHttpContextAccessor accessor,
|
||||
ISearchService searchService)
|
||||
{
|
||||
_logger = logger;
|
||||
_accessor = accessor;
|
||||
_alias = tenantManager.GetAlias();
|
||||
_searchService = searchService;
|
||||
}
|
||||
|
||||
public async Task<Models.SearchResults> SearchAsync(int moduleId, SearchQuery searchQuery)
|
||||
{
|
||||
var results = await _searchService.SearchAsync(searchQuery);
|
||||
return results;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Oqtane.Infrastructure;
|
||||
using Oqtane.Modules.SearchResults.Services;
|
||||
|
||||
namespace Oqtane.Modules.SearchResults.Startup
|
||||
{
|
||||
public class ServerStartup : IServerStartup
|
||||
{
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
{
|
||||
}
|
||||
|
||||
public void ConfigureMvc(IMvcBuilder mvcBuilder)
|
||||
{
|
||||
}
|
||||
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddTransient<ISearchResultsService, ServerSearchResultsService>();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user