Implemented "Add" command and finished Db stuff.

This commit is contained in:
2025-01-31 21:42:43 +03:30
parent 07feac2f65
commit f0339e5c0e
8 changed files with 161 additions and 48 deletions

View File

@@ -1,64 +1,64 @@
using JsonFlatFileDataStore;
using TBDel.Interface;
using TBDel.Models;
namespace TBDel.Services;
public class DbService : IDbService
public class DbService
{
private readonly DataStore _store;
/*private readonly IDataCollection<FileEntry> _fileCollection;
private readonly IDataCollection<FolderEntry> _folderCollection;*/
private readonly IDocumentCollection<FileEntry> _fileCollection;
private readonly IDocumentCollection<FolderEntry> _folderCollection;
public DbService(string filePath) // Constructor takes the file path
public DbService()
{
/*_store = new DataStore(filePath);
string dbPath =
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "TBDel_Db.json");
var _store = new DataStore(dbPath,minifyJson:true);
_fileCollection = _store.GetCollection<FileEntry>();
_folderCollection = _store.GetCollection<FolderEntry>();*/
_folderCollection = _store.GetCollection<FolderEntry>();
}
public async Task<Boolean> AddFileEntryAsync(FileEntry entry)
{
//await _fileCollection.InsertOneAsync(entry);
return false;
return await _fileCollection.InsertOneAsync(entry);
}
public async Task<Boolean> AddFolderEntryAsync(FolderEntry entry)
{
//await _folderCollection.InsertOneAsync(entry);
return false;
return await _folderCollection.InsertOneAsync(entry);
}
public async Task<List<FileEntry>> GetFileEntriesAsync()
{
//return _fileCollection.AsQueryable().ToList();
return new List<FileEntry>();
return _fileCollection.AsQueryable().ToList();
}
public async Task<List<FolderEntry>> GetFolderEntriesAsync()
{
//return _folderCollection.AsQueryable().ToList();
return new List<FolderEntry>();
return _folderCollection.AsQueryable().ToList();
}
public async Task<Boolean> RemoveFileEntryAsync(string path)
public async Task<Boolean> RemoveFileEntryAsync(string path)
{
//var entryToRemove = _fileCollection.AsQueryable().FirstOrDefault(e => e.Path == path);
/*if (entryToRemove != null)
var entryToRemove = _fileCollection.AsQueryable().FirstOrDefault(e => e.Path == path);
if (entryToRemove != null)
{
await _fileCollection.DeleteOneAsync(e => e.Path == path); // or entryToRemove.Path
}*/
return 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)
var entryToRemove = _folderCollection.AsQueryable().FirstOrDefault(e => e.Path == path);
if (entryToRemove != null)
{
await _folderCollection.DeleteOneAsync(e => e.Path == path); // or entryToRemove.Path
}*/
return await _folderCollection.DeleteOneAsync(e => e.Path == path); // or entryToRemove.Path
}
return false;
}
}