This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
//TODO: means something that needs to be done but is awaiting something else. This is a *MUST* do.
|
//TODO: means something that needs to be done but is awaiting something else. This is a *MUST* do.
|
||||||
//LOOKAT: means something that I want to think about and revisit later but is not urgent
|
//LOOKAT: means something that I want to think about and revisit later but is not urgent
|
||||||
//BEFORE_RELEASE: means something that MUST be changed before release, usually special debugging code for development or testing
|
//BEFORE_RELEASE: means something that MUST be changed before release, usually special debugging code for development or testing
|
||||||
|
//BUGBUG: means there's a bug here that is known
|
||||||
|
|
||||||
|
|
||||||
Error messages / Numbers
|
Error messages / Numbers
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ using System.Collections.Generic;
|
|||||||
|
|
||||||
namespace AyaNova.Api.ControllerHelpers
|
namespace AyaNova.Api.ControllerHelpers
|
||||||
{
|
{
|
||||||
internal static class LocaleIdFromContext
|
internal static class UserLocaleIdFromContext
|
||||||
{
|
{
|
||||||
internal static long Id(IDictionary<object, object> HttpContextItems)
|
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
|
//Log
|
||||||
EventLogProcessor.AddEntry(new Event(biz.userId, o.Id, AyaType.Widget, AyaEvent.Modified), ct);
|
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();
|
await ct.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
catch (DbUpdateConcurrencyException)
|
catch (DbUpdateConcurrencyException)
|
||||||
@@ -290,7 +290,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
await ct.SaveChangesAsync();
|
await ct.SaveChangesAsync();
|
||||||
|
|
||||||
//this will save the context as part of it's operations
|
//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)
|
catch (DbUpdateConcurrencyException)
|
||||||
@@ -358,7 +358,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
await ct.SaveChangesAsync();
|
await ct.SaveChangesAsync();
|
||||||
|
|
||||||
//this will save the context as part of it's operations
|
//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
|
//return success and link
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ namespace AyaNova.Biz
|
|||||||
List<SearchKey> SearchKeyMatches = new List<SearchKey>();
|
List<SearchKey> SearchKeyMatches = new List<SearchKey>();
|
||||||
|
|
||||||
//Build search query based on searchParameters
|
//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?
|
//In name?
|
||||||
if (searchParameters.NameOnly)
|
if (searchParameters.NameOnly)
|
||||||
@@ -188,6 +188,10 @@ namespace AyaNova.Biz
|
|||||||
//Trigger the search
|
//Trigger the search
|
||||||
SearchKeyMatches = await q.ToListAsync();
|
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
|
//PUT THE RESULTS INTO MATCHING OBJECTS LIST
|
||||||
foreach (SearchKey SearchKeyMatch in SearchKeyMatches)
|
foreach (SearchKey SearchKeyMatch in SearchKeyMatches)
|
||||||
{
|
{
|
||||||
|
|||||||
64
test/raven-integration/Search/SearchOps.cs
Normal file
64
test/raven-integration/Search/SearchOps.cs
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
using System;
|
||||||
|
using Xunit;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using FluentAssertions;
|
||||||
|
|
||||||
|
namespace raven_integration
|
||||||
|
{
|
||||||
|
|
||||||
|
public class SearchOps
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test simple phrase only search
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public async void PhraseOnlySearchShouldWork()
|
||||||
|
{
|
||||||
|
|
||||||
|
//CREATE A WIDGET
|
||||||
|
dynamic D = new JObject();
|
||||||
|
D.name = Util.Uniquify("Search Simple Test WIDGET");
|
||||||
|
D.dollarAmount = 1.11m;
|
||||||
|
D.active = true;
|
||||||
|
D.roles = 0;
|
||||||
|
D.notes = "The quick brown and simple fox jumped over the six lazy dogs!";
|
||||||
|
|
||||||
|
ApiResponse a = await Util.PostAsync("Widget", await Util.GetTokenAsync("manager", "l3tm3in"), D.ToString());
|
||||||
|
Util.ValidateDataReturnResponseOk(a);
|
||||||
|
long FirstWidgetId = a.ObjectResponse["result"]["id"].Value<long>();
|
||||||
|
|
||||||
|
D = new JObject();
|
||||||
|
D.name = Util.Uniquify("Search Simple SECOND Test WIDGET");
|
||||||
|
D.dollarAmount = 1.11m;
|
||||||
|
D.active = true;
|
||||||
|
D.roles = 0;
|
||||||
|
D.notes = "This Widget should not be returned in the search as it only contains a single keyword in the name not both";
|
||||||
|
|
||||||
|
a = await Util.PostAsync("Widget", await Util.GetTokenAsync("manager", "l3tm3in"), D.ToString());
|
||||||
|
Util.ValidateDataReturnResponseOk(a);
|
||||||
|
long SecondWidgetId = a.ObjectResponse["result"]["id"].Value<long>();
|
||||||
|
|
||||||
|
//Now see if can find that widget with a phrase search
|
||||||
|
dynamic SearchParameters = new JObject();
|
||||||
|
SearchParameters.phrase = "simple dogs";
|
||||||
|
SearchParameters.nameOnly = false;
|
||||||
|
SearchParameters.typeOnly = 0;//no type
|
||||||
|
a = await Util.PostAsync("Search", await Util.GetTokenAsync("manager", "l3tm3in"), SearchParameters.ToString());
|
||||||
|
Util.ValidateDataReturnResponseOk(a);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//==================================================
|
||||||
|
|
||||||
|
}//eoc
|
||||||
|
}//eons
|
||||||
Reference in New Issue
Block a user