diff options
| author | Ognjen Cirkovic <ciraboxkg@gmail.com> | 2022-03-13 18:32:12 +0100 | 
|---|---|---|
| committer | Ognjen Cirkovic <ciraboxkg@gmail.com> | 2022-03-13 18:32:12 +0100 | 
| commit | c1356ddc1c5cd5cbc1603384555b741824831104 (patch) | |
| tree | 28e87fa770869a6c13dbc9c8d7161e3197817b22 /backend | |
| parent | ce4cf8b1812306a37b2ee89dd25284f41434208f (diff) | |
Proslediti model poslat od frontend-a na python microservice.
Diffstat (limited to 'backend')
| -rw-r--r-- | backend/api/api/Controllers/ModelController.cs | 29 | ||||
| -rw-r--r-- | backend/api/api/Program.cs | 1 | ||||
| -rw-r--r-- | backend/api/api/Services/IMlConnectionService.cs | 8 | ||||
| -rw-r--r-- | backend/api/api/Services/MlConnectionService.cs | 17 | ||||
| -rw-r--r-- | backend/api/api/api.csproj | 2 | 
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..a7c81c43 --- /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("https://jsonplaceholder.typicode.com");//Promeniti na python api kad se odradi +            var request = new RestRequest("posts", Method.Post);//Promeniti na python api kad se odradi +            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> | 
