aboutsummaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
Diffstat (limited to 'backend')
-rw-r--r--backend/api/api/Controllers/UserController.cs3
-rw-r--r--backend/api/api/Services/IUserService.cs2
-rw-r--r--backend/api/api/Services/UserService.cs51
3 files changed, 51 insertions, 5 deletions
diff --git a/backend/api/api/Controllers/UserController.cs b/backend/api/api/Controllers/UserController.cs
index 0287f3cb..741382b8 100644
--- a/backend/api/api/Controllers/UserController.cs
+++ b/backend/api/api/Controllers/UserController.cs
@@ -135,8 +135,7 @@ namespace api.Controllers
else
return BadRequest();
- userService.Update(username, user);
- return NoContent();
+ return Ok(userService.Update(username, user));
}
// DELETE api/<UserController>/5
diff --git a/backend/api/api/Services/IUserService.cs b/backend/api/api/Services/IUserService.cs
index 1cb6a609..e4a23213 100644
--- a/backend/api/api/Services/IUserService.cs
+++ b/backend/api/api/Services/IUserService.cs
@@ -8,7 +8,7 @@ namespace api.Services
List<User> Get();// daje sve korisnike
User GetUserUsername(string username); //daje korisnika po korisnickom imenu
User Create(User user); // kreira korisnika
- void Update(string username, User user); //apdejtuje korisnika po idu
+ bool Update(string username, User user); //apdejtuje korisnika po idu
void Delete(string username);//brise korisnika
}
}
diff --git a/backend/api/api/Services/UserService.cs b/backend/api/api/Services/UserService.cs
index f613f923..607bb04b 100644
--- a/backend/api/api/Services/UserService.cs
+++ b/backend/api/api/Services/UserService.cs
@@ -7,11 +7,22 @@ namespace api.Services
public class UserService : IUserService
{
private readonly IMongoCollection<User> _users;
+ private readonly IMongoClient _client;
+ private readonly IMongoCollection<Model> _models;
+ private readonly IMongoCollection<Dataset> _datasets;
+ private readonly IMongoCollection<FileModel> _fileModels;
+ private readonly IMongoCollection<Predictor> _predictors;
+
public UserService(IUserStoreDatabaseSettings settings, IMongoClient mongoClient)
{
var database = mongoClient.GetDatabase(settings.DatabaseName);
_users = database.GetCollection<User>(settings.CollectionName);
+ _models = database.GetCollection<Model>(settings.ModelCollectionName);
+ _datasets= database.GetCollection<Dataset>(settings.DatasetCollectionName);
+ _fileModels = database.GetCollection<FileModel>(settings.FilesCollectionName);
+ _predictors= database.GetCollection<Predictor>(settings.PredictorCollectionName);
+ _client = mongoClient;
}
public User Create(User user)
{
@@ -26,10 +37,46 @@ namespace api.Services
{
return _users.Find(user => user.Username == username).FirstOrDefault();
}
- public void Update(string username, User user)
+ public bool Update(string username, User user)
{
//username koji postoji u bazi
- _users.ReplaceOne(user => user.Username == username, user);
+ using (var session = _client.StartSession())
+ {
+
+ if(_users.Find(u => u.Username == user.Username).FirstOrDefault()!=null)
+ {
+ return false;
+ }
+
+ //Trenutan MongoDB Server ne podrzava transakcije.Omoguciti Podrsku
+ //session.StartTransaction();
+ try
+ {
+ _users.ReplaceOne(user => user.Username == username, user);
+ if (username != user.Username)
+ {
+ var builderModel = Builders<Model>.Update;
+ var builderDataset = Builders<Dataset>.Update;
+ var builderFileModel = Builders<FileModel>.Update;
+ var builderPredictor = Builders<Predictor>.Update;
+ _models.UpdateMany(x => x.username == username, builderModel.Set(x => x.username, user.Username));
+ _datasets.UpdateMany(x => x.username == username, builderDataset.Set(x => x.username, user.Username));
+ _fileModels.UpdateMany(x => x.username == username, builderFileModel.Set(x => x.username, user.Username));
+ _predictors.UpdateMany(x => x.username == username, builderPredictor.Set(x => x.username, user.Username));
+ }
+
+ //session.AbortTransaction();
+
+
+ //session.CommitTransaction();
+ }
+ catch (Exception e)
+ {
+ //session.AbortTransaction();
+ return false;
+ }
+ return true;
+ }
}
public void Delete(string username)
{