This commit is contained in:
@@ -2,7 +2,7 @@ using System.Collections.Generic;
|
||||
|
||||
namespace AyaNova.Api.ControllerHelpers
|
||||
{
|
||||
internal static class LocaleIdFromContext
|
||||
internal static class UserLocaleIdFromContext
|
||||
{
|
||||
internal static long Id(IDictionary<object, object> HttpContextItems)
|
||||
{
|
||||
103
server/AyaNova/Controllers/SearchController.cs
Normal file
103
server/AyaNova/Controllers/SearchController.cs
Normal file
@@ -0,0 +1,103 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.JsonPatch;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
using AyaNova.Models;
|
||||
using AyaNova.Api.ControllerHelpers;
|
||||
using AyaNova.Biz;
|
||||
|
||||
|
||||
namespace AyaNova.Api.Controllers
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Search
|
||||
/// </summary>
|
||||
[ApiVersion("8.0")]
|
||||
[Route("api/v{version:apiVersion}/[controller]")]
|
||||
[Produces("application/json")]
|
||||
[Authorize]
|
||||
public class SearchController : Controller
|
||||
{
|
||||
private readonly AyContext ct;
|
||||
private readonly ILogger<WidgetController> log;
|
||||
private readonly ApiServerState serverState;
|
||||
|
||||
/// <summary>
|
||||
/// ctor
|
||||
/// </summary>
|
||||
/// <param name="dbcontext"></param>
|
||||
/// <param name="logger"></param>
|
||||
/// <param name="apiServerState"></param>
|
||||
public SearchController(AyContext dbcontext, ILogger<WidgetController> logger, ApiServerState apiServerState)
|
||||
{
|
||||
ct = dbcontext;
|
||||
log = logger;
|
||||
serverState = apiServerState;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Post search parameters
|
||||
///
|
||||
/// Required roles: Any
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="searchParams"></param>
|
||||
/// <returns>SearchResult list</returns>
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> PostSearch([FromBody] Search.SearchRequestParameters searchParams)
|
||||
{
|
||||
if (!serverState.IsOpen)
|
||||
{
|
||||
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
|
||||
}
|
||||
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(new ApiErrorResponse(ModelState));
|
||||
}
|
||||
|
||||
//Do the search
|
||||
var SearchResults = await Search.DoSearch(ct, UserLocaleIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items), searchParams);
|
||||
|
||||
return Ok(new ApiOkResponse(SearchResults));
|
||||
|
||||
// if (o == null)
|
||||
// {
|
||||
// //error return
|
||||
// return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
|
||||
// //save to get Id
|
||||
// await ct.SaveChangesAsync();
|
||||
|
||||
// //Log now that we have the Id
|
||||
// EventLogProcessor.AddEntry(new Event(biz.userId, o.Id, AyaType.Widget, AyaEvent.Created), ct);
|
||||
// await ct.SaveChangesAsync();
|
||||
|
||||
// //this will save the context as part of it's operations
|
||||
// Search.ProcessNewObjectKeywords(ct, UserLocaleIdFromContext.Id(HttpContext.Items), o.Id, AyaType.Widget, o.Name, o.Notes, o.Name);
|
||||
|
||||
|
||||
// //return success and link
|
||||
// return CreatedAtAction("GetWidget", new { id = o.Id }, new ApiCreatedResponse(o));
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
|
||||
//------------
|
||||
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
@@ -210,7 +210,7 @@ namespace AyaNova.Api.Controllers
|
||||
{
|
||||
//Log
|
||||
EventLogProcessor.AddEntry(new Event(biz.userId, o.Id, AyaType.Widget, AyaEvent.Modified), ct);
|
||||
Search.ProcessUpdatedObjectKeywords(ct, LocaleIdFromContext.Id(HttpContext.Items), o.Id, AyaType.Widget, o.Name, o.Notes, o.Name);
|
||||
Search.ProcessUpdatedObjectKeywords(ct, UserLocaleIdFromContext.Id(HttpContext.Items), o.Id, AyaType.Widget, o.Name, o.Notes, o.Name);
|
||||
await ct.SaveChangesAsync();
|
||||
}
|
||||
catch (DbUpdateConcurrencyException)
|
||||
@@ -290,7 +290,7 @@ namespace AyaNova.Api.Controllers
|
||||
await ct.SaveChangesAsync();
|
||||
|
||||
//this will save the context as part of it's operations
|
||||
Search.ProcessUpdatedObjectKeywords(ct, LocaleIdFromContext.Id(HttpContext.Items), o.Id, AyaType.Widget, o.Name, o.Notes, o.Name);
|
||||
Search.ProcessUpdatedObjectKeywords(ct, UserLocaleIdFromContext.Id(HttpContext.Items), o.Id, AyaType.Widget, o.Name, o.Notes, o.Name);
|
||||
|
||||
}
|
||||
catch (DbUpdateConcurrencyException)
|
||||
@@ -358,7 +358,7 @@ namespace AyaNova.Api.Controllers
|
||||
await ct.SaveChangesAsync();
|
||||
|
||||
//this will save the context as part of it's operations
|
||||
Search.ProcessNewObjectKeywords(ct, LocaleIdFromContext.Id(HttpContext.Items), o.Id, AyaType.Widget, o.Name, o.Notes, o.Name);
|
||||
Search.ProcessNewObjectKeywords(ct, UserLocaleIdFromContext.Id(HttpContext.Items), o.Id, AyaType.Widget, o.Name, o.Notes, o.Name);
|
||||
|
||||
|
||||
//return success and link
|
||||
|
||||
@@ -175,7 +175,7 @@ namespace AyaNova.Biz
|
||||
List<SearchKey> SearchKeyMatches = new List<SearchKey>();
|
||||
|
||||
//Build search query based on searchParameters
|
||||
var q = ct.SearchKey.Where(m => DictionaryMatches.Contains(m.Id));
|
||||
var q = ct.SearchKey.Distinct().Where(m => DictionaryMatches.Contains(m.Id));
|
||||
|
||||
//In name?
|
||||
if (searchParameters.NameOnly)
|
||||
@@ -188,6 +188,10 @@ namespace AyaNova.Biz
|
||||
//Trigger the search
|
||||
SearchKeyMatches = await q.ToListAsync();
|
||||
|
||||
BUGBUG: the current simple phrase search test is returning records when only one of the two search words matches "simple dogs"
|
||||
//However only one widget created in the test has both words, teh other only has one and should not return a result
|
||||
//Need to rejig this so only if all words are matching does it consider it a hit
|
||||
|
||||
//PUT THE RESULTS INTO MATCHING OBJECTS LIST
|
||||
foreach (SearchKey SearchKeyMatch in SearchKeyMatches)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user