aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--backend/api/api/Controllers/FileUploadController.cs11
-rw-r--r--backend/api/api/Data/UserStoreDatabaseSettings.cs1
-rw-r--r--backend/api/api/Interfaces/IUserStoreDatabaseSettings.cs1
-rw-r--r--backend/api/api/Models/FileModel.cs14
-rw-r--r--backend/api/api/Program.cs1
-rw-r--r--backend/api/api/Services/FileService.cs27
-rw-r--r--backend/api/api/Services/IFileService.cs9
-rw-r--r--backend/api/api/appsettings.json17
8 files changed, 71 insertions, 10 deletions
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<IUserService, UserService>();
builder.Services.AddScoped<IAuthService, AuthService>();
builder.Services.AddScoped<IMlConnectionService, MlConnectionService>();
builder.Services.AddScoped<IModelService, ModelService>();
+builder.Services.AddScoped<IFileService, FileService>();
//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<FileModel> _file;
+
+ public FileService(IUserStoreDatabaseSettings settings, IMongoClient mongoClient)
+ {
+ var database = mongoClient.GetDatabase(settings.DatabaseName);
+ _file = database.GetCollection<FileModel>(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"
+ }
}