41 lines
1.4 KiB
C#
41 lines
1.4 KiB
C#
using ChatApi;
|
|
using ChatRAG.Models;
|
|
using Microsoft.Extensions.Options;
|
|
using MongoDB.Driver;
|
|
|
|
namespace ChatRAG.Repositories
|
|
{
|
|
public class TextDataService
|
|
{
|
|
private readonly IMongoCollection<TextoComEmbedding> _textsCollection;
|
|
|
|
public TextDataService(
|
|
IOptions<DomvsDatabaseSettings> bookStoreDatabaseSettings)
|
|
{
|
|
var mongoClient = new MongoClient(
|
|
bookStoreDatabaseSettings.Value.ConnectionString);
|
|
|
|
var mongoDatabase = mongoClient.GetDatabase(
|
|
bookStoreDatabaseSettings.Value.DatabaseName);
|
|
|
|
_textsCollection = mongoDatabase.GetCollection<TextoComEmbedding>(
|
|
bookStoreDatabaseSettings.Value.SharepointCollectionName);
|
|
}
|
|
|
|
public async Task<List<TextoComEmbedding>> GetAsync() =>
|
|
await _textsCollection.Find(_ => true).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);
|
|
}
|
|
}
|