aboutsummaryrefslogtreecommitdiff
path: root/backend/api
diff options
context:
space:
mode:
Diffstat (limited to 'backend/api')
-rw-r--r--backend/api/api/Controllers/AuthController.cs7
-rw-r--r--backend/api/api/Controllers/DatasetController.cs43
-rw-r--r--backend/api/api/Controllers/UserController.cs2
-rw-r--r--backend/api/api/Interfaces/IUserStoreDatabaseSettings.cs1
-rw-r--r--backend/api/api/Models/Dataset.cs21
-rw-r--r--backend/api/api/Services/DatasetService.cs40
-rw-r--r--backend/api/api/Services/IDatasetService.cs13
-rw-r--r--backend/api/api/Services/UserService.cs13
-rw-r--r--backend/api/api/appsettings.json5
9 files changed, 141 insertions, 4 deletions
diff --git a/backend/api/api/Controllers/AuthController.cs b/backend/api/api/Controllers/AuthController.cs
index 01354f87..e1601815 100644
--- a/backend/api/api/Controllers/AuthController.cs
+++ b/backend/api/api/Controllers/AuthController.cs
@@ -30,6 +30,13 @@ namespace api.Controllers
return Ok(_auth.Login(user));
}
+ [HttpGet("Auth")]
+ [Authorize(Roles ="User")]
+ public async Task<ActionResult<string>> TestAuth()
+ {
+ return Ok("works");
+ }
+
}
diff --git a/backend/api/api/Controllers/DatasetController.cs b/backend/api/api/Controllers/DatasetController.cs
new file mode 100644
index 00000000..e1b888a1
--- /dev/null
+++ b/backend/api/api/Controllers/DatasetController.cs
@@ -0,0 +1,43 @@
+using Microsoft.AspNetCore.Mvc;
+
+// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
+
+namespace api.Controllers
+{
+ [Route("api/[controller]")]
+ [ApiController]
+ public class DatasetController : ControllerBase
+ {
+ // GET: api/<DatasetController>
+ [HttpGet]
+ public IEnumerable<string> Get()
+ {
+ return new string[] { "value1", "value2" };
+ }
+
+ // GET api/<DatasetController>/5
+ [HttpGet("{id}")]
+ public string Get(int id)
+ {
+ return "value";
+ }
+
+ // POST api/<DatasetController>
+ [HttpPost]
+ public void Post([FromBody] string value)
+ {
+ }
+
+ // PUT api/<DatasetController>/5
+ [HttpPut("{id}")]
+ public void Put(int id, [FromBody] string value)
+ {
+ }
+
+ // DELETE api/<DatasetController>/5
+ [HttpDelete("{id}")]
+ public void Delete(int id)
+ {
+ }
+ }
+}
diff --git a/backend/api/api/Controllers/UserController.cs b/backend/api/api/Controllers/UserController.cs
index 85f8218d..caf78d9c 100644
--- a/backend/api/api/Controllers/UserController.cs
+++ b/backend/api/api/Controllers/UserController.cs
@@ -37,6 +37,7 @@ namespace api.Controllers
return user;
}
+
// GET api/<UserController>/5
//potrebno za profile page
[HttpGet("{id}")]
@@ -49,6 +50,7 @@ namespace api.Controllers
return user;
}
+
// POST api/<UserController>
[HttpPost]
public ActionResult<User> Post([FromBody] User user)
diff --git a/backend/api/api/Interfaces/IUserStoreDatabaseSettings.cs b/backend/api/api/Interfaces/IUserStoreDatabaseSettings.cs
index 43fe9b3a..8d2a175f 100644
--- a/backend/api/api/Interfaces/IUserStoreDatabaseSettings.cs
+++ b/backend/api/api/Interfaces/IUserStoreDatabaseSettings.cs
@@ -5,5 +5,6 @@
string ConnectionString { get; set; }
string DatabaseName { get; set; }
string CollectionName { get; set; }
+ string DatasetCollectionName { get; set; }
}
}
diff --git a/backend/api/api/Models/Dataset.cs b/backend/api/api/Models/Dataset.cs
new file mode 100644
index 00000000..448a6aa9
--- /dev/null
+++ b/backend/api/api/Models/Dataset.cs
@@ -0,0 +1,21 @@
+using MongoDB.Bson;
+using MongoDB.Bson.Serialization.Attributes;
+
+namespace api.Models
+{
+ 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("extension")]
+ public string extension { get; set; }
+ [BsonElement("name")]
+ public string name { get; set; }
+
+ }
+}
diff --git a/backend/api/api/Services/DatasetService.cs b/backend/api/api/Services/DatasetService.cs
new file mode 100644
index 00000000..154c9438
--- /dev/null
+++ b/backend/api/api/Services/DatasetService.cs
@@ -0,0 +1,40 @@
+using api.Interfaces;
+using api.Models;
+using MongoDB.Driver;
+
+namespace api.Services
+{
+ public class DatasetService : IDatasetService
+ {
+ private readonly IMongoCollection<Dataset> _dataset;
+
+ public DatasetService(IUserStoreDatabaseSettings settings, IMongoClient mongoClient)
+ {
+ var database = mongoClient.GetDatabase(settings.DatabaseName);
+ _dataset = database.GetCollection<Dataset>(settings.DatasetCollectionName);
+ }
+ //kreiranje dataseta
+ public Dataset Create(Dataset dataset)
+ {
+ _dataset.InsertOne(dataset);
+ return dataset;
+ }
+
+ //brisanje odredjenog name-a
+ public void Delete(string uploaderId, string name)
+ {
+ _dataset.DeleteOne(dataset => dataset.UploaderId == uploaderId && dataset.name == name); ;
+ }
+
+ public Dataset Get(string uploaderId)
+ {
+ return _dataset.Find(dataset => dataset.UploaderId == uploaderId).FirstOrDefault();
+ }
+
+ //ako je potrebno da se zameni name ili ekstenzija
+ public void Update(string uploaderId, Dataset dataset)
+ {
+ _dataset.ReplaceOne(dataset => dataset.UploaderId == uploaderId, dataset);
+ }
+ }
+}
diff --git a/backend/api/api/Services/IDatasetService.cs b/backend/api/api/Services/IDatasetService.cs
new file mode 100644
index 00000000..22633c3c
--- /dev/null
+++ b/backend/api/api/Services/IDatasetService.cs
@@ -0,0 +1,13 @@
+
+using api.Models;
+
+namespace api.Services
+{
+ public interface IDatasetService
+ {
+ Dataset Get(string uploaderId);
+ Dataset Create(Dataset dataset);
+ void Update(string uploaderId, Dataset dataset);
+ void Delete(string uploaderId, string name);
+ }
+}
diff --git a/backend/api/api/Services/UserService.cs b/backend/api/api/Services/UserService.cs
index e1d1e8b7..c626889d 100644
--- a/backend/api/api/Services/UserService.cs
+++ b/backend/api/api/Services/UserService.cs
@@ -23,6 +23,7 @@ namespace api.Services
{
return _users.Find(user => true).ToList();
}
+
public User GetUserUsername(string username)
{
return _users.Find(user => user.Username == username).FirstOrDefault();
@@ -53,4 +54,14 @@ namespace api.Services
"firstName" : "Ivan",
"lastName" : "Ljubisavljevic"
}
- */ \ No newline at end of file
+
+{
+ "_id": {
+ "$oid": "62291140d88e6bcf95c96a58"
+ },
+ "uploaderId":"",
+ "extension" : "",
+ "name" : ""
+}
+
+*/
diff --git a/backend/api/api/appsettings.json b/backend/api/api/appsettings.json
index 204eba33..3661f171 100644
--- a/backend/api/api/appsettings.json
+++ b/backend/api/api/appsettings.json
@@ -14,11 +14,10 @@
"ConnectionString": "mongodb://127.0.0.1:27017/",
"DatabaseName": "si_project",
"CollectionName": "User"
-
*/
"ConnectionString": "mongodb+srv://si_user:si_user@sidatabase.twtfm.mongodb.net/myFirstDatabase?retryWrites=true&w=majority",
"DatabaseName": "si_db",
- "CollectionName": "users"
-
+ "CollectionName": "users",
+ "DatasetCollectionName" : "Dataset"
}
}