From bfc6000083eac78e411ba39b02b8859101f23706 Mon Sep 17 00:00:00 2001 From: Ognjen Cirkovic Date: Sat, 19 Mar 2022 16:15:47 +0100 Subject: Omoguceno brisanje temp fajlova. --- backend/api/api/.gitignore | 1 + backend/api/api/Controllers/FileController.cs | 51 ++++++++++++++++++++++++++- backend/api/api/Models/FileModel.cs | 2 ++ backend/api/api/Program.cs | 2 ++ backend/api/api/Services/FileService.cs | 18 ++++++++++ backend/api/api/Services/IFileService.cs | 2 ++ backend/api/api/Services/TempFileService.cs | 33 +++++++++++++++++ backend/api/api/api.csproj | 2 +- 8 files changed, 109 insertions(+), 2 deletions(-) create mode 100644 backend/api/api/Services/TempFileService.cs (limited to 'backend') diff --git a/backend/api/api/.gitignore b/backend/api/api/.gitignore index 242abea5..9a89b63c 100644 --- a/backend/api/api/.gitignore +++ b/backend/api/api/.gitignore @@ -5,6 +5,7 @@ ##Ignore contents for UploadedFiles Folder UploadedFiles/* +TempFiles/* # User-specific files *.rsuser diff --git a/backend/api/api/Controllers/FileController.cs b/backend/api/api/Controllers/FileController.cs index 3bfdad93..fb3df61a 100644 --- a/backend/api/api/Controllers/FileController.cs +++ b/backend/api/api/Controllers/FileController.cs @@ -74,7 +74,9 @@ namespace api.Controllers FileModel fileModel= new FileModel(); fileModel.path=fullPath; fileModel.username=username; - fileModel=_fileservice.Create(fileModel); + fileModel.date = DateTime.Now.ToUniversalTime(); + fileModel =_fileservice.Create(fileModel); + return Ok(fileModel); } @@ -107,6 +109,53 @@ namespace api.Controllers } + [HttpPost("TempUpload")] + public async Task> TempUpload([FromForm] IFormFile file) + { + + //get username from jwtToken + string username = ""; + //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(), "TempFiles"); + //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.date = DateTime.Now.ToUniversalTime(); + fileModel = _fileservice.Create(fileModel); + + + return Ok(fileModel); + } + + } } diff --git a/backend/api/api/Models/FileModel.cs b/backend/api/api/Models/FileModel.cs index 9e7c8b5d..30211372 100644 --- a/backend/api/api/Models/FileModel.cs +++ b/backend/api/api/Models/FileModel.cs @@ -10,5 +10,7 @@ namespace api.Models public string _id { get; set; } public string username { get; set; } public string path { get; set; } + [BsonDateTimeOptions(Kind = DateTimeKind.Utc)] + public DateTime date { get; set; } } } diff --git a/backend/api/api/Program.cs b/backend/api/api/Program.cs index 65399bdf..c8cf0784 100644 --- a/backend/api/api/Program.cs +++ b/backend/api/api/Program.cs @@ -34,6 +34,8 @@ builder.Services.AddScoped(); builder.Services.AddScoped(); +builder.Services.AddHostedService(); + //Add Authentication builder.Services.AddAuthentication( JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options => { diff --git a/backend/api/api/Services/FileService.cs b/backend/api/api/Services/FileService.cs index e68a0fe3..7b101af5 100644 --- a/backend/api/api/Services/FileService.cs +++ b/backend/api/api/Services/FileService.cs @@ -30,5 +30,23 @@ namespace api.Services return null; return file.path; } + public void Delete(string id) + { + _file.DeleteOne(file => file._id == id); + + } + public void DeleteTempFiles() + { + List files = _file.Find(file => file.username == "").ToList(); + foreach (var file in files) + { + if ((DateTime.Now.ToUniversalTime() - file.date).TotalMinutes >= 2) + { + Delete(file._id); + if (File.Exists(file.path)) + File.Delete(file.path); + } + } + } } } diff --git a/backend/api/api/Services/IFileService.cs b/backend/api/api/Services/IFileService.cs index 7446e283..66bfc93d 100644 --- a/backend/api/api/Services/IFileService.cs +++ b/backend/api/api/Services/IFileService.cs @@ -5,6 +5,8 @@ namespace api.Services public interface IFileService { FileModel Create(FileModel file); + void Delete(string id); + void DeleteTempFiles(); string GetFilePath(string id, string username); } } \ No newline at end of file diff --git a/backend/api/api/Services/TempFileService.cs b/backend/api/api/Services/TempFileService.cs new file mode 100644 index 00000000..300c81ee --- /dev/null +++ b/backend/api/api/Services/TempFileService.cs @@ -0,0 +1,33 @@ +using api.Interfaces; +using MongoDB.Driver; + +namespace api.Services +{ + public class TempFileService : IHostedService + { + private readonly FileService _fileService; + private Timer _timer; + + public TempFileService(IUserStoreDatabaseSettings settings, IMongoClient mongoClient) + { + _fileService = new FileService(settings,mongoClient); + } + public Task StartAsync(CancellationToken cancellationToken) + { + _timer = new Timer(RemoveTempFiles,null,TimeSpan.Zero,TimeSpan.FromMinutes(1)); + + + return Task.CompletedTask; + } + + public Task StopAsync(CancellationToken cancellationToken) + { + _timer?.Change(Timeout.Infinite, 0); + return Task.CompletedTask; + } + private void RemoveTempFiles(object state) + { + _fileService.DeleteTempFiles(); + } + } +} diff --git a/backend/api/api/api.csproj b/backend/api/api/api.csproj index f63407ca..658f7c05 100644 --- a/backend/api/api/api.csproj +++ b/backend/api/api/api.csproj @@ -21,8 +21,8 @@ + - -- cgit v1.2.3 From bccd19ea14c8e94a5e075b4018d71231d9a338d5 Mon Sep 17 00:00:00 2001 From: Ognjen Cirkovic Date: Sat, 19 Mar 2022 16:17:03 +0100 Subject: Dodato da brise fajlove starije od 1 dana. I vrsi proveru svaka 3 sata. --- backend/api/api/Services/FileService.cs | 2 +- backend/api/api/Services/TempFileService.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'backend') diff --git a/backend/api/api/Services/FileService.cs b/backend/api/api/Services/FileService.cs index 7b101af5..2467616e 100644 --- a/backend/api/api/Services/FileService.cs +++ b/backend/api/api/Services/FileService.cs @@ -40,7 +40,7 @@ namespace api.Services List files = _file.Find(file => file.username == "").ToList(); foreach (var file in files) { - if ((DateTime.Now.ToUniversalTime() - file.date).TotalMinutes >= 2) + if ((DateTime.Now.ToUniversalTime() - file.date).TotalDays >= 1) { Delete(file._id); if (File.Exists(file.path)) diff --git a/backend/api/api/Services/TempFileService.cs b/backend/api/api/Services/TempFileService.cs index 300c81ee..297f5ef4 100644 --- a/backend/api/api/Services/TempFileService.cs +++ b/backend/api/api/Services/TempFileService.cs @@ -14,7 +14,7 @@ namespace api.Services } public Task StartAsync(CancellationToken cancellationToken) { - _timer = new Timer(RemoveTempFiles,null,TimeSpan.Zero,TimeSpan.FromMinutes(1)); + _timer = new Timer(RemoveTempFiles,null,TimeSpan.Zero,TimeSpan.FromHours(3)); return Task.CompletedTask; -- cgit v1.2.3 From 3f4b29011e2f525bd8c2bd81a1dd5f8f741d1de3 Mon Sep 17 00:00:00 2001 From: Ognjen Cirkovic Date: Sun, 20 Mar 2022 12:29:30 +0100 Subject: Omoguceno preuzimanje temp fajla. --- backend/api/api/Controllers/FileController.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'backend') diff --git a/backend/api/api/Controllers/FileController.cs b/backend/api/api/Controllers/FileController.cs index fb3df61a..8c47dc4f 100644 --- a/backend/api/api/Controllers/FileController.cs +++ b/backend/api/api/Controllers/FileController.cs @@ -155,6 +155,17 @@ namespace api.Controllers return Ok(fileModel); } + [HttpGet("DownloadTemp")] + public async Task DownloadTemp(string id) + { + string filePath = _fileservice.GetFilePath(id,""); + if (filePath == null) + return BadRequest(); + + return File(System.IO.File.ReadAllBytes(filePath), "application/octet-stream", Path.GetFileName(filePath)); + + } + } -- cgit v1.2.3 From 72564a9d2d6b9c7f4be8e786fadd40ce9248c7c1 Mon Sep 17 00:00:00 2001 From: Ognjen Cirkovic Date: Mon, 21 Mar 2022 17:30:57 +0100 Subject: Omoguceno preuzimaje guest Tokena. --- backend/api/api/Controllers/AuthController.cs | 6 ++++++ backend/api/api/Models/JwtToken.cs | 16 ++++++++++++++++ backend/api/api/Services/AuthService.cs | 5 +++++ backend/api/api/Services/IAuthService.cs | 1 + 4 files changed, 28 insertions(+) (limited to 'backend') diff --git a/backend/api/api/Controllers/AuthController.cs b/backend/api/api/Controllers/AuthController.cs index 7167d1bf..901454e1 100644 --- a/backend/api/api/Controllers/AuthController.cs +++ b/backend/api/api/Controllers/AuthController.cs @@ -30,6 +30,12 @@ namespace api.Controllers return Ok(_auth.Login(user)); } + [HttpPost("guestToken")] + public async Task> guestToken() + { + + return Ok(_auth.GuestToken()); + } [HttpGet("Auth")] [Authorize(Roles ="User")] diff --git a/backend/api/api/Models/JwtToken.cs b/backend/api/api/Models/JwtToken.cs index a98d1967..f262fd23 100644 --- a/backend/api/api/Models/JwtToken.cs +++ b/backend/api/api/Models/JwtToken.cs @@ -69,6 +69,22 @@ namespace api.Models } + public string GenGuestToken() + { + var tokenHandler = new JwtSecurityTokenHandler(); + var key = Encoding.ASCII.GetBytes(_configuration.GetSection("AppSettings:JwtToken").Value); + var tokenDescriptor = new SecurityTokenDescriptor + { + Subject = new ClaimsIdentity(new[] { new Claim("name",""), + new Claim("role", "Guest")}), + Expires = DateTime.UtcNow.AddMinutes(20), + SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature) + }; + var token = tokenHandler.CreateToken(tokenDescriptor); + return tokenHandler.WriteToken(token); + + } + } diff --git a/backend/api/api/Services/AuthService.cs b/backend/api/api/Services/AuthService.cs index 4f838463..8ef96e2e 100644 --- a/backend/api/api/Services/AuthService.cs +++ b/backend/api/api/Services/AuthService.cs @@ -57,6 +57,11 @@ namespace api.Services return null; } + public string GuestToken() + { + return _jwt.GenGuestToken(); + } + } } diff --git a/backend/api/api/Services/IAuthService.cs b/backend/api/api/Services/IAuthService.cs index 591d122d..9a109208 100644 --- a/backend/api/api/Services/IAuthService.cs +++ b/backend/api/api/Services/IAuthService.cs @@ -7,5 +7,6 @@ namespace api.Services string Login(AuthRequest user); string Register(RegisterRequest user); string RenewToken(string token); + public string GuestToken(); } } \ No newline at end of file -- cgit v1.2.3 From 69e90d3ca764612302e87e80b401055bc4cf139a Mon Sep 17 00:00:00 2001 From: Ognjen Cirkovic Date: Mon, 21 Mar 2022 17:40:27 +0100 Subject: Omoguceno da User i Guest koriste isti API za upload i download fajla. --- backend/api/api/Controllers/FileController.cs | 75 +++++---------------------- 1 file changed, 12 insertions(+), 63 deletions(-) (limited to 'backend') diff --git a/backend/api/api/Controllers/FileController.cs b/backend/api/api/Controllers/FileController.cs index 8c47dc4f..a6bab373 100644 --- a/backend/api/api/Controllers/FileController.cs +++ b/backend/api/api/Controllers/FileController.cs @@ -24,12 +24,13 @@ namespace api.Controllers [HttpPost("Csv")] - [Authorize(Roles = "User")] + [Authorize(Roles = "User,Guest")] public async Task> CsvUpload([FromForm]IFormFile file) { //get username from jwtToken string username; + string folderName; var header = Request.Headers[HeaderNames.Authorization]; if (AuthenticationHeaderValue.TryParse(header, out var headerValue)) { @@ -41,6 +42,14 @@ namespace api.Controllers return null; }else return BadRequest(); + if (username == "") + { + folderName = "TempFiles"; + } + else + { + folderName = "UploadedFiles"; + } //Check filetype @@ -50,7 +59,7 @@ namespace api.Controllers if (string.IsNullOrEmpty(ext) || ! permittedExtensions.Contains(ext)) { return BadRequest("Wrong file type"); } - var folderPath=Path.Combine(Directory.GetCurrentDirectory(),"UploadedFiles",username); + var folderPath=Path.Combine(Directory.GetCurrentDirectory(),folderName, username); //Check Directory if (!Directory.Exists(folderPath)) { @@ -82,7 +91,7 @@ namespace api.Controllers } [HttpGet("Download")] - [Authorize(Roles = "User")] + [Authorize(Roles = "User,Guest")] public async Task DownloadFile(string id) { //Get Username @@ -108,65 +117,5 @@ namespace api.Controllers } - - [HttpPost("TempUpload")] - public async Task> TempUpload([FromForm] IFormFile file) - { - - //get username from jwtToken - string username = ""; - //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(), "TempFiles"); - //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.date = DateTime.Now.ToUniversalTime(); - fileModel = _fileservice.Create(fileModel); - - - return Ok(fileModel); - } - - [HttpGet("DownloadTemp")] - public async Task DownloadTemp(string id) - { - string filePath = _fileservice.GetFilePath(id,""); - if (filePath == null) - return BadRequest(); - - return File(System.IO.File.ReadAllBytes(filePath), "application/octet-stream", Path.GetFileName(filePath)); - - } - - - } } -- cgit v1.2.3 From eb99a65bf8fe1679066d223fe7ff514aee9c6244 Mon Sep 17 00:00:00 2001 From: Ognjen Cirkovic Date: Mon, 21 Mar 2022 18:00:40 +0100 Subject: Omoguceno dodavanje dataseta i modela guestu. --- backend/api/api/Controllers/DatasetController.cs | 3 ++- backend/api/api/Controllers/ModelController.cs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'backend') diff --git a/backend/api/api/Controllers/DatasetController.cs b/backend/api/api/Controllers/DatasetController.cs index c0ba0039..f08e55f8 100644 --- a/backend/api/api/Controllers/DatasetController.cs +++ b/backend/api/api/Controllers/DatasetController.cs @@ -96,11 +96,12 @@ namespace api.Controllers // POST api//add [HttpPost("add")] - [Authorize(Roles = "User")] + [Authorize(Roles = "User,Guest")] public ActionResult Post([FromBody] Dataset dataset) { //da li ce preko tokena da se ubaci username ili front salje //dataset.username = usernameToken; + //username = "" ako je GUEST DODAO var existingDataset = _datasetService.GetOneDataset(dataset.username, dataset.name); if (existingDataset != null) diff --git a/backend/api/api/Controllers/ModelController.cs b/backend/api/api/Controllers/ModelController.cs index 1d03d924..77bf1ef3 100644 --- a/backend/api/api/Controllers/ModelController.cs +++ b/backend/api/api/Controllers/ModelController.cs @@ -83,9 +83,10 @@ namespace api.Controllers // POST api//add [HttpPost("add")] - [Authorize(Roles = "User")] + [Authorize(Roles = "User,Guest")] public ActionResult Post([FromBody] Model model) { + //username="" ako je GUEST var existingModel = _modelService.GetOneModel(model.username, model.name); if (existingModel != null) -- cgit v1.2.3 From cb1dafcef1dcf491788e115e3f63665e80ca2071 Mon Sep 17 00:00:00 2001 From: Ognjen Cirkovic Date: Mon, 21 Mar 2022 18:43:27 +0100 Subject: Omoguceno brisanje i temp modela i dataseta. --- backend/api/api/Services/FileService.cs | 19 +------- backend/api/api/Services/IFileService.cs | 2 - backend/api/api/Services/TempFileService.cs | 8 ++-- backend/api/api/Services/TempRemovalService.cs | 62 ++++++++++++++++++++++++++ 4 files changed, 67 insertions(+), 24 deletions(-) create mode 100644 backend/api/api/Services/TempRemovalService.cs (limited to 'backend') diff --git a/backend/api/api/Services/FileService.cs b/backend/api/api/Services/FileService.cs index 2467616e..b02d0da4 100644 --- a/backend/api/api/Services/FileService.cs +++ b/backend/api/api/Services/FileService.cs @@ -30,23 +30,6 @@ namespace api.Services return null; return file.path; } - public void Delete(string id) - { - _file.DeleteOne(file => file._id == id); - - } - public void DeleteTempFiles() - { - List files = _file.Find(file => file.username == "").ToList(); - foreach (var file in files) - { - if ((DateTime.Now.ToUniversalTime() - file.date).TotalDays >= 1) - { - Delete(file._id); - if (File.Exists(file.path)) - File.Delete(file.path); - } - } - } + } } diff --git a/backend/api/api/Services/IFileService.cs b/backend/api/api/Services/IFileService.cs index 66bfc93d..7446e283 100644 --- a/backend/api/api/Services/IFileService.cs +++ b/backend/api/api/Services/IFileService.cs @@ -5,8 +5,6 @@ namespace api.Services public interface IFileService { FileModel Create(FileModel file); - void Delete(string id); - void DeleteTempFiles(); string GetFilePath(string id, string username); } } \ No newline at end of file diff --git a/backend/api/api/Services/TempFileService.cs b/backend/api/api/Services/TempFileService.cs index 297f5ef4..adfe8c75 100644 --- a/backend/api/api/Services/TempFileService.cs +++ b/backend/api/api/Services/TempFileService.cs @@ -5,16 +5,16 @@ namespace api.Services { public class TempFileService : IHostedService { - private readonly FileService _fileService; + private readonly TempRemovalService _removalService; private Timer _timer; public TempFileService(IUserStoreDatabaseSettings settings, IMongoClient mongoClient) { - _fileService = new FileService(settings,mongoClient); + _removalService = new TempRemovalService(settings, mongoClient); } public Task StartAsync(CancellationToken cancellationToken) { - _timer = new Timer(RemoveTempFiles,null,TimeSpan.Zero,TimeSpan.FromHours(3)); + _timer = new Timer(RemoveTempFiles,null,TimeSpan.Zero,TimeSpan.FromHours(6)); return Task.CompletedTask; @@ -27,7 +27,7 @@ namespace api.Services } private void RemoveTempFiles(object state) { - _fileService.DeleteTempFiles(); + _removalService.DeleteTemps(); } } } diff --git a/backend/api/api/Services/TempRemovalService.cs b/backend/api/api/Services/TempRemovalService.cs new file mode 100644 index 00000000..6e99945b --- /dev/null +++ b/backend/api/api/Services/TempRemovalService.cs @@ -0,0 +1,62 @@ +using api.Interfaces; +using api.Models; +using MongoDB.Driver; + +namespace api.Services +{ + public class TempRemovalService + { + private readonly IMongoCollection _file; + private readonly IMongoCollection _model; + private readonly IMongoCollection _dataset; + + public TempRemovalService(IUserStoreDatabaseSettings settings, IMongoClient mongoClient) + { + var database = mongoClient.GetDatabase(settings.DatabaseName); + _file = database.GetCollection(settings.FilesCollectionName); + _model= database.GetCollection(settings.ModelCollectionName); + _dataset = database.GetCollection(settings.DatasetCollectionName); + } + public void DeleteTemps() + { + List files = _file.Find(file => file.username == "").ToList(); + foreach (var file in files) + { + if ((DateTime.Now.ToUniversalTime() - file.date).TotalDays >= 1) + { + DeleteFile(file._id); + List datasets = _dataset.Find(dataset => dataset.fileId == file._id).ToList(); + foreach(var dataset in datasets) + { + DeleteDataset(dataset._id); + List models = _model.Find(model => model.datasetId == dataset._id).ToList(); + foreach(var model in models) + { + DeleteModel(model._id); + } + } + if (File.Exists(file.path)) + File.Delete(file.path); + } + } + } + + + + + public void DeleteFile(string id) + { + _file.DeleteOne(file => file._id == id); + } + public void DeleteModel(string id) + { + _model.DeleteOne(model=>model._id==id); + } + public void DeleteDataset(string id) + { + _dataset.DeleteOne(dataset => dataset._id == id); + } + + + } +} -- cgit v1.2.3 From b4f0cd025a86c68a5c35a58e62c22b7cedf3d8b5 Mon Sep 17 00:00:00 2001 From: Ognjen Cirkovic Date: Mon, 21 Mar 2022 19:17:44 +0100 Subject: Omoguceno brisanje modela ukoliko gost koristi public dataset. --- backend/api/api/Services/TempRemovalService.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'backend') diff --git a/backend/api/api/Services/TempRemovalService.cs b/backend/api/api/Services/TempRemovalService.cs index 6e99945b..f96f1273 100644 --- a/backend/api/api/Services/TempRemovalService.cs +++ b/backend/api/api/Services/TempRemovalService.cs @@ -25,11 +25,11 @@ namespace api.Services if ((DateTime.Now.ToUniversalTime() - file.date).TotalDays >= 1) { DeleteFile(file._id); - List datasets = _dataset.Find(dataset => dataset.fileId == file._id).ToList(); + List datasets = _dataset.Find(dataset => dataset.fileId == file._id && dataset.username=="").ToList(); foreach(var dataset in datasets) { DeleteDataset(dataset._id); - List models = _model.Find(model => model.datasetId == dataset._id).ToList(); + List models = _model.Find(model => model.datasetId == dataset._id && model.username=="").ToList(); foreach(var model in models) { DeleteModel(model._id); @@ -39,6 +39,18 @@ namespace api.Services File.Delete(file.path); } } + //Brisanje modela ukoliko gost koristi vec postojeci dataset + List models1= _model.Find(model =>model.username == "").ToList(); + foreach(var model in models1) + { + DateTime modelDate = DateTime.Parse(model.dateCreated); + if ((DateTime.Now.ToUniversalTime() - modelDate.ToUniversalTime()).TotalDays >= 1) + { + DeleteModel(model._id); + } + } + + } -- cgit v1.2.3 From dae1245ec41724a15386bfb065d6600ee728191c Mon Sep 17 00:00:00 2001 From: Ognjen Cirkovic Date: Tue, 22 Mar 2022 16:14:47 +0100 Subject: model.dateCreated je DateTime. Metoda uskladjena da radi sa DateTime. --- backend/api/api/Services/TempRemovalService.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'backend') diff --git a/backend/api/api/Services/TempRemovalService.cs b/backend/api/api/Services/TempRemovalService.cs index f96f1273..342304f0 100644 --- a/backend/api/api/Services/TempRemovalService.cs +++ b/backend/api/api/Services/TempRemovalService.cs @@ -43,8 +43,7 @@ namespace api.Services List models1= _model.Find(model =>model.username == "").ToList(); foreach(var model in models1) { - DateTime modelDate = DateTime.Parse(model.dateCreated); - if ((DateTime.Now.ToUniversalTime() - modelDate.ToUniversalTime()).TotalDays >= 1) + if ((DateTime.Now.ToUniversalTime() - model.dateCreated.ToUniversalTime()).TotalDays >= 1) { DeleteModel(model._id); } -- cgit v1.2.3