63 lines
1.9 KiB
C#
63 lines
1.9 KiB
C#
using Microsoft.Extensions.Options;
|
|
using MongoDB.Bson;
|
|
using MongoDB.Driver;
|
|
using SharpCompress.Common;
|
|
using UGQDatabase.Models;
|
|
using UGQDataAccess.Settings;
|
|
using ServerCommon.UGQ;
|
|
|
|
namespace UGQDataAccess.Repository;
|
|
|
|
|
|
public class QuestDialogRepository : BaseRepository<QuestDialogEntity>
|
|
{
|
|
private const string CollectionName = "QuestDialog";
|
|
|
|
public QuestDialogRepository(IMongoClient mongoClient, IOptions<UGQDatabaseSettings> settings) :
|
|
base(mongoClient, settings.Value.DatabaseName, CollectionName)
|
|
{
|
|
}
|
|
|
|
public async Task<(ServerErrorCode, QuestDialogEntity)> add(QuestDialogEntity entity)
|
|
{
|
|
await Collection.InsertOneAsync(entity);
|
|
return (ServerErrorCode.Success, entity);
|
|
}
|
|
|
|
public async Task<QuestDialogEntity?> get(string id)
|
|
{
|
|
var filter = Builders<QuestDialogEntity>.Filter
|
|
.Eq(x => x.Id, id);
|
|
|
|
var entity = await Collection.Find(filter).FirstOrDefaultAsync();
|
|
return entity;
|
|
}
|
|
|
|
public async Task<List<QuestDialogEntity>> get(IEnumerable<string> ids)
|
|
{
|
|
var filter = Builders<QuestDialogEntity>.Filter
|
|
.In(x => x.Id, ids);
|
|
|
|
return await Collection.Find(filter).ToListAsync();
|
|
}
|
|
|
|
public async Task<(ServerErrorCode, QuestDialogEntity?)> updateSequences(string dialogId, List<DialogSequenceEntity> sequences)
|
|
{
|
|
var filter = Builders<QuestDialogEntity>.Filter
|
|
.Eq(x => x.Id, dialogId);
|
|
|
|
var update = Builders<QuestDialogEntity>.Update
|
|
.Set(x => x.Sequences, sequences)
|
|
.Set(x => x.UpdatedAt, DateTime.UtcNow);
|
|
|
|
var options = new FindOneAndUpdateOptions<QuestDialogEntity>
|
|
{
|
|
ReturnDocument = ReturnDocument.After,
|
|
};
|
|
|
|
var updated = await Collection.FindOneAndUpdateAsync(filter, update, options);
|
|
return (ServerErrorCode.Success, updated);
|
|
}
|
|
}
|
|
|