45 lines
1.6 KiB
C#
45 lines
1.6 KiB
C#
using ChatApi;
|
|
using ChatRAG.Models;
|
|
using Microsoft.Extensions.Options;
|
|
using MongoDB.Bson;
|
|
using MongoDB.Driver;
|
|
|
|
namespace ChatRAG.Data
|
|
{
|
|
public class TextDataRepository
|
|
{
|
|
private readonly IMongoCollection<TextoComEmbedding> _textsCollection;
|
|
|
|
public TextDataRepository(
|
|
IOptions<DomvsDatabaseSettings> bookStoreDatabaseSettings)
|
|
{
|
|
var mongoClient = new MongoClient(
|
|
bookStoreDatabaseSettings.Value.ConnectionString);
|
|
|
|
var mongoDatabase = mongoClient.GetDatabase(
|
|
bookStoreDatabaseSettings.Value.DatabaseName);
|
|
|
|
_textsCollection = mongoDatabase.GetCollection<TextoComEmbedding>(
|
|
bookStoreDatabaseSettings.Value.TextCollectionName);
|
|
}
|
|
|
|
public async Task<List<TextoComEmbedding>> GetAsync() =>
|
|
await _textsCollection.Find(_ => true).ToListAsync();
|
|
|
|
public async Task<List<TextoComEmbedding>> GetByProjectIdAsync(string projectId) =>
|
|
await _textsCollection.Find(s => s.ProjetoId == ObjectId.Parse(projectId).ToString()).ToListAsync();
|
|
|
|
public async Task<TextoComEmbedding?> GetAsync(string id) =>
|
|
await _textsCollection.Find(x => x.Id == id).FirstOrDefaultAsync();
|
|
|
|
public async Task CreateAsync(TextoComEmbedding newBook) =>
|
|
await _textsCollection.InsertOneAsync(newBook);
|
|
|
|
public async Task UpdateAsync(string id, TextoComEmbedding updatedBook) =>
|
|
await _textsCollection.ReplaceOneAsync(x => x.Id == id, updatedBook);
|
|
|
|
public async Task RemoveAsync(string id) =>
|
|
await _textsCollection.DeleteOneAsync(x => x.Id == id);
|
|
}
|
|
}
|