Basic DB service loose implementation (no DI)
This commit is contained in:
		
							
								
								
									
										13
									
								
								Interface/IDbService.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								Interface/IDbService.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,13 @@
 | 
				
			|||||||
 | 
					using TBDel.Models;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace TBDel.Interface;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public interface IDbService
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    Task<Boolean> AddFileEntryAsync(FileEntry entry);
 | 
				
			||||||
 | 
					    Task<Boolean> AddFolderEntryAsync(FolderEntry entry);
 | 
				
			||||||
 | 
					    Task<List<FileEntry>> GetFileEntriesAsync();
 | 
				
			||||||
 | 
					    Task<List<FolderEntry>> GetFolderEntriesAsync();
 | 
				
			||||||
 | 
					    Task<Boolean> RemoveFileEntryAsync(string path);
 | 
				
			||||||
 | 
					    Task<Boolean> RemoveFolderEntryAsync(string path);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										8
									
								
								Models/DbEntry.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								Models/DbEntry.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
				
			|||||||
 | 
					namespace TBDel.Models;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// The DB entry - A list of files and folders
 | 
				
			||||||
 | 
					public class DbEntry
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    public List<FileEntry> Files { get; set; } = new();
 | 
				
			||||||
 | 
					    public List<FolderEntry> Folders { get; set; } = new();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -0,0 +1,9 @@
 | 
				
			|||||||
 | 
					namespace TBDel.Models;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class FileEntry
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    // File path
 | 
				
			||||||
 | 
					    public string Path { get; set; } = string.Empty;
 | 
				
			||||||
 | 
					    // Date added
 | 
				
			||||||
 | 
					    public DateTime DateAdded { get; set; }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -0,0 +1,6 @@
 | 
				
			|||||||
 | 
					namespace TBDel.Models;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// The same as FileEntry
 | 
				
			||||||
 | 
					public class FolderEntry : FileEntry
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1 +1,3 @@
 | 
				
			|||||||
 | 
					using TBDel.Interface;
 | 
				
			||||||
 | 
					using TBDel.Services;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -0,0 +1,64 @@
 | 
				
			|||||||
 | 
					using JsonFlatFileDataStore;
 | 
				
			||||||
 | 
					using TBDel.Interface;
 | 
				
			||||||
 | 
					using TBDel.Models;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace TBDel.Services;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class DbService : IDbService
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    private readonly DataStore _store;
 | 
				
			||||||
 | 
					    /*private readonly IDataCollection<FileEntry> _fileCollection;
 | 
				
			||||||
 | 
					    private readonly IDataCollection<FolderEntry> _folderCollection;*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public DbService(string filePath) // Constructor takes the file path
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        /*_store = new DataStore(filePath);
 | 
				
			||||||
 | 
					        _fileCollection = _store.GetCollection<FileEntry>();
 | 
				
			||||||
 | 
					        _folderCollection = _store.GetCollection<FolderEntry>();*/
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public async Task<Boolean> AddFileEntryAsync(FileEntry entry)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        //await _fileCollection.InsertOneAsync(entry);
 | 
				
			||||||
 | 
					        return false; 
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public async Task<Boolean> AddFolderEntryAsync(FolderEntry entry)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        //await _folderCollection.InsertOneAsync(entry);
 | 
				
			||||||
 | 
					        return false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public async Task<List<FileEntry>> GetFileEntriesAsync()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        //return _fileCollection.AsQueryable().ToList();
 | 
				
			||||||
 | 
					        return new List<FileEntry>();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public async Task<List<FolderEntry>> GetFolderEntriesAsync()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        //return _folderCollection.AsQueryable().ToList();
 | 
				
			||||||
 | 
					        return new List<FolderEntry>();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public async Task<Boolean> RemoveFileEntryAsync(string path)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        //var entryToRemove = _fileCollection.AsQueryable().FirstOrDefault(e => e.Path == path);
 | 
				
			||||||
 | 
					        /*if (entryToRemove != null)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            await _fileCollection.DeleteOneAsync(e => e.Path == path); // or entryToRemove.Path
 | 
				
			||||||
 | 
					        }*/
 | 
				
			||||||
 | 
					        return false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public async Task<Boolean> RemoveFolderEntryAsync(string path)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        //var entryToRemove = _folderCollection.AsQueryable().FirstOrDefault(e => e.Path == path);
 | 
				
			||||||
 | 
					        /*if (entryToRemove != null)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            await _folderCollection.DeleteOneAsync(e => e.Path == path); // or entryToRemove.Path
 | 
				
			||||||
 | 
					        }*/
 | 
				
			||||||
 | 
					        return false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -7,4 +7,8 @@
 | 
				
			|||||||
    <Nullable>enable</Nullable>
 | 
					    <Nullable>enable</Nullable>
 | 
				
			||||||
  </PropertyGroup>
 | 
					  </PropertyGroup>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  <ItemGroup>
 | 
				
			||||||
 | 
					    <PackageReference Include="JsonFlatFileDataStore" Version="2.4.2" />
 | 
				
			||||||
 | 
					  </ItemGroup>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
</Project>
 | 
					</Project>
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user