From c1356ddc1c5cd5cbc1603384555b741824831104 Mon Sep 17 00:00:00 2001 From: Ognjen Cirkovic Date: Sun, 13 Mar 2022 18:32:12 +0100 Subject: Proslediti model poslat od frontend-a na python microservice. --- backend/api/api/Controllers/ModelController.cs | 29 ++++++++++++++++++++++++ backend/api/api/Program.cs | 1 + backend/api/api/Services/IMlConnectionService.cs | 8 +++++++ backend/api/api/Services/MlConnectionService.cs | 17 ++++++++++++++ backend/api/api/api.csproj | 2 ++ 5 files changed, 57 insertions(+) create mode 100644 backend/api/api/Controllers/ModelController.cs create mode 100644 backend/api/api/Services/IMlConnectionService.cs create mode 100644 backend/api/api/Services/MlConnectionService.cs diff --git a/backend/api/api/Controllers/ModelController.cs b/backend/api/api/Controllers/ModelController.cs new file mode 100644 index 00000000..5e22c61d --- /dev/null +++ b/backend/api/api/Controllers/ModelController.cs @@ -0,0 +1,29 @@ +using api.Services; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; + +namespace api.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class ModelController : ControllerBase + { + + private IMlConnectionService _mlService; + + public ModelController(IMlConnectionService mlService) + { + _mlService = mlService; + } + + [HttpPost("sendModel")] + [Authorize(Roles = "User")] + public async Task> Test([FromBody] object model) + { + var result = await _mlService.SendModelAsync(model); + return Ok(result); + } + + } +} diff --git a/backend/api/api/Program.cs b/backend/api/api/Program.cs index 2c569daf..702ef259 100644 --- a/backend/api/api/Program.cs +++ b/backend/api/api/Program.cs @@ -28,6 +28,7 @@ builder.Services.AddSingleton(s => builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); +builder.Services.AddScoped(); //Add Authentication builder.Services.AddAuthentication( diff --git a/backend/api/api/Services/IMlConnectionService.cs b/backend/api/api/Services/IMlConnectionService.cs new file mode 100644 index 00000000..f38fb50a --- /dev/null +++ b/backend/api/api/Services/IMlConnectionService.cs @@ -0,0 +1,8 @@ + +namespace api.Services +{ + public interface IMlConnectionService + { + Task SendModelAsync(object model); + } +} \ No newline at end of file diff --git a/backend/api/api/Services/MlConnectionService.cs b/backend/api/api/Services/MlConnectionService.cs new file mode 100644 index 00000000..a7c81c43 --- /dev/null +++ b/backend/api/api/Services/MlConnectionService.cs @@ -0,0 +1,17 @@ +using RestSharp; + +namespace api.Services +{ + public class MlConnectionService : IMlConnectionService + { + public async Task SendModelAsync(object model) + { + RestClient client = new RestClient("https://jsonplaceholder.typicode.com");//Promeniti na python api kad se odradi + var request = new RestRequest("posts", Method.Post);//Promeniti na python api kad se odradi + request.AddJsonBody(model); + var result = await client.ExecuteAsync(request); + return result.Content;//Response od ML microservisa + + } + } +} diff --git a/backend/api/api/api.csproj b/backend/api/api/api.csproj index 46842c3e..f38621ca 100644 --- a/backend/api/api/api.csproj +++ b/backend/api/api/api.csproj @@ -10,6 +10,8 @@ + + -- cgit v1.2.3 From 0fc05f3be0332b38acbefe86319aebd4affc456c Mon Sep 17 00:00:00 2001 From: Ognjen Cirkovic Date: Tue, 15 Mar 2022 16:44:54 +0100 Subject: Dodata putanja do python API-a. --- backend/api/api/Services/MlConnectionService.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/api/api/Services/MlConnectionService.cs b/backend/api/api/Services/MlConnectionService.cs index a7c81c43..7adade0c 100644 --- a/backend/api/api/Services/MlConnectionService.cs +++ b/backend/api/api/Services/MlConnectionService.cs @@ -6,8 +6,8 @@ namespace api.Services { public async Task SendModelAsync(object model) { - RestClient client = new RestClient("https://jsonplaceholder.typicode.com");//Promeniti na python api kad se odradi - var request = new RestRequest("posts", Method.Post);//Promeniti na python api kad se odradi + RestClient client = new RestClient("http://localhost:5000"); + var request = new RestRequest("data", Method.Post); request.AddJsonBody(model); var result = await client.ExecuteAsync(request); return result.Content;//Response od ML microservisa -- cgit v1.2.3 From ca592566e80a7a83fff85e0b5a11bcca06f7e017 Mon Sep 17 00:00:00 2001 From: Sonja Galovic Date: Tue, 15 Mar 2022 21:27:46 +0100 Subject: Uredjena stranica add-model i komponenta dataset-load. --- .../dataset-load/dataset-load.component.css | 6 + .../dataset-load/dataset-load.component.html | 57 +++- .../dataset-load/dataset-load.component.ts | 43 +++ .../app/_pages/add-model/add-model.component.css | 17 ++ .../app/_pages/add-model/add-model.component.html | 322 +++++++++------------ .../src/assets/images/add_model_background.jpg | Bin 0 -> 56906 bytes frontend/src/assets/images/logo_crop.png | Bin 11447 -> 0 bytes frontend/src/assets/images/logo_dark_crop.png | Bin 10987 -> 0 bytes 8 files changed, 250 insertions(+), 195 deletions(-) create mode 100644 frontend/src/assets/images/add_model_background.jpg delete mode 100644 frontend/src/assets/images/logo_crop.png delete mode 100644 frontend/src/assets/images/logo_dark_crop.png diff --git a/frontend/src/app/_elements/dataset-load/dataset-load.component.css b/frontend/src/app/_elements/dataset-load/dataset-load.component.css index e69de29b..05819702 100644 --- a/frontend/src/app/_elements/dataset-load/dataset-load.component.css +++ b/frontend/src/app/_elements/dataset-load/dataset-load.component.css @@ -0,0 +1,6 @@ +#divInputs { + margin-left: 20px; +} +#divOutputs { + margin-left: 20px; +} \ No newline at end of file diff --git a/frontend/src/app/_elements/dataset-load/dataset-load.component.html b/frontend/src/app/_elements/dataset-load/dataset-load.component.html index c89add43..16830e11 100644 --- a/frontend/src/app/_elements/dataset-load/dataset-load.component.html +++ b/frontend/src/app/_elements/dataset-load/dataset-load.component.html @@ -1,19 +1,21 @@
- + - - - -      -   - -

+ + +      + +      - - - + + + +
@@ -26,7 +28,7 @@
{{item}}
- +
@@ -39,4 +41,35 @@ {{rowsNumber}} x {{colsNumber}} +
+
+
+

Izaberite ulazne kolone:

+
+
+
+ +   + +
+
+
+
+

Izaberite izlaznu kolonu:

