aboutsummaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
authorDanijel Andjelkovic <adanijel99@gmail.com>2022-03-16 18:17:13 +0100
committerDanijel Andjelkovic <adanijel99@gmail.com>2022-03-16 18:17:13 +0100
commit5a04e31b7e63663f548fa7d9119ab947be46aedf (patch)
tree6d093d64c471166ef6d649c24f41d80d8a568296 /backend
parentd96b69f4ca8eac83140b3b451f59621aed2bb517 (diff)
parentcba3740a4f35d91421f5a185195bdfc087810b8a (diff)
Merge branch 'dev' of http://gitlab.pmf.kg.ac.rs/igrannonica/neuronstellar into dev
Diffstat (limited to 'backend')
-rw-r--r--backend/api/api/Controllers/AuthController.cs2
-rw-r--r--backend/api/api/Controllers/DatasetController.cs50
-rw-r--r--backend/api/api/Controllers/FileController.cs (renamed from backend/api/api/Controllers/FileUploadController.cs)44
-rw-r--r--backend/api/api/Controllers/ModelController.cs97
-rw-r--r--backend/api/api/Controllers/UserController.cs3
-rw-r--r--backend/api/api/Data/UserStoreDatabaseSettings.cs2
-rw-r--r--backend/api/api/Interfaces/IUserStoreDatabaseSettings.cs2
-rw-r--r--backend/api/api/Models/Dataset.cs45
-rw-r--r--backend/api/api/Models/FileModel.cs14
-rw-r--r--backend/api/api/Models/JwtToken.cs2
-rw-r--r--backend/api/api/Models/Model.cs45
-rw-r--r--backend/api/api/Program.cs4
-rw-r--r--backend/api/api/Services/DatasetService.cs18
-rw-r--r--backend/api/api/Services/FileService.cs34
-rw-r--r--backend/api/api/Services/IDatasetService.cs8
-rw-r--r--backend/api/api/Services/IFileService.cs10
-rw-r--r--backend/api/api/Services/IMlConnectionService.cs8
-rw-r--r--backend/api/api/Services/IModelService.cs15
-rw-r--r--backend/api/api/Services/MlConnectionService.cs17
-rw-r--r--backend/api/api/Services/ModelService.cs47
-rw-r--r--backend/api/api/api.csproj2
-rw-r--r--backend/api/api/appsettings.json19
22 files changed, 403 insertions, 85 deletions
diff --git a/backend/api/api/Controllers/AuthController.cs b/backend/api/api/Controllers/AuthController.cs
index 6dfe483a..7167d1bf 100644
--- a/backend/api/api/Controllers/AuthController.cs
+++ b/backend/api/api/Controllers/AuthController.cs
@@ -49,8 +49,6 @@ namespace api.Controllers
return Ok(newToken);
-
-
}
diff --git a/backend/api/api/Controllers/DatasetController.cs b/backend/api/api/Controllers/DatasetController.cs
index fcebc4b0..3d008744 100644
--- a/backend/api/api/Controllers/DatasetController.cs
+++ b/backend/api/api/Controllers/DatasetController.cs
@@ -18,32 +18,32 @@ namespace api.Controllers
}
- // GET: api/<DatasetController>/{id}/datasets
- [HttpGet("{id}/datasets")]
- public ActionResult<List<Dataset>> Get(string id)
+ // GET: api/<DatasetController>/{username}/datasets
+ [HttpGet("{username}/datasets")]
+ public ActionResult<List<Dataset>> Get(string username)
{
- return _datasetService.GetAllDatesets(id);
+ return _datasetService.GetAllDatesets(username);
}
- // GET api/<DatasetController>/{id}/{name}
- [HttpGet("{id}/{name}")]
- public ActionResult<Dataset> Get(string id, string name)
+ // GET api/<DatasetController>/{username}/{name}
+ [HttpGet("{username}/{name}")]
+ public ActionResult<Dataset> Get(string username, string name)
{
- var dataset = _datasetService.GetOneDataset(id, name);
+ var dataset = _datasetService.GetOneDataset(username, name);
if (dataset == null)
- return NotFound($"Dataset with name = {name} or user with id = {id} not found");
+ return NotFound($"Dataset with name = {name} or user with username = {username} not found");
return dataset;
}
- // POST api/<DatasetController>/post
- [HttpPost("post")]
+ // POST api/<DatasetController>/add
+ [HttpPost("add")]
public ActionResult<Dataset> Post([FromBody] Dataset dataset)
{
- var existingUser = _datasetService.GetOneDataset(dataset.uploaderId,dataset.name);
+ var existingDataset = _datasetService.GetOneDataset(dataset.username, dataset.name);
- if (existingUser != null)
+ if (existingDataset != null)
return NotFound($"Dateset with name = {dataset.name} exisits");
else
{
@@ -53,30 +53,30 @@ namespace api.Controllers
}
}
- // PUT api/<DatasetController>/{id}/{name}
- [HttpPut("{id}/{name}")]
- public ActionResult Put(string id, string name, [FromBody] Dataset dataset)
+ // PUT api/<DatasetController>/{username}/{name}
+ [HttpPut("{username}/{name}")]
+ public ActionResult Put(string username, string name, [FromBody] Dataset dataset)
{
- var existingDataset = _datasetService.GetOneDataset(id, name);
+ var existingDataset = _datasetService.GetOneDataset(username, name);
//ne mora da se proverava
if (existingDataset == null)
- return NotFound($"Dataset with name = {name} or user with id = {id} not found");
+ return NotFound($"Dataset with name = {name} or user with username = {username} not found");
- _datasetService.Update(id, name, dataset);
+ _datasetService.Update(username, name, dataset);
return NoContent();
}
- // DELETE api/<DatasetController>/5
- [HttpDelete("{id}")]
- public ActionResult Delete(string id, string name)
+ // DELETE api/<DatasetController>/username/name
+ [HttpDelete("{username}/{name}")]
+ public ActionResult Delete(string username, string name)
{
- var dataset = _datasetService.GetOneDataset(id, name);
+ var dataset = _datasetService.GetOneDataset(username, name);
if (dataset == null)
- return NotFound($"Dataset with name = {name} or user with id = {id} not found");
+ return NotFound($"Dataset with name = {name} or user with username = {username} not found");
- _datasetService.Delete(dataset.uploaderId,dataset.name);
+ _datasetService.Delete(dataset.username, dataset.name);
return Ok($"Dataset with name = {name} deleted");
diff --git a/backend/api/api/Controllers/FileUploadController.cs b/backend/api/api/Controllers/FileController.cs
index 68ab814d..3bfdad93 100644
--- a/backend/api/api/Controllers/FileUploadController.cs
+++ b/backend/api/api/Controllers/FileController.cs
@@ -1,5 +1,6 @@
using System.Net.Http.Headers;
using api.Models;
+using api.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Net.Http.Headers;
@@ -7,15 +8,17 @@ namespace api.Controllers
{
[Route("api/[controller]")]
[ApiController]
- public class FileUploadController : ControllerBase
+ public class FileController : ControllerBase
{
private string[] permittedExtensions = { ".csv" };
private readonly IConfiguration _configuration;
private JwtToken _token;
- public FileUploadController(IConfiguration configuration)
+ private IFileService _fileservice;
+ public FileController(IConfiguration configuration,IFileService fileService)
{
_configuration = configuration;
_token = new JwtToken(configuration);
+ _fileservice = fileService;
}
@@ -68,9 +71,42 @@ namespace api.Controllers
{
await file.CopyToAsync(stream);
}
+ FileModel fileModel= new FileModel();
+ fileModel.path=fullPath;
+ fileModel.username=username;
+ fileModel=_fileservice.Create(fileModel);
- return Ok(fullPath);
+ return Ok(fileModel);
}
+
+ [HttpGet("Download")]
+ [Authorize(Roles = "User")]
+ public async Task<ActionResult> DownloadFile(string id)
+ {
+ //Get Username
+ string username;
+ var header = Request.Headers[HeaderNames.Authorization];
+ if (AuthenticationHeaderValue.TryParse(header, out var headerValue))
+ {
+
+ var scheme = headerValue.Scheme;
+ var parameter = headerValue.Parameter;
+ username = _token.TokenToUsername(parameter);
+ if (username == null)
+ return null;
+ }
+ else
+ return BadRequest();
+
+ string filePath = _fileservice.GetFilePath(id, username);
+ if (filePath == null)
+ return BadRequest();
+
+ return File(System.IO.File.ReadAllBytes(filePath),"application/octet-stream", Path.GetFileName(filePath));
+
+ }
+
+
+
}
}
-
diff --git a/backend/api/api/Controllers/ModelController.cs b/backend/api/api/Controllers/ModelController.cs
new file mode 100644
index 00000000..deb622b8
--- /dev/null
+++ b/backend/api/api/Controllers/ModelController.cs
@@ -0,0 +1,97 @@
+using api.Models;
+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;
+ private readonly IModelService _modelService;
+
+
+ public ModelController(IMlConnectionService mlService, IModelService modelService)
+ {
+ _mlService = mlService;
+ _modelService = modelService;
+ }
+
+ [HttpPost("sendModel")]
+ [Authorize(Roles = "User")]
+ public async Task<ActionResult<string>> Test([FromBody] object model)
+ {
+ var result = await _mlService.SendModelAsync(model);
+ return Ok(result);
+ }
+
+ // GET: api/<ModelController>/{username}/models
+ [HttpGet("{username}/models")]
+ public ActionResult<List<Model>> Get(string username)
+ {
+ return _modelService.GetAllModels(username);
+ }
+
+ //id korisnika, name modela
+ // GET api/<ModelController>/{username}/{name}
+ [HttpGet("{username}/{name}")]
+ public ActionResult<Model> Get(string username, string name)
+ {
+ var model = _modelService.GetOneModel(username, name);
+
+ if (model == null)
+ return NotFound($"Model with name = {name} or user with username = {username} not found");
+
+ return model;
+ }
+
+ // POST api/<ModelController>/add
+ [HttpPost("add")]
+ public ActionResult<Model> Post([FromBody] Model model)
+ {
+ var existingModel = _modelService.GetOneModel(model.username, model.name);
+
+ if (existingModel != null)
+ return NotFound($"Model with name = {model.name} exisits");
+ else
+ {
+ _modelService.Create(model);
+
+ return CreatedAtAction(nameof(Get), new { id = model._id }, model);
+ }
+ }
+
+ // PUT api/<ModelController>/{username}/{name}
+ [HttpPut("{username}/{name}")]
+ public ActionResult Put(string username, string name, [FromBody] Model model)
+ {
+ var existingModel = _modelService.GetOneModel(username, name);
+
+ if (existingModel == null)
+ return NotFound($"Model with name = {name} or user with username = {username} not found");
+
+ _modelService.Update(username, name, model);
+ return NoContent();
+ }
+
+ // DELETE api/<ModelController>/username
+ [HttpDelete("{username}/{name}")]
+ public ActionResult Delete(string username, string name)
+ {
+ var model = _modelService.GetOneModel(username, name);
+
+ if (model == null)
+ return NotFound($"Model with name = {name} or user with username = {username} not found");
+
+ _modelService.Delete(model.username, model.name);
+
+ return Ok($"Model with name = {name} deleted");
+
+ }
+
+ }
+}
diff --git a/backend/api/api/Controllers/UserController.cs b/backend/api/api/Controllers/UserController.cs
index d41a42e3..58121656 100644
--- a/backend/api/api/Controllers/UserController.cs
+++ b/backend/api/api/Controllers/UserController.cs
@@ -1,5 +1,6 @@
using api.Models;
using api.Services;
+using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Diagnostics;
@@ -72,6 +73,7 @@ namespace api.Controllers
// PUT api/<UserController>/5
[HttpPut("{id}")]
+ [Authorize(Roles = "User")]
public ActionResult Put(string id, [FromBody] User user)
{
var existingUser = userService.Get(id);
@@ -86,6 +88,7 @@ namespace api.Controllers
// DELETE api/<UserController>/5
[HttpDelete("{id}")]
+ [Authorize(Roles = "User")]
public ActionResult Delete(string id)
{
var user = userService.Get(id);
diff --git a/backend/api/api/Data/UserStoreDatabaseSettings.cs b/backend/api/api/Data/UserStoreDatabaseSettings.cs
index 0d923fc7..6416ab05 100644
--- a/backend/api/api/Data/UserStoreDatabaseSettings.cs
+++ b/backend/api/api/Data/UserStoreDatabaseSettings.cs
@@ -10,5 +10,7 @@ namespace api.Data
public string DatabaseName { get; set; } = String.Empty;
public string CollectionName { get; set; } = String.Empty;
public string DatasetCollectionName { get; set; } = String.Empty;
+ public string ModelCollectionName { get; set; } = String.Empty;
+ public string FilesCollectionName { get; set; } = String.Empty;
}
}
diff --git a/backend/api/api/Interfaces/IUserStoreDatabaseSettings.cs b/backend/api/api/Interfaces/IUserStoreDatabaseSettings.cs
index 8d2a175f..82312649 100644
--- a/backend/api/api/Interfaces/IUserStoreDatabaseSettings.cs
+++ b/backend/api/api/Interfaces/IUserStoreDatabaseSettings.cs
@@ -6,5 +6,7 @@
string DatabaseName { get; set; }
string CollectionName { get; set; }
string DatasetCollectionName { get; set; }
+ string ModelCollectionName { get; }
+ string FilesCollectionName { get; set; }
}
}
diff --git a/backend/api/api/Models/Dataset.cs b/backend/api/api/Models/Dataset.cs
index 0dc87f40..6cb0b1e9 100644
--- a/backend/api/api/Models/Dataset.cs
+++ b/backend/api/api/Models/Dataset.cs
@@ -1,46 +1,25 @@
-using MongoDB.Bson;
+using System;
+using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
namespace api.Models
{
- public class Dataset
- {
- internal string uploaderId;
+ public class Dataset
+ {
+ public string username;
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]//mongo data type to .net
public string _id { get; set; }
- [BsonElement("uploaderId")]
- public string UploaderId { get; set; }
- [BsonElement("name")]
public string name { get; set; }
-
public string description { get; set; }
- //datetime
- public string dateCreated { get; set; }
-
- public int[] inputColumns { get; set; }
- public int columnToPredict { get; set; }
- public bool randomTestSet { get; set; }
- public int randomTestSetDistribution { get; set; }
-
-
- public string type { get; set; }
- public string encoding { get; set; }
- public string optimizer { get; set; }
- public string lossFunction { get; set; }
- public int inputNeurons { get; set; }
- public int hiddenLayerNeurons { get; set; }
- public int hiddenLayers { get; set; }
- public int batchSize { get; set; }
- public string inputLayerActivationFunction { get; set; }
- public string hiddenLayerActivationFunction { get; set; }
- public string outputLayerActivationFunction { get; set; }
-
-
- [BsonElement("extension")]
+ public string[] header { get; set; }
+ public int fileId { get; set; }
public string extension { get; set; }
-
-
+ public bool isPublic { get; set; }
+ public bool accessibleByLink { get; set; }
+ public string dateCreated { get; set; }
+ public string lastUpdated { get; set; }
}
}
+
diff --git a/backend/api/api/Models/FileModel.cs b/backend/api/api/Models/FileModel.cs
new file mode 100644
index 00000000..9e7c8b5d
--- /dev/null
+++ b/backend/api/api/Models/FileModel.cs
@@ -0,0 +1,14 @@
+using MongoDB.Bson;
+using MongoDB.Bson.Serialization.Attributes;
+
+namespace api.Models
+{
+ public class FileModel
+ {
+ [BsonId]
+ [BsonRepresentation(BsonType.ObjectId)]
+ public string _id { get; set; }
+ public string username { get; set; }
+ public string path { get; set; }
+ }
+}
diff --git a/backend/api/api/Models/JwtToken.cs b/backend/api/api/Models/JwtToken.cs
index 7cbd6f54..a98d1967 100644
--- a/backend/api/api/Models/JwtToken.cs
+++ b/backend/api/api/Models/JwtToken.cs
@@ -23,7 +23,7 @@ namespace api.Models
{
Subject = new ClaimsIdentity(new[] { new Claim("name", user.UserName),
new Claim("role", "User")}),
- Expires = DateTime.UtcNow.AddDays(1),
+ Expires = DateTime.UtcNow.AddMinutes(20),
SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
};
var token = tokenHandler.CreateToken(tokenDescriptor);
diff --git a/backend/api/api/Models/Model.cs b/backend/api/api/Models/Model.cs
new file mode 100644
index 00000000..7b22ded8
--- /dev/null
+++ b/backend/api/api/Models/Model.cs
@@ -0,0 +1,45 @@
+using MongoDB.Bson;
+using MongoDB.Bson.Serialization.Attributes;
+
+namespace api.Models
+{
+ public class Model
+ {
+
+ [BsonId]
+ [BsonRepresentation(BsonType.ObjectId)]//mongo data type to .net
+ public string _id { get; set; }
+ public string username { get; set; }
+
+
+ public string name { get; set; }
+ public string description { get; set; }
+ //datetime
+ public string dateCreated { get; set; }
+ public string lastUpdated { get; set; }
+ //proveriti id
+ public string datasetId { get; set; }
+
+ //Test set settings
+ public int[] inputColumns { get; set; }
+ public int columnToPredict { get; set; }
+ public bool radnomOrder {get;set;}
+ public bool randomTestSet { get; set; }
+ public int randomTestSetDistribution { get; set; }
+
+ //Neural net training
+ public string type { get; set; }
+ public string encoding { get; set; }
+ public string optimizer { get; set; }
+ public string lossFunction { get; set; }
+ public int inputNeurons { get; set; }
+ public int hiddenLayerNeurons { get; set; }
+ public int hiddenLayers { get; set; }
+ public int batchSize { get; set; }
+ public string inputLayerActivationFunction { get; set; }
+ public string hiddenLayerActivationFunction { get; set; }
+ public string outputLayerActivationFunction { get; set; }
+
+
+ }
+}
diff --git a/backend/api/api/Program.cs b/backend/api/api/Program.cs
index 2c569daf..f3287b4c 100644
--- a/backend/api/api/Program.cs
+++ b/backend/api/api/Program.cs
@@ -28,6 +28,10 @@ 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>();
+builder.Services.AddScoped<IModelService, ModelService>();
+builder.Services.AddScoped<IFileService, FileService>();
+
//Add Authentication
builder.Services.AddAuthentication(
diff --git a/backend/api/api/Services/DatasetService.cs b/backend/api/api/Services/DatasetService.cs
index 1b6d22be..80c31758 100644
--- a/backend/api/api/Services/DatasetService.cs
+++ b/backend/api/api/Services/DatasetService.cs
@@ -21,23 +21,25 @@ namespace api.Services
}
//brisanje odredjenog name-a
- public void Delete(string uploaderId, string name)
+ public void Delete(string username, string name)
{
- _dataset.DeleteOne(dataset => (dataset.UploaderId == uploaderId && dataset.name == name));
+ _dataset.DeleteOne(dataset => (dataset.username == username && dataset.name == name));
}
- public List<Dataset> GetAllDatesets(string uploaderId)
+
+ public List<Dataset> GetAllDatesets(string username)
{
- return _dataset.Find(dataset => dataset.uploaderId == uploaderId).ToList();
+ return _dataset.Find(dataset => dataset.username == username).ToList();
}
- public Dataset GetOneDataset(string uploaderId, string name)
+
+ public Dataset GetOneDataset(string username, string name)
{
- return _dataset.Find(dataset => dataset.UploaderId == uploaderId && dataset.name == name).FirstOrDefault();
+ return _dataset.Find(dataset => dataset.username == username && dataset.name == name).FirstOrDefault();
}
//ako je potrebno da se zameni name ili ekstenzija
- public void Update(string uploaderId, string name, Dataset dataset)
+ public void Update(string username, string name, Dataset dataset)
{
- _dataset.ReplaceOne(dataset => dataset.UploaderId == uploaderId && dataset.name == name, dataset);
+ _dataset.ReplaceOne(dataset => dataset.username == username && dataset.name == name, dataset);
}
}
}
diff --git a/backend/api/api/Services/FileService.cs b/backend/api/api/Services/FileService.cs
new file mode 100644
index 00000000..e68a0fe3
--- /dev/null
+++ b/backend/api/api/Services/FileService.cs
@@ -0,0 +1,34 @@
+using api.Interfaces;
+using api.Models;
+using MongoDB.Driver;
+
+namespace api.Services
+{
+ public class FileService : IFileService
+ {
+
+ private readonly IMongoCollection<FileModel> _file;
+
+ public FileService(IUserStoreDatabaseSettings settings, IMongoClient mongoClient)
+ {
+ var database = mongoClient.GetDatabase(settings.DatabaseName);
+ _file = database.GetCollection<FileModel>(settings.FilesCollectionName);
+ }
+
+ public FileModel Create(FileModel file)
+ {
+ if (file == null)
+ return null;
+ _file.InsertOne(file);
+ return file;
+
+ }
+ public string GetFilePath(string id, string username)
+ {
+ FileModel file = _file.Find(x => x._id == id && x.username == username).FirstOrDefault();
+ if (file == null)
+ return null;
+ return file.path;
+ }
+ }
+}
diff --git a/backend/api/api/Services/IDatasetService.cs b/backend/api/api/Services/IDatasetService.cs
index 9cf8c3cb..49013e29 100644
--- a/backend/api/api/Services/IDatasetService.cs
+++ b/backend/api/api/Services/IDatasetService.cs
@@ -5,10 +5,10 @@ namespace api.Services
{
public interface IDatasetService
{
- Dataset GetOneDataset(string uploaderId, string name);
- List<Dataset> GetAllDatesets(string uploaderId);
+ Dataset GetOneDataset(string username, string name);
+ List<Dataset> GetAllDatesets(string username);
Dataset Create(Dataset dataset);
- void Update(string uploaderId, string name, Dataset dataset);
- void Delete(string uploaderId, string name);
+ void Update(string username, string name, Dataset dataset);
+ void Delete(string username, string name);
}
}
diff --git a/backend/api/api/Services/IFileService.cs b/backend/api/api/Services/IFileService.cs
new file mode 100644
index 00000000..7446e283
--- /dev/null
+++ b/backend/api/api/Services/IFileService.cs
@@ -0,0 +1,10 @@
+using api.Models;
+
+namespace api.Services
+{
+ public interface IFileService
+ {
+ FileModel Create(FileModel file);
+ string GetFilePath(string id, string username);
+ }
+} \ No newline at end of file
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/IModelService.cs b/backend/api/api/Services/IModelService.cs
new file mode 100644
index 00000000..149afd4a
--- /dev/null
+++ b/backend/api/api/Services/IModelService.cs
@@ -0,0 +1,15 @@
+using System;
+using api.Models;
+
+namespace api.Services
+{
+ public interface IModelService
+ {
+ Model GetOneModel(string username, string name);
+ List<Model> GetAllModels(string username);
+ Model Create(Model model);
+ void Update(string username, string name, Model model);
+ void Delete(string username, string name);
+ }
+}
+
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/Services/ModelService.cs b/backend/api/api/Services/ModelService.cs
new file mode 100644
index 00000000..33dea30e
--- /dev/null
+++ b/backend/api/api/Services/ModelService.cs
@@ -0,0 +1,47 @@
+using System;
+using api.Interfaces;
+using api.Models;
+using MongoDB.Driver;
+
+namespace api.Services
+{
+ public class ModelService : IModelService
+ {
+
+ private readonly IMongoCollection<Model> _model;
+
+ public ModelService(IUserStoreDatabaseSettings settings, IMongoClient mongoClient)
+ {
+ var database = mongoClient.GetDatabase(settings.DatabaseName);
+ _model = database.GetCollection<Model>(settings.ModelCollectionName);
+ }
+
+ public Model Create(Model model)
+ {
+ _model.InsertOne(model);
+ return model;
+ }
+
+ public void Delete(string username, string name)
+ {
+ _model.DeleteOne(model => (model.username == username && model.name == name));
+ }
+
+ public List<Model> GetAllModels(string username)
+ {
+ return _model.Find(model => model.username == username).ToList();
+ }
+
+ public Model GetOneModel(string username, string name)
+ {
+ return _model.Find(model => model.username == username && model.name == name).FirstOrDefault();
+ }
+
+ public void Update(string username, string name, Model model)
+ {
+ _model.ReplaceOne(model => model.username == username && model.name == name, model);
+ }
+
+ }
+}
+
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>
diff --git a/backend/api/api/appsettings.json b/backend/api/api/appsettings.json
index 9b4f00a3..86363075 100644
--- a/backend/api/api/appsettings.json
+++ b/backend/api/api/appsettings.json
@@ -9,16 +9,19 @@
}
},
"AllowedHosts": "*",
- "UserStoreDatabaseSettings": {
- /* LocalHost
+ "UserStoreDatabaseSettings": {
+ /* LocalHost
"ConnectionString": "mongodb://127.0.0.1:27017/",
"DatabaseName": "si_project",
"CollectionName": "User",
- "DatasetCollectionName" : "Dataset"
+ "DatasetCollectionName" : "Dataset",
+ "ModelCollectionName" : "Model"
*/
- "ConnectionString": "mongodb+srv://si_user:si_user@sidatabase.twtfm.mongodb.net/myFirstDatabase?retryWrites=true&w=majority",
- "DatabaseName": "si_db",
- "CollectionName": "users",
- "DatasetCollectionName": "Dataset"
- }
+ "ConnectionString": "mongodb+srv://si_user:si_user@sidatabase.twtfm.mongodb.net/myFirstDatabase?retryWrites=true&w=majority",
+ "DatabaseName": "si_db",
+ "CollectionName": "users",
+ "DatasetCollectionName": "Dataset",
+ "ModelCollectionName": "Model",
+ "FilesCollectionName": "Files"
+ }
}