Forum authro search is working
This commit is contained in:
parent
bf9ec07808
commit
44c733b582
@ -56,7 +56,10 @@ namespace BL.Services
|
||||
|
||||
public IEnumerable<FoorumDTO> SearchFoorumAuthor(string query)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
foreach (var f in _foorumRepository.GetMany(f => f.Author.ToLower().Contains(query.ToLower())))
|
||||
{
|
||||
yield return _factory.Create(f);
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<FoorumDTO> SearchFoorumTitle(string query)
|
||||
|
@ -4,6 +4,7 @@ using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Web.Http;
|
||||
using System.Web.Http.Controllers;
|
||||
using BL.DTOs;
|
||||
using BL.Interfaces;
|
||||
|
||||
|
26
WebApi/Controllers/SearchController.cs
Normal file
26
WebApi/Controllers/SearchController.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Web.Http;
|
||||
using BL.Interfaces;
|
||||
|
||||
namespace WebApi.Controllers
|
||||
{
|
||||
public class SearchController : ApiController
|
||||
{
|
||||
private readonly IFoorumService _foorumService;
|
||||
|
||||
public SearchController(IFoorumService foorumService)
|
||||
{
|
||||
_foorumService = foorumService;
|
||||
}
|
||||
|
||||
|
||||
public IHttpActionResult Get(string author)
|
||||
{
|
||||
return Ok(_foorumService.SearchFoorumAuthor(author));
|
||||
}
|
||||
}
|
||||
}
|
@ -112,6 +112,7 @@
|
||||
<Compile Include="App_Start\NinjectWebCommon.cs" />
|
||||
<Compile Include="App_Start\WebApiConfig.cs" />
|
||||
<Compile Include="Controllers\FoorumController.cs" />
|
||||
<Compile Include="Controllers\SearchController.cs" />
|
||||
<Compile Include="Global.asax.cs">
|
||||
<DependentUpon>Global.asax</DependentUpon>
|
||||
</Compile>
|
||||
|
@ -1,8 +1,10 @@
|
||||
<h1>api</h1>
|
||||
<a href="/api/foorum">foorum</a>
|
||||
<br/>
|
||||
<button onclick="getForum(prompt('ForumId: ', '1'))">GetForum</button>
|
||||
<button onclick="getForums()">GetAllForums</button>
|
||||
<button onclick="addForum()">AddForum</button>
|
||||
<button onclick="searchForumAuthor(prompt('Author: ', 'veeb'))">SearchForumAuthor</button>
|
||||
<code><pre id="output"></pre></code>
|
||||
|
||||
<script>
|
||||
@ -42,4 +44,13 @@
|
||||
body: JSON.stringify(dto)
|
||||
});
|
||||
}
|
||||
|
||||
function searchForumAuthor(author) {
|
||||
fetch("/api/search?author="+author).then(resp => {
|
||||
return resp.json();
|
||||
}).then(data => {
|
||||
console.log(data);
|
||||
out.innerText = JSON.stringify(data, null, 2);
|
||||
});
|
||||
}
|
||||
</script>
|
Loading…
Reference in New Issue
Block a user