+
+
+
+ +   + +
+
+
+
+
+ \ No newline at end of file diff --git a/frontend/src/app/_elements/dataset-load/dataset-load.component.ts b/frontend/src/app/_elements/dataset-load/dataset-load.component.ts index cde3e8b1..c772dc35 100644 --- a/frontend/src/app/_elements/dataset-load/dataset-load.component.ts +++ b/frontend/src/app/_elements/dataset-load/dataset-load.component.ts @@ -20,6 +20,9 @@ export class DatasetLoadComponent { rowsNumber: number = 0; colsNumber: number = 0; + checkedInputCols: Array = []; + checkedOutputCol: string = ''; + constructor(private ngxCsvParser: NgxCsvParser) { } @@ -51,4 +54,44 @@ export class DatasetLoadComponent { console.log('Error', error); }); } + + getCheckedInputCols() : Array { + this.checkedInputCols = new Array(); + let checkboxes = document.getElementsByName("cbs"); + + for (let i = 0; i < checkboxes.length; i++) { + let thatCb = checkboxes[i]; + if (thatCb.checked) + this.checkedInputCols.push(thatCb.value); + } + //console.log(this.checkedInputCols); + return this.checkedInputCols; + } + getCheckedOutputCol() : string { + this.checkedOutputCol = ''; + let radiobuttons = document.getElementsByName("rbs"); + + for (let i = 0; i < radiobuttons.length; i++) { + let thatRb = radiobuttons[i]; + if (thatRb.checked) { + this.checkedOutputCol = thatRb.value; + break; + } + } + //console.log(this.checkedOutputCol); + return this.checkedOutputCol; + } + validationInputsOutput() { + if (this.checkedInputCols.length == 0) { + alert("Molimo Vas da izaberete ulaznu kolonu/kolone za mrežu.") + return; + } + for (let i = 0; i < this.checkedInputCols.length; i++) { + if (this.checkedInputCols[i] == this.checkedOutputCol) { + let colName = this.checkedOutputCol; + alert("Izabrali ste istu kolonu (" + colName + ") kao ulaznu i izlaznu iz mreže. Korigujte izbor."); + return; + } + } + } } diff --git a/frontend/src/app/_pages/add-model/add-model.component.css b/frontend/src/app/_pages/add-model/add-model.component.css index e69de29b..004b9cac 100644 --- a/frontend/src/app/_pages/add-model/add-model.component.css +++ b/frontend/src/app/_pages/add-model/add-model.component.css @@ -0,0 +1,17 @@ +#header { + background-color: #003459; + padding-top: 25px; + padding-bottom: 20px; +} +#header h1 { + font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif; + text-align: center; + color: white; +} + +#wrapper { + background-image: url('/assets/images/add_model_background.jpg'); +} +#container { + border-radius: 8px; +} \ No newline at end of file diff --git a/frontend/src/app/_pages/add-model/add-model.component.html b/frontend/src/app/_pages/add-model/add-model.component.html index bc292bb9..e141b228 100644 --- a/frontend/src/app/_pages/add-model/add-model.component.html +++ b/frontend/src/app/_pages/add-model/add-model.component.html @@ -1,189 +1,145 @@ -
- -

Nov model:

-
- -
- -
- -
- -
-
- -
- -
- -
-
- - - -
- - -
- -
-
- - -
-
- -
-
- -

Parametri treniranja

- -
- -
- -
-
- -
- -
- -
-
- -
- -
- +
+
+    + +
+
+
+ +
+ +
+
+
+ +
+

Izvor podataka:

+ +
+ +

Parametri treniranja:

+ +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + -
-
- -
- -
- -
-
- -
- -
- -
-
- -
- -
- -
-
- -
- -
- -
-
- -
- -
- -
-
- -
- -
- -
-
- -
- -
- + +
+
+ + +
+
+ +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
- -
- -
- +

+
+
+ +
-
-
-
- -
- -
\ No newline at end of file + diff --git a/frontend/src/assets/images/add_model_background.jpg b/frontend/src/assets/images/add_model_background.jpg new file mode 100644 index 00000000..d86f0566 Binary files /dev/null and b/frontend/src/assets/images/add_model_background.jpg differ diff --git a/frontend/src/assets/images/logo_crop.png b/frontend/src/assets/images/logo_crop.png deleted file mode 100644 index 1775a465..00000000 Binary files a/frontend/src/assets/images/logo_crop.png and /dev/null differ diff --git a/frontend/src/assets/images/logo_dark_crop.png b/frontend/src/assets/images/logo_dark_crop.png deleted file mode 100644 index d66f13e2..00000000 Binary files a/frontend/src/assets/images/logo_dark_crop.png and /dev/null differ -- cgit v1.2.3 From 9b120a7ab2f10133f1cdb4cd793680e38c83fffd Mon Sep 17 00:00:00 2001 From: Ivan Ljubisavljevic Date: Tue, 15 Mar 2022 22:31:51 +0100 Subject: Ispravljen model za dataset, odradjen model za model dataseta --- backend/api/api/Controllers/AuthController.cs | 2 -- backend/api/api/Controllers/UserController.cs | 3 ++ backend/api/api/Models/Dataset.cs | 43 +++++++----------------- backend/api/api/Models/Model.cs | 47 +++++++++++++++++++++++++++ backend/api/api/Services/DatasetService.cs | 6 ++-- 5 files changed, 64 insertions(+), 37 deletions(-) create mode 100644 backend/api/api/Models/Model.cs diff --git a/backend/api/api/Controllers/AuthController.cs b/backend/api/api/Controllers/AuthController.cs index 6dfe483a..7167d1bf 100644 --- a/backend/api/api/Controllers/AuthController.cs +++ b/backend/api/api/Controllers/AuthController.cs @@ -49,8 +49,6 @@ namespace api.Controllers return Ok(newToken); - - } diff --git a/backend/api/api/Controllers/UserController.cs b/backend/api/api/Controllers/UserController.cs index d41a42e3..58121656 100644 --- a/backend/api/api/Controllers/UserController.cs +++ b/backend/api/api/Controllers/UserController.cs @@ -1,5 +1,6 @@ using api.Models; using api.Services; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using System.Diagnostics; @@ -72,6 +73,7 @@ namespace api.Controllers // PUT api//5 [HttpPut("{id}")] + [Authorize(Roles = "User")] public ActionResult Put(string id, [FromBody] User user) { var existingUser = userService.Get(id); @@ -86,6 +88,7 @@ namespace api.Controllers // DELETE api//5 [HttpDelete("{id}")] + [Authorize(Roles = "User")] public ActionResult Delete(string id) { var user = userService.Get(id); diff --git a/backend/api/api/Models/Dataset.cs b/backend/api/api/Models/Dataset.cs index 0dc87f40..d58b3143 100644 --- a/backend/api/api/Models/Dataset.cs +++ b/backend/api/api/Models/Dataset.cs @@ -1,46 +1,25 @@ -using MongoDB.Bson; +using System; +using MongoDB.Bson; using MongoDB.Bson.Serialization.Attributes; namespace api.Models { - public class Dataset - { + public class Dataset + { internal string uploaderId; [BsonId] [BsonRepresentation(BsonType.ObjectId)]//mongo data type to .net public string _id { get; set; } - [BsonElement("uploaderId")] - public string UploaderId { get; set; } - [BsonElement("name")] public string name { get; set; } - public string description { get; set; } - //datetime - public string dateCreated { get; set; } - - public int[] inputColumns { get; set; } - public int columnToPredict { get; set; } - public bool randomTestSet { get; set; } - public int randomTestSetDistribution { get; set; } - - - public string type { get; set; } - public string encoding { get; set; } - public string optimizer { get; set; } - public string lossFunction { get; set; } - public int inputNeurons { get; set; } - public int hiddenLayerNeurons { get; set; } - public int hiddenLayers { get; set; } - public int batchSize { get; set; } - public string inputLayerActivationFunction { get; set; } - public string hiddenLayerActivationFunction { get; set; } - public string outputLayerActivationFunction { get; set; } - - - [BsonElement("extension")] + public string header { get; set; } + public int fileId { get; set; } public string extension { get; set; } - - + public bool isPublic { get; set; } + public bool accessibleByLink { get; set; } + public string dateCreated { get; set; } + public string lastUpdated { get; set; } } } + diff --git a/backend/api/api/Models/Model.cs b/backend/api/api/Models/Model.cs new file mode 100644 index 00000000..2e2dd5be --- /dev/null +++ b/backend/api/api/Models/Model.cs @@ -0,0 +1,47 @@ +using MongoDB.Bson; +using MongoDB.Bson.Serialization.Attributes; + +namespace api.Models +{ + public class Model + { + internal string uploaderId; + + [BsonId] + [BsonRepresentation(BsonType.ObjectId)]//mongo data type to .net + public string _id { get; set; } + [BsonElement("uploaderId")] + public string UploaderId { get; set; } + + + public string name { get; set; } + public string description { get; set; } + //datetime + public string dateCreated { get; set; } + public string lastUpdated { get; set; } + //proveriti id + public string datasetId { get; set; } + + //Test set settings + public int[] inputColumns { get; set; } + public int columnToPredict { get; set; } + public bool radnomOrder {get;set;} + public bool randomTestSet { get; set; } + public int randomTestSetDistribution { get; set; } + + //Neural net training + public string type { get; set; } + public string encoding { get; set; } + public string optimizer { get; set; } + public string lossFunction { get; set; } + public int inputNeurons { get; set; } + public int hiddenLayerNeurons { get; set; } + public int hiddenLayers { get; set; } + public int batchSize { get; set; } + public string inputLayerActivationFunction { get; set; } + public string hiddenLayerActivationFunction { get; set; } + public string outputLayerActivationFunction { get; set; } + + + } +} diff --git a/backend/api/api/Services/DatasetService.cs b/backend/api/api/Services/DatasetService.cs index 1b6d22be..32136a2e 100644 --- a/backend/api/api/Services/DatasetService.cs +++ b/backend/api/api/Services/DatasetService.cs @@ -23,7 +23,7 @@ namespace api.Services //brisanje odredjenog name-a public void Delete(string uploaderId, string name) { - _dataset.DeleteOne(dataset => (dataset.UploaderId == uploaderId && dataset.name == name)); + _dataset.DeleteOne(dataset => (dataset.uploaderId == uploaderId && dataset.name == name)); } public List GetAllDatesets(string uploaderId) { @@ -31,13 +31,13 @@ namespace api.Services } public Dataset GetOneDataset(string uploaderId, string name) { - return _dataset.Find(dataset => dataset.UploaderId == uploaderId && dataset.name == name).FirstOrDefault(); + return _dataset.Find(dataset => dataset.uploaderId == uploaderId && dataset.name == name).FirstOrDefault(); } //ako je potrebno da se zameni name ili ekstenzija public void Update(string uploaderId, string name, Dataset dataset) { - _dataset.ReplaceOne(dataset => dataset.UploaderId == uploaderId && dataset.name == name, dataset); + _dataset.ReplaceOne(dataset => dataset.uploaderId == uploaderId && dataset.name == name, dataset); } } } -- cgit v1.2.3 From 69f60f492f2d729e74e888f6f43d44e71c814ff4 Mon Sep 17 00:00:00 2001 From: Sonja Galovic Date: Tue, 15 Mar 2022 22:45:57 +0100 Subject: Preuredjivanje funkcionalnosti add-model komponente i dataset-load komponente. --- frontend/src/app/_data/Model.ts | 4 +- .../dataset-load/dataset-load.component.html | 42 +++++----------- .../dataset-load/dataset-load.component.ts | 45 +++-------------- .../app/_pages/add-model/add-model.component.css | 3 -- .../app/_pages/add-model/add-model.component.html | 33 ++++++++++++- .../app/_pages/add-model/add-model.component.ts | 57 ++++++++++++++++++++-- frontend/src/app/_services/models.service.spec.ts | 16 ++++++ frontend/src/app/_services/models.service.ts | 18 +++++++ frontend/src/app/app.component.html | 2 +- frontend/src/styles.css | 8 ++- 10 files changed, 143 insertions(+), 85 deletions(-) create mode 100644 frontend/src/app/_services/models.service.spec.ts create mode 100644 frontend/src/app/_services/models.service.ts diff --git a/frontend/src/app/_data/Model.ts b/frontend/src/app/_data/Model.ts index 1a120ca7..43342fb0 100644 --- a/frontend/src/app/_data/Model.ts +++ b/frontend/src/app/_data/Model.ts @@ -7,8 +7,8 @@ export default class Model { public datasetId?: number, // Test set settings - public inputColumns: number[] = [0], - public columnToPredict: number = 1, + public inputColumns: string[] = [], + public columnToPredict: string = '', public randomOrder: boolean = true, public randomTestSet: boolean = true, public randomTestSetDistribution: number = 0.10, //0.1-0.9 (10% - 90%) diff --git a/frontend/src/app/_elements/dataset-load/dataset-load.component.html b/frontend/src/app/_elements/dataset-load/dataset-load.component.html index 16830e11..2a611a96 100644 --- a/frontend/src/app/_elements/dataset-load/dataset-load.component.html +++ b/frontend/src/app/_elements/dataset-load/dataset-load.component.html @@ -1,5 +1,16 @@
+
+ + +
+ +
+ +
+ +
-
-
-
-

