From 686c049223a62f0a6926e08d8743ef9661200874 Mon Sep 17 00:00:00 2001 From: "DESKTOP-S0O2C44\\ROG" Date: Wed, 30 Mar 2022 17:49:50 +0200 Subject: Sitne izmene oko predict stranice.(Nije zavrsneno) #53 #66 --- backend/api/api/Controllers/ModelController.cs | 12 +++++++++--- backend/api/api/Controllers/PredictorController.cs | 3 +-- backend/api/api/Services/IModelService.cs | 1 + backend/api/api/Services/ModelService.cs | 5 +++++ 4 files changed, 16 insertions(+), 5 deletions(-) (limited to 'backend') diff --git a/backend/api/api/Controllers/ModelController.cs b/backend/api/api/Controllers/ModelController.cs index 0be7894e..d8bc1515 100644 --- a/backend/api/api/Controllers/ModelController.cs +++ b/backend/api/api/Controllers/ModelController.cs @@ -129,8 +129,9 @@ namespace api.Controllers // POST api//add [HttpPost("add")] [Authorize(Roles = "User,Guest")] - public ActionResult Post([FromBody] Model model) + public ActionResult Post([FromBody] Model model)//, bool overwrite) { + bool overwrite = false; //username="" ako je GUEST model.inputNeurons = model.inputColumns.Length; if (_modelService.CheckHyperparameters(model.inputNeurons, model.hiddenLayerNeurons, model.hiddenLayers, model.outputNeurons) == false) @@ -138,11 +139,16 @@ namespace api.Controllers var existingModel = _modelService.GetOneModel(model.username, model.name); - if (existingModel != null) + if (existingModel != null && !overwrite) return NotFound($"Model with name = {model.name} exisits"); else { - _modelService.Create(model); + if (existingModel == null) + _modelService.Create(model); + else + { + _modelService.Replace(model); + } return CreatedAtAction(nameof(Get), new { id = model._id }, model); } diff --git a/backend/api/api/Controllers/PredictorController.cs b/backend/api/api/Controllers/PredictorController.cs index 8f2167c4..98e2695e 100644 --- a/backend/api/api/Controllers/PredictorController.cs +++ b/backend/api/api/Controllers/PredictorController.cs @@ -74,8 +74,7 @@ namespace api.Controllers return _predictorService.SearchPredictors(name, username); } - //SEARCH za predictore (public ili private sa ovim imenom ) - // GET api//search/{name} + // GET api//{name} [HttpGet("{id}")] [Authorize(Roles = "User")] public ActionResult GetPredictor(string id) diff --git a/backend/api/api/Services/IModelService.cs b/backend/api/api/Services/IModelService.cs index 637d09a3..3e70a1c3 100644 --- a/backend/api/api/Services/IModelService.cs +++ b/backend/api/api/Services/IModelService.cs @@ -11,6 +11,7 @@ namespace api.Services List GetLatestModels(string username); //List GetPublicModels(); Model Create(Model model); + Model Replace(Model model); void Update(string username, string name, Model model); void Delete(string username, string name); bool CheckHyperparameters(int inputNeurons, int hiddenLayerNeurons, int hiddenLayers, int outputNeurons); diff --git a/backend/api/api/Services/ModelService.cs b/backend/api/api/Services/ModelService.cs index eae8c78b..c2b4e692 100644 --- a/backend/api/api/Services/ModelService.cs +++ b/backend/api/api/Services/ModelService.cs @@ -20,6 +20,11 @@ namespace api.Services _model.InsertOne(model); return model; } + public Model Replace(Model model) + { + _model.ReplaceOne(m => m._id == model._id, model); + return model; + } public void Delete(string username, string name) { -- cgit v1.2.3