aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOgnjen Cirkovic <ciraboxkg@gmail.com>2022-03-15 21:14:30 +0000
committerOgnjen Cirkovic <ciraboxkg@gmail.com>2022-03-15 21:14:30 +0000
commit8e07a63b822d5e07443c23495f4264883c8793b8 (patch)
treee12f0affb1e30258cc80902762f481844db19154
parentd6c8dc0a22cfe3cb0ed1579f5dc7c4c0e6d9b3de (diff)
parent0fc05f3be0332b38acbefe86319aebd4affc456c (diff)
Merge branch 'connect-backend-ML' into 'dev'
Connect backend ml See merge request igrannonica/neuronstellar!22
-rw-r--r--backend/api/api/Controllers/ModelController.cs29
-rw-r--r--backend/api/api/Program.cs1
-rw-r--r--backend/api/api/Services/IMlConnectionService.cs8
-rw-r--r--backend/api/api/Services/MlConnectionService.cs17
-rw-r--r--backend/api/api/api.csproj2
5 files changed, 57 insertions, 0 deletions
diff --git a/backend/api/api/Controllers/ModelController.cs b/backend/api/api/Controllers/ModelController.cs
new file mode 100644
index 00000000..5e22c61d
--- /dev/null
+++ b/backend/api/api/Controllers/ModelController.cs
@@ -0,0 +1,29 @@
+using api.Services;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+
+namespace api.Controllers
+{
+ [Route("api/[controller]")]
+ [ApiController]
+ public class ModelController : ControllerBase
+ {
+
+ private IMlConnectionService _mlService;
+
+ public ModelController(IMlConnectionService mlService)
+ {
+ _mlService = mlService;
+ }
+
+ [HttpPost("sendModel")]
+ [Authorize(Roles = "User")]
+ public async Task<ActionResult<string>> Test([FromBody] object model)
+ {
+ var result = await _mlService.SendModelAsync(model);
+ return Ok(result);
+ }
+
+ }
+}
diff --git a/backend/api/api/Program.cs b/backend/api/api/Program.cs
index 2c569daf..702ef259 100644
--- a/backend/api/api/Program.cs
+++ b/backend/api/api/Program.cs
@@ -28,6 +28,7 @@ builder.Services.AddSingleton<IMongoClient>(s =>
builder.Services.AddScoped<IDatasetService, DatasetService>();
builder.Services.AddScoped<IUserService, UserService>();
builder.Services.AddScoped<IAuthService, AuthService>();
+builder.Services.AddScoped<IMlConnectionService, MlConnectionService>();
//Add Authentication
builder.Services.AddAuthentication(
diff --git a/backend/api/api/Services/IMlConnectionService.cs b/backend/api/api/Services/IMlConnectionService.cs
new file mode 100644
index 00000000..f38fb50a
--- /dev/null
+++ b/backend/api/api/Services/IMlConnectionService.cs
@@ -0,0 +1,8 @@
+
+namespace api.Services
+{
+ public interface IMlConnectionService
+ {
+ Task<string> SendModelAsync(object model);
+ }
+} \ No newline at end of file
diff --git a/backend/api/api/Services/MlConnectionService.cs b/backend/api/api/Services/MlConnectionService.cs
new file mode 100644
index 00000000..7adade0c
--- /dev/null
+++ b/backend/api/api/Services/MlConnectionService.cs
@@ -0,0 +1,17 @@
+using RestSharp;
+
+namespace api.Services
+{
+ public class MlConnectionService : IMlConnectionService
+ {
+ public async Task<string> SendModelAsync(object model)
+ {
+ RestClient client = new RestClient("http://localhost:5000");
+ var request = new RestRequest("data", Method.Post);
+ request.AddJsonBody(model);
+ var result = await client.ExecuteAsync(request);
+ return result.Content;//Response od ML microservisa
+
+ }
+ }
+}
diff --git a/backend/api/api/api.csproj b/backend/api/api/api.csproj
index 46842c3e..f38621ca 100644
--- a/backend/api/api/api.csproj
+++ b/backend/api/api/api.csproj
@@ -10,6 +10,8 @@
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.3" />
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.16.0" />
+ <PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
+ <PackageReference Include="RestSharp" Version="107.3.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.16.0" />
</ItemGroup>