Izaberite ulazne kolone:

-
-
-
- -   - -
-
-
-
-

Izaberite izlaznu kolonu:

-
-
-
- -   - -
-
-
-
-
+
\ No newline at end of file diff --git a/frontend/src/app/_elements/dataset-load/dataset-load.component.ts b/frontend/src/app/_elements/dataset-load/dataset-load.component.ts index c772dc35..d9d045ce 100644 --- a/frontend/src/app/_elements/dataset-load/dataset-load.component.ts +++ b/frontend/src/app/_elements/dataset-load/dataset-load.component.ts @@ -1,5 +1,6 @@ import { Component, ViewChild } from '@angular/core'; import { NgxCsvParser, NgxCSVParserError } from 'ngx-csv-parser'; +import Dataset from 'src/app/_data/Dataset'; @Component({ selector: 'app-dataset-load', @@ -23,7 +24,10 @@ export class DatasetLoadComponent { checkedInputCols: Array = []; checkedOutputCol: string = ''; + dataset: Dataset; + constructor(private ngxCsvParser: NgxCsvParser) { + this.dataset = new Dataset(); } @ViewChild('fileImportInput', { static: false }) fileImportInput: any; @@ -49,49 +53,12 @@ export class DatasetLoadComponent { else this.rowsNumber = this.csvRecords.length; this.colsNumber = this.csvRecords[0].length; + + this.dataset.header = this.csvRecords[0]; } }, (error: NgxCSVParserError) => { console.log('Error', error); }); } - getCheckedInputCols() : Array { - this.checkedInputCols = new Array(); - let checkboxes = document.getElementsByName("cbs"); - - for (let i = 0; i < checkboxes.length; i++) { - let thatCb = checkboxes[i]; - if (thatCb.checked) - this.checkedInputCols.push(thatCb.value); - } - //console.log(this.checkedInputCols); - return this.checkedInputCols; - } - getCheckedOutputCol() : string { - this.checkedOutputCol = ''; - let radiobuttons = document.getElementsByName("rbs"); - - for (let i = 0; i < radiobuttons.length; i++) { - let thatRb = radiobuttons[i]; - if (thatRb.checked) { - this.checkedOutputCol = thatRb.value; - break; - } - } - //console.log(this.checkedOutputCol); - return this.checkedOutputCol; - } - validationInputsOutput() { - if (this.checkedInputCols.length == 0) { - alert("Molimo Vas da izaberete ulaznu kolonu/kolone za mrežu.") - return; - } - for (let i = 0; i < this.checkedInputCols.length; i++) { - if (this.checkedInputCols[i] == this.checkedOutputCol) { - let colName = this.checkedOutputCol; - alert("Izabrali ste istu kolonu (" + colName + ") kao ulaznu i izlaznu iz mreže. Korigujte izbor."); - return; - } - } - } } diff --git a/frontend/src/app/_pages/add-model/add-model.component.css b/frontend/src/app/_pages/add-model/add-model.component.css index 004b9cac..5184733d 100644 --- a/frontend/src/app/_pages/add-model/add-model.component.css +++ b/frontend/src/app/_pages/add-model/add-model.component.css @@ -9,9 +9,6 @@ color: white; } -#wrapper { - background-image: url('/assets/images/add_model_background.jpg'); -} #container { border-radius: 8px; } \ No newline at end of file diff --git a/frontend/src/app/_pages/add-model/add-model.component.html b/frontend/src/app/_pages/add-model/add-model.component.html index 19d69148..5c4411b9 100644 --- a/frontend/src/app/_pages/add-model/add-model.component.html +++ b/frontend/src/app/_pages/add-model/add-model.component.html @@ -32,6 +32,37 @@

Izvor podataka:

+ +
+
+
+

Izaberite ulazne kolone:

+
+
+
+ +   + +
+
+
+
+

Izaberite izlaznu kolonu:

+
+
+
+ +   + +
+
+
+
+

Parametri treniranja:

@@ -109,7 +140,7 @@
- +
diff --git a/frontend/src/app/_pages/add-model/add-model.component.ts b/frontend/src/app/_pages/add-model/add-model.component.ts index 3cb47d61..3c8c32c6 100644 --- a/frontend/src/app/_pages/add-model/add-model.component.ts +++ b/frontend/src/app/_pages/add-model/add-model.component.ts @@ -1,6 +1,9 @@ -import { Component, OnInit } from '@angular/core'; +import { Component, OnInit, ViewChild } from '@angular/core'; import Model from 'src/app/_data/Model'; import { ANNType, Encoding, ActivationFunction, LossFunction, Optimizer } from 'src/app/_data/Model'; +import { DatasetLoadComponent } from 'src/app/_elements/dataset-load/dataset-load.component'; +import { ModelsService } from 'src/app/_services/models.service'; + @Component({ selector: 'app-add-model', @@ -9,7 +12,9 @@ import { ANNType, Encoding, ActivationFunction, LossFunction, Optimizer } from ' }) export class AddModelComponent implements OnInit { - newModel: Model + @ViewChild(DatasetLoadComponent) datasetLoadComponent?: DatasetLoadComponent; + + newModel: Model; ANNType = ANNType; Encoding = Encoding; @@ -18,7 +23,7 @@ export class AddModelComponent implements OnInit { Optimizer = Optimizer; Object = Object; - constructor() { + constructor(private models: ModelsService) { this.newModel = new Model(); } @@ -26,7 +31,51 @@ export class AddModelComponent implements OnInit { } addModel() { - //TODO + this.getCheckedInputCols(); + this.getCheckedOutputCol(); + if (this.validationInputsOutput()) + this.models.addModel(this.newModel).subscribe((response) => { + console.log(response); + }); + } + + getCheckedInputCols() { + this.newModel.inputColumns = []; + let checkboxes = document.getElementsByName("cbs"); + + for (let i = 0; i < checkboxes.length; i++) { + let thatCb = checkboxes[i]; + if (thatCb.checked) + this.newModel.inputColumns.push(thatCb.value); + } + //console.log(this.checkedInputCols); + } + getCheckedOutputCol() { + this.newModel.columnToPredict = ''; + let radiobuttons = document.getElementsByName("rbs"); + + for (let i = 0; i < radiobuttons.length; i++) { + let thatRb = radiobuttons[i]; + if (thatRb.checked) { + this.newModel.columnToPredict = thatRb.value; + break; + } + } + //console.log(this.checkedOutputCol); + } + validationInputsOutput() : boolean { + if (this.newModel.inputColumns.length == 0) { + alert("Molimo Vas da izaberete ulaznu kolonu/kolone za mrežu.") + return false; + } + for (let i = 0; i < this.newModel.inputColumns.length; i++) { + if (this.newModel.inputColumns[i] == this.newModel.columnToPredict) { + let colName = this.newModel.columnToPredict; + alert("Izabrali ste istu kolonu (" + colName + ") kao ulaznu i izlaznu iz mreže. Korigujte izbor."); + return false; + } + } + return true; } } diff --git a/frontend/src/app/_services/models.service.spec.ts b/frontend/src/app/_services/models.service.spec.ts new file mode 100644 index 00000000..b5b25752 --- /dev/null +++ b/frontend/src/app/_services/models.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { ModelsService } from './models.service'; + +describe('ModelsService', () => { + let service: ModelsService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(ModelsService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/frontend/src/app/_services/models.service.ts b/frontend/src/app/_services/models.service.ts new file mode 100644 index 00000000..bd91a811 --- /dev/null +++ b/frontend/src/app/_services/models.service.ts @@ -0,0 +1,18 @@ +import { HttpClient } from '@angular/common/http'; +import { Injectable } from '@angular/core'; +import Model from '../_data/Model'; +import { AuthService } from './auth.service'; +import { API_SETTINGS } from 'src/config'; + + +@Injectable({ + providedIn: 'root' +}) +export class ModelsService { + + constructor(private http: HttpClient, private authService: AuthService) { } + + addModel(model: Model) { + return this.http.post(`${API_SETTINGS.apiURL}/model/sendModel`, model, { headers: this.authService.authHeader(), responseType: 'text' }); + } +} diff --git a/frontend/src/app/app.component.html b/frontend/src/app/app.component.html index 7f2d4225..35e5adb1 100644 --- a/frontend/src/app/app.component.html +++ b/frontend/src/app/app.component.html @@ -1,4 +1,4 @@ -
+
\ No newline at end of file diff --git a/frontend/src/styles.css b/frontend/src/styles.css index b671a2a7..d37ab6f1 100644 --- a/frontend/src/styles.css +++ b/frontend/src/styles.css @@ -1,5 +1,3 @@ -/* You can add global styles to this file, and also import other style files - -html, body { height: 100%; } -body { margin: 0; font-family: Roboto, "Helvetica Neue", sans-serif; } -*/ +body { + background-image: url('/assets/images/add_model_background.jpg'); +} \ No newline at end of file -- cgit v1.2.3 From 5113a89e636e40bf745a30b52794cf4e43404ae7 Mon Sep 17 00:00:00 2001 From: Ivan Ljubisavljevic Date: Tue, 15 Mar 2022 23:30:15 +0100 Subject: Ispravljen model Dataset-a, odradjen crud modela. Napravljena tabela za modele i izmenjena za dataset --- backend/api/api/Controllers/DatasetController.cs | 4 +- backend/api/api/Controllers/ModelController.cs | 74 +++++++++++++++++++++- .../api/Interfaces/IUserStoreDatabaseSettings.cs | 1 + backend/api/api/Models/Dataset.cs | 2 +- backend/api/api/Program.cs | 2 + backend/api/api/Services/IModelService.cs | 15 +++++ backend/api/api/Services/ModelService.cs | 47 ++++++++++++++ backend/api/api/appsettings.json | 6 +- 8 files changed, 144 insertions(+), 7 deletions(-) create mode 100644 backend/api/api/Services/IModelService.cs create mode 100644 backend/api/api/Services/ModelService.cs diff --git a/backend/api/api/Controllers/DatasetController.cs b/backend/api/api/Controllers/DatasetController.cs index fcebc4b0..8ad92149 100644 --- a/backend/api/api/Controllers/DatasetController.cs +++ b/backend/api/api/Controllers/DatasetController.cs @@ -41,9 +41,9 @@ namespace api.Controllers [HttpPost("post")] public ActionResult Post([FromBody] Dataset dataset) { - var existingUser = _datasetService.GetOneDataset(dataset.uploaderId,dataset.name); + var existingDataset = _datasetService.GetOneDataset(dataset.uploaderId,dataset.name); - if (existingUser != null) + if (existingDataset != null) return NotFound($"Dateset with name = {dataset.name} exisits"); else { diff --git a/backend/api/api/Controllers/ModelController.cs b/backend/api/api/Controllers/ModelController.cs index 5e22c61d..ac45f45b 100644 --- a/backend/api/api/Controllers/ModelController.cs +++ b/backend/api/api/Controllers/ModelController.cs @@ -1,4 +1,5 @@ -using api.Services; +using api.Models; +using api.Services; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; @@ -11,10 +12,13 @@ namespace api.Controllers { private IMlConnectionService _mlService; + private readonly IModelService _modelService; + - public ModelController(IMlConnectionService mlService) + public ModelController(IMlConnectionService mlService, IModelService modelService) { _mlService = mlService; + _modelService = modelService; } [HttpPost("sendModel")] @@ -25,5 +29,71 @@ namespace api.Controllers return Ok(result); } + //id korisnika + // GET: api//{id}/datasets + [HttpGet("{id}/models")] + public ActionResult> Get(string id) + { + return _modelService.GetAllModels(id); + } + + //id korisnika, name modela + // GET api//{id}/{name} + [HttpGet("{id}/{name}")] + public ActionResult Get(string id, string name) + { + var model = _modelService.GetOneModel(id, name); + + if (model == null) + return NotFound($"Model with name = {name} or user with id = {id} not found"); + + return model; + } + + // POST api//post + [HttpPost("post")] + public ActionResult Post([FromBody] Model model) + { + var existingModel = _modelService.GetOneModel(model.uploaderId, model.name); + + if (existingModel != null) + return NotFound($"Model with name = {model.name} exisits"); + else + { + _modelService.Create(model); + + return CreatedAtAction(nameof(Get), new { id = model._id }, model); + } + } + + // PUT api//{id}/{name} + [HttpPut("{id}/{name}")] + public ActionResult Put(string id, string name, [FromBody] Model model) + { + var existingModel = _modelService.GetOneModel(id, name); + + //ne mora da se proverava + if (existingModel == null) + return NotFound($"Model with name = {name} or user with id = {id} not found"); + + _modelService.Update(id, name, model); + return NoContent(); + } + + // DELETE api//5 + [HttpDelete("{id}")] + public ActionResult Delete(string id, string name) + { + var model = _modelService.GetOneModel(id, name); + + if (model == null) + return NotFound($"Model with name = {name} or user with id = {id} not found"); + + _modelService.Delete(model.uploaderId, model.name); + + return Ok($"Model with name = {name} deleted"); + + } + } } diff --git a/backend/api/api/Interfaces/IUserStoreDatabaseSettings.cs b/backend/api/api/Interfaces/IUserStoreDatabaseSettings.cs index 8d2a175f..46ece53c 100644 --- a/backend/api/api/Interfaces/IUserStoreDatabaseSettings.cs +++ b/backend/api/api/Interfaces/IUserStoreDatabaseSettings.cs @@ -6,5 +6,6 @@ string DatabaseName { get; set; } string CollectionName { get; set; } string DatasetCollectionName { get; set; } + string ModelCollectionName { get; } } } diff --git a/backend/api/api/Models/Dataset.cs b/backend/api/api/Models/Dataset.cs index d58b3143..de88fd4f 100644 --- a/backend/api/api/Models/Dataset.cs +++ b/backend/api/api/Models/Dataset.cs @@ -13,7 +13,7 @@ namespace api.Models public string _id { get; set; } public string name { get; set; } public string description { get; set; } - public string header { get; set; } + public string[] header { get; set; } public int fileId { get; set; } public string extension { get; set; } public bool isPublic { get; set; } diff --git a/backend/api/api/Program.cs b/backend/api/api/Program.cs index 702ef259..24cc5cfe 100644 --- a/backend/api/api/Program.cs +++ b/backend/api/api/Program.cs @@ -29,6 +29,8 @@ builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); +builder.Services.AddScoped(); + //Add Authentication builder.Services.AddAuthentication( diff --git a/backend/api/api/Services/IModelService.cs b/backend/api/api/Services/IModelService.cs new file mode 100644 index 00000000..988f3ab9 --- /dev/null +++ b/backend/api/api/Services/IModelService.cs @@ -0,0 +1,15 @@ +using System; +using api.Models; + +namespace api.Services +{ + public interface IModelService + { + Model GetOneModel(string uploaderId, string name); + List GetAllModels(string uploaderId); + Model Create(Model model); + void Update(string uploaderId, string name, Model model); + void Delete(string uploaderId, string name); + } +} + diff --git a/backend/api/api/Services/ModelService.cs b/backend/api/api/Services/ModelService.cs new file mode 100644 index 00000000..97402d90 --- /dev/null +++ b/backend/api/api/Services/ModelService.cs @@ -0,0 +1,47 @@ +using System; +using api.Interfaces; +using api.Models; +using MongoDB.Driver; + +namespace api.Services +{ + public class ModelService : IModelService + { + + private readonly IMongoCollection _model; + + public ModelService(IUserStoreDatabaseSettings settings, IMongoClient mongoClient) + { + var database = mongoClient.GetDatabase(settings.DatabaseName); + _model = database.GetCollection(settings.ModelCollectionName); + } + + public Model Create(Model model) + { + _model.InsertOne(model); + return model; + } + + public void Delete(string uploaderId, string name) + { + _model.DeleteOne(model => (model.uploaderId == uploaderId && model.name == name)); + } + + public List GetAllModels(string uploaderId) + { + return _model.Find(model => model.uploaderId == uploaderId).ToList(); + } + + public Model GetOneModel(string uploaderId, string name) + { + return _model.Find(model => model.uploaderId == uploaderId && model.name == name).FirstOrDefault(); + } + + public void Update(string uploaderId, string name, Model model) + { + _model.ReplaceOne(model => model.uploaderId == uploaderId && model.name == name, model); + } + + } +} + diff --git a/backend/api/api/appsettings.json b/backend/api/api/appsettings.json index 9b4f00a3..63030c15 100644 --- a/backend/api/api/appsettings.json +++ b/backend/api/api/appsettings.json @@ -14,11 +14,13 @@ "ConnectionString": "mongodb://127.0.0.1:27017/", "DatabaseName": "si_project", "CollectionName": "User", - "DatasetCollectionName" : "Dataset" + "DatasetCollectionName" : "Dataset", + "ModelCollectionName" : "Model" */ "ConnectionString": "mongodb+srv://si_user:si_user@sidatabase.twtfm.mongodb.net/myFirstDatabase?retryWrites=true&w=majority", "DatabaseName": "si_db", "CollectionName": "users", - "DatasetCollectionName": "Dataset" + "DatasetCollectionName": "Dataset", + "ModelCollectionName": "Model" } } -- cgit v1.2.3 From f0e05dade823673fbf6568f50f64b93859000f32 Mon Sep 17 00:00:00 2001 From: Sonja Galovic Date: Wed, 16 Mar 2022 00:06:21 +0100 Subject: Promenjena veza add-model strane i dataset-load komponente. Dodat models.service - slanje dataseta i modela backendu. --- .../_elements/dataset-load/dataset-load.component.ts | 9 +++++---- .../app/_modals/login-modal/login-modal.component.ts | 17 ++++++++++------- .../src/app/_pages/add-model/add-model.component.html | 6 +++--- .../src/app/_pages/add-model/add-model.component.ts | 4 ++++ frontend/src/app/_pages/home/home.component.html | 2 +- frontend/src/app/_services/auth-guard.service.ts | 2 +- frontend/src/app/_services/models.service.ts | 4 ++++ 7 files changed, 28 insertions(+), 16 deletions(-) diff --git a/frontend/src/app/_elements/dataset-load/dataset-load.component.ts b/frontend/src/app/_elements/dataset-load/dataset-load.component.ts index d9d045ce..8465c3d6 100644 --- a/frontend/src/app/_elements/dataset-load/dataset-load.component.ts +++ b/frontend/src/app/_elements/dataset-load/dataset-load.component.ts @@ -1,4 +1,4 @@ -import { Component, ViewChild } from '@angular/core'; +import { Component, EventEmitter, Output, ViewChild } from '@angular/core'; import { NgxCsvParser, NgxCSVParserError } from 'ngx-csv-parser'; import Dataset from 'src/app/_data/Dataset'; @@ -9,6 +9,8 @@ import Dataset from 'src/app/_data/Dataset'; }) export class DatasetLoadComponent { + @Output() loaded = new EventEmitter(); + delimiter: string = ""; delimiterOptions: Array = [",", ";", "\t", "razmak", "|"]; //podrazumevano "," @@ -21,9 +23,6 @@ export class DatasetLoadComponent { rowsNumber: number = 0; colsNumber: number = 0; - checkedInputCols: Array = []; - checkedOutputCol: string = ''; - dataset: Dataset; constructor(private ngxCsvParser: NgxCsvParser) { @@ -55,6 +54,8 @@ export class DatasetLoadComponent { this.colsNumber = this.csvRecords[0].length; this.dataset.header = this.csvRecords[0]; + + this.loaded.emit("loaded"); } }, (error: NgxCSVParserError) => { console.log('Error', error); diff --git a/frontend/src/app/_modals/login-modal/login-modal.component.ts b/frontend/src/app/_modals/login-modal/login-modal.component.ts index 87686f10..d17d7017 100644 --- a/frontend/src/app/_modals/login-modal/login-modal.component.ts +++ b/frontend/src/app/_modals/login-modal/login-modal.component.ts @@ -25,13 +25,16 @@ export class LoginModalComponent implements OnInit { } doLogin() { - this.authService.login(this.username, this.password).subscribe((response) => { //ako nisu ok podaci, ne ide hide nego mora opet da ukucava!!!!podesi - console.log(response); - this.authService.authenticate(response); - (document.getElementById('closeButton')).click(); - }, error => { - console.warn(error); //NETACNI PODACI - }); + if (this.username.length > 0 && this.password.length > 0) { + this.authService.login(this.username, this.password).subscribe((response) => { //ako nisu ok podaci, ne ide hide nego mora opet da ukucava!!!!podesi + console.log(response); + this.authService.authenticate(response); + (document.getElementById('closeButton')).click(); + }, error => { + console.warn(error); //NETACNI PODACI + }); + } + } resetData() { this.username = ''; diff --git a/frontend/src/app/_pages/add-model/add-model.component.html b/frontend/src/app/_pages/add-model/add-model.component.html index 5c4411b9..f5270127 100644 --- a/frontend/src/app/_pages/add-model/add-model.component.html +++ b/frontend/src/app/_pages/add-model/add-model.component.html @@ -30,11 +30,11 @@

Izvor podataka:

- +
-
-
+
+

Izaberite ulazne kolone:

diff --git a/frontend/src/app/_pages/add-model/add-model.component.ts b/frontend/src/app/_pages/add-model/add-model.component.ts index 3c8c32c6..c18ad324 100644 --- a/frontend/src/app/_pages/add-model/add-model.component.ts +++ b/frontend/src/app/_pages/add-model/add-model.component.ts @@ -13,6 +13,7 @@ import { ModelsService } from 'src/app/_services/models.service'; export class AddModelComponent implements OnInit { @ViewChild(DatasetLoadComponent) datasetLoadComponent?: DatasetLoadComponent; + datasetLoaded: boolean = false; newModel: Model; @@ -31,6 +32,9 @@ export class AddModelComponent implements OnInit { } addModel() { + if (this.datasetLoadComponent) + this.models.addDataset(this.datasetLoadComponent?.dataset); + this.getCheckedInputCols(); this.getCheckedOutputCol(); if (this.validationInputsOutput()) diff --git a/frontend/src/app/_pages/home/home.component.html b/frontend/src/app/_pages/home/home.component.html index 374cb324..7245f602 100644 --- a/frontend/src/app/_pages/home/home.component.html +++ b/frontend/src/app/_pages/home/home.component.html @@ -1,4 +1,4 @@ -
+

Započnite sa treniranjem!

diff --git a/frontend/src/app/_services/auth-guard.service.ts b/frontend/src/app/_services/auth-guard.service.ts index b6d3678d..057996e0 100644 --- a/frontend/src/app/_services/auth-guard.service.ts +++ b/frontend/src/app/_services/auth-guard.service.ts @@ -15,7 +15,7 @@ export class AuthGuardService implements CanActivate { if (this.auth.isAuthenticated()) { return true; } - this.router.navigate(['login']); + this.router.navigate(['']); return false; } } diff --git a/frontend/src/app/_services/models.service.ts b/frontend/src/app/_services/models.service.ts index bd91a811..f85ca44e 100644 --- a/frontend/src/app/_services/models.service.ts +++ b/frontend/src/app/_services/models.service.ts @@ -3,6 +3,7 @@ import { Injectable } from '@angular/core'; import Model from '../_data/Model'; import { AuthService } from './auth.service'; import { API_SETTINGS } from 'src/config'; +import Dataset from '../_data/Dataset'; @Injectable({ @@ -15,4 +16,7 @@ export class ModelsService { addModel(model: Model) { return this.http.post(`${API_SETTINGS.apiURL}/model/sendModel`, model, { headers: this.authService.authHeader(), responseType: 'text' }); } + addDataset(dataset: Dataset) { + return this.http.post(`${API_SETTINGS.apiURL}/model/uploadDataset`, dataset, { headers: this.authService.authHeader(), responseType: 'text' }); + } } -- cgit v1.2.3 From cc865e07387e2b61b0753143848cf9f4846c2bbe Mon Sep 17 00:00:00 2001 From: Ognjen Cirkovic Date: Wed, 16 Mar 2022 00:13:51 +0100 Subject: Jwt token istice za 20 min. --- backend/api/api/Models/JwtToken.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/api/api/Models/JwtToken.cs b/backend/api/api/Models/JwtToken.cs index 7cbd6f54..a98d1967 100644 --- a/backend/api/api/Models/JwtToken.cs +++ b/backend/api/api/Models/JwtToken.cs @@ -23,7 +23,7 @@ namespace api.Models { Subject = new ClaimsIdentity(new[] { new Claim("name", user.UserName), new Claim("role", "User")}), - Expires = DateTime.UtcNow.AddDays(1), + Expires = DateTime.UtcNow.AddMinutes(20), SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature) }; var token = tokenHandler.CreateToken(tokenDescriptor); -- cgit v1.2.3 From ac510357b82b54550dc2e07e14195b6f70043e29 Mon Sep 17 00:00:00 2001 From: Ivan Ljubisavljevic Date: Wed, 16 Mar 2022 00:16:37 +0100 Subject: Više se ne pristupa Modelu i Datasetu uz pomoć id-a ulogovanog korisnika nego preko username-a MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/api/api/Controllers/DatasetController.cs | 14 +++---- backend/api/api/Controllers/ModelController.cs | 45 +++++++++++------------ backend/api/api/Data/UserStoreDatabaseSettings.cs | 1 + backend/api/api/Models/Dataset.cs | 2 +- backend/api/api/Models/Model.cs | 4 +- backend/api/api/Services/DatasetService.cs | 18 +++++---- backend/api/api/Services/IDatasetService.cs | 8 ++-- backend/api/api/Services/IModelService.cs | 8 ++-- backend/api/api/Services/ModelService.cs | 16 ++++---- 9 files changed, 58 insertions(+), 58 deletions(-) diff --git a/backend/api/api/Controllers/DatasetController.cs b/backend/api/api/Controllers/DatasetController.cs index 8ad92149..babdbe9a 100644 --- a/backend/api/api/Controllers/DatasetController.cs +++ b/backend/api/api/Controllers/DatasetController.cs @@ -41,7 +41,7 @@ namespace api.Controllers [HttpPost("post")] public ActionResult Post([FromBody] Dataset dataset) { - var existingDataset = _datasetService.GetOneDataset(dataset.uploaderId,dataset.name); + var existingDataset = _datasetService.GetOneDataset(dataset.username, dataset.name); if (existingDataset != null) return NotFound($"Dateset with name = {dataset.name} exisits"); @@ -67,16 +67,16 @@ namespace api.Controllers return NoContent(); } - // DELETE api//5 - [HttpDelete("{id}")] - public ActionResult Delete(string id, string name) + // DELETE api//username + [HttpDelete("{username}")] + public ActionResult Delete(string username, string name) { - var dataset = _datasetService.GetOneDataset(id, name); + var dataset = _datasetService.GetOneDataset(username, name); if (dataset == null) - return NotFound($"Dataset with name = {name} or user with id = {id} not found"); + return NotFound($"Dataset with name = {name} or user with username = {username} not found"); - _datasetService.Delete(dataset.uploaderId,dataset.name); + _datasetService.Delete(dataset.username, dataset.name); return Ok($"Dataset with name = {name} deleted"); diff --git a/backend/api/api/Controllers/ModelController.cs b/backend/api/api/Controllers/ModelController.cs index ac45f45b..dde44472 100644 --- a/backend/api/api/Controllers/ModelController.cs +++ b/backend/api/api/Controllers/ModelController.cs @@ -29,23 +29,22 @@ namespace api.Controllers return Ok(result); } - //id korisnika - // GET: api//{id}/datasets - [HttpGet("{id}/models")] - public ActionResult> Get(string id) + // GET: api//{username}/models + [HttpGet("{username}/models")] + public ActionResult> Get(string username) { - return _modelService.GetAllModels(id); + return _modelService.GetAllModels(username); } //id korisnika, name modela - // GET api//{id}/{name} - [HttpGet("{id}/{name}")] - public ActionResult Get(string id, string name) + // GET api//{username}/{name} + [HttpGet("{username}/{name}")] + public ActionResult Get(string username, string name) { - var model = _modelService.GetOneModel(id, name); + var model = _modelService.GetOneModel(username, name); if (model == null) - return NotFound($"Model with name = {name} or user with id = {id} not found"); + return NotFound($"Model with name = {name} or user with username = {username} not found"); return model; } @@ -54,7 +53,7 @@ namespace api.Controllers [HttpPost("post")] public ActionResult Post([FromBody] Model model) { - var existingModel = _modelService.GetOneModel(model.uploaderId, model.name); + var existingModel = _modelService.GetOneModel(model.username, model.name); if (existingModel != null) return NotFound($"Model with name = {model.name} exisits"); @@ -66,30 +65,30 @@ namespace api.Controllers } } - // PUT api//{id}/{name} - [HttpPut("{id}/{name}")] - public ActionResult Put(string id, string name, [FromBody] Model model) + // PUT api//{username}/{name} + [HttpPut("{username}/{name}")] + public ActionResult Put(string username, string name, [FromBody] Model model) { - var existingModel = _modelService.GetOneModel(id, name); + var existingModel = _modelService.GetOneModel(username, name); //ne mora da se proverava if (existingModel == null) - return NotFound($"Model with name = {name} or user with id = {id} not found"); + return NotFound($"Model with name = {name} or user with username = {username} not found"); - _modelService.Update(id, name, model); + _modelService.Update(username, name, model); return NoContent(); } - // DELETE api//5 - [HttpDelete("{id}")] - public ActionResult Delete(string id, string name) + // DELETE api//username + [HttpDelete("{username}")] + public ActionResult Delete(string username, string name) { - var model = _modelService.GetOneModel(id, name); + var model = _modelService.GetOneModel(username, name); if (model == null) - return NotFound($"Model with name = {name} or user with id = {id} not found"); + return NotFound($"Model with name = {name} or user with username = {username} not found"); - _modelService.Delete(model.uploaderId, model.name); + _modelService.Delete(model.username, model.name); return Ok($"Model with name = {name} deleted"); diff --git a/backend/api/api/Data/UserStoreDatabaseSettings.cs b/backend/api/api/Data/UserStoreDatabaseSettings.cs index 0d923fc7..d2391c71 100644 --- a/backend/api/api/Data/UserStoreDatabaseSettings.cs +++ b/backend/api/api/Data/UserStoreDatabaseSettings.cs @@ -10,5 +10,6 @@ namespace api.Data public string DatabaseName { get; set; } = String.Empty; public string CollectionName { get; set; } = String.Empty; public string DatasetCollectionName { get; set; } = String.Empty; + public string ModelCollectionName { get; set; } = String.Empty; } } diff --git a/backend/api/api/Models/Dataset.cs b/backend/api/api/Models/Dataset.cs index de88fd4f..6cb0b1e9 100644 --- a/backend/api/api/Models/Dataset.cs +++ b/backend/api/api/Models/Dataset.cs @@ -6,7 +6,7 @@ namespace api.Models { public class Dataset { - internal string uploaderId; + public string username; [BsonId] [BsonRepresentation(BsonType.ObjectId)]//mongo data type to .net diff --git a/backend/api/api/Models/Model.cs b/backend/api/api/Models/Model.cs index 2e2dd5be..7b22ded8 100644 --- a/backend/api/api/Models/Model.cs +++ b/backend/api/api/Models/Model.cs @@ -5,13 +5,11 @@ namespace api.Models { public class Model { - internal string uploaderId; [BsonId] [BsonRepresentation(BsonType.ObjectId)]//mongo data type to .net public string _id { get; set; } - [BsonElement("uploaderId")] - public string UploaderId { get; set; } + public string username { get; set; } public string name { get; set; } diff --git a/backend/api/api/Services/DatasetService.cs b/backend/api/api/Services/DatasetService.cs index 32136a2e..80c31758 100644 --- a/backend/api/api/Services/DatasetService.cs +++ b/backend/api/api/Services/DatasetService.cs @@ -21,23 +21,25 @@ namespace api.Services } //brisanje odredjenog name-a - public void Delete(string uploaderId, string name) + public void Delete(string username, string name) { - _dataset.DeleteOne(dataset => (dataset.uploaderId == uploaderId && dataset.name == name)); + _dataset.DeleteOne(dataset => (dataset.username == username && dataset.name == name)); } - public List GetAllDatesets(string uploaderId) + + public List GetAllDatesets(string username) { - return _dataset.Find(dataset => dataset.uploaderId == uploaderId).ToList(); + return _dataset.Find(dataset => dataset.username == username).ToList(); } - public Dataset GetOneDataset(string uploaderId, string name) + + public Dataset GetOneDataset(string username, string name) { - return _dataset.Find(dataset => dataset.uploaderId == uploaderId && dataset.name == name).FirstOrDefault(); + return _dataset.Find(dataset => dataset.username == username && dataset.name == name).FirstOrDefault(); } //ako je potrebno da se zameni name ili ekstenzija - public void Update(string uploaderId, string name, Dataset dataset) + public void Update(string username, string name, Dataset dataset) { - _dataset.ReplaceOne(dataset => dataset.uploaderId == uploaderId && dataset.name == name, dataset); + _dataset.ReplaceOne(dataset => dataset.username == username && dataset.name == name, dataset); } } } diff --git a/backend/api/api/Services/IDatasetService.cs b/backend/api/api/Services/IDatasetService.cs index 9cf8c3cb..49013e29 100644 --- a/backend/api/api/Services/IDatasetService.cs +++ b/backend/api/api/Services/IDatasetService.cs @@ -5,10 +5,10 @@ namespace api.Services { public interface IDatasetService { - Dataset GetOneDataset(string uploaderId, string name); - List GetAllDatesets(string uploaderId); + Dataset GetOneDataset(string username, string name); + List GetAllDatesets(string username); Dataset Create(Dataset dataset); - void Update(string uploaderId, string name, Dataset dataset); - void Delete(string uploaderId, string name); + void Update(string username, string name, Dataset dataset); + void Delete(string username, string name); } } diff --git a/backend/api/api/Services/IModelService.cs b/backend/api/api/Services/IModelService.cs index 988f3ab9..149afd4a 100644 --- a/backend/api/api/Services/IModelService.cs +++ b/backend/api/api/Services/IModelService.cs @@ -5,11 +5,11 @@ namespace api.Services { public interface IModelService { - Model GetOneModel(string uploaderId, string name); - List GetAllModels(string uploaderId); + Model GetOneModel(string username, string name); + List GetAllModels(string username); Model Create(Model model); - void Update(string uploaderId, string name, Model model); - void Delete(string uploaderId, string name); + void Update(string username, string name, Model model); + void Delete(string username, string name); } } diff --git a/backend/api/api/Services/ModelService.cs b/backend/api/api/Services/ModelService.cs index 97402d90..33dea30e 100644 --- a/backend/api/api/Services/ModelService.cs +++ b/backend/api/api/Services/ModelService.cs @@ -22,24 +22,24 @@ namespace api.Services return model; } - public void Delete(string uploaderId, string name) + public void Delete(string username, string name) { - _model.DeleteOne(model => (model.uploaderId == uploaderId && model.name == name)); + _model.DeleteOne(model => (model.username == username && model.name == name)); } - public List GetAllModels(string uploaderId) + public List GetAllModels(string username) { - return _model.Find(model => model.uploaderId == uploaderId).ToList(); + return _model.Find(model => model.username == username).ToList(); } - public Model GetOneModel(string uploaderId, string name) + public Model GetOneModel(string username, string name) { - return _model.Find(model => model.uploaderId == uploaderId && model.name == name).FirstOrDefault(); + return _model.Find(model => model.username == username && model.name == name).FirstOrDefault(); } - public void Update(string uploaderId, string name, Model model) + public void Update(string username, string name, Model model) { - _model.ReplaceOne(model => model.uploaderId == uploaderId && model.name == name, model); + _model.ReplaceOne(model => model.username == username && model.name == name, model); } } -- cgit v1.2.3 From 5eddd6dde8a348ef767f2e270fe2c0fd001033e0 Mon Sep 17 00:00:00 2001 From: Ognjen Cirkovic Date: Wed, 16 Mar 2022 13:10:54 +0100 Subject: Kada se uploaduje file podaci se upisuju u bazu. --- .../api/api/Controllers/FileUploadController.cs | 11 +++++++-- backend/api/api/Data/UserStoreDatabaseSettings.cs | 1 + .../api/Interfaces/IUserStoreDatabaseSettings.cs | 1 + backend/api/api/Models/FileModel.cs | 14 +++++++++++ backend/api/api/Program.cs | 1 + backend/api/api/Services/FileService.cs | 27 ++++++++++++++++++++++ backend/api/api/Services/IFileService.cs | 9 ++++++++ backend/api/api/appsettings.json | 17 +++++++------- 8 files changed, 71 insertions(+), 10 deletions(-) create mode 100644 backend/api/api/Models/FileModel.cs create mode 100644 backend/api/api/Services/FileService.cs create mode 100644 backend/api/api/Services/IFileService.cs diff --git a/backend/api/api/Controllers/FileUploadController.cs b/backend/api/api/Controllers/FileUploadController.cs index 68ab814d..3869a6fe 100644 --- a/backend/api/api/Controllers/FileUploadController.cs +++ b/backend/api/api/Controllers/FileUploadController.cs @@ -1,5 +1,6 @@ using System.Net.Http.Headers; using api.Models; +using api.Services; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.Net.Http.Headers; @@ -12,10 +13,12 @@ namespace api.Controllers private string[] permittedExtensions = { ".csv" }; private readonly IConfiguration _configuration; private JwtToken _token; - public FileUploadController(IConfiguration configuration) + private IFileService _fileservice; + public FileUploadController(IConfiguration configuration,IFileService fileService) { _configuration = configuration; _token = new JwtToken(configuration); + _fileservice = fileService; } @@ -68,8 +71,12 @@ namespace api.Controllers { await file.CopyToAsync(stream); } + FileModel fileModel= new FileModel(); + fileModel.path=fullPath; + fileModel.username=username; + fileModel=_fileservice.Create(fileModel); - return Ok(fullPath); + return Ok(fileModel); } } } diff --git a/backend/api/api/Data/UserStoreDatabaseSettings.cs b/backend/api/api/Data/UserStoreDatabaseSettings.cs index d2391c71..6416ab05 100644 --- a/backend/api/api/Data/UserStoreDatabaseSettings.cs +++ b/backend/api/api/Data/UserStoreDatabaseSettings.cs @@ -11,5 +11,6 @@ namespace api.Data public string CollectionName { get; set; } = String.Empty; public string DatasetCollectionName { get; set; } = String.Empty; public string ModelCollectionName { get; set; } = String.Empty; + public string FilesCollectionName { get; set; } = String.Empty; } } diff --git a/backend/api/api/Interfaces/IUserStoreDatabaseSettings.cs b/backend/api/api/Interfaces/IUserStoreDatabaseSettings.cs index 46ece53c..82312649 100644 --- a/backend/api/api/Interfaces/IUserStoreDatabaseSettings.cs +++ b/backend/api/api/Interfaces/IUserStoreDatabaseSettings.cs @@ -7,5 +7,6 @@ string CollectionName { get; set; } string DatasetCollectionName { get; set; } string ModelCollectionName { get; } + string FilesCollectionName { get; set; } } } diff --git a/backend/api/api/Models/FileModel.cs b/backend/api/api/Models/FileModel.cs new file mode 100644 index 00000000..9e7c8b5d --- /dev/null +++ b/backend/api/api/Models/FileModel.cs @@ -0,0 +1,14 @@ +using MongoDB.Bson; +using MongoDB.Bson.Serialization.Attributes; + +namespace api.Models +{ + public class FileModel + { + [BsonId] + [BsonRepresentation(BsonType.ObjectId)] + public string _id { get; set; } + public string username { get; set; } + public string path { get; set; } + } +} diff --git a/backend/api/api/Program.cs b/backend/api/api/Program.cs index 24cc5cfe..f3287b4c 100644 --- a/backend/api/api/Program.cs +++ b/backend/api/api/Program.cs @@ -30,6 +30,7 @@ builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); +builder.Services.AddScoped(); //Add Authentication diff --git a/backend/api/api/Services/FileService.cs b/backend/api/api/Services/FileService.cs new file mode 100644 index 00000000..29520387 --- /dev/null +++ b/backend/api/api/Services/FileService.cs @@ -0,0 +1,27 @@ +using api.Interfaces; +using api.Models; +using MongoDB.Driver; + +namespace api.Services +{ + public class FileService : IFileService + { + + private readonly IMongoCollection _file; + + public FileService(IUserStoreDatabaseSettings settings, IMongoClient mongoClient) + { + var database = mongoClient.GetDatabase(settings.DatabaseName); + _file = database.GetCollection(settings.FilesCollectionName); + } + + public FileModel Create(FileModel file) + { + if (file == null) + return null; + _file.InsertOne(file); + return file; + + } + } +} diff --git a/backend/api/api/Services/IFileService.cs b/backend/api/api/Services/IFileService.cs new file mode 100644 index 00000000..14d843ca --- /dev/null +++ b/backend/api/api/Services/IFileService.cs @@ -0,0 +1,9 @@ +using api.Models; + +namespace api.Services +{ + public interface IFileService + { + FileModel Create(FileModel file); + } +} \ No newline at end of file diff --git a/backend/api/api/appsettings.json b/backend/api/api/appsettings.json index 63030c15..86363075 100644 --- a/backend/api/api/appsettings.json +++ b/backend/api/api/appsettings.json @@ -9,18 +9,19 @@ } }, "AllowedHosts": "*", - "UserStoreDatabaseSettings": { - /* LocalHost + "UserStoreDatabaseSettings": { + /* LocalHost "ConnectionString": "mongodb://127.0.0.1:27017/", "DatabaseName": "si_project", "CollectionName": "User", "DatasetCollectionName" : "Dataset", "ModelCollectionName" : "Model" */ - "ConnectionString": "mongodb+srv://si_user:si_user@sidatabase.twtfm.mongodb.net/myFirstDatabase?retryWrites=true&w=majority", - "DatabaseName": "si_db", - "CollectionName": "users", - "DatasetCollectionName": "Dataset", - "ModelCollectionName": "Model" - } + "ConnectionString": "mongodb+srv://si_user:si_user@sidatabase.twtfm.mongodb.net/myFirstDatabase?retryWrites=true&w=majority", + "DatabaseName": "si_db", + "CollectionName": "users", + "DatasetCollectionName": "Dataset", + "ModelCollectionName": "Model", + "FilesCollectionName": "Files" + } } -- cgit v1.2.3 From dd855dc9241274d1d7e80efd208f243810163d23 Mon Sep 17 00:00:00 2001 From: Ognjen Cirkovic Date: Wed, 16 Mar 2022 13:13:11 +0100 Subject: Promenjeno ime FileUploadController u FileController. --- backend/api/api/Controllers/FileController.cs | 83 ++++++++++++++++++++++ .../api/api/Controllers/FileUploadController.cs | 83 ---------------------- 2 files changed, 83 insertions(+), 83 deletions(-) create mode 100644 backend/api/api/Controllers/FileController.cs delete mode 100644 backend/api/api/Controllers/FileUploadController.cs diff --git a/backend/api/api/Controllers/FileController.cs b/backend/api/api/Controllers/FileController.cs new file mode 100644 index 00000000..395c8cea --- /dev/null +++ b/backend/api/api/Controllers/FileController.cs @@ -0,0 +1,83 @@ +using System.Net.Http.Headers; +using api.Models; +using api.Services; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Net.Http.Headers; +namespace api.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class FileController : ControllerBase + { + private string[] permittedExtensions = { ".csv" }; + private readonly IConfiguration _configuration; + private JwtToken _token; + private IFileService _fileservice; + public FileController(IConfiguration configuration,IFileService fileService) + { + _configuration = configuration; + _token = new JwtToken(configuration); + _fileservice = fileService; + + } + + + [HttpPost("Csv")] + [Authorize(Roles = "User")] + public async Task> CsvUpload([FromForm]IFormFile file) + { + + //get username from jwtToken + string username; + var header = Request.Headers[HeaderNames.Authorization]; + if (AuthenticationHeaderValue.TryParse(header, out var headerValue)) + { + + var scheme = headerValue.Scheme; + var parameter = headerValue.Parameter; + username = _token.TokenToUsername(parameter); + if (username == null) + return null; + }else + return BadRequest(); + + + //Check filetype + var filename=file.FileName; + var ext=Path.GetExtension(filename).ToLowerInvariant(); + var name = Path.GetFileNameWithoutExtension(filename).ToLowerInvariant(); + if (string.IsNullOrEmpty(ext) || ! permittedExtensions.Contains(ext)) { + return BadRequest("Wrong file type"); + } + var folderPath=Path.Combine(Directory.GetCurrentDirectory(),"UploadedFiles",username); + //Check Directory + if (!Directory.Exists(folderPath)) + { + Directory.CreateDirectory(folderPath); + } + //Index file if same filename + var fullPath = Path.Combine(folderPath, filename); + int i=0; + + while (System.IO.File.Exists(fullPath)) { + i++; + fullPath = Path.Combine(folderPath,name+i.ToString()+ext); + } + + + //Write file + using (var stream=new FileStream(fullPath, FileMode.Create)) + { + await file.CopyToAsync(stream); + } + FileModel fileModel= new FileModel(); + fileModel.path=fullPath; + fileModel.username=username; + fileModel=_fileservice.Create(fileModel); + + return Ok(fileModel); + } + } +} + diff --git a/backend/api/api/Controllers/FileUploadController.cs b/backend/api/api/Controllers/FileUploadController.cs deleted file mode 100644 index 3869a6fe..00000000 --- a/backend/api/api/Controllers/FileUploadController.cs +++ /dev/null @@ -1,83 +0,0 @@ -using System.Net.Http.Headers; -using api.Models; -using api.Services; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Net.Http.Headers; -namespace api.Controllers -{ - [Route("api/[controller]")] - [ApiController] - public class FileUploadController : ControllerBase - { - private string[] permittedExtensions = { ".csv" }; - private readonly IConfiguration _configuration; - private JwtToken _token; - private IFileService _fileservice; - public FileUploadController(IConfiguration configuration,IFileService fileService) - { - _configuration = configuration; - _token = new JwtToken(configuration); - _fileservice = fileService; - - } - - - [HttpPost("Csv")] - [Authorize(Roles = "User")] - public async Task> CsvUpload([FromForm]IFormFile file) - { - - //get username from jwtToken - string username; - var header = Request.Headers[HeaderNames.Authorization]; - if (AuthenticationHeaderValue.TryParse(header, out var headerValue)) - { - - var scheme = headerValue.Scheme; - var parameter = headerValue.Parameter; - username = _token.TokenToUsername(parameter); - if (username == null) - return null; - }else - return BadRequest(); - - - //Check filetype - var filename=file.FileName; - var ext=Path.GetExtension(filename).ToLowerInvariant(); - var name = Path.GetFileNameWithoutExtension(filename).ToLowerInvariant(); - if (string.IsNullOrEmpty(ext) || ! permittedExtensions.Contains(ext)) { - return BadRequest("Wrong file type"); - } - var folderPath=Path.Combine(Directory.GetCurrentDirectory(),"UploadedFiles",username); - //Check Directory - if (!Directory.Exists(folderPath)) - { - Directory.CreateDirectory(folderPath); - } - //Index file if same filename - var fullPath = Path.Combine(folderPath, filename); - int i=0; - - while (System.IO.File.Exists(fullPath)) { - i++; - fullPath = Path.Combine(folderPath,name+i.ToString()+ext); - } - - - //Write file - using (var stream=new FileStream(fullPath, FileMode.Create)) - { - await file.CopyToAsync(stream); - } - FileModel fileModel= new FileModel(); - fileModel.path=fullPath; - fileModel.username=username; - fileModel=_fileservice.Create(fileModel); - - return Ok(fileModel); - } - } -} - -- cgit v1.2.3 From 21811505a810392700de63dd132b5924a5bc08c7 Mon Sep 17 00:00:00 2001 From: Ognjen Cirkovic Date: Wed, 16 Mar 2022 13:42:32 +0100 Subject: Omoguceno preuzimanje fajlova uz autorizaciju. --- backend/api/api/Controllers/FileController.cs | 31 ++++++++++++++++++++++++++- backend/api/api/Services/FileService.cs | 7 ++++++ backend/api/api/Services/IFileService.cs | 1 + 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/backend/api/api/Controllers/FileController.cs b/backend/api/api/Controllers/FileController.cs index 395c8cea..3bfdad93 100644 --- a/backend/api/api/Controllers/FileController.cs +++ b/backend/api/api/Controllers/FileController.cs @@ -78,6 +78,35 @@ namespace api.Controllers return Ok(fileModel); } + + [HttpGet("Download")] + [Authorize(Roles = "User")] + public async Task DownloadFile(string id) + { + //Get Username + string username; + var header = Request.Headers[HeaderNames.Authorization]; + if (AuthenticationHeaderValue.TryParse(header, out var headerValue)) + { + + var scheme = headerValue.Scheme; + var parameter = headerValue.Parameter; + username = _token.TokenToUsername(parameter); + if (username == null) + return null; + } + else + return BadRequest(); + + string filePath = _fileservice.GetFilePath(id, username); + if (filePath == null) + return BadRequest(); + + return File(System.IO.File.ReadAllBytes(filePath),"application/octet-stream", Path.GetFileName(filePath)); + + } + + + } } - diff --git a/backend/api/api/Services/FileService.cs b/backend/api/api/Services/FileService.cs index 29520387..e68a0fe3 100644 --- a/backend/api/api/Services/FileService.cs +++ b/backend/api/api/Services/FileService.cs @@ -23,5 +23,12 @@ namespace api.Services return file; } + public string GetFilePath(string id, string username) + { + FileModel file = _file.Find(x => x._id == id && x.username == username).FirstOrDefault(); + if (file == null) + return null; + return file.path; + } } } diff --git a/backend/api/api/Services/IFileService.cs b/backend/api/api/Services/IFileService.cs index 14d843ca..7446e283 100644 --- a/backend/api/api/Services/IFileService.cs +++ b/backend/api/api/Services/IFileService.cs @@ -5,5 +5,6 @@ namespace api.Services public interface IFileService { FileModel Create(FileModel file); + string GetFilePath(string id, string username); } } \ No newline at end of file -- cgit v1.2.3 From cba3740a4f35d91421f5a185195bdfc087810b8a Mon Sep 17 00:00:00 2001 From: Ivan Ljubisavljevic Date: Wed, 16 Mar 2022 14:12:14 +0100 Subject: Ispravljna funkcija za brisanje dataseta i modela. Izmenjeno rutiranje za crud operacije --- backend/api/api/Controllers/DatasetController.cs | 38 ++++++++++++------------ backend/api/api/Controllers/ModelController.cs | 7 ++--- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/backend/api/api/Controllers/DatasetController.cs b/backend/api/api/Controllers/DatasetController.cs index babdbe9a..3d008744 100644 --- a/backend/api/api/Controllers/DatasetController.cs +++ b/backend/api/api/Controllers/DatasetController.cs @@ -18,27 +18,27 @@ namespace api.Controllers } - // GET: api//{id}/datasets - [HttpGet("{id}/datasets")] - public ActionResult> Get(string id) + // GET: api//{username}/datasets + [HttpGet("{username}/datasets")] + public ActionResult> Get(string username) { - return _datasetService.GetAllDatesets(id); + return _datasetService.GetAllDatesets(username); } - // GET api//{id}/{name} - [HttpGet("{id}/{name}")] - public ActionResult Get(string id, string name) + // GET api//{username}/{name} + [HttpGet("{username}/{name}")] + public ActionResult Get(string username, string name) { - var dataset = _datasetService.GetOneDataset(id, name); + var dataset = _datasetService.GetOneDataset(username, name); if (dataset == null) - return NotFound($"Dataset with name = {name} or user with id = {id} not found"); + return NotFound($"Dataset with name = {name} or user with username = {username} not found"); return dataset; } - // POST api//post - [HttpPost("post")] + // POST api//add + [HttpPost("add")] public ActionResult Post([FromBody] Dataset dataset) { var existingDataset = _datasetService.GetOneDataset(dataset.username, dataset.name); @@ -53,22 +53,22 @@ namespace api.Controllers } } - // PUT api//{id}/{name} - [HttpPut("{id}/{name}")] - public ActionResult Put(string id, string name, [FromBody] Dataset dataset) + // PUT api//{username}/{name} + [HttpPut("{username}/{name}")] + public ActionResult Put(string username, string name, [FromBody] Dataset dataset) { - var existingDataset = _datasetService.GetOneDataset(id, name); + var existingDataset = _datasetService.GetOneDataset(username, name); //ne mora da se proverava if (existingDataset == null) - return NotFound($"Dataset with name = {name} or user with id = {id} not found"); + return NotFound($"Dataset with name = {name} or user with username = {username} not found"); - _datasetService.Update(id, name, dataset); + _datasetService.Update(username, name, dataset); return NoContent(); } - // DELETE api//username - [HttpDelete("{username}")] + // DELETE api//username/name + [HttpDelete("{username}/{name}")] public ActionResult Delete(string username, string name) { var dataset = _datasetService.GetOneDataset(username, name); diff --git a/backend/api/api/Controllers/ModelController.cs b/backend/api/api/Controllers/ModelController.cs index dde44472..deb622b8 100644 --- a/backend/api/api/Controllers/ModelController.cs +++ b/backend/api/api/Controllers/ModelController.cs @@ -49,8 +49,8 @@ namespace api.Controllers return model; } - // POST api//post - [HttpPost("post")] + // POST api//add + [HttpPost("add")] public ActionResult Post([FromBody] Model model) { var existingModel = _modelService.GetOneModel(model.username, model.name); @@ -71,7 +71,6 @@ namespace api.Controllers { var existingModel = _modelService.GetOneModel(username, name); - //ne mora da se proverava if (existingModel == null) return NotFound($"Model with name = {name} or user with username = {username} not found"); @@ -80,7 +79,7 @@ namespace api.Controllers } // DELETE api//username - [HttpDelete("{username}")] + [HttpDelete("{username}/{name}")] public ActionResult Delete(string username, string name) { var model = _modelService.GetOneModel(username, name); -- cgit v1.2.3
{{col}}