From 60782001174dc7f6f8f5670bff5aaca54667b734 Mon Sep 17 00:00:00 2001 From: Danijel Anđelković Date: Sat, 4 Jun 2022 01:17:55 +0200 Subject: Dodao poredjenje modela/prediktora nad eksperimentom. Popravio bug sa dodavanjem novog prediktora. --- backend/api/api/Controllers/PredictorController.cs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'backend/api') diff --git a/backend/api/api/Controllers/PredictorController.cs b/backend/api/api/Controllers/PredictorController.cs index 6ff7746a..56095553 100644 --- a/backend/api/api/Controllers/PredictorController.cs +++ b/backend/api/api/Controllers/PredictorController.cs @@ -21,7 +21,7 @@ namespace api.Controllers private readonly IHubContext _ichat; private readonly IModelService _modelService; - public PredictorController(IPredictorService predictorService, IConfiguration configuration, IJwtToken Token, IMlConnectionService mlConnectionService, IExperimentService experimentService,IUserService userService, IHubContext ichat,IModelService modelService) + public PredictorController(IPredictorService predictorService, IConfiguration configuration, IJwtToken Token, IMlConnectionService mlConnectionService, IExperimentService experimentService, IUserService userService, IHubContext ichat, IModelService modelService) { _predictorService = predictorService; jwtToken = Token; @@ -78,7 +78,7 @@ namespace api.Controllers //public ActionResult> Search(string name) //{ // string username = getUsername(); - + // if (username == null) // return BadRequest(); @@ -138,7 +138,7 @@ namespace api.Controllers List lista = _predictorService.SortPredictors(userId, ascdsc, latest); - if(latest == 0) + if (latest == 0) return lista; else { @@ -155,19 +155,23 @@ namespace api.Controllers [HttpPost("add")] public async Task> Post([FromBody] Predictor predictor) { - var user=_userService.GetUserById(predictor.uploaderId); + var user = _userService.GetUserById(predictor.uploaderId); predictor.dateCreated = DateTime.Now.ToUniversalTime(); var model = _modelService.GetOneModel(predictor.modelId); - if (model == null || user==null) + if (model == null || user == null) return BadRequest("Model not found or user doesnt exist"); - Predictor p=_predictorService.Exists(predictor.modelId, predictor.experimentId); - if (p == null) + Predictor p = _predictorService.Exists(predictor.modelId, predictor.experimentId); + + if (p == null) { _predictorService.Create(predictor); - else + } + else { + predictor._id = p._id; _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); + await _ichat.Clients.Client(connection).SendAsync("NotifyPredictor", predictor._id, model._id); return CreatedAtAction(nameof(Get), new { id = predictor._id }, predictor); } -- cgit v1.2.3