Compare commits
3 Commits
master
...
feature/se
Author | SHA1 | Date | |
---|---|---|---|
![]() |
659e3bd4d9 | ||
![]() |
7e3cd2142a | ||
![]() |
b111ce2c2c |
@ -1,4 +1,5 @@
|
||||
using BitSearch.API.Models;
|
||||
using BitSearch.API.Services;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.WebUtilities;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
@ -24,12 +25,15 @@ namespace BitSearch.API.Controllers
|
||||
private readonly ILogger<SearchController> _logger;
|
||||
private readonly IConfiguration Configuration;
|
||||
private readonly IHttpClientFactory _httpClientFactory;
|
||||
private readonly IAnaliseService _analiseService;
|
||||
|
||||
public SearchController(ILogger<SearchController> logger, IConfiguration configuration, IHttpClientFactory httpClientFactory)
|
||||
public SearchController(ILogger<SearchController> logger, IConfiguration configuration, IHttpClientFactory httpClientFactory,
|
||||
IAnaliseService analiseService)
|
||||
{
|
||||
_logger = logger;
|
||||
_httpClientFactory = httpClientFactory;
|
||||
Configuration = configuration;
|
||||
_analiseService = analiseService;
|
||||
}
|
||||
|
||||
[HttpGet("ranking")]
|
||||
@ -94,12 +98,9 @@ namespace BitSearch.API.Controllers
|
||||
{
|
||||
var tweetsDto = JsonConvert.DeserializeObject<TweeterResponse>(await response.Content.ReadAsStringAsync());
|
||||
tweetsDto.data = tweetsDto.data.Where(d => d.lang == "en");
|
||||
var microServiceClient = _httpClientFactory.CreateClient();
|
||||
var microServiceRequest = new HttpRequestMessage(HttpMethod.Get, "http://127.0.0.1:5000/analysis");
|
||||
microServiceRequest.Content = JsonContent.Create(tweetsDto);
|
||||
var microServiceResponse = await microServiceClient.SendAsync(microServiceRequest);
|
||||
var analise = await _analiseService.AnaliseTweets(tweetsDto);
|
||||
|
||||
return Ok(await microServiceResponse.Content.ReadAsStringAsync());
|
||||
return Ok(analise);
|
||||
//return Ok(tweetsDto);
|
||||
}
|
||||
|
||||
|
13
BitSearch/BitSearch.API/Services/IAnaliseService.cs
Normal file
13
BitSearch/BitSearch.API/Services/IAnaliseService.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using BitSearch.API.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BitSearch.API.Services
|
||||
{
|
||||
public interface IAnaliseService
|
||||
{
|
||||
Task<string> AnaliseTweets(TweeterResponse tweets);
|
||||
}
|
||||
}
|
18
BitSearch/BitSearch.API/Services/MoqAnalise.cs
Normal file
18
BitSearch/BitSearch.API/Services/MoqAnalise.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using BitSearch.API.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BitSearch.API.Services
|
||||
{
|
||||
public class MoqAnalise : IAnaliseService
|
||||
{
|
||||
public Task<string> AnaliseTweets(TweeterResponse tweets)
|
||||
{
|
||||
var moqResponse = "result: {'pos_prec': 0.875, 'neg_prec': 0.125' }";
|
||||
|
||||
return Task.FromResult<string>(moqResponse);
|
||||
}
|
||||
}
|
||||
}
|
28
BitSearch/BitSearch.API/Services/RealAnalise.cs
Normal file
28
BitSearch/BitSearch.API/Services/RealAnalise.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using BitSearch.API.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BitSearch.API.Services
|
||||
{
|
||||
public class RealAnalise : IAnaliseService
|
||||
{
|
||||
private readonly IHttpClientFactory _httpClientFactory;
|
||||
public RealAnalise(IHttpClientFactory httpClientFactor)
|
||||
{
|
||||
_httpClientFactory = httpClientFactor;
|
||||
}
|
||||
public async Task<string> AnaliseTweets(TweeterResponse tweets)
|
||||
{
|
||||
var microServiceClient = _httpClientFactory.CreateClient();
|
||||
var microServiceRequest = new HttpRequestMessage(HttpMethod.Get, "http://127.0.0.1:5000/analysis");
|
||||
microServiceRequest.Content = JsonContent.Create(tweets);
|
||||
var microServiceResponse = await microServiceClient.SendAsync(microServiceRequest);
|
||||
|
||||
return await microServiceResponse.Content.ReadAsStringAsync();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
using BitSearch.API.Services;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.HttpsPolicy;
|
||||
@ -28,6 +29,7 @@ namespace BitSearch.API
|
||||
{
|
||||
|
||||
services.AddControllers();
|
||||
services.AddScoped<IAnaliseService, RealAnalise>();
|
||||
services.AddSwaggerGen(c =>
|
||||
{
|
||||
c.SwaggerDoc("v1", new OpenApiInfo { Title = "BitSearch.API", Version = "v1" });
|
||||
|
Loading…
Reference in New Issue
Block a user