This commit is contained in:
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
|
||||
Reference in New Issue
Block a user