diff options
Diffstat (limited to 'backend')
-rw-r--r-- | backend/api/api/Controllers/ModelController.cs | 12 | ||||
-rw-r--r-- | backend/api/api/Controllers/PredictorController.cs | 3 | ||||
-rw-r--r-- | backend/api/api/Services/IModelService.cs | 1 | ||||
-rw-r--r-- | backend/api/api/Services/ModelService.cs | 5 |
4 files changed, 16 insertions, 5 deletions
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/<ModelController>/add [HttpPost("add")] [Authorize(Roles = "User,Guest")] - public ActionResult<Model> Post([FromBody] Model model) + public ActionResult<Model> 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/<PredictorController>/search/{name} + // GET api/<PredictorController>/{name} [HttpGet("{id}")] [Authorize(Roles = "User")] public ActionResult<Predictor> 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<Model> GetLatestModels(string username); //List<Model> 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) { |