diff options
author | Sonja Galovic <galovicsonja@gmail.com> | 2022-05-19 23:35:21 +0200 |
---|---|---|
committer | Sonja Galovic <galovicsonja@gmail.com> | 2022-05-19 23:35:21 +0200 |
commit | 863881a77f00810f3298aaf6fc451edfe733d121 (patch) | |
tree | a0f8deb87a71f4047032c8bf3944e9e17eed4e87 /backend/api | |
parent | 104616db42f10c5a009b3e23e599e8e7bad939c2 (diff) | |
parent | 8d41b2ec76f7566bf51598670b51141cad9b66ef (diff) |
Merge branch 'redesign' of http://gitlab.pmf.kg.ac.rs/igrannonica/neuronstellar into redesign
Diffstat (limited to 'backend/api')
-rw-r--r-- | backend/api/api/Controllers/PredictorController.cs | 6 | ||||
-rw-r--r-- | backend/api/api/Interfaces/IPredictorService.cs | 1 | ||||
-rw-r--r-- | backend/api/api/Services/ExperimentService.cs | 1 | ||||
-rw-r--r-- | backend/api/api/Services/PredictorService.cs | 5 |
4 files changed, 12 insertions, 1 deletions
diff --git a/backend/api/api/Controllers/PredictorController.cs b/backend/api/api/Controllers/PredictorController.cs index 3a9e6649..6ff7746a 100644 --- a/backend/api/api/Controllers/PredictorController.cs +++ b/backend/api/api/Controllers/PredictorController.cs @@ -160,7 +160,11 @@ namespace api.Controllers var model = _modelService.GetOneModel(predictor.modelId); if (model == null || user==null) return BadRequest("Model not found or user doesnt exist"); - _predictorService.Create(predictor); + Predictor p=_predictorService.Exists(predictor.modelId, predictor.experimentId); + if (p == null) + _predictorService.Create(predictor); + else + _predictorService.Update(p._id, predictor); if (ChatHub.CheckUser(user._id)) foreach(var connection in ChatHub.getAllConnectionsOfUser(user._id)) await _ichat.Clients.Client(connection).SendAsync("NotifyPredictor", predictor._id,model.name); diff --git a/backend/api/api/Interfaces/IPredictorService.cs b/backend/api/api/Interfaces/IPredictorService.cs index 16f0432a..8a8308be 100644 --- a/backend/api/api/Interfaces/IPredictorService.cs +++ b/backend/api/api/Interfaces/IPredictorService.cs @@ -12,5 +12,6 @@ namespace api.Services List<Predictor> GetPublicPredictors(); List<Predictor> SortPredictors(string userId, bool ascdsc, int latest); void Update(string id, Predictor predictor); + public Predictor Exists(string modelId, string experimentId); } }
\ No newline at end of file diff --git a/backend/api/api/Services/ExperimentService.cs b/backend/api/api/Services/ExperimentService.cs index dde9111d..40dad224 100644 --- a/backend/api/api/Services/ExperimentService.cs +++ b/backend/api/api/Services/ExperimentService.cs @@ -56,5 +56,6 @@ namespace api.Services _experiment.DeleteOne(experiment => (experiment.uploaderId == userId && experiment._id == id)); _predictor.DeleteMany(predictor => (predictor.uploaderId == userId && predictor.experimentId == id)); } + } } diff --git a/backend/api/api/Services/PredictorService.cs b/backend/api/api/Services/PredictorService.cs index 756cc943..3c088a81 100644 --- a/backend/api/api/Services/PredictorService.cs +++ b/backend/api/api/Services/PredictorService.cs @@ -62,5 +62,10 @@ namespace api.Services { _predictor.ReplaceOne(predictor => predictor._id == id, predictor); } + public Predictor Exists(string modelId, string experimentId) + { + Predictor p=_predictor.Find(pre=> pre.modelId == modelId && pre.experimentId==experimentId).FirstOrDefault(); + return p; + } } } |