From 1b6a8d3a61b0c8afb916043f6b6bd069dac55e57 Mon Sep 17 00:00:00 2001 From: Ivan Ljubisavljevic Date: Wed, 18 May 2022 21:54:14 +0200 Subject: GetModelById dodat - upgrade --- backend/api/api/Controllers/DatasetController.cs | 2 -- backend/api/api/Controllers/ModelController.cs | 20 ++++++++++++++++++++ backend/api/api/Interfaces/IModelService.cs | 1 + backend/api/api/Services/ModelService.cs | 5 +++++ 4 files changed, 26 insertions(+), 2 deletions(-) (limited to 'backend/api') diff --git a/backend/api/api/Controllers/DatasetController.cs b/backend/api/api/Controllers/DatasetController.cs index 80c9f2a9..e4741412 100644 --- a/backend/api/api/Controllers/DatasetController.cs +++ b/backend/api/api/Controllers/DatasetController.cs @@ -227,8 +227,6 @@ namespace api.Controllers dataset.fileId = fileModel1._id; - //nesto - dataset.isPreProcess = true; _datasetService.Create(dataset); diff --git a/backend/api/api/Controllers/ModelController.cs b/backend/api/api/Controllers/ModelController.cs index c9e36ca4..39eb7830 100644 --- a/backend/api/api/Controllers/ModelController.cs +++ b/backend/api/api/Controllers/ModelController.cs @@ -149,6 +149,26 @@ namespace api.Controllers return model; } + + // GET api//byid/{id} + [HttpGet("byid/{id}")] + [Authorize(Roles = "User,Guest")] + public ActionResult GetModelById(string id) + { + string userId = getUserId(); + + if (userId == null) + return BadRequest(); + + var model = _modelService.GetOneModelById(userId, id); + + if (model == null) + return NotFound($"Model with id = {id} not found"); + + return model; + } + + //odraditi da vraca modele prema nekom imenu diff --git a/backend/api/api/Interfaces/IModelService.cs b/backend/api/api/Interfaces/IModelService.cs index 8c4543de..41cd279c 100644 --- a/backend/api/api/Interfaces/IModelService.cs +++ b/backend/api/api/Interfaces/IModelService.cs @@ -6,6 +6,7 @@ namespace api.Services public interface IModelService { Model GetOneModel(string userId, string name); + Model GetOneModelById(string userId, string name); Model GetOneModel(string id); List GetMyModels(string userId); List GetMyModelsByType(string userId, string problemType); diff --git a/backend/api/api/Services/ModelService.cs b/backend/api/api/Services/ModelService.cs index e852d71f..71db6340 100644 --- a/backend/api/api/Services/ModelService.cs +++ b/backend/api/api/Services/ModelService.cs @@ -65,6 +65,11 @@ namespace api.Services return _model.Find(model => model.uploaderId == userId && model.name == name).FirstOrDefault(); } + public Model GetOneModelById(string userId, string id) + { + return _model.Find(model => model.uploaderId == userId && model._id == id).FirstOrDefault(); + } + public Model GetOneModel(string id) { return _model.Find(model => model._id == id).FirstOrDefault(); -- cgit v1.2.3